Icon+Unicon/Intro: Difference between revisions

m
moved contractions
m (moved contractions)
Line 248:
====error throwing====
Errors can be thrown using the function
 
== Contractions ==
Icon/Unicon have a rich set of operators which combined with the fact that all successful expressions produce values makes possible contractions. These appeal of these is somewhat a question of style and if taken to extremes there is also the possibility of being overtaken by one-liners. Having said that Icon/Unicon contractions are hardly in the same league as those of [[APL]] or [[J]]. A number of examples are presented below.
 
 
These examples initializes sum and adding all the contents of arglist.
<lang Icon>sum := 0 # initial and
every sum +:= !arglist do something() # loop in two statements
 
sum := 0; every sum +:= !arglist do something() # ; splice
 
every (sum := 0) +:= !arglist do something() # a common contraction
 
while sum := 0) +:= !arglist do something() # an error</lang>
 
Examples of using program control structures in expressions:
<lang Icon>
(if i > j then i else j) := 0 # sets the larger of i and j to 0
d := if a > b then a-b else b-a # sets d to the positive difference of a and b
x := case expr of {
1: "Text 1"
2: "Text 2"
default: "Undefined text"
} # sets x to a string based on the value of expression</lang>
 
= Appendix A - Icon and Unicon Differences (Details) =
Anonymous user