Multiplication tables: Difference between revisions

Content added Content deleted
(+Icon+Unicon)
m (→‎{{header|Icon}}: cleaned up contraction)
Line 922: Line 922:
lim := 13
lim := 13
wid := 5
wid := 5
every writes(right("* |" | (1 to lim) | "\n",wid)|right("\n",wid*(lim+1),"_")) # header rows
every writes(right("* |" | (1 to lim) | "\n",wid)|right("\n",wid*(lim+1),"_")) # header row and separator
every (i := 1 to lim) &
every (i := 1 to lim) &
writes(right( i||" |" | (j := 1 to lim, (if j < i then "" else i*j)\1) | "\n",wid)) # content
writes(right( i||" |" | (j := 1 to lim, if j < i then "" else i*j) | "\n",wid)) # table content and triangle
end </lang>
end </lang>


The above example is a somewhat exaggerated example of contractions. In both cases 'every' is used to force all alternatives including row labels, column headings, content, line terminators. The upper triangle is produced by embedding an 'if' expression inside the object of an 'every' (normally an error prone construct which would malfunction if not for the operator limiting generation to a single result (i.e. via expr \ 1).
The above example is a somewhat exaggerated example of contractions. In both cases 'every' is used to force all alternatives including row labels, column headings, content, line terminators. The upper triangle is produced by embedding an 'if' expression inside the object of an 'every' (normally an error prone construct which would malfunction if not carefully separated from the generators for 'i' and 'j' - an all too tempting possibility once you get into this mind set.)




Line 945: Line 945:
12 | 144 156
12 | 144 156
13 | 169 </pre>
13 | 169 </pre>



==={{header|Unicon}}===
==={{header|Unicon}}===