bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Suggestion: Support multi-line lambda functions


From: Juergen Sauermann
Subject: Re: [Bug-apl] Suggestion: Support multi-line lambda functions
Date: Wed, 11 May 2016 16:05:25 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

Hi Louis,

that assumption is correct. The reason is that I do not want lambdas in GNU APL to behave
differently than user-defined functions.

/// Jürgen


On 05/09/2016 11:25 PM, Louis de Forcrand wrote:
I assume it is intended that variables defined in lambdas aren't local. I personally find
that the functional style of lambdas is hindered by the lingering variables in the WS,
but this is personal preference, and it is possible to redefine any lambda as regular
function anyway.

Louis

On 09 May 2016, at 16:02, Juergen Sauermann <address@hidden> wrote:

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:
It seems as though using the foo←{...} style of writing functions is quite popular in the Dyalog community.

An example file written in this style can be found here: https://github.com/mattcunningham/apl-bayesian-classifier/blob/master/bayes.full.apl

As we can see, functions are declared in this style:

      foo ← {
          x ← 1+⍵
          y ← 1+⍺
          x+y
      }

I'd like to see this being supported in GNU APL as well.

Related, I'd like to be able to use  inside a lambda function. Whenever I port a function from Dyalog I end up having to rewrite these using ⊣ and ⊢, which is not hard but feels arbitrary. Right now  doesnt work at all in lambdas, so adding support for it shouldn't cause any compatibility issues with APL2.

Regards,
Elias




reply via email to

[Prev in Thread] Current Thread [Next in Thread]