Icon+Unicon/Intro: Difference between revisions

Content deleted Content added
→‎Contractions: - extreme title, more examples, replace due to logged out
Line 564:
sum := 0; every sum +:= !arglist do something() # ; splice
 
every (sum := 0) +:= !arglist do something() # a common contraction, iteration begins at the !
 
while (sum := 0) +:= !arglist do something() # an error. while will only get the first result</lang>
 
More examples of initialization in every loops:<lang Icon>every put(L := [], !X) # creates a empty list before populating it
every (s := "") || !S # create a null string before appending</lang>
 
Examples of using program control structures in expressions:
Line 599 ⟶ 602:
}</lang>
 
=== Extreme Contractions ===
 
Deciding on the level of contraction is an art and, like any art form, easy to abuse. For example, the following procedure (from the Van de Corput Sequence task solution):
Line 615 ⟶ 617:
This is probably only lovable by J programmers.
 
 
Here is another example taken from [[Sierpinski_carpet|Sierpinski Carpet]] which we will explain in detail:
 
The procedure IsFilled is used to determine if the carpet is to be filled. The original version is a fairly straightforward translation of Java which in turn was translated from Python. About the only natural contraction for the language is the use of the fact that operators return values and comparisons can be chained.<lang Icon>procedure IsFilled(x,y)