Loops, Folds and Tuples
For-loops Given an initial state defined by a number of variables, a for-loop iterates through its argument array modifying the state. A←… ⋄ B←… ⋄ C←… ⍝ initial state :For item :In items ⍝ iterating through array “items” A←A … item ⍝ new value for A depending on item C←C … A … item ⍝ new value for C depending on A and item … ⍝ state updated :EndFor A B C ⍝ […]
Type Comments
I’ve taken to commenting the closing brace of my inner dfns with a home-grown type notation pinched from the Functional Programming community: dref←{ ⍝ Value for name ⍵ in dictionary ⍺ names values←⍺ ⍝ dictionary pair (names⍳⊂⍵)⊃values ⍝ value corresponding to name ⍵ } ⍝ :: Value ← Dict ∇ Name I keep changing my […]
Name Colouring for Dfns
APL is sometimes criticised because expressions that include names cannot, in general, be parsed without knowing whether the names represent functions or variables. For example, the name thing in the expression thing⍳3 could reference an array (in which case the ⍳ is dyadic) or it could reference a function (making the ⍳ monadic). An APL […]
Foo, Shmoo
“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 […]
Musings on Reduction
In one man’s humble opinion, reduction (⌿) is the Queen of Operators. Each (¨) comes a close second, but doesn’t get the cigar because each can be written in terms of reduction. Two special cases are of interest: reduction along axes of length 1 (or reduction of a scalar) and reduction along axes of length […]
Selective Expression Tracing
Operator trace from dfns.dws is a simple and low-tech tool for displaying intermediate results of functions, during the evaluation of an expression. For example, what’s going on here? (+⌿ ÷ ≢) 1 2 3 4 2.5 We can guess that the above fork is computing the average of the right argument. To see how this works: )copy dfns […]
Data-driven Conditionals
ACKNOWLEDGEMENT: My thanks to Andy Shiers for simplifying the examples Visitors to APL from other languages are sometimes a bit sniffy about our use of numbers (1 0) for Boolean values True and False. They’re further bemused by our fondness for moving conditional processing out of code and into data. For example, instead of: 0=2|⍵: […]