Conversation started Jan 24, 2018 at 18:30.
Jan 24, 2018 18:30
Welcome to the APL learning session!
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.
@Adám why those numbers specifically?
@EriktheOutgolfer Not really any reason. I guess they go from least to most "complex". Try it online!
0 is undefined (but valid name). ¯1 is invalid name.
so I guess (1>⎕NC) can determine if there's anything "attached" to a specific "name"
1 is really rare these days. It is a line label, and can only occur while a tradfn/tradop is running or suspended. Try it online!
@EriktheOutgolfer I'd say 0=⎕NC tells you whether a name is available to you.
@Adám available? hm
Jan 24, 2018 18:40
@EriktheOutgolfer As in, you may use it.
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!
⎕←⎕NC th
@RosLuP
VALUE ERROR
@RosLuP You need quotes.
⎕←⎕NC 'th'
@RosLuP
0
Jan 24, 2018 18:44
@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:
⍞←⎕NC'var' 'ref' ⊣ var←42 ⊣ ref←#
@Adám 2.1 9.2
⎕←⎕NC '⎕NC'
@RosLuP
¯1
yeah good luck assigning to ⎕NC
Using those same codes, you can also use ⎕NL (Name List) to enquire which items of those name classifications are visible: All of dfns' operators.
@EriktheOutgolfer Right, the beauty of having a language where you never risk clashing with a built-in.
Jan 24, 2018 18:48
@Adám "clashing with a built-in" isn't necessarily bad unless you happen to use that built-in, then you're doomed
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 You want all dops that begin with satisfy the regex bs*?
Jan 24, 2018 18:53
@Adám uh, bs.*, but there's a DOMAIN ERROR
⎕←⎕NL '?'
@RosLuP
DOMAIN ERROR
@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.
@EriktheOutgolfer ⎕NL is an ISO system function from long before regex. I guess we don't tinker with it.
Anyway, let's move on.
@RosLuP What are you trying to do?
Jan 24, 2018 18:57
is there a more elegant way of getting a single item array of hello than 1⍴⊂'hello'?
@dzaima ,⊂'hello'
If you find that the name you want to use is unavailable, you may want to EXpunge its current value with ⎕EX:
⍞←⎕NC'var' ⊣ ⎕EX 'var' ⊣ var←42
@Adám 0
I created, removed, and enquired ^
⍞←⎕EX'+'⋄+
@EriktheOutgolfer 0
Jan 24, 2018 18:59
what, it should say +
⍞←⎕EX,'+'⋄+
@EriktheOutgolfer 0
In all operator diadic d 1 2 3 4 d 9 is 1 d 9,2 d 9,3 d 9, 4 d 9?
@EriktheOutgolfer No, it displays the result of ⎕EX which was 0 to tell you that the name is still unavailable (because it is invalid).
⍞←⎕EX'÷'⋄⍞←+
@EriktheOutgolfer 0
Jan 24, 2018 19:01
⎕←EX'+'⋄⎕←+
@EriktheOutgolfer
VALUE ERROR
@RosLuP Only scalar functions map like that. They are + - × ÷ etc.
⎕←⎕EX'+'⋄⎕←+
@EriktheOutgolfer
0
+
Jan 24, 2018 19:02
@EriktheOutgolfer What is the difference in what you entered so that it gave you VALUE ERROR instead of the above ^^ ?
@Adám missing a ⎕
@EriktheOutgolfer No, you cannot expunge built-ins.
@EriktheOutgolfer Oh, right. Silly me.
What does it mean 'scalar function' ? That has its arguments each scalar?
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.
Jan 24, 2018 19:06
@Adám that caused me headaches multiple times. I ended up doing var⊢← 42 and that works by some reason
⎕⊢←var⊢← 42
@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.
@RosLuP bot won't reply since it doesn't start with ⎕← or ⍞←
@RosLuP ^ and that wouldn't work anyway, as you cannot modify .
⎕←var⊢← 42
Jan 24, 2018 19:09
@RosLuP
VALUE ERROR
⍞←var ⊣ var+←42 ⊣ var←42
@Adám 84
@Adám I mean I understand why it works, but why that doesn't have the same shadowing is strange
@RosLuP You increase var's value when it doesn't already exist.
@RosLuP does var exist
ninja :/
Jan 24, 2018 19:10
@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 looks like a bug to me?
@Adám ok that that works is even more strange.
@EriktheOutgolfer @dzaima Why?
@Adám either you shadow it or you don't, not only sometimes (even less in the same expression)
@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 >_>
Jan 24, 2018 19:12
⍞←var ⊣ var+←42 ⊣ var←ava←a
@RosLuP VALUE ERROR
@dzaima The first (the rightmost) var takes the global value because there is no local value. Then the assignment shadows to create a local.
@RosLuP a needs a value.
⍞←var ⊣ var+←42 ⊣ var←ava←3
@RosLuP 45
@EriktheOutgolfer Yeah. Well, at least here you have the option to overwrite or shadow.
Jan 24, 2018 19:15
@Adám the problem is that the overwriting option is pretty shadowed itself
@dzaima shadowed?
maybe some pun...
@Adám It took me a couple minutes to think that ⊢← should work
@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.
@Adám uh, what?
Jan 24, 2018 19:17
But, since this is PPCG, and it may save you a byte or two var∘← will set var globally from inside a dfn, even if it was previously undefined.
⎕←{xorg⊢←⍵}2⋄⎕←xorg
@EriktheOutgolfer
VALUE ERROR
@EriktheOutgolfer Wat?
⎕←{xorg∘←⍵}2⋄⎕←xorg
@EriktheOutgolfer
2
2
Jan 24, 2018 19:18
oh yeah it does happen
@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 It still works in my 17.0 from Jan 17…
@Adám I mean when it gets released
@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:
⍞←⎕Á
Jan 24, 2018 19:30
@Adám ÁÂÃÇÈÊËÌÍÎÏÐÒÓÔÕÙÚÛÝþãìðòõ
isn't that a bit deprecated :P
@EriktheOutgolfer The system function is. But not the usage of those characters in names.
@all CMC: List all characters that a name may begin with without piecing it together by yourself (⎕A,⎕Á,'_∆⍙')
@Adám you forgot 819⌶⎕A :P
@EriktheOutgolfer true. How much more so grounds for the CMC.
Hint: there are actually many more than those.
⎕←xorg←9⋄⎕←{xorg⊢←⍵}2
Jan 24, 2018 19:34
@RosLuP
9
2
I can do it in 19 chars.
@Adám not the circle (underbar) letters right
@EriktheOutgolfer Those too, but there are even more.
Anybody? No?
⍞←n/⍨0≤⎕NC⍪n←⎕UCS⍳1E6
@Adám ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüþ∆∇⍙⍵⍺ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ
@Adám argh, I couldn't remember ⎕UCS
Jan 24, 2018 19:37
@dzaima Hm. As in Universal Character Set? Feel free to ask!
@Adám I forgot the command name :p
@Adám You can't begin a name with ⍺ or ⍵
@dzaima again, feel free to ask :p
@EriktheOutgolfer eh, asking felt like spoiling part of the solution for others
@H.PWiz in dfns they're actually considered variables...
Jan 24, 2018 19:39
Btw, ⎕AV is the Atomic Vector (the character set or "code page") but you don't need to worry about that, especially now with SBCS.
@H.PWiz Well, in a dfn or dop, you can.
@Adám that's what I tried using instead of ⎕UCS⍳1E6 before Erik mentioned underbar letters
@dzaima Right, in Classic, it'd be:
⍞←⎕AV/⍨0≤⎕NC⍪⎕AV
@Adám ⍺⍵_abcdefghijklmnopqrstuvwxyz∆ABCDEFGHIJKLMNOPQRSTUVWXYZ⍙ÁÂÃÇÈÊËÌÍÎÏÐÒÓÔÕÙÚÛÝþãìðòõÀÄÅÆÉÑÖØÜßàáâäåæçèéêëíîïñ∇óôöøùúûü
@Adám I guess I was thinking variable names
@Adám well then a more appropriate CMC would've been all possible 1 letter variable names
Jan 24, 2018 19:41
@dzaima ⍺⍺ and ⍵⍵.
@Adám but not ⍺hello
⎕AV is only really useful to get a quick view at the character set:
⎕←7 32⍴32↓⎕AV
@Adám
pqrstuvwxyz¯.⍬0123456789⊢¥$£¢
∆ABCDEFGHIJKLMNOPQRSTUVWXYZý·
⍙ÁÂÃÇÈÊËÌÍÎÏÐÒÓÔÕÙÚÛÝþãìðòõ{€}⊣⌷
¨ÀÄÅÆ⍨ÉÑÖØÜßàáâäåæçèéêëíîïñ[/⌿\⍀
<≤=≥>≠∨∧-+÷×?∊⍴~↑↓⍳○*⌈⌊∇∘(⊂⊃∩∪⊥⊤
|;,⍱⍲⍒⍋⍉⌽⊖⍟⌹!⍕⍎⍫⍪≡≢óôöø"#&´┘┐┌└
┼─├┤┴┬│@ùúû^ü`∣¶:⍷¿¡⋄←→⍝)] §⎕⍞⍣
@dzaima True.
Btw, the only reason the bot includes and is because I've set it up to run the code inside a dfn:
#tio apl ⎕←n/⍨0≤⎕NC⍪n←⎕UCS⍳1E6
@Adám ooh, that makes much more sense
Jan 24, 2018 19:45
@Adám
ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüþ∆⍙ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ
@dzaima ^ see, now it is running on the bare metal.
@Adám why doesn't C/⍨0≤⎕NC¨C←⎕UCS⍳128 work
⎕←C/⍨0≤⎕NC¨C←⎕UCS⍳128
@EriktheOutgolfer
DOMAIN ERROR
(note: 128 to be replaced with 1E5 as soon as I get around this)
@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:
⍞←⎕SD
Jan 24, 2018 19:52
@Adám 0 0
@all Those are really all the basic system functions. If you've paid attention and have perfect memory, then you are basically APL masters now.
@Adám can't close ⎕SM...
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
@EriktheOutgolfer You have to kill it using its window handle.
@RosLuP but those aren't very golfy, Adám's SBCS doesn't support those...
Jan 24, 2018 19:56
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?
@Adám except that when I click the red X it won't close
@Adám keep what? let's get to the meat, OO!
@EriktheOutgolfer Are you running Marinus code by any chance? It does a tight loops, creating new windows… Golfing!
@Adám no I ran ⎕SM←'lans armstrong'1 1
@EriktheOutgolfer Just clear the workspace with ⎕CLEAR.
@EriktheOutgolfer ⎕SM should be localised (e.g. by being in a dfn). Then when the function terminates, the window will close.
Thank you for participating in the lesson!
 
Conversation ended Jan 24, 2018 at 20:00.