|
From: | Juergen Sauermann |
Subject: | Re: [Bug-apl] Suggestion: Support multi-line lambda functions |
Date: | Mon, 09 May 2016 16:02:34 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
Hi Elias, there are reasons why ◊ (and multi-line lambdas) are not supported in GNU APL. In GNU APL lambdas are implemented as user-defined functions and they follow the same syntax and other rules as user-defined functions. For example (GNU APL): (A B C) ← 1 2 3 FOO←{ A B C ⍵} FOO 42 1 2 3 42 At this point GNU APL and Dyalog give the same result. And in GNU APL we get: ⎕CR 'FOO' λ←FOO ⍵ λ← A B C ⍵ which shows how lambdas are turned into regular user-defined functions. But now look at this (hypothetical example as far as GNU APL is concerned). (A B C) ← 1 2 3 FOO←{ A ◊ B ◊ C ⍵} FOO 42 In GNU APL we would get either ⎕CR 'FOO' λ←FOO ⍵ λ←A ◊ B ◊ C ⍵ or maybe: ⎕CR 'FOO' λ←FOO ⍵ A ◊ B ◊ λ←C ⍵ Even though we cannot do FOO←{ A ◊ B ◊ C ⍵} in GNU APL, we can create the corresponding user-defined functions manually: ⎕CR 'FOO' λ←FOO ⍵ λ← A ◊ B ◊ C ⍵ FOO 42 2 3 42 1 or maybe: ⎕CR 'FOO' λ←FOO ⍵ λ← A ◊ B ◊ C ⍵ A ◊ B ◊ λ←C ⍵ FOO 42 2 3 42 1 2 3 42 And now compare that with Dyalog (as per tryAPL): FOO 42 1 The reason for this is that Dyalog APL has different rules for multi-statements and multi-lines in lambdas than for the same APL statements and lines in user-defined functions. As it looks, a Dyalog lambda returns when the first statement has a (non-committed ?) value while a user-defined function (with the exact same statements and lines) returns after the last line (or after →0). I personally believe that having two functions that look the same but behave differently depending on how they were created is a BAD THING. It would also create problems with )LOADing and )SAVEing workspaces because, as far as I remember, the ⎕FX of functions is stored in those files. ----------------------------------------- I have also discussed the lambda matter with Morten Kromberg of Dyalog last year. The starting point of the discussion was basically Morten's proposal to remove lamdas from GNU APL completely, an my equally keen counter-proposal that Dyalog makes lambdas compatible with user-defined functions. Obviously, none of the proposals was feasible without breaking the backward-compatibility of the affected APL interpreter. And of course each of us would expect the other to change his interpreter. However, we could agree that having incompatible lambdas in GNU APL and Dyalog would be even worse, and since multi-statement and multi-lines were present in Dyalog lambdas, but not in GNU APL, I promised to Morten that I will not develop lambdas in GNU APL any further. And so be it. /// Jürgen On 05/09/2016 06:57 AM, Elias Mårtenson
wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |