2 ->2 ->4 ->6 ->10 ->16 ->26 ->42 ->68 ->110 ->178 ->288 ->466 0 1If 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.
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:
({ri|,+/->2raari|}riu10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riuN-2) 0 1
rec
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. riu 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:
({ri|,+/->2raari|}riu10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riuN-2) 0 1
rec
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:
({ri|,+/->2raari|}riu12-2) 0 1
2 ->2 ->4 ->6 ->10 ->16 ->26 ->42 ->68 ->110 ->178 ->288 ->466 0 1But:
({ri|,+/->2raari|}riu(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:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riu(N-2)) 0 1
rec
/ 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. riu 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:
({ri|,+/->2raari|}riu10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riuN-2) 0 1
rec
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:
({ri|,+/->2raari|}riu12-2) 0 1
2 ->2 ->4 ->6 ->10 ->16 ->26 ->42 ->68 ->110 ->178 ->288 ->466 0 1But:
({ri|,+/->2raari|}riu(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:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riu(N-2)) 0 1
rec
/ Rav
On 6/6/2022 4:03 PM, Charles Brenner wrote:Thanks Bob. That's good to know and I didn't.
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. riu 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:
({ri|,+/->2raari|}riu10) 0 1
0 1 1 2 3 5 8 13 21 34 55 89
But this doesn't work:
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riuN-2) 0 1
rec
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:
({ri|,+/->2raari|}riu12-2) 0 1
2 ->2 ->4 ->6 ->10 ->16 ->26 ->42 ->68 ->110 ->178 ->288 ->466 0 1But:
({ri|,+/->2raari|}riu(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: >>
rec
[0] AraEFIBONACCI N
[1] AraE({ri|,+/->2raari|}riu(N-2)) 0 1
rec
/ Rav
strand right operands. While they all implement short right scope, in
APL2 and NARS2000
friu1 2 3 raEraA (friu1) 2 3
whereas in Dyalog
friu1 2 3 raEraA friu(1 2 3)
Thanks Bob. That's good to know and I didn't.
Another situation where Morton chose to abandon APL2's parenthesis requirement is multiple assignment:
In APL2: (one another)raE1 'ther'
Dyalog permits: one anotherraE1 'ther'
Morton expressed remorse for this, and eventually I saw why. I often invoke the display utility function #.disp, i.e. disp (3 2ri|'a' 23 ('b' 'cd')). Sometimes when my program crashed while inside namespace #.ns, I would thoughtlessly write disp xraEFunction ri|7, which usually works fine. But if Function returns a 2-element vector, uh oh!
So I began writing (xyz abc)raE ..., 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 superfluous monadic rea for clarity.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 06:20:34 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,699 |