Category:Guish: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 166:
 
<pre> a = 'my string'; puts &quot;this is: @{a}&quot;
puts &quot;sum of 1 + 5 is: @(return add(1, 5))&quot;</pre>
Anything embedded inside '''{}''' is treated as a code block and no variable substitution is done at definition time.
 
Line 209:
<pre> a = 1
after 4 {a = 0}
while {eq(@a, 1)} {
wait 1 puts 'true'
}
Line 282:
; '''self'''
: variable holding the window id when in signal code.
; '''any(...)args'''
: refers to the block in which there are positional arguments and function arguments (alternative syntax).
; '''FILE'''
: variable holding the path of current source file.
Line 321 ⟶ 323:
; '''=&gt; &lt;signal&gt; &lt;subcmd&gt;'''
: register a sub-command &lt;subcmd&gt; to run when &lt;signal&gt; triggers. For normal signals (eg. signals tied to elements), there must exist an implied subject.
; '''global &lt;var!&gt; = [&lt;valsignal&gt;]'''
: unregister a sub-command &lt;subcmd&gt; previously registered on signal &lt;signal&gt;.
: defines a variable using the same rules of variable definition, but defining that variable in the global scope; this usually can be used inside functions to define a global variable which doesn't exist already.
; '''q'''
: quit guish (exit status 0).
Line 444 ⟶ 446:
; '''m &lt;x&gt; &lt;y&gt;'''
: move element to coords &lt;x&gt; &lt;y&gt;.
; '''/ [&lt;l|L|a|A|p|x|n&gt; [&lt;...&gt;]]'''
: draws/fills lines, points and arcs depending on operation (See Drawing operations subsection). Origin coordinates correspond to the bottom-left corner as default Cartesian axes (instead of upper-left one used for windows/elements). If no operation is given, then all drawings are discarded from the implied element.
; '''A &lt;element&gt; &lt;alignment&gt;'''
Line 465 ⟶ 467:
 
 
; '''l [&lt;color&gt; &lt;x1&gt; &lt;y1&gt; &lt;x2&gt; &lt;y2&gt; [&lt;...&gt;]]'''
: draws lines between given points using color &lt;color&gt; (beware this command consumes all the phrase). If no arguments are given, then all element lines are discarded.
; '''L [&lt;color&gt; &lt;x1&gt; &lt;y1&gt; &lt;x2&gt; &lt;y2&gt; [&lt;...&gt;]]'''
: fills the polygon described by given points using color &lt;color&gt; (beware this command consumes all the phrase). If no arguments are given, then all filled polygons are discarded.
; '''a [&lt;color&gt; &lt;x&gt; &lt;y&gt; &lt;w&gt; &lt;h&gt; &lt;alpha&gt; &lt;beta&gt; [&lt;...&gt;]]'''
: draws an arc using color &lt;color&gt; and whose &quot;center&quot; is at &lt;x&gt; &lt;y&gt;, major and minor axes are respectively &lt;w&gt; and &lt;h&gt;, start and stop angles are &lt;alpha&gt; and &lt;beta&gt; (consumes all the phrase). If no arguments are given, then all element arcs are discarded.
; '''A [&lt;color&gt; &lt;x&gt; &lt;y&gt; &lt;w&gt; &lt;h&gt; &lt;alpha&gt; &lt;beta&gt; [&lt;...&gt;]]'''
: fills an arc using color &lt;color&gt; and whose &quot;center&quot; is at &lt;x&gt; &lt;y&gt;, major and minor axes are respectively &lt;w&gt; and &lt;h&gt;, start and stop angles are &lt;alpha&gt; and &lt;beta&gt; (consumes all the phrase). If no arguments are given, then all element arcs are discarded.
; '''p [&lt;color&gt; [&lt;...&gt;]]'''
: draws given points using color &lt;color&gt; (beware this command consumes all the phrase). If no arguments are given, then all points are discarded.
; '''slice(x [&lt;sicolor&gt;, [&lt;ei&gt;, ...)&gt;]]'''
: draws given pixels using color &lt;color&gt; (beware this command consumes all the phrase). If no arguments are given, then all pixels are discarded.
; '''n [&lt;color&gt; &lt;name&gt; &lt;x&gt; &lt;y&gt;]'''
: draws given point using color &lt;color&gt; and putting the text &lt;name&gt; at that point. If no arguments are given, then all points are discarded.
Line 630 ⟶ 634:
Every phrase is reduced to an empty phrase while evaluating:
 
<pre> a = 234 ;{i1=|i|;&lt;'input1'+}(); {i2=|i|;&lt;'input2'+}() |b|&lt;btn+</pre>
This example is composed by 2 phrases, and the code block in each phrase is executed before each assignment.
 
Line 654 ⟶ 658:
 
 
With the '''=''' operator (actually, it's a special statement command), it's possible to assign a valuevalues 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, shell command substitution quotes '''``''', or external window id substitution '''&lt;( )'''. If the special '''&amp;''' operator is used, instead of '''@''', then if the variable given doesn't exist, an error will be generated.
 
<pre> b = 123; puts &amp;@a</pre>
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 =).
 
In addition, if there is more than one value to assign, a block is automatically created (embedding those values) and assigned to that variable:
 
<pre> a = 1 # this simply assigns '1' to the variable 'a'
b = 1, 2, 3, 4 # this instead assigns the block '{1, 2, 3, 4}' to the variable 'a'
c = {1, 2, 3, 4} # same but explicit</pre>
Each block has it's own scope, and variable resolution works by searching from the last scope to the first. Ex:
 
