Search code examples
aplgnu-apl

Is it possible to return lambdas in a function?


Consider the following function, which should return a function that adds two to any given argument:

∇r←addtwo
  r←{⍵+2}
∇

This code loads without any errors, but I just cannot use the return value without causing errors.

      addtwo ⍝ doesn't cause errors
      addtwo 1
VALUE ERROR
      addtwo 1
      ^
      x←addtwo
VALUE ERROR
      x←addtwo
      ^

I am using GNU-APL 1.8.


Solution

  • I believe Dyalog APL is the only implementation allowing this. Try it online!

    Even though this could work, it isn't the normal APL way of doing things. You may want to look into writing your own operator instead.