« first day (1927 days earlier)      last day (720 days later) » 

8:55 AM
@Adám should I expect spawn to work in a notebook context?
 
@xpqz Yes, it is just another primitive.
 
9:19 AM
@Adám Ok, let me ask the question a different way -- given that the APL bits should work, is there anything in the jupyter-kernel that might serialise output differently or otherwise make different assumptions than a normal session? The reason I ask is that the cultivation examples on the topic, when run in jupyter, look quite different.
Here's my 'normal' session:
      {⎕←'Started waiting',⍵,'s' ⋄ ⎕←'Elapsed:',(⎕DL ⍵),'s'}&¨0.6 1.2 1.8 ⋄ ⎕DL 1 ⋄ ⎕←'    Unrelated stuff'
Started waiting 0.6 s
Started waiting 1.8 s
Started waiting 1.2 s
Elapsed: 0.611686 s
    Unrelated stuff
Elapsed: 1.231548 s
Elapsed: 1.841549 s
Here's jupyter:
Started waiting 0.6 s
Started waiting 1.8 s
Started waiting 1.2 s
Elapsed: 0.610196 s
    Unrelated stuff
 
Huh, that seems a bit impossible. You get the starting message but not the ending message. Maybe the kernel doesn't handle incoming print requests right, after the code has terminated. TIO also suffers from this: Try it online!
Adding ⎕TSYNC⎕TNUMS~0 to the bottom of the request fixes the problem. Maybe the kernel should do that. Try it online!
 
What's that, forcing some tcp buffer?
 
@Adám Thanks for offering to help with un-dinosauring the code in my APL book. I will take you up on that. I also mis-stated the target audience; I wrote it to help Raspberry Pi users to experiment with APL. Many will be school students but some will be hobbyists or teachers.
 
@xpqz No, synchronising (awaiting) all threads except 0 (which is the main thread and is always sync'ed).
 
But today I have another problem. More details soon.
@xpqz I have encountered the same problem in the past.
 
9:33 AM
@Adám Ah yes, with ⎕TSYNC {⎕←'Started waiting',⍵,'s' ⋄ ⎕←'Elapsed:',(⎕DL ⍵),'s'}&¨0.6 1.2 1.8 ⋄ ⎕DL 1 ⋄ ⎕←' Unrelated stuff' it does the right thing:
Started waiting 0.6 s
Started waiting 1.8 s
Started waiting 1.2 s
Elapsed: 0.604144 s
    Unrelated stuff
Elapsed: 1.21084 s
Elapsed: 1.82021 s
 
So maybe the kernel should add that to every request.
 
Well. Thinking about async/await in other languages, I'd probably expect to have to spell it out, and perhaps it's more of a surprise how the session does not require it. But the difference in behaviour isn't ideal, I guess.
I can raise an issue against the kernel.
 
The session doesn't need it because it stays "open" so whenever the printing happens, it happens.
 
Do you think the kernel's behaviour is what is expected? I can argue it both ways in my head.
Perhaps it just needs documenting.
 
I'd say for the purpose of the kernel it should behave similarly to the session
 
9:48 AM
@RikedyP That's certainly the path of least surprise.
 
@xpqz We're working on it right now.
 
@Adám Amazing. Bugs fixed while-u-wait.
 
10:22 AM
@xpqz won't be today I'm afraid
 
11:00 AM
goodness, developing with ]link is a joy
 
 
1 hour later…
12:28 PM
@Adám I was testing my solution on problems.tryapl.org/psets/… and got this message: "Submission caused SYNTAX ERROR with (' this is a test ') as right argument"
Looks like it's still using the old test case with missing spaces?
 
@rabbitgrowth More likely, the error message output doesn't preserve whitespace.
Nope, indeed, the test case wasn't updated. I'll fix that.
 
Thanks!
 
apl quest soon?
 
1:09 PM
I have a vector of character vectors, and I want a boolean to tell me which vectors start with three backticks. I can do it with each, but I can' t get rank to give me a simpler solution.
 
@RomillyCocking 3=+/∧\'`'=↑vec_of_vecs or something?
 
That's what I started with, but a rank solution would be cleaner
 
3('```'≡↑)⍤1↑vec_of_vecs like-wise
 
@RomillyCocking yeah or (⍷⍤1)
certainly won't be faster
 
Speed doesn't matter for this problem, but elegance does. blog.rareschool.com/2022/05/apl-and-python-go-head-to-head.html
 
1:25 PM
I think RikedyP's solution is the most elegant
 
I don't even have to do the ↑ in RickedyPs solution, as the data comes from a native file and I can just as easily get a matrix as a vector of vectors. And it's old skool - the way I'd have tackled it in the 80s.
 
('`'∧.=3∘↑)¨ is how I wrote it a while ago. On nested vectors
I found myself using highly nested structures when I parsed markdown. A more flat approach would be awesome - although particularly difficult, I imagine
github.com/mlochbaum/BQN/blob/master/md.bqn I haven't read through this, but I imagine there's some stellar techniques used
 
All I want is to remove the backticks and add 4 spaces to the code lies between them. A simple problem, thank goodness.
 
Haha, okay :)
 
Iand I am nearly there now
 
2:21 PM
 
2:56 PM
@Razetime Yup, 3 minutes or so.
Welcome to APL Quest 2014-4! Today's quest is Space The Final Frontier:
> Write a dfn that removes extraneous (leading, trailing, and multiple) spaces from a character vector.
Quite a few ways to attack this. Any bids?
 
{(' '=⊃⍵)↓⍵[⍸2≠2+/' '⍷⍵,' ']}
But not working for all edge cases
 
' '∘(1↓,⊢⍤/⍨1(⊢∨⌽)0,≠)
 
@Richard I recommend putting backticks around code, or else, backslash will eventually bite you :-)
@xpqz Someone has been APLcarting…
 
That's much better than my ⊢(/⍨)((⌽∘(∨\)∘⌽∧∨\∧1∘⌽∨⊢)≠∘' ') :)
 
@Richard Which case not? Huh, it only fails on a scalar, which the problem spec doesn't even require handling — though it is tested for.
 
3:02 PM
@Adám I couldn't possibly say.
 
@Richard Btw, a[⍸b] is a/⍨b
 
@Adám such as a single space
 
It works fine on a single space as long as it is a vector.
> from a character vector.
We should probably amend the problem text or the test case.
 
I've come up with this solution for my conversion problem - written thus for exposition:
convert←{ ⍝ pandoc format to markdown format
 t←3=+/∧\'`'=⍵
 n←2|+\t
 
@RomillyCocking Rank doesn't "open up" elements, so you need …⊃⍤0
 
3:05 PM
(~t)⌿(¯4×t<n)⌽⍵,⍤1 4⍴' '
}
 
@RomillyCocking You can post a single multi-line code block by pasting it in (or using Shift-Enter for newlines) and then pressing Ctrl+K.
 
It's a character matrix not a vector of vectors
Ty, I'd forgotten
 
@rabbitgrowth I wouldn't say so. Yours is very readable.
@RomillyCocking Didn't we discuss this: ⊣/'```'⍷matrix
Anyone up for a regex solution to remove those pesky spaces?
 
'^ +| +$| +(?= )'⎕R''
 
@xpqz can you explain this neat solution?!
 
3:09 PM
@rabbitgrowth Lookahead, nice. How about using an exception pattern?
 
'^ *' ' +' ' *$'⎕R'' ' ' ''⊢
 
What's an exception pattern?
 
[^ ...] <- negated char class
@Richard Perhaps easier as a dfn: {1↓(x∨1⌽x←0,⍺≠⍵)/⍺,⍵}
 
@rabbitgrowth Not something intrinsic. I just use the term to mean using multiple regexes where the first one gets replaced with itself. Not sure it makes sense here.
@xpqz You can combine the first and last with |
pattern_for_spaces_to_keep ' '⎕R'&' '' uses an exception pattern, and then removes all other spaces.
 
Sure. I just like the fact that you can express that sort of thing as multiple patterns on the "apl side" rather than in the regex. It's a cool feature.
 
3:15 PM
@RomillyCocking I have a nice expression {⍵∧⊃1 = 1 0 ¯1 +.⌽ ⊂⍵}∘{((3=1⊥⊢)⌺(⍪3 1))'`'=⍵}, from here you turn off the last 1 - if the sum of the result is odd. And do some kludging for ⊆ or ⊂ then you have an implementation of inline triple backticks that matches the markdown spec
 
