« first day (1827 days earlier)      last day (118 days later) » 

5:25 AM
@xpqz much better support for tacit code
 
 
5 hours later…
10:55 AM
Added Lessons 14 & 24: xpqz.github.io/cultivations
 
 
4 hours later…
2:48 PM
@xpqz are lesson additions accepted?
 
@xpqz "Since APL does not enforce a naming scheme" … (but I highly recommend adopting a naming scheme)
"of dfns' operators" → "the dfns workspace's operators"
"[workspace available]" broken link
I'd remove mention of ⎕Á as it makes little sense, and it isn't even true that it is the list of non-ASCII identifier letters.
"⎕S can also take a scalar integer as right operand." → "⎕S can also take an integer scalar or vector as right operand."
⍠ missing backticks.
For counting uppercase letters, you could add ≢'\p{Lu}' ⎕S 0 ⊢ 'Programming Puzzles and Code Golf' ⍝ Unicode uppercase letter property
@xpqz Possible to make computation output use the same font as code?
 
3:08 PM
@Adám Probably, but I've not understood how to affect fonts in jupyter-book
@Razetime I'm keen to have blanks or under-explained concepts expanded, and especially more examples.
 
cool. I'll pr sometime then
 
@hyper-neutrino Can you get chat.stackexchange.com/users/538311/user1136288 access?
 
@Razetime Thanks! Or just open issues. Whatever you prefer. As it came up before, if you do issue PRs, make sure they target the .ipynb source, not the _build/.html, as those are overwritten by jupyter-book.
 
alright
 
@xpqz I just noticed today that my cultivations never covered inner and outer product.
 
3:17 PM
It would be a miracle if they didn't miss something....
I'm pondering how/if to reorder the OO/tradfn stuff.
Let me know if you have strong opinions there.
 
@xpqz "User-defined functions" mentions the three types, but then only speaks about dfns. I'd put tradfns (and eventually the chapter on tacit) up there.
 
And keep the OO stuff as its own section?
 
Yes.
 
Ok.
I didn't realise until I tackled the regex chapter that you can use the namespace in the operator function to pass stuff between each match. That's pretty cool.
From yesterday, do you think I should expunge the mention of {x∘←⍵}, as it's problematic?
 
Well, it isn't going away, but the syntax really makes no sense. Much better, imo, to teach {⎕THIS.x←⍵} which is more versatile too, since it allows assigning to any namespace.
 
3:29 PM
@Adám 👍
 
@hyper-neutrino Thanks.
 
@Adám oh, i didn't know quad THIS is a thing in plain dfns
 
@user1136288 Hi taronish. You should now have access, so feel free to introduce yourself. You might need to reload the page first, though. Also, since you're new to Stack Exchange chat, have a look at apl.wiki/APL_Orchard#Features
@KamilaSzewczyk Note that it isn't exactly like this in JS.
 
hm. how does it work?
 
It is simply a reference to the current namespace, i.e. not to the current (or next outer) scope.
@xpqz What's actually happening in x∘← is binding the symbol (!) x as left argument to the "function". Yes, Dyalog APL has symbols (like K), but you're just restricted from using them. This works(!):
      f←x∘←
      x
VALUE ERROR: Undefined name: x
      x
      ∧
      f 10
      x
10
 
3:34 PM
It's fabulous! So many foot-gun opportunities.
 
3:50 PM
@Adám Thank you for granting my access. I'm still getting my bearings on this new chat system.
First order of business is to figure out how to change my name to something a bit more recognizable.
 
It'll change automatically after you chat for a little while.
 
Ah, ok. Well in any case, hello everybody. I'm taronish, and I'm excited to be trying to teach myself APL for fun. I have no experience at all in array programming, but it has already been rather eye-opening for me. In my day job, I'm a clojure programmer, and I live in Switzerland.
 
What materials, if any, do you use for studying APL?
 
Well, I first started by just trying to jump directly into advent of code 2021, but I stalled out after 8.5 problems. Then I stumbled across Learning APL by Stefan Kruger, which has been extremely helpful to me.
At this point, what I'm finding most fun is just working through past problems from the APL problem solving competitions, and then occasionally searching APLCart when I have no idea how to accomplish a task ... but I prefer to understand what I'm doing, so sometimes it takes me a long time to interpret a code snippet I've borrowed.
 
Sounds like you're well on your way. Do not hesitate to ask for an explanation of borrowed snippets, though.
 
4:03 PM
I've also watched what videos I could find on youtube, but some of them go at a pace that is a little bit hard for me to follow as a learner. Sometimes I will take a video from code-report for example, and just pause it to puzzle some things apart.
@Adám Thank you, that is extremely generous. I'll ask for help when I get totally stumped.
 
@user1136288 People here are usually very willing to help. Also feel free to ask for feedback on your solutions, even if they do work.
Say, you might suspect there's a better/neater/faster way.
 
Indeed
 
4:19 PM
Yes, I'm sure my solutions can often be improved. I remember on one of the early AOC2021 solutions, I could only figure out how to solve it with execute (⍎), because it consisted of commands like 'forward 10' and 'back 5', and I had no idea what to do with that in APL so I wrote functions called things like forward and back and then used eval. I'm sure it was pretty bad. :)
 
@user1136288 I'm glad you found Learning APL useful. I'm always interested to hear feedback (good and bad) from people who use it to learn.
 
Pro tip: xpqz is the author.
 
@xpqz Ah! Thank you for the very cool book. Honestly, I think a lot of my problems come from a world view defined (or distorted) by exposure to other programming languages. I will, however, try to think about whether there is any useful feedback I could provide.
 
@user1136288 Sounds like you know your Lisp.. that's a good springboard in my opinion.
 
Yeah, exposure to other programming languages does tend to be a hindrance (besides for making some things much easier to pick up, of course). They should teach APL in school…
 
4:26 PM
@user1136288 Maybe this?
adventofcode.com/2021/day/2
d←↑' '(≠⊆⊢)¨⊃⎕NGET'../d/2'1
(fw dn up)←+/m←('forward' 'down' 'up'∘.≡⊣/d)×⍤1 1⊢⍎¨⊢/d
fw×dn-up
aim←-⌿+\1↓m
(+/aim×0⌷m)×+/0⌷m
 
> They should teach APL in school…
I wanted to be a teacher before getting into programming
 
AoC was hard this year, IMO
 
@Adám I'm curious, have you ever worked with C/++ more extensively?
i know that you've been doing APL since the very beginning but i'm also wondering how does it impact your ability to use more conventional technologies
 
@xpqz This will still take a little effort to puzzle my way through. I'm not fast at reading APL!
@xpqz I think lisp is not a bad place to come from, but when I see something like a map operation (¨), it was still sort of a shock to me that an expression like 1 2 3 +¨1 would work ... mentally, I was stuck at mapping a monadic function across an array on the right ...
 
@KamilaSzewczyk Not C(++), but I do do some JS. I tend to feel very handicapped there, always reaching for .map and [...]s.
@user1136288 You do realise ¨ makes no difference in that specific case, right?
 
4:32 PM
@Adám Yes, sorry, + wasn't a great example! :)
 
@Adám i see. i gave C++ as an example of a strongly typed language wondering if you liked it.
there's also Haskell and Agda.
 
CMC: Shortest APL expression containing where the ¨ cannot be left out.
 
they yield the same thing, don't they
 
Hmm
 
(⊂1 2)∘+¨1 2 vs (⊂1 2)∘+1 2
      1 2∘+1 2
2 4
      1 2∘+¨1 2
┌───┬───┐
│2 3│3 4│
└───┴───┘
even simpler
my initial guess: {⍵∘+¨⍵} at 7 bytes
 
4:37 PM
I have a 5-byter.
@KamilaSzewczyk An expression that returns an array.
 
so 1 2∘+¨1 2 is fine?
 