Line 721 ⟶ 730:
; '''&lt;s&gt; .. &lt;e&gt;'''
: returns integers starting at &lt;s&gt; and ending at &lt;e&gt; (inclusive) as multiple tokens.
; '''&lt;var&gt; = [&lt;val&gt;, [&lt;val1&gt;, ...]]'''
: defines a variable (consumes all the phrase). If no value is given, an empty token is assigned to the variable. If a single value is given, that value is assigned to the variable. If multiple values are given, then all these values are wrapped inside a block, and this block is assigned to the variable.
: defines a variable.
; '''&lt;attr&gt; .= [&lt;val&gt;, [&lt;val1&gt;, ...]]'''
: defines an element using the implied subject attribute (consumes all the phrase). If no value is given, an empty token is assigned to the variable. If a single value is given, that value is assigned to the variable. If multiple values are given, then all these values are wrapped inside a block, and this block is assigned to the variable.
: defines an element (implied subject) attribute.
 
== Unary ==
Line 732 ⟶ 741:
; '''@&lt;varname|num&gt;'''
: dereferences a variable name (or positional argument).
; '''&amp;&lt;varname|num&gt;'''
: dereferences a variable name (or positional argument) and gives error if the variable does not exist.
; '''@*'''
: returns all function parameters as tokens (usable with command line parameters too).
Line 799 ⟶ 806:
; '''eval(...)'''
: evaluates code by first stringifying all given arguments and then returns the result of evaluation if any. Beware that this function runs in the &quot;current&quot; scope, and can modify it.
; '''call(&lt;name&gt;, ...)'''
: gets a variable name and a variable number of arguments, then calls the function whose name is &quot;name&quot; with those arguments and returns the result (if any).
; '''builtin(&lt;func&gt;, ...)'''
: gets the name of a builtin function and a variable number of arguments, then calls the builtin function with those arguments and returns the result (if any). It's useful when overriding builtin functions.
Line 815 ⟶ 820:
; '''if(&lt;cond&gt;, [&lt;v1&gt;, [&lt;v2&gt;]])'''
: if &lt;cond&gt; is true and &lt;v1&gt; is given, returns &lt;v1&gt;, else if &lt;cond&gt; is false and &lt;v2&gt; is given, returns &lt;v2&gt;.
; '''unless(&lt;cond&gt;, [&lt;v1&gt;, [&lt;v2&gt;]])'''
: if &lt;cond&gt; is false and &lt;v1&gt; is given, returns &lt;v1&gt;, else if &lt;cond&gt; is true and &lt;v2&gt; is given, returns &lt;v2&gt;.
; '''alland(...)'''
: returns the first true argument; if there are no true arguments, returns the last one which is false. ThisThe function isevaluates special,any asblock the evaluation will be interrupted as soon as there is at least 1 true argumentgiven.
; '''countor(...)'''
: returns the last true argument if all arguments are true, otherwise returns the first false argument. ThisThe function isevaluates special,any asblock the evaluation will be interrupted as soon as there is at least 1 false argumentgiven.
; '''flat(...)'''
: returns all given arguments; if a block is found, then it is flatted.
Line 831 ⟶ 842:
; '''popb()'''
: pops the first argument from function arguments (works with command line parameters too). This function is somewhat special, as if there are no arguments to pop.
; '''slice(&lt;si&gt;, &lt;ei&gt;, ...)'''
: returns arguments starting at &quot;si&quot; and ending at &quot;ei&quot; (inclusive). This function is somewhat special, as when there is nothing to get, it'll return nothing (statement behaviour).
; '''times(&lt;n&gt;, &lt;arg&gt;)'''
: returns a sequence of tokens made by &lt;n&gt; times &lt;arg&gt;. This function is somewhat special, as when there are 0 tokens to replicate, it'll return nothing (statement behaviour).
; '''get(&lt;name&gt;)'''
: returns the value of the variable with name &lt;name&gt;, or an empty token if the variable does not exist.
; '''at(&lt;n&gt;, ...)'''
: returns the &quot;nth&quot; argument given (by index). This function is somewhat special, as when there is nothing to get, it'll return nothing (statement behaviour).
; '''true(&lt;arg&gt;)'''
: returns 1 if &lt;arg&gt; is true, 0 otherwise.
Line 865 ⟶ 872:
; '''seq(&lt;t1&gt;, &lt;t2&gt;, ...)'''
: returns 1 if all arguments are equal (string comparison), 0 otherwise.
; '''count(...)'''
: returns the number of given arguments.
; '''any(...)'''
: returns the first true argument; if there are no true arguments, returns the last one which is false. This function is special, as the evaluation will be interrupted as soon as there is at least 1 true argument.
; '''all(...)'''
: returns the last true argument if all arguments are true, otherwise returns the first false argument. This function is special, as the evaluation will be interrupted as soon as there is at least 1 false argument.
; '''add(...)'''
: perform addition.
Line 905 ⟶ 906:
; '''xor(&lt;n1&gt;, &lt;n2&gt;, ...)'''
: perform bitwise XOR.
; '''andband(&lt;n1&gt;, &lt;n2&gt;, ...)'''
: perform bitwise AND.
; '''orbor(&lt;n1&gt;, &lt;n2&gt;, ...)'''
: perform bitwise OR.
; '''lsh(&lt;n1&gt;, &lt;n2&gt;, ...)'''
39

edits