« first day (1850 days earlier)      last day (227 days later) » 

6:48 AM
How would you increase the width of apl output.
```
┌→───────────────────────────────
│422 425 460 462 478 486 468 441 449 410 470 455
└~───────────────────────────────
──────────────────────────────+
427 512 487 409 462 476 482 394 484 392 486 |
──────────────────────────────+
```
Just making it so that the array doesnt just get cut off in the middle on a large screen
 
7:10 AM
]rows on
 
7:21 AM
@Perigord Either ^ or set ⎕PW (Print Width) to a large value. Also, when posting code blocks, put them in their own message (consecutive messages are joined visually) and press Ctrl+k before Enter.
 
0
Q: APL Fork/Train with Compression

j_v_wow_dI want to select elements from an array based on some test. Currently, I am trying to do that with a compression, and I would like to write it as a tacit function. (I'm very new to APL, so feel free to suggest other options.) Below is a minimal (not-)working example. The third line below shows th...

 
 
1 hour later…
8:32 AM
today is the apl quest right?
 
aye - 15:00 (although I might miss it today)
 
@Adám I'm trying to work with the dyalog executable mapl over a websocket, and running into some issues. There’s a TL;DR at the bottom, but I’ve left lots of info here to ensure I avoid the XY Problem).
(A pointer to any general info on how it gets invoked when piped would be handy, because it's behaving differently than when I run mapl straight in the shell. And these documented flags don’t seem to account for the differences.)
Specifically, I want to send some output back every time input is piped in. Right now, when a line errors, I get sent back nothing. By default, the session actually terminated, but passing the -q flag forces it to keep running. However I still don’t get the error back, I just get to keep my connection open.
For this particular use case, when it errors it’s not even imperative I get the error back. But I do need to get something just to know that line finished running.
I’ve played around with making an rlwrap filter, and with prepending all the inputs with a printing dfn. So one of those approaches should be possible, but it felt a bit overdone.
 
TL;DR: Over a websocket, how do I force Dyalog mapl to send output when it errors and not terminate the session?
--
The long-text-can't-be-formatted-thing is such a pain.
 
9:45 AM
@AviFS Not an expert on this, but I suspect the problem is error messages going to stderr instead of stdout. You can either redirect, or simply trap all errors, printing their message (or anything you want) to stdout.
 
 
2 hours later…
11:18 AM
Hi! Can ⌸ (Key) somehow be "inserted" between two columns of a table, in the same way that +/ can be used to sum the rows of such a table?

That is, is there an expression which calculates the same result as `1 2 3 {⍺ ⍵}⌸ 4 5 6`, in the same way that `+/ 1 2 3 ,[1.5] 4 5 6` gives the same result as `1 2 3 + 4 5 6`?
 
@BojanPetrović something like this:
      ⊃{⍺ ⍵}⌸/↓1 2 3,[1.5]4 5 6
┌─┬─┐
│1│4│
├─┼─┤
│2│5│
├─┼─┤
│3│6│
└─┴─┘
      ⊃{⍺ ⍵}⌸/↓⍉1 2 3,[1.5]4 5 6
┌─┬─┐
│1│4│
├─┼─┤
│2│5│
├─┼─┤
│3│6│
└─┴─┘
 
@Razetime Wow, that's it! Thanks a lot.
 
11:38 AM
@Razetime @BojanPetrović It may be more efficient to use ⊂[1] instead of ↓⍉. If you data is simple, you can also use ,⌿ instead.
 
ah yes i should remember ⊂[1]
 
12:01 PM
Announcement: APL Quest in 3 hours.
 
@Adám I didn't expect that the result of ,⌿ will be boxed. Could you explain why that happens? I couldn't deduce that from glancing at the documentation.
 
@BojanPetrović Reductions apply to each collection (vector) of elements along the appropriate axis. Since we're reducing vectors, each one has to become a scalar, i.e. enclosed.
You see it too with the need for after the Key application. We're reducing the 2-element vector to an enclosed scalar.
 
 
3 hours later…
3:00 PM
Welcome to the third APL Quest! Today's problem is What Is In a Word:
> Write a dfn which returns the number of words in the given character vector.
> For simplicity’s sake, you can consider the space character ' ' to be the only word separator.
 
did Iverson consider characters to be a datatype?
 
(≢' '∘≠⊆⊢),
 
≢' '∘≠⊆⊢
 
@PyGamer0 Eventually, yes, but I don't think so in his original mathematical notation.
 
≢' '∘≠⊆, ?
 
3:00 PM
{≢⍵⊆⍨' '≠⍵}
 
Whoa, some people have prepared :-)
 
lol everyone has the same solution
 
OK, that's all very good. Now, notice that this is not especially efficient, as we create one string (i.e. pointer) for each word, just to count them. Can we come up with something better?
 
{≢'(\w+)'⎕S'&'⊢⍵}
 
I actually wrote down {≢⊆⍨,' '≠⍵} too. Is there a way to express this as a tacit function without using parentheses?
 
3:02 PM
@xpqz That should be [^ ] instead of \w methinks.
 
Passed all basic and edge cases – good job!
 
@rabbitgrowth You don't need the , there, do you?
@xpqz We should fix that!
@rabbitgrowth ≢⊆⍨⍤≠∘' '
 
If I omit the ,, I get "Passed all basic tests – for extra points, consider cases like (' ') as right argument which should give (0)"
 
This is slightly better, as the generated vectors are at least compact bit Booleans.
 
maybe something like this?

{+/2</' '≠⍵}
But I didn't test it, sorry. :)
 
3:04 PM
Fails for multiple spaces?
 
@rabbitgrowth Ah, we should update the spec to say "given scalar or vector".
@BojanPetrović It is certainly going in the right direction.
@xpqz No, because it detects where a space is followed by a non-space.
The only issue with the solution is that it doesn't handle the text beginning with a non-space; it fails to count that word.
How might we fix this?
 
add a space at the beginning
 
That's one valid way. Any other ideas?
Think about the result of ' '≠' ',⍵ — what can we know about the result?
 
Starts with 1
0
 
0
 
3:10 PM
Right, so how might we use that, instead of prepending a space?
 
+/2</0,1↓' '≠⍵
+/2</0,' '≠⍵
 
that's like adding a space?
 
More efficient, as adding a bit
 
Correct.
Can we do even better?
 
yes true
 
3:12 PM
For the next optimisation we need to be aware of what exactly happens in memory when we do 0,
 
Needs to reallocate the array
 
doing a rotate?
rotate right
 
@xpqz Exactly. Since there's only one reference to the ' '≠⍵ result, how might we be able to reuse the existing pocket?
@Richard I don't think that'll help.
 
, sorryno that will add the last one on the front
 
Exactly.
 
3:14 PM
Reverse the array and add at the end
 
But reversing is going to be O(n) too. I want O(1)
I'll let you ponder that for a moment… How about some code golf? Can someone find my 7-character solution? Note that ≢' '∘≠⊆, is 8.
Hint: Mine (ab)uses a very different approach.
 
ovs
Instead of prepending a 0 we can add the first element to final result:
{(⊃+(+/2</⊢))' '≠⍵}
This can probably done a bit nicer
 
Interesting. Not what I had in mind, but that should work.
@ovs (Press Ctrl+k before Enter for code blocks.) Btw, you don't need the inner paren if you use 1⊥ for summation instead of +/.
 
Not good (yet) at golfing Adam, so no suggestions
 
It should also return 0 for empty character vectors right?
 
3:19 PM
Hm, for some reason, 1⊥ runs much slower for me, so never mind.
@BojanPetrović Yes.
 
@ovs fails on a single space
 
But you just need to ravel for that to work.
Much bigger problem is that it fails on an empty vector, but that can be handled with a guard.
I guess I'll reveal my (very odd) solution: ≢∘⊃⎕VFI — does anyone understand how it works?
 
wtf
 
wtf
 
:)
 
