Jump to content

Icon+Unicon/Intro: Difference between revisions

Operators
(→‎Contractions: just to take steve`s jem over the top :))
(Operators)
Line 217:
 
Icon/Unicon performs implicit type conversions (called coercion) where it makes sense to do so. At the same time dangerous coercions are disallowed. Details of these coercions are covered under the topic of [[Icon+Unicon/Intro#DataTypes|Data Types]]. Where a coercion is not possible, a run-time error is generated.
 
=== Lists of Operators ===
 
In the lists below the following represent data by type:
: x - anything
: s - string
: n - numeric
: c - cset
: S - set (or cset)
: i - integer
 
==== Unary ====
<lang Icon> !x # generate elements
/x # null test
\x # non null test
+n # number (forces conversion)
-n # negate number
=s # tab(match(s))
*x # size
.x # dereference to value
?x # random element/value
|x # repeated alternation
~c # cset complement
^ # regenerate co-expression</lang>
 
==== Binary ====
The operators below may be used in augmented form i.e. op:=
<lang Icon> n ^ n # power
n * n # multiplication
n / n # division
n % n # modulus
n + n # addition
n - n # subtraction
 
S ** S # intersection
S ++ S # union
S -- S # difference
n = n # equal
n ~- n # unequal
n < n # less than
n <= n # less than or equal
n > n # greater than
n >= n # greater than or equal
s == s # equal
s ~== s # unequal
s << s # less than
s <<= s # less than or equal
s >> s # greater than
s >>= s # greater than or equal
 
x === x # equivalent
x ~=== x # not equivalent
s ? expr # scanning
x @ C # activate
s || s # string concatenation
L || L # list concatenation
x & x # conjunction
x | x # alternation
 
s ? expr # scanning
x @ C # activate
s || s # string concatenation
L || L # list concatenation
x & x # conjunction
x | x # alternation</lang>
 
The operators below may not be used in augmented form i.e. op:=
 
<lang Icon> v := expr # assign
v1 :=: v2 # swap
v <- expr # conditional assign
v1 <-> v2 # reversible swap
 
x1 \ i # limit generation to i results </lang>
 
== Program Flow and Control ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.