We're going through system functions. Let's continue with various such which deal with functions and other items under program control.
If you want to have an application start without having the user enter a command (e.g. a function name) to boot it, you can assign an expression to ⎕LX (Latent eXpression) and then save your workspace with ⎕SAVE. When the workspace is loaded (including from the command line) APL will do ⍎⎕LX.
This is what happens when you load the various workspaces supplied with APL: Try it online!
Since APL does not enforce a naming scheme, you may wonder what a certain name is.
⎕NC (Name Classification) to the rescue!
Each type of item has a number. 2 is variable, 3 is function, 4 is operator, 9 is object.
Sometimes you want even more info. If the argument to ⎕NC is nested, then the values get a decimal which mean: .1=traditional, .2=field/direct, .3=property/tacit, .4=class, .5=interface, .6=external class, .7=external interface. Try it online!
@RosLuP There you go! All names will be 0 for the bot, since it is running a new clean session each time. However you can define some things and then look:
You can also specify decimals to get just those specific things. and you can get just things beginning with specific letters by giving a list of letters as left argument: Try it online!
If you'd rather have a VTV (vector of text vectors, i.e. a list of strings), then use negative numbers. APLers often use this shortcut to list everything: ⎕NL-⍳9
@EriktheOutgolfer Yeah, there is no facility for that 'bs' ⎕NL 4.2 just gives you dops that begin with b or with s, but you can do 'bs.*'⎕S'&'⎕NL ¯4.2.
If you only want to use an already used name temporarily, then you can use ⎕SHADOW instead of ⎕EX. The name will then be freed up for your use until the current function terminates.
Note that shadowing happens automatically in dfns and dops when you just do regular assignments. I.e. in a dfn, var←42 really means ⎕SHADOW 'var' ⋄ var←42.
I wouldn't recommend using ⎕SHADOW though. It is much better to localise your variables in the function header by putting ;varName at the end of the header.
@dzaima Yes, regular assignments. You can access global names, and modify them to with modified assignment, which is why var⊢←42 works. It is just like var+←42 adds 42 to the current value, but instead it replaces the current value completely.
@dzaima You wouldn't want to shadow if you explicitly modify the existing variable, would you? If you want a new var based on the global var, but without overwriting the global, do var←var+42
@Adám maybe I'm too used to Python's behavior where var+=5 in a function doesn't affect the global var...then again you can't assign to a global var without mentioning it explicitly with global in the function >_>
@EriktheOutgolfer Btw, there is bug which allows you to assign to an undefined global name from inside a dfn, but I'm not really supposed to tell you, since it may go away without warning.
@EriktheOutgolfer But it is a quirk of how ← is implemented, so only use it for golfing, never for production. In FP, you shouldn't set globals, and dfns are designed for FP.
@Adám well, in that case, I hope for the "bug" to remain in Dyalog 17.0 :P >_> remembers APL isn't intended for golfing please, please, please make the bug go away ASAP
@EriktheOutgolfer I'm pretty sure it will stay for a while, as customer production code may use it.
OK, let's say you've build a bunch of functions that call each other, and then you run it, and it stops due to some bug. Now you need some situational awareness.
You already know that ⎕NL will let you check which names are defined, and ⎕NC what type of things they are.
⎕SI (Stack Indicator) will give you a list of function names on the stack: Try it online!
⎕LC (Line Count) will give you a list of corresponding line numbers where each function in ⎕SI is holding: Try it online!
If you get a WS FULL error, you may want to check how much memory is being used to represent a variable. Use ⎕SIZE: Try it online!
And of course you need to know how much Workspace Available (⎕WA) you have: Try it online!
@all Any questions before we move to the miscellaneous category?
Just for reference, you may want to know which non-ASCII characters are allowed in names:
@EriktheOutgolfer Because ⎕NC returns a vector (it is intended to run with name lists in the style of ⎕NL's result), and you can't use a vector of vectors to compress.
If you want to create an old school application with a terminal style UI, then you can use ⎕SM (Screen Map). For good reason, I can't demo this on TIO or TryAPL, but Marinus has used it on occasion.
⎕SD are the Screen Dimensions, but since TIO is running head-less:
One could use ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ for name of function and operators; the usual letter for variables ... So do not are possible names subscript and top script... If one has name for a function as above one can definitely eliminate spaces for example Ⓓa (as Ⓓ function call; apply to variable a) and compose names the same
Of course, there are still plenty of things we have not covered. OO for instance. Another subject would be programming techniques and keeping order in your APL code. What do you guys want to address next week?