3:22 PM
Exactly!
I guess I should explain…
 
what is ⎕VFI (cant find docs)
 
verify fix input
 
You can always press F1 on it or enter ]help ⎕vfi
⎕VFI tries to parse a character vector that (by default) has the numbers separated by (one or more) spaces, returning two vectors.
The first vector is Boolean, indicating conversion success for each "token".
 
Creative
 
The second vector has the converted values, with 0 as value for bad tokens.
 
3:25 PM
@Adám im on android how do i press F1 \o/
its 8:55pm here lol
 
@PyGamer0 Like this: ⋄ ]help ⎕vfi
 
oh
that makes it easier to find
 
However, we don't actually care if anything was well-formed or not, or indeed what the values are, so we get the first vector and count its length with
Works for scalar characters and for the empty character vector too :-)
 
ah :) so you are misusing it, depending on it to return errors ;)
 
3:27 PM
No, I'm not depending on errors.
 
I'll try and remember that trick.
 
It always returns successBoolean convertedValues
 
the first verctor returns for every letter it couldn't convert it except the space?
 
@xpqz Well, it isn't the most performant…
 
there's gotta be a funny way abusing command line arguments
 
3:28 PM
@Richard No for every sequence of non-spaces.
 
ok!
 
Wonder if you can do something similar with ⎕CSV
 
