Assigning a niladic function

symbol to string in kdb
kdb list of integers
list of symbols kdb
indexing in kdb
kdb+ divide
kdb+ operator
cast to integer kdb+
0 operator kdb

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}

Niladic function, In APL syntax, a niladic function is a special type of function that takes no arguments and is evaluated immediately when it is encountered in a statement. The function header defines whether a custom function is niladic (no arguments), monadic (one right argument) or dyadic (left and right arguments), the local name of the result (to the left of the ← assign arrow), and whether it has any local variables (each separated by semicolon ';').

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.

Argument, In APL syntax, an argument is one of the values passed to a function. The valence of a function is determined by the number of arguments it takes: niladic  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.

I'm not sure what you're trying to do so forgive me for answering the wrong question.

To me it sounds like you want an optional right argument. In APL2 I would do something like this:

'' ⎕EA 'G←F ra'

If ra is undefined, the Value Error will be caught and nothing happens. If you want a default value for G, make that assignment to the left of EA.

6. Functions - Q for Mortals, In particular, a function can be assigned to a variable, whereupon it acquires a name. A nullary function in q is a function that has no meaningful input. This is​  Niladic functions are functions that do not accept any parameters, are specified without parentheses, and return only one result. Following is the list of Niladic functions: Niladic function (SQL-92)

Functions – thinq-kdb, Assigning the function to function name(f in the case above) is optional. A function is assigned to a variable to name it. Niladic – A function with valence 0​. (computing) Of an operator or function in a program, having no arguments

A Control Operator, In current APL, the “niladic-function syndrome” prohibits named-function assignment because its niladic functions are syntactic anomalies: while F F1 (​with F1 a  Definition of niladic in the Definitions.net dictionary. Meaning of niladic. What does niladic mean? Information and translations of niladic in the most comprehensive dictionary definitions resource on the web.

User-defined Functions and Operators, Such functions are called niladic functions. as a right argument to another (​possibly user-defined) function, or simply displayed, by not making any assignment. The development of these ideas led to an elegant, consistent underlying structure for all procedures, where a procedure is defined as a structured sequence of APL expressions, instances of which

Comments
  • Some APL dialects allow treating a function like a sort of value, using to assign such function values to a name, reminiscent of some proposals by Iverson. E.g. Sum←{+/⍵} ( is the right argument) and or even Sum←+/. They may also allow using names of functions in further function definitions, e.g. ColSum←Sum⍉. However, this doesn't work for niladic functions, as they immediately return a value rather than be treated as a value. OP is asking how to do it for niladic functions.