Icon+Unicon/Intro: Difference between revisions

Content added Content deleted
(→‎Unary: format)
Line 291: Line 291:


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:
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>
<lang Icon> while x1 +:= x2 # accumulation
while x1 +:= x2 # accumulation
while x1 *:= x2 # product
while x1 *:= x2 # product
while S1 ++= S2 # builds a set/cset
while S1 ++= S2 # builds a set/cset
Line 302: Line 301:


Some others are less obvious, such as:
Some others are less obvious, such as:
<lang Icon> if lastx ~===:= x then ... # do work and remember when something changed</lang>
<lang Icon>
if lastx ~===:= x then ... # do work and remmeber when something changed
</lang>


Others are obscure or even a bit baffling, such as:
Others are obscure or even a bit baffling, such as:
</lang Icon> x1 ===:= x2 # obscure x1 := x1, can this be more that a no-op?
</lang Icon>
x1 ===:= x2 # obscure x1 := x1, can this be more that a no-op?
s1 ==:= s2 # ensures arguments are both strings (assigns but no value change)
s1 ==:= s2 # ensures arguments are both strings (assigns but no value change)
n1 =:= n2 # numeric version of above
n1 =:= n2 # numeric version of above