Zark Example not working

General APL language issues

Zark Example not working

Postby neeraj on Sun May 10, 2020 4:42 am

I was perusing an old issue of Zark and came across this

      ⍴3 0 1/2
4
⍴3 0 1/¨2
(empty)

M←2 3 ⍴⍳6
⍴3 0 1/M
2 4
⍴3 0 1/¨M
2 3


Dyalog APL does not produce these results. Has the behavior or definition of / changed over the decades? Is ⎕ML responsible?
neeraj
 
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: Zark Example not working

Postby Phil Last on Sun May 10, 2020 10:24 am

"/" had in traditional APL two more-or-less unrelated "functions": reduction and compression. Reduction, referred to as "insert" by KEI, is a hidden sequential loop, called "left-fold" in functional languages and is an operator; an "adverb" according to KEI. Compression, enhanced to "Replication" by the allowing of a natural number left "argument" could be seen as a function or an operator; its making no difference in standard APL.

When IBM and Dyalog diverged in their implementation of "nested" APL in about 1982 Dyalog decided to treat replication as a function while IBM maintained its status as an operator.

It makes the difference you've dsicovered because the array left "operand" is bound tightly to the "/" as an operator so applying it under "each" does not match it with the right argument of the derived function but to each item of it. Whereas if "/" is a function then the conformity is applied at the topmost level.

Dyalog has decided to dub "/⌿\⍀", all of which behave this way. as "hybrids".
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Zark Example not working

Postby petermsiegel on Sun May 10, 2020 4:43 pm

And of course you can make a small adjustment:
Code: Select all
       ⍴3 0 1∘/¨2
(empty)
       ⍴3 0 1∘/¨M
2 3
petermsiegel
 
Posts: 141
Joined: Thu Nov 11, 2010 11:04 pm

Re: Zark Example not working

Postby neeraj on Mon May 11, 2020 3:09 am

An adverb takes a noun or verb to create a derived verb. So if I understand correctly in
      3 0 1∘/


we are creating a derived verb which itself is used with the operator ¨ .

Many years ago, in one of an articles I read a long time ago it said that the left operand of / is everything that is to the left of /. I asked KEI this question during a presentation in Toronto and he kind of nodded in agreement but did not explain. I never really understood that statement. So what happens to right to left execution? For e.g.

      4 + 3 0 1 /¨ 2

will probably get evaluated as

      4 + (3 0 1 /¨ 2)

and not as
      (4 + 3 0 1) /¨ 2
neeraj
 
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: Zark Example not working

Postby Roger|Dyalog on Mon May 11, 2020 8:06 pm

neeraj wrote:So what happens to right to left execution?

APL was never entirely "right to left". For example, in the expression (2+3)×4-6 the order of execution is:

      4-6
2+3
(2+3)×(4-6)

Even without parens, it wasn’t entirely “right-to-left”: +/3+⍳4 is evaluated (+/)(3+(⍳4)) and not +(/(3+(⍳4)). A better summary of APL syntax is:

  • Operators are executed before functions.
  • The left argument of an operator is the entire function phrase which precedes it.
  • The right argument of a function is the entire array phrase which follows it.
  • A function is applied dyadically if possible.
  • A parenthesized expression must be completely evaluated before its result can be used.
A more complete and formal description can be found in http://dfns.dyalog.com/n_parse.htm or (coming soon) [Hui and Kromberg 2020].

The treatment of /⌿\⍀ differs between dialects. The implementation of Dyalog APL started in 1982 and version 1.0 released in 1983-04, before information about APL2 became publicly available. Backward compatibility is axiomatic with Dyalog APL and so it was not and is not possible to change the definition. The difference is regrettable but kind of minor.
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest