Anyway, ⎕NULL is a scalar null value. It isn't really used much in APL itself, but you can meet it e.g. when importing spreadsheets where it represents empty cells.
@Pavel But it is not JSON null, which is represented as ⊂'null' to match true and false being ⊂'true' and ⊂'false'.
Let's go on with more advanced features.
⎕CMD and ⎕SH are exactly identical, but obviously the first feels more natural to Windows users while the second feels more natural to UNIX users. Pressing f1 on them will give you the help appropriate for that OS.
As you of course can guess, they are used to call the OS command processor.
@Adám In e.g. python's equivalent of ⎕SH, you can either pass a full command, or a list containing the executable to run and then the arguments to pass in, which wouldn't be processed by the shell.
It has a ton of options for almost anything you could want. Again, the full documentation is available by pressing F1 with the cursor on it, and also online. Now you know it exists.
Btw, it can import and export directly to and from text files.
⎕DR is Data Representation. Monadically, it will tell you how an array is represented internally, and dyadically, it allows you to convert between data types:
@EriktheOutgolfer 6 means a memory pointer, and 32 means 32-bit. However, TIO really runs a 64-bit system. This is the exception; pointers are always 326 even on 64 bit systems.
The number 42 gave us 83, where 3 means integer and 8 means 8-bit.
You can also combine two steps of ⎕DR into one. A two-element left argument will interpret the right argument as that type, then convert it to the type given by the second element of the left argument.
⎕FMT is ForMaT. It is like a beefed up version of ⍕.
⍕ returns a vector for single line arguments, and a matrix otherwise. ⎕FMT always returns a matrix.
Also, ⍕ treats control characters as normal characters, while ⎕FMT will resolve them:
So you see that the c really was erased by the backspace.
Dyadic ⎕FMT gives you access to a whole new language, namely a formatting specification language. I won't go though all the details here (see docs!), but here's a taste:
The formatting string I3,F5.2 means that each row should first have an integer, then a float which uses five characters in width and has 2 decimals, then this formatting is cycled as much as needed for all the columns (here twice).
@RosLuP
Rebuilding user command cache... done
ls: cannot open directory '../': Permission denied
⍎DOMAIN ERROR: Command interpreter returned failure code 2
__field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕SH'ls ../'
∧
Real time: 1.260 s
User time: 1.120 s
Sys. time: 0.069 s
CPU share: 94.31 %
Exit code: 0
Finally, while you can import any JSON object, not every APL namespace can be exported. E.g. a namespace with APL functions cannot be converted to JSON. (Would be cool though if they were converted to JavaScript objects with the equivalent JavaScript functions…)
@EriktheOutgolfer Well, you don't have to.
Again, ⎕JSON has some more advanced options — see the docs.
(There is valid JSON which is not valid JavaScript, and JavaScript object notation which is not valid JSON.)
@EriktheOutgolfer ⎕JSON is fully compliant with JSON, though, but we do allow some leniency which allows you to create some JavaScript objects which are not valid JSON.
@Pavel
Rebuilding user command cache... done
⍎DOMAIN ERROR: The right argument cannot be converted to JSON (⎕IO=1)
__field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕JSON ⎕NULL
∧
Real time: 1.046 s
User time: 0.944 s
Sys. time: 0.047 s
CPU share: 94.70 %
Exit code: 0
@Pavel We opted for a generalised system for strings without quotes, rather than special casing null. The i-beam that preceded ⎕JSON did in fact use ⎕NULL. By using enclosed strings, we can losslessly roundtrip.
⎕MAP is a function I'll only mention and not demonstrate (again, see docs) because TIO makes this hard. It basically allows you to use a file as an array instead of keeping the array in memory. Very useful.
@RosLuP
Rebuilding user command cache... done
⍎DOMAIN ERROR: Invalid character at offset 1 (⎕IO=1)
__field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←⎕JSON('hello','world')
∧
Real time: 1.041 s
User time: 0.947 s
Sys. time: 0.052 s
CPU share: 96.07 %
Exit code: 0
@RosLuP
Rebuilding user command cache... done
⍎DOMAIN ERROR: Invalid left argument
__field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''←box on -fns=on -trains=tree''⊣enableSALT⋄''''' ⋄ ⎕←2 ⎕JSON('hello','world')
∧
Real time: 1.049 s
User time: 0.953 s
Sys. time: 0.045 s
CPU share: 95.13 %
Exit code: 0
⎕VFI is Verify and Fix Input. It takes a string and returns two lists. It cuts the string into space separated fields. Then it attempts to convert each field to a number. If it succeeds then the corresponding element of the left result list is 1 (else 0) and the corresponding element of the right list is the number (else 0).
@RosLuP You need to stop ⊂ from taking 'hello' as left argument:
⎕XML is converts to and from XML, but the corresponding APL format is rather involved. I usually just use ⎕XML to verify that my XML is valid or to normalise whitespace: