A non-niladic function F can be assigned to a variable G with
G ← F
However, if F is niladic, how do I prevent it from being evaluated?
You can't.
In a way, niladic functions behave like arrays, except their value isn't determined until they are used. This also means that they exhibit value semantics rather than reference semantics. Note also, that niladic functions cannot be operands of operators, but rather their result will become the operand.
A way to circumvent both of these issues, is to wrap the niladic function in a dfn so that it takes a dummy argument (or two), and thus:
G←{F}
APL evaluates expressions from right to left. As soon as all arguments of a function are present the function is evaluated and the function and its arguments are replaced by the result of the evaluation.
Now consider your example G←F. If F is monadic or duadic, then F cannot be evaluated because its right argument is missing. In parser terminology the token F is shifted rather than being reduced, The first expression that can be reduced is then G←F which assigns F to G.
On the other hand, if F is niladic, then F can be (and therefore will be) evaluated immediately (with, say, result Z), so that the assignmet will be G←Z and not G←F.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With