I have been experimenting with simple lambda functions to see how they work. But I ran into behavior that I don't understand, and I haven't found good documentation to explain what is going on.
This works as expected:
({⍵,+/¯2↑⍵}⍣10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
∇
[0] A←FIBONACCI N
[1] A←({⍵,+/¯2↑⍵}⍣N-2) 0 1
∇
FIBONACCI 12
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
If I tried to do this using only normal defined functions I would have to use two separate functions, so it seems to me that using a lambda function should be a cleaner way to perform the operation. But I don't see how to make this work.
--- Brian McGuinness
On 6/5/2022 4:08 PM, Brian McGuinness wrote:Nice work. That solves the puzzle except for a small point of language. ⍣ is an operator hence, contrary to the rule for a function, it has short right scope - i.e. "12" or "(12-2)" - (and long left scope).
I have been experimenting with simple lambda functions to see how they work. But I ran into behavior that I don't understand, and I haven't found good documentation to explain what is going on.
This works as expected:
({⍵,+/¯2↑⍵}⍣10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
∇
[0] A←FIBONACCI N
[1] A←({⍵,+/¯2↑⍵}⍣N-2) 0 1
∇
FIBONACCI 12
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
If I tried to do this using only normal defined functions I would have to use two separate functions, so it seems to me that using a lambda function should be a cleaner way to perform the operation. But I don't see how to make this work.
--- Brian McGuinnessIf I understand correctly, it doesn't look to me like doing the same
thing with a defined function is doing anything differently. In
immediate execution mode:
({⍵,+/¯2↑⍵}⍣12-2) 0 1
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
But:
({⍵,+/¯2↑⍵}⍣(12-2)) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
I'm not familiar with the power function, but perhaps it's a precedence issue, which the parentheses solves. So change your defined function to:
∇
[0] A←FIBONACCI N
[1] A←({⍵,+/¯2↑⍵}⍣(N-2)) 0 1
∇
/ Rav
On Sunday, June 5, 2022 at 3:11:09 PM UTC-7, Rav wrote:
On 6/5/2022 4:08 PM, Brian McGuinness wrote:Nice work. That solves the puzzle except for a small point of language. ⍣ is an operator hence, contrary to the rule for a function, it has short right scope - i.e. "12" or "(12-2)" - (and long left scope).
I have been experimenting with simple lambda functions to see how they work. But I ran into behavior that I don't understand, and I haven't found good documentation to explain what is going on.If I understand correctly, it doesn't look to me like doing the same
This works as expected:
({⍵,+/¯2↑⍵}⍣10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
∇
[0] A←FIBONACCI N
[1] A←({⍵,+/¯2↑⍵}⍣N-2) 0 1
∇
FIBONACCI 12
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
If I tried to do this using only normal defined functions I would have to use two separate functions, so it seems to me that using a lambda function should be a cleaner way to perform the operation. But I don't see how to make this work.
--- Brian McGuinness
thing with a defined function is doing anything differently. In
immediate execution mode:
({⍵,+/¯2↑⍵}⍣12-2) 0 1
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
But:
({⍵,+/¯2↑⍵}⍣(12-2)) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
I'm not familiar with the power function, but perhaps it's a precedence
issue, which the parentheses solves. So change your defined function to:
∇
[0] A←FIBONACCI N
[1] A←({⍵,+/¯2↑⍵}⍣(N-2)) 0 1
∇
/ Rav
On 6/6/2022 4:03 PM, Charles Brenner wrote:
On Sunday, June 5, 2022 at 3:11:09 PM UTC-7, Rav wrote:Charles is exactly right. Moreover, there is one difference in the way dyadic operators work in APL2 and NARS2000 versus Dyalog with numeric
On 6/5/2022 4:08 PM, Brian McGuinness wrote:Nice work. That solves the puzzle except for a small point of language. is an operator hence, contrary to the rule for a function, it has short right scope - i.e. "12" or "(12-2)" - (and long left scope).
I have been experimenting with simple lambda functions to see how they work. But I ran into behavior that I don't understand, and I haven't found good documentation to explain what is going on.If I understand correctly, it doesn't look to me like doing the same
This works as expected:
({,+/¯2↑}10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
∇
[0] A←FIBONACCI N
[1] A←({,+/¯2↑}N-2) 0 1
∇
FIBONACCI 12
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
If I tried to do this using only normal defined functions I would have to use two separate functions, so it seems to me that using a lambda function should be a cleaner way to perform the operation. But I don't see how to make this work.
--- Brian McGuinness
thing with a defined function is doing anything differently. In
immediate execution mode:
({,+/¯2↑}12-2) 0 1
¯2 ¯2 ¯4 ¯6 ¯10 ¯16 ¯26 ¯42 ¯68 ¯110 ¯178 ¯288 ¯466 0 1
But:
({,+/¯2↑}(12-2)) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
I'm not familiar with the power function, but perhaps it's a precedence >> issue, which the parentheses solves. So change your defined function to: >>
∇
[0] A←FIBONACCI N
[1] A←({,+/¯2↑}(N-2)) 0 1
∇
/ Rav
strand right operands. While they all implement short right scope, in
APL2 and NARS2000
f1 2 3 ←→ (f1) 2 3
whereas in Dyalog
f1 2 3 ←→ f(1 2 3)
Thanks Bob. That's good to know and I didn't.Function 7, which usually works fine. But if Function returns a 2-element vector, uh oh!
Another situation where Morton chose to abandon APL2's parenthesis requirement is multiple assignment:
In APL2: (one another)←1 'ther'
Dyalog permits: one another←1 'ther'
Morton expressed remorse for this, and eventually I saw why. I often invoke the display utility function #.disp, i.e. disp (3 2'a' 23 ('b' 'cd')). Sometimes when my program crashed while inside namespace #.ns, I would thoughtlessly write disp x
So I began writing (xyz abc)← ..., and having thus violated my life-long habit of always omitting unnecessary punctuation in my APL code, the floodgates are getting shakey. Occasionally I now add extra parentheses for symmetry or a superfluousmonadic ⊆ for clarity.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 429 |
Nodes: | 16 (2 / 14) |
Uptime: | 112:22:34 |
Calls: | 9,055 |
Calls today: | 2 |
Files: | 13,395 |
Messages: | 6,016,192 |