the first APL one-liner ever written

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

the first APL one-liner ever written

Postby Roger|Dyalog on Sat May 02, 2020 6:46 pm

What is the first APL one-liner ever written? Is that even knowable? I have a possible contender. (And a contender for the second APL one-liner ever written.) From Some Exercises in APL Language Design, §28:

      x← 5 ¯2.7 0 6

1 ¯1 0 1

x × (x>0)-(x<0)
5 2.7 0 6

The expression (x>0)-(x<0) is probably the first APL one-liner ever written (A Programming Language, 1962, §1.4). What makes it work are that propositions have result 0 or 1 rather than true or false and that functions work on entire arrays rather than just on scalars.

Falkoff and Iverson explained the 0-1 definition in The Design of APL in characteristically plain but telling language:
A very general and useful set of functions was introduced by adopting the relation symbols < ≤ = ≥ > ≠ to represent functions (i.e., propositions) rather than assertions. The result of any proposition was defined to be 0 or 1 (rather than, say, true or false) so that it would lie in the domain of other arithmetic functions. …

The adoption of the relation symbols as functions does not preclude their use as assertions in informal sentences. For example, although one might feel compelled to substitute “x≤y is true” for “x≤y” in the sentence “If x≤y then (x<y)∨(x=y)”, there is no more reason to do so than to substitute “Bob is there is true” for “Bob is there” in the sentence which begins “If Bob is there then …”.

Knuth wrote enthusiastically about this (the 0-1 thing, not the array thing) in Two Notes on Notation 1992, calling it Iverson’s convention or Iverson brackets and saying that it led to “substantial improvements in exposition and technique”. If the worked examples in TNN look familiar it’s because the simplification steps resemble APL golfing.
Posts: 207
Joined: Thu Jul 28, 2011 10:53 am

Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest