« first day (2172 days earlier)      last day (488 days later) » 

7:41 AM
@user18945337 Hi Dawn Bimler, if you want to participate here, just email access@apl.chat
 
8:31 AM
0
Q: Haskell version of APL trains

j_v_wow_dTLDR: Is there a Haskell library that offers function definitions (preferably with concise notation or naming) for handling common patterns of multi-argument function composition such as those in APL? Full Question: I'm new to Haskell and I have recently found myself asking the types of compositi...

 
9:25 AM
@Adám should that not be 4=(4=4) -> 4=1 -> 0 ?
 
@SilasPoulson Yes, but the outcome is ofc. the same.
 
 
2 hours later…
 
1 hour later…
1:00 PM
(On problems.tryapl.org there are syntax errors in the test cases for double trouble)
 
Welcome to APL Quest 2017-9! Today's quest is Double Trouble:
> Write a function that takes a character vector or scalar and returns a Boolean vector indicating anywhere an element is followed by an element of the same value.
@essielovett I'll have a look. Should be fixed now (or whenever it finishes building).
 
{2=/⍵,0}
 
That's very clear.
Unfortunately, it is also terribly inefficient. Can you think of why?
 
Or 0,~
 
You mean 0,⍨
 
1:03 PM
Yes
Sorry I am on mobile
 
{0,⍨2=/⍵} will however fail on the empty case.
Look at that, the reference solution is wrong: {((1↓⍵),' ')=⍵} — Who can explain why that's wrong?
 
@Adám was even supprised it was working
@Adám not working for Zilde
 
It'd be '' but that actually works.
1↓⍵ is '' and ('',' ')='' works because APL is lenient in treating the singleton vector space as a scalar.
@Richard Do you want me to explain why it works and why it is so inefficient?
 
Because it are two days types?
 
days? auto-correct for data?
 
1:09 PM
Data Yes
 
Yes. That's actually the answer to both whys.
0 will never match any letter, so it is safe to add that comparison
 
@Adám Fails if the input ends with a space?
 
But since we have a simple vector of mixed types, the internal representation will blow up into a vector of pointers to scalar arrays. That means the 2=/ has to go pointer chasing n times. Oof.
@rabbitgrowth Exactly.
An obvious efficient (and correct) solution is {''≡⍵:'' ⋄ 0,⍨2=/⍵} but here is a challenge: Write it so it is both efficient and doesn't have a guard.
 
Adding a rare character at the end of the vector.
 
That fails if the vector ends with the rare character. And there are only 1114112 characters to choose from.
 
1:14 PM
≢↑2=/,∘' '
 
Did not you use a blanc namespace or something like that once?
 
Ah, yes I did. That's just as bad as the 0, only it works for all data types.
@rabbitgrowth Fails on ' '
 
oops, should have listened to myself haha
 
I have two very different approaches.
 
Curious!
 
1:20 PM
I can reveal or give y'all some more time.
 
I can take it as homework
 
OK, but I'll probably put it in the video,.
 
Here's my stab at it: (≢↑2=/,∘¯1)⍤⎕UCS
 
Then I just dont look at the video or 'll think about another one
 
@B.Wilson Ooh, that's a very nice idea!
You could also put ⎕UCS inside: (≢↑2=/⎕UCS,¯1⍨)
@B.Wilson The only case where this has a drop in efficiency is when you have characters in the range 128–255 (and similarly for multi-byte chars) where the character data can be stored internally as unsigned integers, but the numeric representation is signed, so it'll blow up to twice the width.
 
1:26 PM
Ah! I forgot about Constant!
 
Even without it, you can do ¯1,⍨⎕UCS
 
Maybe comparing a rotated version
 
That risks the first and last character matching.
 
@Adám Nice! I love this kind of mentoring prod :)
 
:-D Shall we leave it here for now and let Richard ponder?
 
1:28 PM
@Adám Yes
 
I guess you could replace ¯1 with INT_MAX or anything positive outside the Unicode range.
 
No, the ¯1 isn't the problem, as the numbers have to be signed anyway (you don't have access to unsigned ints in any APL I know of).
But thank you all for this one, and see you next week for 2017-10: Squaring Off.
 
@Adám Wait. I didn't grok this properly. Why is 128-255 special? Since registers are at least 32bits wide, doesn't all of Unicode fit in the range of both signed and unsigned integers?
 
my terrible attempt: {0@(≢⍵)⍣(×≢⍵)⊢⍵}⊢=1⌽,
 
Though, I guess you would want to stuff the string inside an unsigned char array when possible.
@rabbitgrowth Ooh. That's a good start, I think!
The fixup is just ugly. What about something like this: (≢↑¯1↓⊢=1⌽,)
 
1:46 PM
ah, that's so much nicer
 
And you were faster than my approach!
    cmpx '(≢↑¯1↓⊢=1⌽,)a' '(≢↑2=/,∘¯1)⍤⎕UCS a'
(≢↑¯1↓⊢=1⌽,)a      → 3.8E¯4 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
(≢↑2=/,∘¯1)⍤⎕UCS a → 5.6E¯4 | +48% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
Just set a←⎕UCS ?⍤⍴⍨ 1e6
 
⌽⍤⍷⍨<⊢=1⌽, also seems to work
 
2:11 PM
Thank you @Adám @xpqz @essielovett, for the discussion on IDE and editors. (I got a little late viewing the messages)
 
@rabbitgrowth Ooh. Masking off with a boolean. I like! Using seems a bit overkill. Less visually clean but somewhat faster is ((-⍤≢↑1⍨)<⊢=1⌽,)
 
2:28 PM
Nice! I've learned about overtake but always forget to use it
 
2:41 PM
@Adám {0,⍨0=+\⍣¯1⎕UCS⍵}
 
@SilasPoulson thanks Silas that is helpful.
 
Oh, remove the 0,⍨ even
So 0=+\⍣¯1⍤⎕UCS
Apparently needs a 1⌽, I suppose I don't fully understand this inverse
 
My favourite inverse is ⍸⍣¯1
 

« first day (2172 days earlier)      last day (488 days later) »