Category:Guish: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 126:
A button which is a factory of buttons (run this with '''-z''' option).
Here the evaluation of the code block is done when the click signal is triggered.
Line 163 ⟶ 160:
<pre> a = 'my string'; puts "this is: @{a}"</pre>
Anything embedded inside '''{}''' is treated as a code block and no variable substitution is done at definition time
<pre> a = 1234; fn = {puts("here", %a)}; fn()</pre>
To "execute" a block, simply use parens '''()'''. If arguments are given, they can be referenced inside block by using '''@n''', where "n" is a number which represents a specific argument by position. To refer to all arguments given to the block as a "list" instead, it's possible to use '''@*''' operator (when in string interpolation, argument separator is a space).
Line 653 ⟶ 651:
With the '''=''' operator (actually, it's a special statement command), it's possible to assign a value to a variable, reusing it later by simply referencing it using '''@''' operator when not inside quotes or by wrapping it inside '''@{}''' when in double quotes or shell command substitution quotes '''``'''.
In addition, with the special operator '''%''', it is possible to substitute a variable into a code block at definition time; in this case if the variable is not defined, the "%var" will remain inside the block, instead of being removed as in plain variable subsitution with '''@''' operator.
There are two methods to define/create empty variables: by explicitely assing an empty string to a variable (ex. a = "") or by simply omit the value (ex. a =).
Line 680:
<pre> a = [a, b]; for x @a { puts @x }</pre>
Beware that this works just for assignment and '''
== Element substitution ==
Line 767:
; '''read([<file>])'''
: reads and returns a line (
; '''write(<text>, <file>)'''
: writes text into file and returns the number of characters written. Creates the file if it doesn't exist yet.
Line 779:
: returns the value of the environment variable "var"
; '''rev(...)'''
: returns a reversed list of
; '''
: sets variables, works exactly like assignment with special operator '''=''', but in expressions. This function is somewhat special, it'll return nothing (statement behaviour)
; '''list(...)'''
: returns all given arguments; if a block is found, then it is flatted.
; '''block(...)'''
: returns a code block, embedding the given arguments into '''{}'''.
; '''some(...)'''
: returns given arguments. If nothing is given, returns an empty string.
; '''puts(...)'''
: prints given
; '''push(...)'''
: pushes given
; '''pushb(...)'''
: pushes given
; '''pop()'''
: pops the last
; '''popb()'''
: pops the first
; '''
: returns
; '''head(...)'''
: returns the first
; '''tail(...)'''
: returns all
; '''times(<n>, <
: returns a "list" made by &
; '''
: returns the value of the variable with name "name", or an empty token if the variable doesn't exist.
; '''in(<substr>, <token>)'''
: returns 1 if substr is found in token, otherwise 0.
; '''join(<sep>, ...)'''
: returns a single token from a variable number of tokens, joining them using &
; '''range(<start>, <end>)'''
: returns numbers starting at "start" and ending at "end" (inclusive) as multiple tokens.
; '''
: returns 1 if "name" is a variable, otherwise 0.
; '''isvar(<name>)'''
Line 827 ⟶ 829:
: returns 1 if all arguments are equal (string comparison), 0 otherwise.
; '''count(...)'''
: returns the number of given
; '''any(...)'''
: returns 1 if at least one token is not empty and not equal to 0, 0 otherwise. This function is special, as the evaluation will be interrupted as soon as there is at least 1 true argument.
|