Reputation: 11377
If I have a vector of functions in APL, is there a way to get a vector of the function names as strings? I have tried DISPLAY and ⍕ without successs:
)copy display
C:\Program Files (x86)\Dyalog\Dyalog APL 16.0 Classic\ws\display.DWS sa
ved Thu Jul 25 08:51:54 2019
functions ← (DISPLAY) DISPLAY
DISPLAY functions
∇DISPLAY ∇DISPLAY ∇DISPLAY
DISPLAY ⍕functions
∇DISPLAY ⍕ ∇DISPLAY ∇DISPLAY
Also, why are there no borders around the elements in the output of the calls to DISPLAY?
Upvotes: 2
Views: 166
Reputation: 701
Unfortunately, APL is not a functional language, so there is no such thing as an array of functions.
What you have in functions
is an 2-train or atop: https://apl.wiki/atop
DISPLAY functions
then becomes an atop of an atop (f(g h))⍵
and DISPLAY⍕functions
is a 3-train or fork: https://apl.wiki/fork
One way you can get close in Dyalog APL is an array of namespaces that all contain similarly named functions. Then you can call all of the functions with the same arguments in one call:
ns_array←⎕ns¨3⍴⊂⍬
ns_array[1].dfn←{⍺+⍵}
ns_array[2].dfn←{2×⍵}
ns_array[3].dfn←{'wow'}
3 ns_array.dfn 42
┌──┬──┬───┐
│45│84│wow│
└──┴──┴───┘
For more information about possible ways to simulate arrays of functions in Dyalog see https://dfns.dyalog.com/n_Function_arrays.htm
As for the DISPLAY
function. It requires an APL array argument. These are names of name class 2. You can get the name class of an array with ⎕NC'name'
.
You might find it nicer to turn boxing on with ]box on
for boxed nested-array display in the session.
In fact, use ]box on -trains=tree
, then type "functions" from your example and hit enter. Then the box user command shows a tree structure of the tacit function you have created. Actually don't do that you'll get large ugly output. Try it with +⌿÷≢
and avg←+⌿÷≢
instead.
Lastly, I generally have ]box on -trains=tree -fns=on
and ]rows -fold=3
in my session (you can save the settings with Session→Save on Windows and {2⎕NQ⎕SE'FileWrite'⊣⎕SE⎕WS'File'⍵}'/path/to/session_file.dse
in RIDE.)
Use ]box -?
and ]rows -?
to see the help for these user commands.
Upvotes: 4