Conversation started Nov 29, 2017 at 18:30.
Nov 29, 2017 6:30 PM
Welcome to the APL learning session
opens abrudz's language bar based on ngn's, admiring its sheer beauty
@EriktheOutgolfer All credit to ngn.
@Adám hah ninja
So, if you do not have an APL keyboard, you can enable one (and get a clickable language bar) using the pinned link.
btw I already have 2 bookmarks: ngn's and abrudz's
Nov 29, 2017 6:32 PM
opens terminal version of Dyalog, amazed that it looks less outdated than the proper Dyalog GUI app
We went through the first 31 functions last time. Let's continue with .
Seriously, y'all should hire a graphic designer
@Pavel We have already done so. Have you seen RIDE 4.1?
@Adám Oh yeah, that looks nice
@Adám not packaged in mydyalog yet unfortunately :(
Nov 29, 2017 6:33 PM
@EriktheOutgolfer Available on GitHub, though.
@Adám Would it have to be built from source to use it from GitHub
@Pavel The chief architect refuses to do custom GUI; wants only default WinForms look.
@Pavel It is in JavaScript. You can just run it using Node.
Anyway…
We're doing ⊂? Nice
Monadic encloses its argument. For reasons discussed previously, simple scalars cannot be enclosed.
What does "encloses" mean?
Nov 29, 2017 6:36 PM
@Pavel Package it into a scalar.
@Adám yeah supposedly some ; link primitive supposed to work some way using the primitive in its implementation and such
trying to get Adáms alt+ keyboard layout after trying to erase the UK layout but windows is fighting me..
⎕←(3 3⍴⎕A),(3 3⍴⎕A) ⍝ concatenation of two matrices.
@Adám
ABCABC
DEFDEF
GHIGHI
⎕←(⊂3 3⍴⎕A),(⊂3 3⍴⎕A) ⍝ concatenation of two enclosed matrices.
Nov 29, 2017 6:37 PM
@Adám
┌───┬───┐
│ABC│ABC│
│DEF│DEF│
│GHI│GHI│
└───┴───┘
The first gave us a matrix of shape 3 6, the second gave a vector of shape 2.
⎕←(3 3⍴⎕A),(⊂3 3⍴⎕A) ⍝ concatenation of a matrix and an enclosed matrix
@Adám
┌─┬─┬─┬───┐
│A│B│C│ABC│
│ │ │ │DEF│
│ │ │ │GHI│
├─┼─┼─┼───┤
│D│E│F│ABC│
│ │ │ │DEF│
│ │ │ │GHI│
├─┼─┼─┼───┤
│G│H│I│ABC│
│ │ │ │DEF│
│ │ │ │GHI│
└─┴─┴─┴───┘
looks like the scalar is being recycled there
Concatenating a scalar to a matrix uses the scalar for each row. Here the entire right-hand matrix was treated as a scalar because it was enclosed.
⎕←(3 3⍴⎕A),'x'
@Adám
ABCx
DEFx
GHIx
Nov 29, 2017 6:40 PM
So you can (and should) use to tell APL how you want the scalar extension (auto-vectorisation) to be applied.
@Adám that's what I meant
is also good for treating text vectors as strings (i.e. in one piece):
⍞←'aaa' 'bbb' 'ccc' ⍳ 'aaa'
@Adám 4 4 4
This says that each one of the three right-side 'a's is found in position 4 (i.e. are not) in the left-side list.
⍞←'aaa' 'bbb' 'ccc' ⍳ ⊂'aaa'
@Adám 1
Nov 29, 2017 6:43 PM
This says that 'aaa' is the first string.
@all Monadic clear?
Dyadic is partition. It encloses (hence sharing the symbol) pieces of the right argument as indicated by the left argument. Best to use an example:
⎕←1 0 0 1 0 1 0 0 0 1 0⊂'Hello World'
@Adám
┌───┬──┬────┬──┐
│Hel│lo│ Wor│ld│
└───┴──┴────┴──┘
Every time there is a 1, we begin a new partition. If the left argument begins with 0s we lose data:
⎕←0 0 0 1 0 1 0 0 0 1 0⊂'Hello World'
@Adám
┌──┬────┬──┐
│lo│ Wor│ld│
└──┴────┴──┘
Nov 29, 2017 6:48 PM
Works on higher rank arrays too. It partitions along the last axis:
⎕←1 0 1 0 0 1 0 1 0 0 0 1 1 ⊂ 2 13⍴⎕A
@Adám
┌──┬───┬──┬────┬─┬─┐
│AB│CDE│FG│HIJK│L│M│
│NO│PQR│ST│UVWX│Y│Z│
└──┴───┴──┴────┴─┴─┘
For vectors, 1⊂ is the same as which may be useful in trains where you want to have a left argument.
For higher rank arrays, 1⊂ cuts into columns:
⎕←1 ⊂ 2 13⍴⎕A
@Adám
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│A│B│C│D│E│F│G│H│I│J│K│L│M│
│N│O│P│Q│R│S│T│U│V│W│X│Y│Z│
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
You can use brackets to indicate which axis you wish to cut along:
⎕← 1 ⊂[1] 2 13⍴⎕A
@Adám
┌─────────────┬─────────────┐
│ABCDEFGHIJKLM│NOPQRSTUVWXYZ│
└─────────────┴─────────────┘
Nov 29, 2017 6:51 PM
⎕←1 0 1 1 ⊂[1] 4 3⍴⎕A
@Adám
┌───┬───┬───┐
│ABC│GHI│JKL│
│DEF│   │   │
└───┴───┴───┘
@Adám is there a command to clear the screen, like a shell's clear?
@Pavel Not really. The session is like a paper log. Try ⍪50⍴''
@Pavel In the Windows GUI you can also go in the menu Log>New and that will actually clear your session.
<-- on Linux
Oh well
Can I run shell commands, to exec dyalog and start a new instance?
that still preserves old logs
Nov 29, 2017 6:56 PM
⎕sh seems to work
)clear here open one new 'apl worksheet '
@RosLuP Yeas, but that doesn't clear the visible log.
Pro tip: do not run ⎕sh 'exec dyalog'. It will cause bad things to happen in your terminal.
@Pavel I am pretty sure there is a way to do the same as a command, but I can't seem to find it. I'll try to get back to you on that.
exec replaces your shell with a command
Nov 29, 2017 6:58 PM
@Pavel Nothing bad happened to me.
@H.PWiz try to )off
Well <c-L> fixed that
What is <c-L> supposed to do?
Is (⊂3 3⍴⎕A) one scalar? If is a scalar ⍴⍴ of it is 0?
@RosLuP yes and yes
Nov 29, 2017 7:00 PM
@Pavel Control L clears the terminal. That's what I tried to type
Oh, neat
@RosLuP Feel free to try things like that using the chatbot:
⍞←⍴⍴⊂3 3⍴⎕A
@Adám 0
@all Are we clear about dyadic ?
⍞←⍴⍴1
Nov 29, 2017 7:02 PM
@EriktheOutgolfer 0
Monadic is pretty much the inverse of monadic . It discloses a scalar (again, if possible; a simple scalar remains the same).
If you use it on a high rank array (i.e. not enclosed), it will give you the first (top left) element:
⎕←3 3⍴⎕A ⋄ ⎕←⊂3 3⍴⎕A ⋄ ⎕←⊃⊂3 3⍴⎕A ⋄ ⎕←⊃3 3⍴⎕A
@Adám
ABC
DEF
GHI
┌───┐
│ABC│
│DEF│
│GHI│
└───┘
ABC
DEF
GHI
A
The last feature ("first") means that you can combine it with reverses etc, to get corner elements:
⍞←⊃⌽3 3⍴⎕A ⍝ top right
@Adám C
Nov 29, 2017 7:07 PM
⍞←⊃⊖3 3⍴⎕A ⍝ bottom left
@Adám G
⎕←⊃⌽⊖3 3 ⍴⎕A ⍝ bottom right.
@Adám
I
I often use it with ¨ (each) to get initials:
⍞←⊃¨'Hello' 'World'
@Adám HW
Nov 29, 2017 7:10 PM
Dyadic is "Pick". It digs into nested arrays. Every scalar on its left is the index of an element in subsequent layers of nestedness:
⍞←(⊂2 3)⊃3 3⍴⎕A
@Adám F
⍞← 2 3 1⊃(1 2 3)(4 5 (6 7 8))
@Adám 6
@Adám it can't be used with high-rank arrays, right?
@EriktheOutgolfer I just did in my first example. The index has to be a scalar though, so you have to enclose it.
Nov 29, 2017 7:12 PM
@Adám cool
⍞←(1 2) 2⊃2 2⍴(1 2)(3 4)(5 6)(7 8)
@Adám 4
Here the first index is 1 2, which picks the element (3 4), and the second index is 2, which picks the 4.
Note that 2 2⍴(1 2)(3 4)(5 6)(7 8) is a 2-by-2 matrix of two-element vectors:
⎕← 2 2⍴(1 2)(3 4)(5 6)(7 8)
@Adám
┌───┬───┐
│1 2│3 4│
├───┼───┤
│5 6│7 8│
└───┴───┘
⎕←(⊂1 3)2⊃2 3⍴(1 2)(3 4)(5 6)(7 8)(9 10)(11 12)
@Adám
Nov 29, 2017 7:14 PM
@EriktheOutgolfer

