“We do not realize what tremendous power the structure of an habitual language has. It is not an exaggeration to say that it enslaves us through the mechanism of s[emantic] r[eactions] and that the structure which a language exhibits, and impresses upon us unconsciously, is automatically projected upon the world around us.”
—Korzybski (1930) in Science & Sanity p. 90
I’m trying to train myself to choose nouns as names for my functions, in the hope that doing so will help to free me from the procedural mindset, which was pervasive when I learned to program. In those days, coding concentrated more or less exclusively on the manipulation of state and only rarely on the construction of definitions. In saying this, I’m distinguishing procedures, which legitimately deal in state, from functions, which don’t. Transitive verbs: print, init, reverse(vt), … make good names for procedures.
Many of APL’s primitive monadic functions have nouns as names: floor, reciprocal, reverse(n), shape, …
Except this doesn’t quite work. Each of these names seems to need an “of” when applied to an argument, where the of seems to bind to the word that follows it:
⌊÷blah ⍝ "floor of reciprocal of blah"
I’ve seen dyadic iota documented as index-of, though this grates a bit as “index of” isn’t a noun phrase in English. In fact, as far as I know, all of the romance languages would parse Richard of York as Richard (of York), where (of York) is a noun phrase in the genitive case: York’s Richard; Ricardus Eboracum. Nobody seems to parse it (Richard of) York.
So much for that idea for a blog post; ho hum; back to real work.
Then Nick Nickolov found a Wikipedia entry that suggested: “Some languages, such as the Cariban languages, can be said to have a possessed case, used to indicate the other party (the thing possessed) in a possession relationship”. So the (Richard of) parsing would work in one of the Cariban languages and isn’t therefore a property of any deep structure of language, per se.
Now when I see ceiling, I can still think of it as a noun, but in the possessed case. To emphasise this, for the rest of this posting, I’ll write my function names with a back-tick inflection to represent the case: reverse` meaning reverse-of.
⌊÷blah ⍝ floor` reciprocal` blah
… and when reading my code, I can vocalise the ending with a slight [əv] or [ə] sound as in “Land’v plenty”, “Bagguh chips, please”, “Floor’v reciprocal’v blah”.
But what about dyadic functions? Glad you asked. The left argument of a function (arrays are naturally nouns) can be seen as a noun acting as determiner, technically a noun adjunct: coffee table, bicycle thief, cube root, noun adjunct, … Thus: 2-residue`, N-take`, zilde-reshape`, ⎕AV
-index`…
Practising this discipline has been quite illuminating: it has pushed me towards left argument currying. I now mentally parse ¯2⌽V
as (¯2⌽)V
the ((neg-two)-rotation`) V, where neg qualifies two, which in turn qualifies rotation`.
But surely 2+3
is just a symmetrical expression with respect to its arguments? Well yes, but we could also parse it as follows: Starting from the monadic successor` function 1∘+
, the curried dyadic version 1+
would be the one-successor` and so 2+3
is the two-successor` three.
Now, how should we incorporate operators and their operands into this scheme? “The reverse` each` V“, where each` is functioning as a determiner?
PS: Choosing nouns for the names of functions shouldn’t be confused with J’s excellent taxonomy of language components using parts of speech, in which functions are labelled “verbs”.
PPS: Functions reverse`, successor`, shape`, … could also be seen as properties of their argument. A number N has many properties: its successor, its square-root, its floor, ceiling, prime-factorisation vector, … This is beginning to sound a bit like OO…
A rose by any other name smells just as sweet. I believe the design of APL has a much stronger influence on you as a programmer than your choice of function names.
I am glad you addressed dyadic functions in your blog. But you are not going to get away that easily. 🙂 Sure, you can view 2+3 as the second-successor of 3, but what do you make of 1.2+3 or 1j2+3? And then there are +/ and ∘.+ .
To me, functions as verbs (rather than as nouns or properties) have a big advantage, namely that the idea leads well to that monadic operators are adverbs. That is a big win, because
Adverbs are expressively powerful and readily understood from familiarity in natural languages.
If you have n symbols, you can use them to denote n functions, or n÷2 functions and n÷2 operators, n versus (n÷2)*2 computations.
Each operator can be viewed as a family of functions, and understanding one member of a family goes a long way towards understanding all members of a family.
Ken Iverson called dyadic operators conjunctions, and used the example of “run and hide” where “and” is a “copulative conjunction”. I can use dyadic operators without trouble even though I have never really understood the description or example (run and hide). I did not bother to ask Ken when I had the chance, operating again from the stance of a rose by any other name etc. I see that “copulative conjunction” as a phrase gets lots of hits in Google. Perhaps I should look into it.
I agree with you. The classification into verbs, adverbs, conjunctions, etc is very appealing and helpful. My point is just that, for example, “successor” is a better name than “increment” for the monadic verb 1∘+, because it doesn’t increment(vt) its argument; it leaves it alone and denotes its successor(n) as result.
In contrast, I once worked with a FORTRAN system, in which it was possible to write a subroutine INCREMENT(3), which actually did “increment the value of 3”, so that a subsequent use of the expression (2+3) would evaluate to 6. This feature, and anyone who used it, did not become popular.
“… did not become popular.” Understatement, one of the more endearing English traits.