bug-apl
[Top][All Lists]
Advanced

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

Re: [Bug-apl] Rank operator and function assignment


From: Juergen Sauermann
Subject: Re: [Bug-apl] Rank operator and function assignment
Date: Tue, 04 Mar 2014 18:53:29 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130330 Thunderbird/17.0.5

Hi Elias,

I assume by spec you mean ISO/IEC 13751.

They give the following syntax:

Z ← f ⍤y B (deriving monadically) and
Z ← A f ⍤y B (deriving dyadically).

They say that f ⍤y is a function which is then called with arguments B and possibly A.
Thus Z is a value and not a function; the function is created internally.

The problem with ⍤ is its ambiguity regarding y.
y is expected to be a vector with 1, 2, or 3 elements.
Now look at:

      +⍤1 2 3 4 5
AXIS ERROR
      +⍤1 2 3 4 5
      ^^
The problem is that this could mean several things:

      +⍤1 (2 3 4 5)
2 3 4 5
      +⍤1 2 (3 4 5)
3 4 5
      +⍤1 2 3 (4 5)
4 5

In your example,

      {'foo',⍵}⍤1 4 5⍴⍳10

first 1 4 5⍴⍳10 is computed  and then {'foo',⍵}⍤y B with an empty y
and B the result of 1 4 5⍴⍳10.
The empty y then causes the axis error.

What you probably intended to do is:

      {'foo',⍵}⍤1 (4 5⍴⍳10)
foo 1 2 3 4  5
foo 6 7 8 9 10
foo 1 2 3 4  5
foo 6 7 8 9 10

In GNU APL you can put the y in axis brackets to resolve the ambiguity.
I personally believe [y] B is a clearer syntax than y B.

      {'foo',⍵}⍤[1] 4 5⍴⍳10
foo 1 2 3 4  5
foo 6 7 8 9 10
foo 1 2 3 4  5
foo 6 7 8 9 10

/// Jürgen


n 03/04/2014 05:28 PM, Elias Mårtenson wrote:
I was playing around with the Rank Operator, which is something that isn't really documented in many places. I only saw references to it in the spec, while neither APL2 nor Dyalog mentions it.

Now, there are a few things that behaves strangely, although it may be correct.

First of all, the following works (]BOXING is 8):

      xx ← 4 5⍴⍳10
      {'foo',⍵}⍤1 xx
┌→─────────────┐
↓foo 1 2 3 4  5│
│foo 6 7 8 9 10│
│foo 1 2 3 4  5│
│foo 6 7 8 9 10│
└──────────────┘

But the following does not:

      {'foo',⍵}⍤1 4 5⍴⍳10
RANK ERROR
      λ1⍤1 4 5⍴⍳10
      ^ ^
      ({'foo',⍵}⍤1) 4 5⍴⍳10
RANK ERROR
      (λ1⍤1)4 5⍴⍳10
       ^        ^

Also, the spec says it returns a function, but I can't assign it to a variable:

      a ← {'foo',⍵}⍤1
RANK ERROR
      a←λ1⍤1
        ^ ^

I suppose the last one is expected, since xy←+/ also does not work (but should it?)

Is the behaviour correct, or is there a problem with the parsing?

Regards,
Elias



reply via email to

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