Readability: Difference between revisions

Jump to navigation Jump to search
726 bytes added ,  08:17, 27 September 2020
Line 17: Line 17:


=== IBM ===
=== IBM ===
The [[APL2]] Idiom list includes the following entry:
The [[idiom]] list included with [[APL2]] includes the following entry:<ref>Cason, Stan. [ftp://ftp.software.ibm.com/ps/products/apl2/info/APL2IDIOMS.pdf#page=3 APL2 IDIOMS Library]. IBM.</ref>
:{| style=width:100%
:{| style=width:100%
|<source lang=apl inline>X←'line1',0⍴Y←'line2'</source>||<source lang=apl inline>⍝ Pornography. Combining two lines into one.</source>
|<source lang=apl inline>X←'line1',0⍴Y←'line2'</source>||<source lang=apl inline>⍝ Pornography. Combining two lines into one.</source>
|}
|}
This was a common technique before [[Left]] was added to the language:
This was once a common technique before, even though it is prone to fail in where the value to the left of <source lang=apl inline>,0⍴</source> isn't a vector, for example in the following example where <source lang=apl inline>X</source> becomes a 1-element [[vector]] instead of the intended [[scalar]]:
<source lang=apl>
      X←'l',0⍴Y←'line2'
      Y∘.=X
1
0
0
0
0
</source>
With the addition of [[Left]] (<source lang=apl inline>⊣</source>) to the language, this type of hack became became entirely obsolete:
:<source lang=apl inline>X←'line1' ⊣ Y←'line2'</source>
:<source lang=apl inline>X←'line1' ⊣ Y←'line2'</source>
The primitive leaves its left argument unmodified:
<source lang=apl>
      X←'l' ⊣ Y←'line2'
      Y∘.=X
1 0 0 0 0
</source>
The Diamond [[statement separator]] (<source lang=apl inline>⋄</source>) provides an alternative means of inlining multiple statements:
The Diamond [[statement separator]] (<source lang=apl inline>⋄</source>) provides an alternative means of inlining multiple statements:
:<source lang=apl inline>Y←'line2' ⋄ X←'line1'</source>
:<source lang=apl inline>Y←'line2' ⋄ X←'line1'</source>
Note that in all these cases, <source lang=apl inline>Y</source> is assigned first.
Note that in all the above, <source lang=apl inline>Y</source> is assigned first.


=== Morten Kromberg ===
=== Morten Kromberg ===

Navigation menu