Loops/For: Difference between revisions
→{{header|APL}}: Add dummy argument so nested version works in GNU
m (→{{header|APL}}: formatting) |
(→{{header|APL}}: Add dummy argument so nested version works in GNU) |
||
Line 373:
<lang APL>stars ← { ⍵ 1 ⍴ {⍵/'*'}¨⍳⍵ }</lang>
To stick to the letter of the task description, we can nest an '''each''' inside another one, but it's a little silly. Plus not all dialects support niladic dfns, so the innermost "return one star" function has to take a dummy argument:
<lang APL>stars ← { ⍵ 1 ⍴ { {'*'} ¨ ⍳⍵ } ¨ ⍳⍵ }</lang>▼
▲<lang APL>stars ← { ⍵ 1 ⍴ { {1⌷'*',⍵} ¨ ⍳⍵ } ¨ ⍳⍵ }</lang>
Additionally, Dyalog and some other dialects support the more traditional structured programming controls inside a named function definition (tradfn):
{{works with|Dyalog APL}}
|