`⍬∘+¨1`

I guess containing +¨ is vague I interpreted X∘+ as being invalid
 
oh, smart. that's a nice variation of what i did
 
@xpqz This is neat as a solution, but it (perhaps strangely) always takes me some work to figure out what role the tacks are playing in this kind of code.
 
4:40 PM
@user1136288 ⊢/d just means to take the last column from a matrix.
 
@user1136288 It is so interesting. A lot of people have great trouble grokking and but they are really the simplest possible functions.
 
Well, in isolation I think they're very clear to me. Maybe I'm intimidated by their use in trains and so I freak out when I see them!
 
+¨⍳⍬
Nvm
 
@user1136288 ×⍤1 1⊢ uses the tack to stop "stranding"
 
I don't think I can come up with something shorter
@Adám what was yours?
 
4:42 PM
⍬∘+¨⍬ because I love empty arrays.
 
Technically speaking ¨ makes a difference in +¨/⍬ because it causes an error.
 
What does ⍳⍬ return? An enclosed empty vector?
Yep, interesting
 
Do you understand why it has to return that?
 
I'm looking at the docs to figure out now
 
4:48 PM
I don't think I understand why it is `1 1`.

Is this different? `('forward' 'down' 'up'∘.≡⊣/d)×⍤1⍎¨⊢/d`
Sorry folks, I obviously am making formatting mistakes in this new (to me) chat system.
 
@taronish No. wasn't necessary there at all, and ⍤1 is an abbreviated form of ⍤1 1 (actually ⍤1 1 1)
@taronish Have a read through apl.wiki/APL_Orchard#Basic_formatting and the section thereafter
 
It's probably the same; I was rushing through those at the time...
 
This stuff is so cool, though. I love interactive programming experiences.
 
Yes, APL's development experience is one of the best imo
 
5:07 PM
My answer was pretty close to xpqz's
sf ← (⊢/×⍥↓'forward' 'down' 'up'∘.≡⊣/)↑

⍝ Part 1
sg ← {f d u←+/↑sf⍵⋄f×d-u}

⍝ Part 2
sh ← {h d←(1∘⌷,(+\⍤+/1∘↓))-@3sf⍵⋄h×⍥(+/)⊃×/h d}
I'd change this now my tacit is less sucky
 
 
3 hours later…
7:52 PM
Is it possible to write a multi-line string?
 
No.
 
not really but you can wrap it in a dfn and use ⎕CR or something similar
 
Gotcha
 
@rak1507 I don't see how that would work.
Once we get array notation, you can write a vector of vectors like this:
var←('hello'
'array notation'
'and welcome')
 
That'll be nice, just using var ,← for now
 
7:54 PM
      f←{
       this
       is
       a
       multiline
       string
       }
      ⎕CR 'f'
 f←{
     this
     is
     a
     multiline
     string
 }
      ¯1↓1↓⎕CR 'f'
     this
     is
     a
     multiline
     string