Rebuilding user command cache... done
Was OFF -fns=off
⍎DOMAIN ERROR
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''box on -fns=on''⊣enableSALT' ⋄ ⎕←(⊂1 3)2⊃2 3⍴(1 2)(3 4)(5 6)(7 8)(9 10)(11 12)
                                                                                           ∧

Real time: 1.015 s
User time: 0.930 s
Sys. time: 0.041 s
CPU share: 95.65 %
Exit code: 0
why does it throw?
oh wait do I enclose too much
@EriktheOutgolfer Because the first index was doubly enclosed. Remember stranding!
⍞←(1 3)2⊃2 3⍴(1 2)(3 4)(5 6)(7 8)(9 10)(11 12)
@EriktheOutgolfer 6
Nov 29, 2017 7:16 PM
OK, next up is the new . (Stop me if I go too fast!)
@Adám will take some time to get used to :-D
Monadic is called Nest because it guarantees you that the result is nested (non-simple).
@EriktheOutgolfer Well, you don't have to use stranding if you don't want:
⍞←((⊂1 3),2)⊃2 3⍴(1 2)(3 4)(5 6)(7 8)(9 10)(11 12)
@Adám 6
(1 2)(3 4 5) is already nested, and won't do anything:
⎕←(1 2)(3 4 5) ⋄ ⎕←⊆(1 2)(3 4 5)
@Adám
┌───┬─────┐
│1 2│3 4 5│
└───┴─────┘
┌───┬─────┐
│1 2│3 4 5│
└───┴─────┘
Nov 29, 2017 7:19 PM
And so in :
⍞←⊃¨'Hello' 'World'
Dyalog APL
@Adám HW
What is HW? Is it a vector of chars? So /rho /rho of that is 1? Or possible something else
@RosLuP Yes, correct.
@RosLuP you can use the bot to try out yourself ;)
@RosLuP Also, to write rho (⍴) use the linked language bar on the right (second pinned message), or copy from the list of characters (third pinned).
@RosLuP Even though ¨ would make a list of enclosed items, since the items here are simple scalars, they cannot be enclosed, and thus fuse into a simple vector.
@RosLuP Compare to:
⎕←1↑¨'Hello' 'World'
@Adám
┌─┬─┐
│H│W│
└─┴─┘
Here we take the first 1 element(s) of each, so that makes one 1-element vector for each, and since vectors can be enclosed, the result is nested.
1 2 3 is not nested, so will nest it:
⎕←⊆1 2 3
Nov 29, 2017 7:24 PM
@Adám
┌─────┐
│1 2 3│
└─────┘
Works on higher rank too, of course:
⎕←⊆2 3⍴⊂'abc' ⍝ already nested, so no-op
@Adám
┌───┬───┬───┐
│abc│abc│abc│
├───┼───┼───┤
│abc│abc│abc│
└───┴───┴───┘
⎕←⊆2 3⍴'abc'
@Adám
┌───┐
│abc│
│abc│
└───┘
⎕←⍴⍴(1↑¨'Hello' 'World')
Nov 29, 2017 7:27 PM
@RosLuP
1
Dyadic is also called partition ( and originate with different APL dialects, but Dyalog APL now features both). To distinguish them, we can call "partitioned enclose" and just "partition", but it doesn't say much.
@RosLuP What you want to look at is the depth, not the rank:
⎕←⍴⍴,(1↑¨'Hello' 'World')
@RosLuP
1
⍞←≡1↑¨'Hello' 'World' ⋄ ⍞←≡⊃¨'Hello' 'World'
@Adám 2
Nov 29, 2017 7:29 PM
⎕←≡1↑¨'Hello' 'World' ⋄ ⎕←≡⊃¨'Hello' 'World'
@Adám
2
1
The first one has an additional layer of nesting (="deeper depth").
@RosLuP Both of them are two element vectors, however. The first is a vector of vectors, the second a vector of scalars.
Dyadic works similarly to dyadic but with different rules for the left argument. The left argument is non-negative integer instead of Boolean, and new partitions begin whenever an element is higher than its neighbour on the left. Also, elements indicated by 0s are dropped completely:
⎕←1 0 0 1 1 3 2 2 5 5 0⊆'Hello World'
#tio help
@Adám
┌─┬──┬───┬──┐
│H│lo│ Wo│rl│
└─┴──┴───┴──┘
@Pavel )about is probably a better fit for what you need.
Nov 29, 2017 7:35 PM
)about
@EriktheOutgolfer 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.
@all Is clear?
@Adám for me yeah
Oh, one more trick: 1⊆array is the same as ,⊂array but uses a single dyadic function instead of two monadic ones, i.e. great for trains.
Nov 29, 2017 7:38 PM
@Adám that's useful
Monadic , then.
basically dyadic also does dyadic 's job with ⎕ML ← 3
@EriktheOutgolfer Yes, which means that in most cases you can count as a single byte, even though it isn't in the character set. However, then you can't use , and monadic becomes less powerful.
Monadic is almost the same as monadic (i.e. identity). However, it will "materialise" the default property of a class. For collections, this means the Item property, so in effect it turns collections into vectors of items.
@Adám talking about .NET stuff right?
@EriktheOutgolfer E.g., but it applies to all objects with default property. You can create one yourself too.
Nov 29, 2017 7:44 PM
@Adám example please?
working on it…
hello? can you see this?
@EriktheOutgolfer yes
@Adám phew, many flags make chat irritatingly slow
@EriktheOutgolfer Try it online!
Nov 29, 2017 7:54 PM
@Adám oh
@Adám That's new to me. Nice to know it's how you make classes
⎕←≡0↑¨'Hello' 'World'
@RosLuP
2
@Adám can classes have any number of properties other than default?
@Adám Proposed topic for next learning session: OOP
Nov 29, 2017 7:59 PM
@J.Sallé Yes.
@Pavel Maybe for when we finish with the primitive functions?
@Pavel we're not over with the functions yet :p
Dyadic is similar to dyadic but works its way into the rank instead of the depth. On a 3D array, the first element selects layer, the second row, the third column:
⎕←2 3 4⍴⎕A
now we're through functions which are very important
@Adám
ABCD
EFGH
IJKL

