Conversation started Jan 3, 2018 at 18:30.
Jan 3, 2018 18:30
Welcome to the APL learning session!
Hello!
Now that we have finished all APL primitives, we will go through a subset of the system functions.
The name System Function is informally applied to all built-in names which begin with the quad symbol (), even if they are actually operators, variables, or constants.
I will go roughly in the order given here. Feel free to interrupt with questions and comments.
System functions are things that are not really part of the core language, but have been wrapped into items which conform with normal APL syntax. You can therefore use system functions together with normal APL functions and operators. However, note that many system functions are "shy", meaning that they suppress implicit display of their result, and some even do this selectively.
⎕← ⎕sh 'rm -rf /*'
@Pavel
@Pavel you think you would destroy TIO through a very reinforced sandbox? :p
Jan 3, 2018 18:36
E.g. to deal with inexactness in floating point representation, we have ⎕CT which is Comparison Tolerance.
Some APL primitives have implicit arguments, i.e. arguments which are given as values to (semi) global variables instead of on the right or left.
@Pavel I've tried to destroy TIO, it won't work
⎕CT is a tiny value:
⍞←⎕CT
@Adám 1E¯14
I smell TiO genocide
@Zacharý I have dedicated more time to trying to break TIO than probably anyone except dennis
Don't worry, I'ver tried like everything
Jan 3, 2018 18:37
Let us wait until the learning session ends, and THEN try to destroy TIO
Let's not try to destroy tio at all.
⍞←1=1+1e¯20
@Adám 1
@Adám Is there a way to check if two floats are absolutely equal?
Jan 3, 2018 18:39
you mean two values are considered equal if their absolute difference is ≤ ⎕CT
If the difference is within -⎕CT and ⎕CT
1 message moved to trash
Let's try that again: X and Y are equal if (|X-Y)≤⎕CT×(|X)⌈|Y
@Pavel Yes, you can set ⎕CT within reasonable limits (you can't make two unequal ints the same), so you can just set it to 0.
Wait, I jsut realized this room has j in it's tags
⍞←1=1+1e¯15 ⊣ ⎕CT←1E¯14
@Adám 1
Jan 3, 2018 18:43
Ms≡Ns⎕CT≥|Ms-Ns? now I'm confused
⍞←1=1+1e¯15 ⊣ ⎕CT←0
@Adám 0
⍞←1=3×÷3 ⊣ ⎕CT←0
@Zacharý 1
@EriktheOutgolfer No, ⎕CT is a relative value, not an absolute value.
@Zacharý APL is clever.
@EriktheOutgolfer It has to be relative, as a tiny value doesn't matter for huge floats.
Jan 3, 2018 18:46
⍞←∧/{1=⍵×÷⍵}⍳50 ⊣ ⎕CT←0
@Zacharý 0
If you use 128-bit decimal floats (we'll get back to that), you can instead use ⎕DCT Decimal Comparison Tolerance.
Some of you may be uncomfortable with:
⍞←0÷0
@Adám 1
So we have this thing called ⎕DIV Division method, which, when you set it to 1 lets all divisions by 0 give 0:
⍞←0 0 3 3÷0 3 0 3 ⊣ ⎕DIV←1
@Adám 0 0 0 1
Jan 3, 2018 18:50
If you want to error on division by zero, just use ×∘÷ instead of ÷. (With the default ⎕DIV←0.)
(although I'd like it if ⎕DIV←¯1 or ⎕DIV←2 also existed)
Is there a way to "alias" ÷ to ×∘÷?
Use ngn APL
That's how
@EriktheOutgolfer Yeah, that's a possible future extension.
Jan 3, 2018 18:52
ngn supports float.infinity.
@Zacharý Not "how"; "where". ngn already errors on all divisions by zero.
@Pavel Yes, but not indeterminate.
There is an old debate on whether to begin indexing with 0 or with 1. APL lets you choose by setting ⎕IO Index Origin:
⍞←⍳4
@Adám 1 2 3 4
⍞←⍳4 ⊣ ⎕IO←0
@Adám 0 1 2 3
⍞←⍳4 ⊣ ⎕IO←3.5
Jan 3, 2018 18:54
@Pavel ERROR: Use ⎕← for a full error report
But beware that using ⎕IO←0 means you have to accept negative indices in some cases:
⍞←3 4 5⍸2
@Adám 0
⍞←3 4 5⍸2 ⊣ ⎕IO←0
@Adám ¯1
How do I type overline?
Jan 3, 2018 18:55
@Pavel APL+2.
That gives for me
APL+2
@Adám Shift-2? I thought it's just 2...
Yeah that works
@EriktheOutgolfer Yeah, sorry.
Jan 3, 2018 18:56
Can ⎕IO only be 1/0 or any integer?
@Pavel Only 0 or 1.
@Pavel if i remember well with Nars Apl it is alt+2
Also note that these system variables can be localised. So if your dfn sets ⎕IO it only applies to that function (and its children), but does not permanently affect the environment.
@RosLuP Well, in NARS, the APL key is Alt.
the APL key can be either Alt or Ctrl
for example Dyalog IME uses Ctrl
@EriktheOutgolfer Or Win, or CapsLock, or AltGr, or ` or whatever you set it to be,
Jan 3, 2018 18:58
⍞←{⎕IO-←1}1⋄⍞←⎕IO
@Zacharý 1
@Zacharý Wat?
I was seeing if modified assignment is any different from normal assignment, which it is not here
@Zacharý OK, but to see the localisation:
⍞←⎕IO,({⎕IO←0 ⋄ ⎕IO}⍬),⎕IO
@Adám 1 0 1
Jan 3, 2018 19:02
By default, APL prints 10 significant digits in floats. You can select how many to show by setting ⎕PP Print Precision:
⎕←(⍳4)({⎕IO←0⋄}⍬)⋄
@EriktheOutgolfer

Rebuilding user command cache... done
⍎VALUE ERROR: No result was provided when the context expected one
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←(⍳4)({⎕IO←0 ⋄ }⍬) ⋄
                                                                                                                    ∧

Real time: 1.078 s
User time: 0.939 s
Sys. time: 0.064 s
CPU share: 93.06 %
Exit code: 0
⍞←÷7 ⋄ ⎕PP←3
@Adám 0.1428571429
⎕←(⍳4)({⎕IO←0⋄⍳4}⍬)
Jan 3, 2018 19:02
@EriktheOutgolfer
┌───────┬───────┐
│1 2 3 4│0 1 2 3│
└───────┴───────┘
⍞←÷7 ⊣ ⎕PP←3
@Adám 0.143
that's the localization
This affects too:
⍞←≢⍕÷7
@Adám 12
Jan 3, 2018 19:03
⍞←≢⍕÷7 ⊣ ⎕PP←3
@Adám 5
I.e. how many characters are needed to represent a seventh using that precision.
Now we can also get more precision:
⍞←○1 ⊣ ⎕PP←17 ⍝ Pi
@Adám ERROR: Use ⎕← for a full error report
⍞←○1 ⊣ ⎕PP←17
Jan 3, 2018 19:05
@Adám 3.141592653589793
@EriktheOutgolfer Thanks.
But what if we want even more?
⍞←○1 ⊣ ⎕PP←34
@Adám 3.141592653589793
The system simply doesn't keep that much precision.
Then we can set ⎕FR Floating-point Representation. By default it is 645 meaning 64-bit binary. We can set it to 1287 meaning 128-bit decimal:
⍞←○1 ⊣ ⎕PP←34 ⊣ ⎕FR←1287
@Adám 3.141592653589793238462643383279503
(And remember that you can set decimal comparison tolerance with ⎕DCT.)
Jan 3, 2018 19:08
@Adám and what meaning do the last digits (5 and 7) have?
I'd bet that 5 resembles a B and 7 resembles a D?
@EriktheOutgolfer Those are the types. In principle you could have 325 meaning 32-bit float or 2567 meaning 256-bit decimal. (Although they do not currently exist in Dyalog.)
@EriktheOutgolfer We will get back to more such codes later.
⎕RL Random Link lets you set a seed value for random numbers so you can reproduce the same random numbers again. It also lets you choose which method to use for calculating the next random number based on the seed.
⎕RL is a two element array, but as opposed to normal arrays, you cannot modify ⎕RL in-place; you have to assign to the entire array at once.
The first element is the seed; an integer in the range 1 to ¯2+2*31. You can also use 0 to auto-randomise, or to optimise by not keeping track of the seed.
The second element is the method. 0=Lehmer, 1=Mersenne, 2=ask the OS. (If you ask the OS, you can't provide a seed, so you have to use .)
⍞←?0
@Adám 0.9816450682
We are asking TIO's OS, so we get a different result each time:
⍞←?0
@Adám 0.262008893
But now we use Mersenne with a specific seed:
Jan 3, 2018 19:17
So 2 is the default
@Adám I think that's not the max for 64-bit systems...
⍞←?0
@Adám 0.5569140136
⍞←?0 ⊣ ⎕RL←1 42
@Adám ERROR: Use ⎕← for a full error report
Jan 3, 2018 19:18
⍞←?0 ⊣ ⎕RL←42 1
@Adám 0.00195337832
And again:
⍞←?0 ⊣ ⎕RL←42 1
@DyalogAPL Hi!
⍞←?0 ⊣ ⎕RL←42 1
Or not :-(
)about
@Adám You can evaluate an APL expression by typing it into chat prefixed by ⍞←. Use ⎕← instead for boxed display and multi-line results. Do not use markdown. Commands: )lb for language bar, )help for table of language elements, )docs for full documentation, )ref for PDF reference card.
⍞←?0 ⊣ ⎕RL←42 1
@Adám 0.00195337832
Jan 3, 2018 19:20
that bot is so disobedient at times...
@Pavel No, in a normal system the default is ⍬ 1 but I've set up TIO differently to avoid having repeated random numbers.
@EriktheOutgolfer It has character.
@all Any more questions about these primitives' implicit argument system variables?
I'm guessing something has changed since 14.0? My ⎕RL is 625 items long
@dzaima No, I've only spoken about what you can set ⎕RL to. Afterwards, APL will keep a huge array there as part of the algorithm.
⎕RL is kind of special syntax
@EriktheOutgolfer Yes, and so to with a few of the system names.
Jan 3, 2018 19:25
@Adám ah, but ⎕RL←42 1 gives LENGTH ERROR: Invalid seed value
⍞←?0 ⊣ ⎕RL←42⋄ ⍞←?0 ⊣ ⎕RL←42
@RosLuP 0.00195337832
@dzaima Right. Some things have changed since 14.0. Just not the length of ⎕RL. You used to have to use an I-beam to select method.
⎕←?0 ⊣ ⎕RL←42⋄ ⎕←?0 ⊣ ⎕RL←42
@Adám
0.00195337832
0.00195337832
@RosLuP ^ (you need multiple lines to get those two results)
Let's move on to session stuff.
Jan 3, 2018 19:28
⎕←?0 ⊣ ⎕RL←4002⋄ ⎕←?0 ⊣ ⎕RL←4003
@RosLuP
0.6269819886
0.6279585585
⎕AI Account Info is not very interesting these days, except you can use ⎕AI[3] as an absolute counter of milliseconds since the beginning of the session. This is useful to avoid having to deal with roll-overs when timing stuff.
How long does it take to wait a second?
⎕←3⊃⎕AI ⋄ ⎕DL 1 ⋄ ⎕←3⊃⎕AI
@Adám
1024
2026
1002 milliseconds.
⊢⎕DL 1
⍞←⎕DL 1
Jan 3, 2018 19:31
@EriktheOutgolfer 1.001081
(note ⎕DL is shy)
but otherwise ⎕AI[3] is useful as a timer
@EriktheOutgolfer True, but that doesn't matter, as the bot requires ⍞← anyway.
⎕AN is the Account Name, which for TIO is:
⍞←⎕AN
@Adám runner
⎕CLEAR is a special constant, which when referenced will clear the workspace just like )clear does. For the bot, this isn't useful, but you can try it online!
Philosophical question: Does ⎕CLEAR have a value?
@Adám even if it does you can't see it
Jan 3, 2018 19:37
⎕CY is a function which copies from a workspace file to the current workspace. You give it the name of a workspace file as right argument, and optionally a name list on the left of items to copy. By default, it will copy everything.
Beware that ⎕CY annoyingly does not have a result in versions ≤16.0. We will fix this in 17.0 so it becomes easier to use in scripts, dfns, and tacit functions.
@Adám I think it should be the list of the names of the copied functions
@EriktheOutgolfer That was considered, but it could have performance issues if you copy in a workspace with tens of thousands of functions. Instead it will be the list of functions not copied.
@Adám wait what
@EriktheOutgolfer In anticipation of an upcoming (this doesn't currently exist) ⎕PCY or a variant on ⎕CY which allows you to do a Protected copy by only copying things that would not overwrite existing items in the current workspace, similar to )PCOPY.
⍞←⎕DL 30
Jan 3, 2018 19:43
@RosLuP … meanwhile…
⎕DL is Delay as you saw before. It takes a number (floats are fine) of seconds and (shyly) returns the number of seconds actually used.
@RosLuP 30.030007
@DyalogAPL Nice timing!
⎕DL guarantees a delay of at least what you specified.
⎕←⎕DL 1
@Zacharý
1.001102
@Adám at least it admits its imprecision, I haven't seen any other language gracefully admit its delay offsets
Jan 3, 2018 19:44
⎕←'constant literal'
@Mr.Xcoder
constant literal
@EriktheOutgolfer Iverson was a very honest person ;-)
You may have already used )LOAD. ⎕LOAD is basically the same, but in a function form. Give it the name of a workspace to load.
Did Iverson write the first APL implementation? I thought he just created the notation.
⎕←'I, APL, gracefully admit that I am not perfect. Therefore, you can see how much I actually waited, instead of the intended time period of one (1) second: ',⍕⎕DL 1
@Pavel True. I'm just joking.
Jan 3, 2018 19:47
@EriktheOutgolfer
I, APL, gracefully admit that I am not perfect. Therefore, you can see how much I actually waited, instead of the intended time period of one (1) second: 1.001123
⎕OFF is similar to ⎕CLEAR in that referencing its value causes the workspace to be closed, but it also terminates APL.
⎕OFF has a special syntax though. If you put a value immediately to its right, that will become APL's exit code:
⎕←⎕OFF 42
@Adám

Rebuilding user command cache... done
Cannot exit when fixing a class
⍎DOMAIN ERROR
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕OFF 42
                                                                                                               ∧

Real time: 0.988 s
User time: 0.898 s
Sys. time: 0.049 s
CPU share: 95.91 %
Exit code: 0
@DyalogAPL Yeah, except you can't off APL in the middle of running a script. Try it online instead.
@Adám huh why isn't there a terminate command for scripts?
@EriktheOutgolfer Because it isn't the kind of script you think of. This is a text representation of an object, not a list of commands.
⎕SAVE is similar to )SAVE in that it saves the current workspace to disk.
Jan 3, 2018 19:54
> off APL
However, ⎕SAVE has a trick up its sleeve. If you use ⎕SAVE under program control, you can then use ⎕LOAD on the generated workspace file, and execution will continue where the ⎕SAVE happened, with ⎕SAVE giving the result 0.
This allows you to write applications where the user can close the application and then resume the left-off state when opening the application again.
⎕←⎕LOAD file123
@RosLuP

Rebuilding user command cache... done
⍎VALUE ERROR
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕LOAD file123
                                                                                                                ∧

Real time: 1.096 s
User time: 1.002 s
Sys. time: 0.045 s
CPU share: 95.58 %
Exit code: 0
@RosLuP does that file exist
@RosLuP You need to use quotes around the filename, but there is no file123 workspace on TIO.
⎕←⎕LOAD 'dfns'
Jan 3, 2018 19:57
@Adám

Rebuilding user command cache... done
Cannot load workspace when fixing a class
⍎DOMAIN ERROR
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕LOAD'dfns'
                                                                                                              ∧

Real time: 1.046 s
User time: 0.976 s
Sys. time: 0.036 s
CPU share: 96.78 %
Exit code: 0
@DyalogAPL Except you can't load workspaces inside a script. Try it online instead.
Last for today is ⎕TS Time Stamp which returns the current system time as a 7-element vector; year, month, day, hour, minute, second, millisecond:
⍞←⎕TS
@Adám 2018 1 3 19 59 10 559
And as you can see, time's up for today's lesson.
2
 
Conversation ended Jan 3, 2018 at 19:59.