Icon+Unicon/Intro: Difference between revisions

→‎Lists of Operators: fix re:augments
(→‎Lists of Operators: fix re:augments)
Line 229:
: C - co-expression
: v - variable
 
==== Assignment and Control Operators ====
 
<lang Icon> v := expr # assignassignment
v op:= expr # augmented assignment (see below)
v :=: v # swap
v <- expr # conditional assign
v <-> v # reversible swap</lang>
 
|x # repeated alternation
x | x # alternation</lang>
x \ i # limit generation to i results </lang>
 
==== Unary ====
Line 240 ⟶ 252:
.x # dereference to value
?x # random element/value
|x # repeated alternation
~c # cset complement
^ # regenerate co-expression</lang>
Line 277 ⟶ 288:
s || s # string concatenation
L ||| L # list concatenation
x & x # conjunction</lang>
x | x # alternation</lang>
 
The operators above may be used in augmented form with normal assignment (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:
<lang Icon>
while x1 +:= x2 # accumulation
Line 299 ⟶ 309:
</lang Icon>
x1 ===:= x2 # obscure x1 := x1, can this be more that a no-op?
s1 ==:= s2 # generatesensures errors if s1 and s2arguments are notboth strings, (assigns but otherwiseno avalue no-op?change)
n1 =:= n2 # numeric version of above
x1 &:= x2 # x1 := x2 unless x1 or x2 fails</lang>
# this next one is documented as augmented but appears to generate a compile error
x1 |:= x2 # but if x1 fails, x2 side effects but how would x1</lang>
The operators below may not be used in augmented form.
 
<lang Icon> v := expr # assign
v :=: v # swap
v <- expr # conditional assign
v <-> v # reversible swap
 
Note that some documentation indicates x1 |:= x2 exists, but it isn't implemented at this time.
x \ i # limit generation to i results </lang>
 
== Program Flow and Control ==
Anonymous user