something along these lines
(yes it's a matrix not a string with actual newlines, but easy enough to convert)
 
Not recommended:
      f←{
       triple   spaced
       1e3    .5
       }
      1↓¯1↓⎕CR'f'
     triple spaced
     1000 0.5
 
ugh forgot about that
yeah
 
8:47 PM
@FawnLocke @rak1507 Execute the following gobbledegook to enable multi-line strings in the session:
2
⎕TRAP←2'E' '{⎕DMX.(_≡2⊃⎕DMX.DM):⎕DMX.((OSError{⍵,2⌽(×≢⊃⍬⍴2⌽⍺,⊂'''')/''") ("'',⊃⍬⍴2⌽⊆⍺}Message{⍵,⍺,⍨'': ''/⍨×≢⍺}⊃⍬⍴DM,⊂''''),∊(⎕UCS 13),¨1↓DM)⋄⍎⍵}⎕DMX.(_⊣{100≡ENX:_{⍺,(⎕UCS 13),⍵}←⍞}⍣{2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢⍺}⍣(ENX≡100)⊢_←2⊃DM)'
 
lmao
 
beautiful
 
It works:
      abc←'here
be dragons'
      abc
here
be dragons
 
amazing
 
8:49 PM
doesn't work for me :/
 
Wait, it doesn't?
 
Can't get it to work either
 
Oh, it needs ⎕IO←1. Let me re-write it to be ⎕IO-insensitive.
Now ⎕ML and ⎕IO agnostic:
⎕TRAP←2'E' '{⎕DMX.(_≡⊃⍬⍴1↓⎕DMX.DM):⎕DMX.((OSError{⍵,2⌽(×≢⊃⍬⍴2⌽⍺,⊂'''')/''") ("'',⊃⍬⍴2⌽⊆⍺}Message{⍵,⍺,⍨'': ''/⍨×≢⍺}⊃⍬⍴DM,⊂''''),∊(⎕UCS 13),¨1↓DM)⋄⍎⍵}⎕DMX.(_⊣{100≡ENX:_{⍺,(⎕UCS 13),⍵}←⍞}⍣{2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢⍺}⍣(ENX≡100)⊢_←⊃⍬⍴1↓DM)'
 
still nope :/
 
Wat.
So what happens by you?
 
8:55 PM
just get a syntax error
 
When you enter the above or when you try to use the "feature"?
 
when I try and use it
 
I just tried it with RIDE, and it works there too.
 
I'm using the windows ide atm
 
What environment variables would effect it? Do I press shift+Enter or just Enter
 
9:02 PM
Just Enter, and I don't see what would affect it now I've eliminated ⎕ML and ⎕IO
 
/shrug
 
same
 
oooh.
 
oh, I didn't realise that's a string containing the error not an error
good old ]boxing on -s=max
 
OK, I can fix this, but it'll be ugly ¯\_(⍨)_/¯
 
9:03 PM
Still a cool idea
 
@rak1507 I can fix that too.
@FawnLocke @rak1507 OK try:
⎕TRAP←2'E' '{⎕DMX.(_≡⊃⍬⍴1↓⎕DMX.DM):⍞←⎕DMX.((OSError{⍵,2⌽(×≢⊃⍬⍴2⌽⍺,⊂'''')/''") ("'',⊃⍬⍴2⌽⊆⍺}Message{⍵,⍺,⍨'': ''/⍨×≢⍺}⊃⍬⍴DM,⊂''''),∊(⎕UCS 13),¨1↓DM)⋄⍎⍵}⎕DMX.(_⊣{100≡ENX:_{⍺,(⎕UCS 13),⍵}←⍞}⍣{2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢⍺}⍣(2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢_)⊢_←⊃⍬⍴1↓DM)'
 
different error...
 
?
 
same
 
9:08 PM
Hm.
Oh, stupid me.
@FawnLocke @rak1507 OK, here we go again. Should fix that, and a couple of other issues:
⎕TRAP←2'E' '{⎕DMX.(_≡⊃⍬⍴1↓DM):⍞←⎕DMX.((OSError{⍵,2⌽(×≢⊃⍬⍴2⌽⍺,⊂'''')/''") ("'',⊃⍬⍴2⌽⊆⍺}Message{⍵,⍺,⍨'': ''/⍨×≢⍺}⊃⍬⍴DM,⊂''''),⊃,/(⎕UCS 13),¨1↓DM)⋄⍎⍵}⎕DMX.(_⊣{2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢_:_{⍺,(⎕UCS 10),⍵}←⍞}⍣{2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢⍺}⍣(2|''''''''+.=''''''[^'''']'''''' ''⍝.*''⎕R''&'' ''''⊢_)⊢_←⊃⍬⍴1↓DM)'
(It is getting slightly unreadable at this point, but whatever…)
 
only slightly :P
 
Yep, super cool!
 
yeah, that worked for me
 
Do you mind giving me a brief explanation?
 
who needs lisp! :P
 
