NYCJUG/notationFAQ
< NYCJUG
Jump to navigation
Jump to search
Some frequently-asked questions regarding notation of APL and related languages.
Order of Operations
The following, from http://compilers.iecc.com/comparch/article/96-09-086, gives a couple of reasons why right-to-left evaluation makes more sense than evaluation in the other direction in the context of an array-processing language. A more complete list of the advantages of this direction are given here.
From: "Devon McCormick" <devon_mccormick@smb.com> Newsgroups: comp.compilers Date: 17 Sep 1996 00:20:30 -0400 Organization: Compilers Central References: 96-09-021 Keywords: design On 5 September 1996, Nils M. Holm asks: > Given a language without any operator precedence, would you prefer > > 1) evaluation from the left to the right, like a sequence of identical > Operations in C [a - b + c = (a - b) + c] > > or > > 2) evaluation from the right to the left, like in APL? > [a - b + c = a - (b + c)] > > What are the reasons for your choice? There are 2 related reasons APL chooses right to left precedence: 1) the language supports the notion of applying a function across an array, e.g. +/1 2 3 <-> 1 + 2 + 3, or (for infix function f) f / 1 2 3 <-> 1 f 2 f 3; 2) for a non-commutative function, such as minus, the result is much more interesting evaluated right to left, e.g. -/1 2 3 4 5 becomes the alternating sum (((1 - 2) + 3) - 4) + 5; if evaluation were as in conventional mathematics, this would be equivalent to the less interesting 1 - (2 + 3 + 4 + 5). Similarly, division across a vector gives a continued fraction instead of the first number divided by the product of the remaining numbers. I can find the citation of this if you are interested. -- Devon McCormick devon_mccormick@smb.com
Also, take a look at this small dissertation on the fallacy of "standard mathematical notation".