[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] Dyadic / (replicate) does not work w ith ¨ (each)
From: |
Nick Lobachevsky |
Subject: |
Re: [Bug-apl] Dyadic / (replicate) does not work w ith ¨ (each) |
Date: |
Sat, 15 Feb 2014 07:49:54 +0100 |
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.
http://www.scribd.com/doc/124733639/APL2-Language-Reference-Manual
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'
LENGTH ERROR
+/⊃(//)⎕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'
LENGTH ERROR
+/⊃(//)⎕VFI '1 2 3 cat'
6
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.