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).
 
In addition, being a the last argument a code block, it's possible to pass arguments to it (like functions), by putting them inside brackets '''[]''' (note that this works just for signals):
 
<pre> |b|&lt;generator =&gt;c{|b|&lt;&quot;clone: @{1}&quot;}[&quot;myname&quot;]</pre>
Here the evaluation of the code block is done when the click signal is triggered.
 
Line 163 ⟶ 160:
 
<pre> a = 'my string'; puts &quot;this is: @{a}&quot;</pre>
Anything embedded inside '''{}''' is treated as a code block and no variable substitution is done at definition time. except when using the special operator '''%''':
 
<pre> a = 1234; fn = {puts(&quot;here&quot;, %a)}; fn()</pre>
To &quot;execute&quot; a block, simply use parens '''()'''. If arguments are given, they can be referenced inside block by using '''@n''', where &quot;n&quot; is a number which represents a specific argument by position. To refer to all arguments given to the block as a &quot;list&quot; 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 &quot;%var&quot; 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 = &quot;&quot;) 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 '''deflet''' function '''[]'''.
 
== Element substitution ==
Line 767:
 
; '''read([&lt;file&gt;])'''
: reads and returns a line (expludingexcluding newline) from standard input; if an existing [file] is given, reads and returns all its content. Beware that this function blocks the GUI events, and returns nothing when reading from stdin and source is non-blocking.
; '''write(&lt;text&gt;, &lt;file&gt;)'''
: 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 &quot;var&quot;
; '''rev(...)'''
: returns a reversed list of tokensarguments. This function is somewhat special, as when there are no tokensarguments to get, it'll return nothing (statement behaviour), neither an empty token.
; '''deflet([&lt;var&gt;, &lt;val&gt;], ...)'''
: sets variables, works exactly like assignment with special operator '''=''', but in expressions. This function is somewhat special, it'll return nothing (statement behaviour), neither an empty token.
; '''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 tokensarguments to stdout. This function is somewhat special, it'll return nothing (statement behaviour), neither an empty token.
; '''push(...)'''
: pushes given tokensarguments to acurrent function arguments (when inside a function). This function is somewhat special, it'll return nothing (statement behaviour), neither an empty token.
; '''pushb(...)'''
: pushes given tokensarguments to acurrent function arguments from the beginning (when inside a function). This function is somewhat special, it'll return nothing (statement behaviour), neither an empty token.
; '''pop()'''
: pops the last tokenargument from function arguments (when inside a function). This function is somewhat special, as if there are no arguments to pop, it'll return nothing (statement behaviour), neither an empty token.
; '''popb()'''
: pops the first tokenargument from function arguments (when inside a function). This function is somewhat special, as if there are no arguments to pop, it'll return nothing (statement behaviour), neither an empty token.
; '''takeslice(&lt;si&gt;, &lt;ei&gt;, ...)'''
: returns tokensarguments starting at &quot;si&quot; and ending at &quot;ei&quot; (inclusive). This function is somewhat special, as when there areis no tokensnothing to get, it'll return nothing (statement behaviour), neither an empty token.
; '''head(...)'''
: returns the first tokenargument given. This function is somewhat special, as when there are no tokens to get, it'll return nothing (statement behaviour), neither an empty token.
; '''tail(...)'''
: returns all tokensarguments except the first one. This function is somewhat special, as when there areis one or no tokensnothing to get, it'll return nothing (statement behaviour), neither an empty token.
; '''times(&lt;n&gt;, &lt;tokenarg&gt;)'''
: returns a &quot;list&quot; made by &quotlt;n&quotgt; times &quotlt;tokenarg&quotgt;. This function is somewhat special, as when there are 0 tokens to replicate, it'll return nothing (statement behaviour), neither an empty token.
; '''sliceget(&lt;si&gt;, &lt;ei&gt;, &lt;tokenname&gt;)'''
: returns the portion of a token starting at index &quot;si&quot; and ending at &quot;ei&quot; (inclusive).
; '''get(&lt;i&gt;, &lt;token&gt;)'''
: returns the character of a token at index &quot;i&quot;.
; '''fetch(&lt;name&gt;)'''
: returns the value of the variable with name &quot;name&quot;, or an empty token if the variable doesn't exist.
; '''in(&lt;substr&gt;, &lt;token&gt;)'''
: returns 1 if substr is found in token, otherwise 0.
; '''join(&lt;sep&gt;, ...)'''
: returns a single token from a variable number of tokens, joining them using &quotlt;sep&quotgt;; resulting token will have the same type of &lt;sep&gt;.
; '''range(&lt;start&gt;, &lt;end&gt;)'''
: returns numbers starting at &quot;start&quot; and ending at &quot;end&quot; (inclusive) as multiple tokens.
; '''definedisdef(&lt;name&gt;)'''
: returns 1 if &quot;name&quot; is a variable, otherwise 0.
; '''isvar(&lt;name&gt;)'''
Line 827 ⟶ 829:
: returns 1 if all arguments are equal (string comparison), 0 otherwise.
; '''count(...)'''
: returns the number of given tokensarguments.
; '''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.
39

edits