9:15 PM
Yay.
@FawnLocke It is actually very simple…
 
Fun
 
⎕TRAP←2'E' '…' sets a global trap for syntax errors, saying Execute '…' when and where a syntax error happens.
_←⊃⍬⍴1↓DM captures the middle line of the Diagnostic Message; that's the erroring line.
2|''''+.='''[^'']''' '⍝.*'⎕R'&' '' is used a few times. It replaces strings with themselves and removes comments, then checks if we have an odd number of quotes.
So we check the erroring expression to see if there's a open quote. If not, we re-construct the error message that APL would have printed, and print it.
 
Ah, neat. Cool!
 
Otherwise, we run an input loop, appending LF-delimited lines to the erroring expression.
We keep doing so until the erroring (now extended) expression has an even number of quotes (not counting comments)
Once done, we simply pass it to which doesn't mind literal LFs in its argument.
 
Sweet
 
9:21 PM
is fine with multiline strings‽
 
Literal strings can have any characters, as long as quotes are doubled.
The problem is that it is tricky to insert control chars into your code.
It mostly looks crazy because of the regex /'[^']'/ which in APL is '''[^'']''' but ⎕TRAP needs a string value, so it becomes ''''''[^'''']''''''
 
is there any context other than which will accept newlines in string literals?
 
Everywhere, I think, but it is hard to get them in there.
⎕FIX':namespace' ('⎕←''abc',(⎕UCS 10),'def''')':endnamespace' works
 
if by "hard" you mean "impossible because newlines are handled specially", then that doesn't count
@Adám holy what
 
⎕FX'NL'('''abc',(⎕UCS 10),'def''') works.
As I said, "hard", not impossible.
 
9:25 PM
right, Dyalog thinks newline != new line sometimes
 
Not really, a newline in a vector of charvecs is fine. Problem is reading a text file in and distinguishing between quoted and unquoted newlines. And also, the editor doesn't really let you type literal newlines, but if they are already present, it handles it.
Well, at least the Windows IDE Editor does. Not sure about RIDE.
 
RIDE (like literally the rest of the world) has only one type of newline
 
Is there are documentation on doubling up quote characters?
 
It really shouldn't be much of a problem to detect open quotes and handle them as I do.
@FawnLocke What did you APLcart?
 
'' Just didn't see that because there was a lot of output
 
9:29 PM
@dzaima so the answer is no, not without manually generating the code one way or another (and is manually generating the code executed too)
@Adám link would probably coerce both to the same thing too. And everything else that isn't the dyalog interpreter
 
@dzaima Hm, now I think of it, it shouldn't be too hard to write a pre-processor for ⎕FIX which reads the file, transforms it as necessary and gives it over to ⎕FIX.
The problem would then only be that the interpreter wouldn't remember to write changes back to file, but I think Link would handle that.
 
It's a shame ` would make a good pipe character. Using ` ` for string literals, with escape characters, or string interpolation, whatever would be nice
 
Pipe?
If anything, I'd use "" for more advanced strings (and they should always be rank 1 too).
 
Pipe meaning line continuation
For some reason I thought "" was reserved for something, that is more sane
 
Line continuation is contentious in APL, though, since it'd make your code run buttom-up.
 
9:36 PM
Yeah
 
That said, one of the reasons I can easily do the above hack, and many others like it, is that it is so easy to parse what's a string and what isn't. It'd become much much harder if we added an additional character literal (with or without escapes).
 
Are hacks all that common or useful though? How often do you parse APL source code
 
i don't think you should design your language around allowing writing hacks
 
Probably not, but I personally have to do this more often than you'd think, because I deal with parsing in user commands, TryAPL, competition framework, array notation model, etc.
@FawnLocke Have you seen these?
 
I hadn't, thanks for sharing
 
9:44 PM
Oh, I should amend the JSON one to handle all JS escapes (except octal, eugh).
 
 
2 hours later…

« first day (1827 days earlier)      last day (118 days later) »