MNOP
QRST
UVWX
and we had many timeouts with flags
Nov 29, 2017 7:59 PM
⎕←2⌷2 3 4⍴⎕A
@Adám
MNOP
QRST
UVWX
⎕←2 1⌷2 3 4⍴⎕A
@Adám
MNOP
⎕←2 1 3⌷2 3 4⍴⎕A
@Adám
O
Nov 29, 2017 8:00 PM
Each element of the left argument may be may be any simple array:
⎕←≡'' ''
@RosLuP
2
⎕←(⊂1 3)⌷2 3 4⍴⎕A
@Adám

Rebuilding user command cache... done
Was OFF -fns=off
⍎INDEX ERROR
 __field_initialize_result_←(⎕NS ⍬).⍎'⎕CY''salt''⋄⎕SE.UCMD''box on -fns=on''⊣enableSALT' ⋄ ⎕←(⊂1 3)⌷2 3 4⍴⎕A
                                                                                           ∧

Real time: 1.070 s
User time: 0.918 s
Sys. time: 0.077 s
CPU share: 92.99 %
Exit code: 0
⎕←(⊂1 1)⌷2 3 4⍴⎕A ⍝ sorry!
Nov 29, 2017 8:01 PM
@Adám
ABCD
EFGH
IJKL

ABCD
EFGH
IJKL
⎕←2 (1 3)⌷2 3 4⍴⎕A ⍝ first and third row of second layer
@Adám
MNOP
UVWX
⎕←(1 2)1 3⌷2 3 4⍴⎕A ⍝ third char of first row of layers 1 and 2
@Adám
CO
⎕←(1 2)(2 3)⌷2 3 4⍴⎕A ⍝ rows 2 and 3 of each of layers 1 and 2
Nov 29, 2017 8:04 PM
@Adám
EFGH
IJKL

QRST
UVWX
That concludes this weeks lesson. Thank you all, and feel free to hang around!
 
Conversation ended Nov 29, 2017 at 20:05.