I wonder if speed can be gained by using idioms.
 
@Richard I go through this solution in xpqz.github.io/learnapl/tacit.html
 
@xpqz Thanks! Probably skipped that part because it was too difficult back then.
 
For inline backticks, because it's trivial to extend to multiple lines.
 
@Adam discussion earlier took me back to the traditional 'count leading backticks' solution, which I like as a good example of array vs procedural thinking.
@awagga I think you're solving a more complicated/general problem than mine.
 
3:18 PM
Yes, but related
Just wanted to share :)
 
@xpqz Fails on 'this is a test '
 
I have a feeling backticks could be implemented in a way simpler/shorter/more elegant than my approach. But I am bad at using booleans to their full extent
 
{⍵/⍨(∨\∧⌽∘(∨\)∘⌽)' '≠⍵}
under would be nice here
 
I also tried something with stencil, but that’s still difficult to understand for me. And it also only applies on matrices, isn’t it ?
 
3:22 PM
@Razetime Yeah, f\⍢⌽ could be optimised.
@Richard No, it handles all ranks (above 0).
 
{⍵/⍨(∨\∧∨\⍢⌽)' '≠⍵}
 
@Richard try {⊂⍵}⌺2⊢1 2 3 4
the left operand takes two args
 
@Razetime Uh, did you test this? I don't see how it removes internal extra spaces.
 
oh, it's supposed to do that
back to work then
 
t←(''↑⍨?10),(40↑⎕A)[?1e3⍴40],''↑⍨?10
  Richard⊢t           → 3.8E¯6 |     0% ⎕
  xpqz⊢t              → 1.3E¯6 |   -68%
  rabbitgrowth⊢t      → 1.5E¯6 |   -62%
  rabbitgrowthRegex⊢t → 1.2E¯4 | +3103% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqzRegex⊢t         → 9.2E¯5 | +2303% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqzDfn⊢t           → 1.3E¯6 |   -66%
 
3:24 PM
@Razetime will try that tomorrow. I’m on mobile right now. Thanks!
 
  Richard⊢t      → 3.7E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqz⊢t         → 1.3E¯6 | -66% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  rabbitgrowth⊢t → 1.5E¯6 | -60% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqzDfn⊢t      → 1.3E¯6 | -64% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqz⊢t         → 1.3E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  rabbitgrowth⊢t → 1.5E¯6 | +17% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqzDfn⊢t      → 1.3E¯6 |  +5% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
No surprises that the one I found in aplcart is fast ... :)
 
24 mins ago, by xpqz
@Adám I couldn't possibly say.
 
Is regex always that slow? Is it normaly used for more complex situations? Or to make the solution more readable or easy to make?
 
@Adám The genie is out of the bottle.
@Richard is 9.2E¯5 slow?
 
3:29 PM
@Richard Regex is generally slower than array operations (especially Boolean ones), but when performance isn't critical, and the problem is a good fit, I still use them. However, if you don't use regex features, ⎕R will use fast array code under the covers.
 
@Richard there's a loooot of places that regex is nice. this is a more simple manipulation so arrays are naturally faster
@Adám "don't use regex features?"
like using {⍵.Match}?
 
No, I mean in the patterns; no characters that mean something special in PCRE, or if you turn regex off.
  ' +'⎕R''⊢t  → 6.0E¯5 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  '( )'⎕R''⊢t → 9.5E¯5 | +56% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ' '⎕R''⊢t   → 5.4E¯6 | -92% ⎕⎕
 
Does anyone have a radically different approach?
 
Nobody used yet?
E.g. {⍵/⍨(~1 1∘⍷∨∧\∨∘⌽∧\∘⌽)' '=⍵}
Or {⍵/⍨~' '⍷⍵}(∨\' '≠⍵)/⍵}∘⌽⍣2
@xpqz How about a state machine?
 
@Adám you mirror the input twice?
 
3:37 PM
Yes.
 
@Richard Front and back.
 
