1

I'm using GNU APL. Also, I'm not really sure what the correct name for this is, but the basic idea is that I have a list of things and I want to do something with each pair. It's complex, so I've made a function for it. I notice that this works:

      2+/1 2 3 4 5
┌→──────┐
│3 5 7 9│
└───────┘

I can even use an anonymous lambda to do the same thing:

      2{⍺+⍵}/1 2 3 4 5
┌→──────┐
│3 5 7 9│
└───────┘

However, it doesn't seem to work if I give that function a name:

      ∇R←X FOO Y
         R←X+Y
      ∇

      2FOO/1 2 3 4 5
SYNTAX ERROR
μ-Z__pA_LO_REDUCE_X4_B[3]  μ-T←⊂(⊃μ-B3[μ-H;μ-a-μ-M;μ-L])μ-LO⊃μ-T
                           ^    ^

Spacing differently doesn't seem to have any particular effect. Also, I'm not really able to see the relationship between the error message I got and what I typed in, so any insight into what is going on there would be very helpful to me. Thanks!

Rob
  • 14,746
  • 28
  • 47
  • 65
Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77
  • 1
    Probably a bug. I don't have GNU installed, but dyalog gave me a correct result. – Uriel Oct 16 '17 at 23:29
  • @Uriel is there a more standard way to express this? Am I doing something weird or wrong? – Daniel Lyons Oct 17 '17 at 00:24
  • 1
    I don't think so. It is syntatically ok and works with other APLs, so as I wrote, I believe that's an implementation bug. – Uriel Oct 17 '17 at 07:26

2 Answers2

2

It works with the current GNU APL (1.7, svn 1013).

      ∇r←x foo y
[1] r←x + y
[2] ∇
      2 foo / 1 2 3 4
3 5 7
Adám
  • 6,573
  • 20
  • 37
  • I am using the 1.7 release, but you originally wrote and then edited out that it is fixed in subversion, and that is helpful. Thanks! – Daniel Lyons Oct 17 '17 at 13:51
2

as to the insight:

If you call a primitive operator (like /) with a defined function argument (like FOO) then GNU APL does not evaluate the built-in primitive operator but a built-in macro.

The μ- prefix that you see (and which was never meant to be seen in the first place) distinguishes names in built-in macros from user-defined names. If you remove the y- prefix then the error message that you see becomes a little more readable:

Z__pA_LO_REDUCE_X4_B[3] T←⊂(⊃B3[H;a-M;L])LO⊃T

So you got a syntax error in line 3 of (APL macro) Z__pA_LO_REDUCE_X4_B. The source file Macro.def in the GNU APL sources then tell you the full story:

/// reduce N-wise: Z←A LO/[X] B with positive A
//
mac_def(   Z__pA_LO_REDUCE_X4_B,
" Z←A1 (LO Z__pA_LO_REDUCE_X4_B) [X4] B;rho_B3;B3;rho_Z;rho_Z3;T;H;M;L;a;N;I;I_max\n"
" (X4 rho_Z rho_Z3 rho_B3)←X4 ◊ B3←rho_B3⍴B ◊ I_max←⎕IO+⍴I←,⍳⍴Z←(rho_Z3)⍴0 ◊ N←⎕IO\n"
"LOOPN: (H a L)←⊃I[N] ◊ M←A1+1 ◊ T←B3[H;a-A1;L]\n"
"LOOPM: T← ⊂(⊃B3[H;a-M;L]) LO ⊃T ◊ →(0≥M←M+1)⍴LOOPM\n"
"       Z[H;a;L]←T               ◊ →(I_max>N←N+1)⍴LOOPN\n"
" Z←rho_Z⍴Z\n")

In short: mac_def() is a C++ macro that establishes a defined APL system function which uses a "namespace" μ- to avoid name-clashes with user defined names.

  • great under-the-hood answer. there's just one thing I don't yet understand - would you mind explaining why is a syntax error being thrown out of the macdef function? – Uriel Oct 17 '17 at 11:40
  • simply because there was a fault in the macro itself (which has been corrected in the meantime). The error was actually not thrown by mac_def (which is a C++ macro that is expanded at compile-time of GNU APL). but by line 3 (the LOOPM: line). I dont know which SVN version your GNU APL has, but with that version you could: – Jürgen Sauermann Oct 17 '17 at 12:07
  • I tried to explain it better, but failed several times on the 5 Minutes editing limit. – Jürgen Sauermann Oct 17 '17 at 12:27