APL - System Functions

-- under construction --

Here are some ideas about new system functions for manipulating APL internals. Such as primitives mappings, user function overrides, diagnostics, statistics.

Obtain a list of token names for APL primitives.


Get a token's ID - to be used in other functions.


In this case the token 'CIRC' will have an ID of 4. It is calculated from its ordering in the alphabetic list.

Caution: This ID may change with different versions of the APL environment. The current ID must always be obtained from the current version and not be relied on to remain the same across releases or versions.

Obtain the token's type. The argument can be the name of a user function or the ID of a token.


In this case token 'CIRC' will have a type 20. The number is the sum of one or more of these attributes:

1 - niladic

2 - monadic

4 - dyadic

8 - can accept axis parameter

16 - can be used to moderate an operator

Obtain an object's valence mask. This is a number composed of the sum of valence codes.


Note - this is a static value. Part of the object's definition. This would be defined in the user function's header form. It is NOT the (potentially) dynamic valence with which the function is currently being called in the case of ambivalent functions.

Here is a list of valence masks defined for various objects.

1 - niladic - user fns, user vars, constants (numbers, strings)

2 - monadic - some APL primitives, user fns

4 - dyadic - some APL primitives, user fns

6 - ambivalent - some APL primitives, user fns

Inquire or set a primitive token's function.


When used monadically (no left argument) it returns the token's current function name. The default is an empty string for tokens. This means the token is executing internal code.

The user can override primitive tokens by supplying the name of their own APL function. This is used to try out experimental algorithms or to insert counters for statical profiling.


In the above example the APL primitive for 'Pi times' is overridden with the user's own APL function 'TESTPI2'.

Revised 6 May 2020