Oh, missing a brace there. Should be {⍵/⍨~' '⍷⍵}{(∨\' '≠⍵)/⍵}∘⌽⍣2
 
ovs
Similar to some of the other functions, but at least for me slightly faster than xpqz's tacit function and over 40 years old: dl.acm.org/doi/10.1145/602312.602317
As a dfn: {⍵/⍨B∨1⌽B><\B←⍵≠' '}
 
It’s mirrored, processed and mirrored again using ‘beside’ ?
 
  xpqz⊢t         → 1.3E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  rabbitgrowth⊢t → 1.5E¯6 | +15% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  xpqzDfn⊢t      → 1.3E¯6 |  +4% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ovs⊢t          → 1.1E¯6 | -13% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
 
3:39 PM
nice!
 
@Richard Yes, although it is monadic here, so it could be too.
 
ovs
Yep that matches my results
 
{¯1↓⊃,/,∘' '¨' '(≠⊆⊢),⍵}
 
@Adám can it handle a single space(vector]? Or just spaces Sorry, can’t try it right now. I found this a very readable solution.
 
@ovs Could look like (⊢∨1⌽⊢><\)⍤≠∘' '⍛/
 
3:42 PM
@Razetime Ah yes, I thought of that, but then forgot again. Nice. Will be slow, of course.
 
yep, obviously slow
but i didn't see a splitting solution so i jumped on it
 
@Richard Yes, it does work on ' ', but converts other scalars to vector.
I suppose that's it for this week then?
 
Ah, so that's how you "turn off the first 1"
⊢><\
 
Double those backticks.
 
Thanks again everybody!
 
3:45 PM
@Adám Do you have a working pattern_for_spaces_to_keep?
 
@Richard Thank you! Without participants, there's be no show.
 
Can't figure out how to write that
 
@rabbitgrowth Didn't try. I'll have a go.
Why does '\S (?=.)' match 'x '?
 
Does it?
 
Not for me.
      ]display '\S (?=.)'⎕S'&'⊢'x '
┌⊖────┐
│ ┌⊖┐ │
│ │ │ │
│ └─┘ │
└∊────┘
 
3:50 PM
Uh, no it doesn't. But: ⋄ '\S (?=.)' ' '⎕R'[&]' ''⊢' this is a test '
 
@Adám thi[s ]i[s ][a ]tes[t ]
 
Oh, stupid me.
@rabbitgrowth '\S (?=.*\S)'
\S should probably be [^ ] but whatever.
 
Nice, thanks!
 
'([^ ]) +(?=.*[^ ])' ' '⎕R'\1 ' '' also works.
And '([^ ] ) *(?=.*[^ ])' ' '⎕R'\1' ''
I like using exception patterns. Not many programming languages support that out of the box.
 
@Adám I've ended up with this conv←{t←'```'≡⍤1⊢3↑⍤1⊢⍵ ⋄ n←2|+\t ⋄ (~t)⌿(¯4×t<n)⌽⍵,⍤1 4⍴' '}
which works and is easy to explain.
 
4:02 PM
@RomillyCocking Didn't we find that ⊣/'```'⍷3↑⍤1 was faster? I think it is pretty simple too.
 
Improvements welcome.
 
@RomillyCocking ⍵,⍤1 4⍴' ' doesn't look quite right. Missing ?
 
@Adam and yet it works :)
 
⍵,⍤1 4⍴' ' is the same as ⍵,⍤1⊢⍬
 
Ouch. My version only works because the code lines already have enough trailing spaces.
So now conv2←{t←⊣/'```'⍷3↑⍤1⊢⍵ ⋄ n←2|+\t ⋄ (~t)⌿(¯4×t<n)⌽⍵,⍤1⊢4⍴' '}
@Adám Thanks again.
 
 
2 hours later…
5:42 PM
@Adám ⊃((⊣,' ',⊢)/' '∘≠⊆⊢) late for the party, does this one count?
 
 
4 hours later…
9:58 PM
Here’s what I had (⊢{⍵/⍺}((~¯1↓∧\∨⊢∧1⌽⊢)(1,⍨' '=⊢)))
Dyalog 17 compatible..
 

« first day (1927 days earlier)      last day (720 days later) »