Icon+Unicon/Intro: Difference between revisions

→‎Lists of Operators: tidy + augmentation
(→‎Binary: remove dups)
(→‎Lists of Operators: tidy + augmentation)
Line 232:
==== 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
Line 281 ⟶ 280:
x | x # alternation</lang>
 
The operators above may be used in augmented form (i.e., x1 op:= x2; short for x1 := x1 op x2) . Many of these are common and natural, such as any of the mathematical group, concatenation, and comparisons for sorting. And the most common uses will be building results inside loops or scanning operations. Some of the examples include:
The operators below may not be used in augmented form i.e. op:=
<lang Icon>
while x1 +:= x2 # accumulation
while x1 *:= x2 # product
while S1 ++= S2 # builds a set/cset
while x1 @:= C # repeatedly call a co-expression building on its argument
while s1 ||:= s2 # build a string
while L1 |||:= L2 # build a list
while x1 <:= x2 # find maximum
s1 ?:= expr # replaces string subject</lang>
 
Some others are less obvious, such as:
<lang Icon>
if lastx ~===:= x then ... # do work and remmeber when something changed
</lang>
 
Others are obscure or even a bit baffling, such as:
</lang Icon>
x1 ===:= x2 # obscure x1 := x2, can this be more that a no-op?
s1 ==:= s2 # generates errors if s1 and s2 are not strings, but otherwise
n1 ==:= n2 # numeric version of above
x1 &:= x2 # x1 := x2 unless x1 or x2 fails
x1 |:= x2 # but if x1 fails, x2 side effects but how would x1</lang>
The operators below may not be used in augmented form i.e. op:=
 
<lang Icon> v := expr # assign
Line 288 ⟶ 311:
v <-> v # reversible swap
 
x \ i # limit generation to i results </lang>
 
== Program Flow and Control ==
Anonymous user