@J.Sallé I tried to golf it further, this is the best so far: (⊂|¨∘-∘⍳∧/)⍳∘⊂⊢|⍳∘≢ The challenge itself seems to be off by one, and that prevents shorter solutions. I think the answer for [15] should be 0.
@ngn No, I mean in Dyalog APL, characters are just characters. You need not worry about representation, and monadic ⎕UCS converts back and forth between characters and integers.
@ngn If an application needs ⎕DR then I'd question its methods.
@Adám Yeah tell me about it. I got a whole application developed that runs on any physical machine (unix and pc alike), but when we Docker it into our cloud server the underlying DB breaks because it's not UTF-8.
@Adám Hahahah! I'd love to convince the whole company to switch from Delphi and Java to APL but I highly doubt that's gonna happen.
@ngn our DBA said it shouldn't happen at all because the original DB we backed up to use in the Docker environment is encoded in UTF-8, but apparently the VM disagrees vehemently.
@ngn There's also "Portuguese.1252" and "Portuguese_Brazil.1252" which seem to be relevant. My boss said he's found a fix, but he's not in until later this afternoon.
Informal APL learning session tonight at 18:30 UTC in https://chat.stackexchange.com/rooms/52405/apl. See https://chat.stackexchange.com/transcript/message/41299896 if you don't have 20 Stack Exchange rep points.
is there some way to get all the sizes of an array? i.e. {⍵ ⍵ ⍵ ⍵}(3 1⍴⊂(1 2 3)(4 5 6)) would give (4) (3 1) (2) (3) or similar (if I've understood my code correctly)
@dzaima Good. Unfortunately ]box will not give you the numbers in the frames. Although I've suggested that we fold all the various display tools from dfns into ]box.
@Adám the first form (n f\ a) specifies how many times (n) to iterate the function (f) over the array (a); the second form iterates until convergence - like apl's "fixed point" operator but preserving intermediate results
@ngn The second form is unfortunately more tricky without having some special value indicating repetition until seen-before/first∨last. Didn't we discuss this before?
@Adám an empty result is a valid result, it might be what the programmer intended
@Adám I mean, that zilde might be the result of some expression which just happens to return an empty result. In that case the result from ⍣ should be empty too.
@ngn No, I mean, if we extend ⍣ to handle vectors (or for that sake any simple array) then ⍣⍬ clearly means none. But if we instead let ⍢n mean all iterations from 0 to n, then ⍢⍬ can mean until repeat.
@ngn well, you can implement it as atop ← {⍺←⊢⋄⍺(⍺⍺ ⍵⍵)⍵}, but as a primitive it would make stuff really simpler...next step is to, of course, be able to assign to primitives (maybe primitive∘←function or primitive(⊢←)function should be allowed)
@ngn another way to see it is that, well, why have compose (∘) but not atop (⍤)?
@ngn and, as Adám said, ((this(((is((schizophre((n((ia))))))))))) ;)
@EriktheOutgolfer Uh, or just atop ← {⍺←⊢⋄⍺⍺ ⍺ ⍵⍵ ⍵}. But Dyalog will never allow assignment to primitives like ngn/apl does. There is, however, a possibility we'll allow custom overloading of primitives for classes:
that means there's no possibility that's a variable, and it's undefined, that means it can never be defined, so it's always an error, so it's a syntax error
@Adám I don't have many keys available, Alt is for NARS2000, AltGr is compose key (WinCompose), Shift is used too often...hm, maybe I'll put it to Right Ctrl, but would be uncomfortable...
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?