Re:The Panda Language: No Loops, No Ifs, Just Fun
by gandercrews on Tuesday May 12, 2020 @10:02AM
(#23154063)
rewritten apl version w/ lambdas and commute (vs assignment & parens):
About as short as I can make it, and while its longer than the pandas solution, the primitives are significantly more general (sqr, odd - why include these as language primitives?).
[ Parent
| on HN ]
Re:The Panda Language: No Loops, No Ifs, Just Fun
by eesmith on Tuesday May 12, 2020 @04:32PM
(#23159343)
Thanks! It's been a long time since I tried APL. All I could remember was ⍳ and right-to-left evaluation. The rest was through monkeying around with Rosetta Code examples.
As to your "why" question - I'm assuming to make a neat demo. Something like:
>>> from math import cos, sin
>>> [s for i in range(50) if i&1 and cos(s:=i*i) < sin(i)]
[1, 9, 49, 225, 361, 441, 625, 1089, 1521, 1681, 2025, 2209]
seems more difficult to pull off in a pipeline API.
Re:The Panda Language: No Loops, No Ifs, Just Fun
by gandercrews on Tuesday May 12, 2020 @05:28PM
(#23160115)
nah its pretty straightforward w/ higher order fns.
one of many possible solutions:
{(1○⍺)>2○⍵} {(⍹ ⍵)/⍨⍵ ⍶ ⍹ ⍵} {⍵*2} {⍵/⍨2|⍵}⍳50
1 9 49 225 361 441 625 1089 1521 1681 2025 2209