curryingaplgnu-apl

Currying in GNU APL


I was trying to "curry" a function in GNU APL, however it doesn't seem to work?

For example:

      (1∘+) 1
SYNTAX ERROR
      (1∘+)1
      ^   ^

What am I doing wrong? Is the wrong glyph to use?


Solution

  • GNU APL does not have the Bind meaning of , found in Dyalog and related implementations. Instead, the glyph is exclusively used for the outer product notation, ∘.f.

    However, you can define a reasonable substitute yourself:

    ∇ r←(a o b)z
      →3⌊⎕NC'b'
      r←z a b ⋄ →0
      r←a b z
    ∇
    

    It can be used almost like the primitive, except requiring a space when adjacent to a name on its left or a non-glyph on its right:

          (1o+) 1
    2
          (+o 1) 1
    2
          1o+ 1
    2
    

    Note that the above substitute does not provide function composition. In order to also include this, we have to go for a more involved definition:

    ∇ r←x(a o b)y  ⍝ ∘
      →2⌈¯5+2⊥3⌊⎕NC⍪'ab'
      r←a b y ⋄ →0 ⍝ A∘f
      r←y a b ⋄ →0 ⍝ f∘B
      ⍎'x←{⍵}'/⍨0=⎕NC'x'
      r←x a b y    ⍝ f∘g
    ∇
    

    Now everything works:

          (1o+) 1
    2
          (+o 1) 1
    2
          1o+ 1
    2
          1+o|¯1
    2