[Top][All Lists]

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

Re: [Bug-apl] Dyadic / (replicate) does not work with ¨ (each)

From: Juergen Sauermann
Subject: Re: [Bug-apl] Dyadic / (replicate) does not work with ¨ (each)
Date: Mon, 17 Feb 2014 19:44:35 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130330 Thunderbird/17.0.5


I have changed the parser to degrade / and friends from operator to function in the examples below.

One remaining case is (with / any of / ⌿ \ or ⍀):


where the left / is a function when S is a value and and an operator if S is a function (which is not known at parse time). The binding rules do not help in this
case because there are different bindings when / is a function and when
/ is an operator. Both cases are valid. To deal with this special case,
one can put S in parentheses:


In that case S is assumed to be a value (and the left / is function compress).

See SVN 133.

/// Jürgen

On 02/15/2014 07:49 AM, Nick Lobachevsky wrote:
The / and \ symbols (and their first coordinate versions ⌿ and ⍀) were
overloaded from the start.  Not enough characters on the 2741 typeball
or something.  Symbol pressure.
First, they are the compression and expansion functions.
1 0 1 / 1 2 3
Second, they are the reduction and scan operators.
+/1 2 3
This was well and good until the introduction of APL2 language
extensions such as allowing user functions and functions other than
the 21 scalar dyadic functions as the function argument to scan and
reduction (plus/1 2 3).  Now use of / in the context of an operator
argument results in a syntactic ambiguity.  For more info, check APL2
binding strength.


There were some papers from Phil Benkhard at IBM.

Normally, the workaround to this problem was for the programmer to
supply a cover function for reduction, exactly as in your example.
IBM APL2 and APL2000 would need this.  Dyalog, however, has got this
to work, but not without consequences.  Consider the following:

       //(1 0 1) (1 2 3)
1 3

This would read as "compress reduction".  (In C++ and Java etc. it
would be a comment)

Dyalog also has a system function called []VFI, a kind of portmaneu of
[]VI and []FI, introduced by STSC in the 1960s, available today with
APL2000.  []VI '1 2 3 cat' would return 1 1 1 0, the 1s marking valid
numbers, while []FI '1 2 3 cat' would return 1 2 3 0, converting valid
strings to numbers and invalid ones to zero.  A typical usage might be
([]VI x)/[]FI x.  Dyalog combined them together, such that []VFI '1 2
3 cat' would return a nested vector (1 1 1 0).  But I digress, but to
show there actually exists a practical application.

       //⎕VFI '1 2 3 cat'
1 2 3

But now try

       +///⎕VFI '1 2 3 cat'

       +/⊃(//)⎕VFI '1 2 3 cat'
  1 2 3

This would be a "plus reduction compress reduction", which also does
not return the expected answer of 6.

       +/⊃//⎕VFI '1 2 3 cat'

       +/⊃(//)⎕VFI '1 2 3 cat'

This works in Dyalog, possibly some others.  Plus reduction reduce,
and this works because of the (relatively) new dyadic reduction, 2+/1
2 3 4 5.

       +//(2) (1 2 3 4 5)
  3 5 7 9

In short, to avoid this problem altogether, possibly to avoid
introducing problems in the language parser, some implementations may
disallow / and \ functions as operator arguments.

reply via email to

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