It'll be hard to make it accept multiple separators.
And it'll protest various character sequences.
Anyway, let's get back to my idea for optimising {+/2</0,' '≠⍵}
Any ideas came up?
 
{+/2</(' '=⍵),1}
 
Very good!
 
3:31 PM
aha
{≢⍎ '''',⍨'''','\s+'⎕R'''&'''⊢⍵}
found the funny one
 
You could also have kept the added bit as a 0 and reversed < to >
@Razetime I don't even…
 
this definitely performs worse than VFI
 
:D
 
@Razetime I think this fails on leading/trailing spaces and on a single word.
 
@Razetime I think you need more quotes.
 
3:33 PM
@Adám ah yes
i should add more regex then
(≢'\S+'⎕S 3) is the more sane way
 
⎕SH to wc
 
@Razetime You can use 3 (and other numbers, but 3 should be most performant) instead of '&'
 
oh i see
 
{+/2>/0,⍨' '≠,⍵}
 
Very nice.
You don't even need to ravel since you're concatenating a zero.
OK, so now for performance comparison. I'll use t←'abc '[?1e6⍴4]
All the solutions that rely on bit-Boolean manipulations blow all the others out of the water:
(≢' '∘≠⊆,)t     → 1.7E¯2 |    0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(≢'[^ ]+'⎕S 3)t → 4.1E¯2 | +142% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(≢⊆⍨⍤≠∘' ')t    → 1.6E¯2 |   -4% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(≢∘⊃⎕VFI)t      → 2.5E¯2 |  +47% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(+/2</0,' '∘≠)t → 9.4E¯5 | -100%
 
3:37 PM
@xpqz wish fulfilled {≢⍎ '''',⍨'''','\s+'⎕R'''&'''⊢'\s+$'⎕R''⊢'^\s+'⎕R''⊢⍵}
 
you da man
 
@Adám bit late but I got ≢' '∘≠⊆, too it's sorta obvious
(any chance these can focus on harder questions in the future?)
 
I'm intending to go in order, they should get harder towards the end of every year's set.
 
only slightly. but fair enough
 
And now for comparison of the Boolean methods:
(+/2</0,' '∘≠)t               → 8.6E¯5 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
{0=≢⍵:0 ⋄ (⊃+(+/2</,))' '≠⍵}t → 6.2E¯5 | -28% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(+/2</1,⍨' '∘=)t              → 6.1E¯5 | -29% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(+/2>/0,⍨' '∘≠)t              → 6.0E¯5 | -31% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Notice that concatenating to the end vs the beginning can make a tangible difference.
However, any of these are of course just fine, as alternatives to the above solutions.
Morale: stay flat, work on bit-Booleans, and think about how the pockets are used.
 
3:40 PM
nice
 
@Razetime Fails with a LIMIT ERROR due to there being more tokens in the APL expression than can handle!
 
awesome
 
Sorry, what are "pockets"?
 
{+/⍎'\S+'⎕S'1'⊢⍵}
 
@rabbitgrowth A pocket is an area of the computer's memory that has been designated to hold a flat array.
 
3:43 PM
Got it, thanks!
 
@Razetime You didn't test that, did you?
 
i did not, yes
 
⎕S will return a character vector '1' for each match, so you need to flatten…
 
oh yeah that's an ⎕R
{+/⍎'\S+'⎕R'1'⊢⍵}
there
 
Fails on an empty vector.
 
3:45 PM
ah sad
 
Anyway, at this point, things are getting silly. Any further questions for today?
 
This was a really nice session, thanks everyone!
 
Great. Then see you next week for Keeping Things In Balance!
 
thanks!
 
ok {+/⍎'0','\S+'⎕R'1'⊢⍵} passes all cases
 
3:47 PM
Next puzzle was more chalenging for me, and there will be more different solutions I gues
 
ovs
@Razetime {'S'+.=⍕'\S+'⎕S⊢⍵}
 
@ovs thank you for your funny submission
 
@ovs You're trying to maximise the number of Ss in your solution‽
 
ovs
yesss
 
⎕S⊢ probably has horrible performance.
 
3:49 PM
      {your_solution} ')(2×3)+4('
0
Why exactly is )(2×3)+4( unbalanced?
 
Because you have a negative parenthesis depth along the way.
 
It starts with a close bracket...
and ends with an open.
I have a GREAT solution for Quest 10 :)
 
Hmm okay, I thought the starting ) "balanced" with the ending (
 
Performance for the horrible solutions (using a 1e5-shaped argument):
(≢'[^ ]+'⎕S 3)t                                        → 4.3E¯3 |     0% ⎕
{≢⍎'''',⍨'''','\s+'⎕R'''&'''⊢'\s+$'⎕R''⊢'^\s+'⎕R''⊢⍵}t → 2.3E¯1 | +5295% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
{+/⍎'0','\S+'⎕R'1'⊢⍵}t                                 → 1.2E¯2 |  +166% ⎕⎕
(≢'\S+'⎕S⊢)t                                           → 7.2E¯2 | +1560% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
{'S'+.=⍕'\S+'⎕S⊢⍵}t                                    → 8.4E¯2 | +1853% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
@xpqz Of course. We'll see in a month and a half.
 
@Adám out of curiosity, for the actual comps, is one penalised for regexing?
 
3:55 PM
@xpqz For phase 1, the primary criterion is correctness. As a tie-breaker I look at the quality of the code. Regex isn't necessarily bad, but if there is a good array-solution (as in this case), then that'll score higher (but only in small fractions of a correctness "point").
 
shouldn't that problem use \ if no PCRE is used?
 
@LdBeth backtick backslash backslash backtick, or backtick backtick backslash backtick backtick.
No wait, that isn't right. Only the second method works: \
 
oh, thanks
 
@LdBeth Which problem are you talking about? The balanced parens?
 
Then balanced parens, by keeping a track of nesting level
 
4:00 PM
Yes that sounds right. Let's see next week.
Btw, anyone that wants reminders before these events can sign up for those here.
 
4:24 PM
@xpqz lol
 
 
6 hours later…
10:01 PM
is there a way to get a value to return 0 if its negative and the original number if possitive? if statements get kinda messy.
{0>⌊/⍵:0⋄⍵}
esspecially because i have to use it twice in one of my functions
 
0⌈n
 
lol
(0∘<×⊢)
 
aw i was just getting exited because i found this {(⍵+|⍵)÷2}¯10
thanks
 
@BrianBED don't really see what you want to achieve with the ⌊/ as if the argument is an array, you'd be sometimes returning an array and sometimes a scalar number
 
oh i know i get 2 values as input. i want to get the lower one of those
 
10:33 PM
i've been driving myself insane...
why doesn't this work:
255 255 255⊥¨50 50
i've tried enclosing, and every other way i could enclose the right but i can't figure out the right way to do it
 
what result do you expect?
 
i expect 3264050 3264050
 
(255 255 255∘⊥)¨50 50
 
wat o nice. how do you spot that?
 
or 255 255 255(⊥⍤1 0)50 50
the first one is just "currying" in functional programming sense
 
10:37 PM
li have no idea how ⍤ works, or what the 1 and 0 do... pretty lost. also no idea what currying means
:)
 
the second one is "get left args as an array (1 rank), and right args as individual cells (0 rank)"
 
ahhh
 
@LdBeth (you don't need the parens there)
 
for ¨? no, it is not needed.
CMQ: what does monadic ∊⍤2 do?
 
i love how adam made a page for all the abreviations you guys make lmao. i was just about to ask
 
10:53 PM
@BrianBED currying means if you have a functions takes two arguments and you have already one of the arguments, you make a function out from them that takes the rest of the arguments, having the same result as applying the function to two arguments at the same time
 
11:19 PM
... riighhtt... i maybe understand...
 

« first day (1850 days earlier)      last day (227 days later) »