but why, what's the right way to make an IO.MemoryStream using the byte[] constructor?
I don't believe it
I've just got it
~30-40 tries of guessing combinations, and right when I give up and ask; it's byteStream←(⎕NEW⍠(Type.GetType⊂'System.Byte[]'))IO.MemoryStream(⊂b)
why is (⊂100 102 103) different from ⊂101 102 103? They have the same depth, the same shape, the same rank, they look the same in max boxing, what does that () do which makes the call work!?!
@TessellatingHeckler They are exactly the same in isolation (assuming your first 100 is a typo for 101). You need to provide the whole line of code to see how they differ.
@TessellatingHeckler Ah, I guess I got what you mean. IO.MemoryStream is a class, which is treated the same as an "array" in terms of syntax. So IO.MemoryStream ⊂b tries to call ⊂ dyadically (Partitioned Enclose) between IO.MemoryStream and b, which obviously DOMAIN ERRORs. On the other hand, IO.MemoryStream(⊂b) creates a two-item array by stranding IO.MemoryStream and ⊂b.
@Bubbler Grargh, thank you, that is ringing a bell, did you (or Adam) tell me this last time I got stuck here?
I probably also asked why that makes any sense at all, but nevermind that
the next line is
deflateStream.CopyTo inflatedStream
if I leave it like that, the dfn returns on that line as if it had an output. but if I try assigning the result to a variable, it errors because no result is provided. I think the method is void. If I trace it, stop before that line, and run that line in the interactive session, it works without any error or visible return value and does the copy
Half the length of the C# version. The grouping and UTF-8 decoding of bytes was a massive frustration in C#, a non-issue in APL. The decompression, the other way round.
@Bubbler my PowerShell frontend still has a problem with ⍎ and no-result functions; when I tried that kind of diamond approach, it swallowed all the results when there were some.
Dyalog APL is such fun for the novice. I was looking at Dyalog v18 Nub Sieve example on aplwiki.com. I observed that (~≠'HELLO, WORLD')/'HELLO, WORLD' is LOL. I decided to go without parentheses. 'HELLO, WORLD'/⍨ ~≠ 'HELLO, WORLD' I wrote the dfn version. {⍵/⍨~≠⍵} 'HELLO, WORLD' I learned much writing the train version for (~≠'HELLO, WORLD')/'HELLO, WORLD' (~∘≠ {⍺/⍵} ⊢) 'HELLO, WORLD' Another train using the partition operator giving a boxed LOL, assuming ]box on (~∘≠⊆⊢) 'HELLO, WORLD' So fun to get LOL in APL using that Nub Sieve and the string 'HELLO, WORLD' :)
@TessellatingHeckler I can't think of a way to handle it properly. A simple (but buggy) workaround is to apply ⊢ to the expression (which may give or not give a result) and catch any VALUE ERRORs (error code 6), but it also catches the same error from user code and may give obscure results.
@brgal (If you enter multiple messages in quick succession, SE Chat will merge then visually, and then you can still use markdown's backticks to make your code look better.)
@Adám Thanks again for your teaching ;) I am pretty slow...I really need to practice. Steps to your elegant form: `(~≠ 'HELLO, WORLD') / 'HELLO, WORLD'` `(~∘≠ 'HELLO, WORLD') / 'HELLO, WORLD'` `'HELLO, WORLD' /⍨∘~∘≠ 'HELLO, WORLD' ` `/⍨∘~∘≠⍨ 'HELLO, WORLD'` LOL
@Adám Sorry I do not know how to use the markdown's backticks to make the code look better.
@brgal Pretty much exactly like you did it. You just need to split the lines into separate messages. Alternatively, you can put all the code into a single message and click the "fixed font" button or hit Ctrl+K.
cmc1 proved too hard for this room, so here's something more basic:
cmc[0.5]: given two numbers ⍺ and ⍵ as vectors of decimal digits (possibly very long vectors; endianness - up to you), find the residue of ⍺ mod ⍵ in the same format. (hint)
@Adám interesting. john's divi function computes both quotient and remainder, discards the remainder, and returns the quotient. instead of reusing it for mod, he computes mod as (the bigint equivalent of) ⍵-⍺×⌊⍵÷⍺
i mean he reuses divi as a function, but he could have reused the remainder directly, without wasting resources on × or -
@Bubbler not shitty at all, it's smaller than the one in dfns, and it appears to work
obviously you don't need the multicharacter variable names :)
btw, the point i wanted to make with cmc[0.5] was that long division of big integers is so much more complicated than long division of polynomials over GF(2) :)
@TessellatingHeckler You don't need to output the original array (and then you don't need ⎕←'' either). Also, no need for parenthesising (3 3⍴⍳9), however it could be valuable to show that =⍨ and ≠⍨ penetrate structure, e.g. for 1(2 3) or 1 2 'abc'
I was reading Dyalog APL's 13.0 changelog, which states
> The Index Generator function was changed so that ⍳⍬ would return ⊂⍬ rather than ⎕IO. The former behaviour was considered a bug because ⎕IO is not a valid index into an array with empty shape (that is, a scalar).
@RGS ⌷ takes a vector (or scalar) of indices for each dimension, and ⍳ returns a vector of indices. For a scalar, ⌷ needs a length-zero vector (to match the number of dimensions): ⋄ (0⍴⍳⍬)⌷2
However, it is maybe easier to understand for bracketed scatter-indexing ⋄ 2[⊂⍬] where the brackets contains an array of vectors. Each vector has to have a length corresponding to the rank of the array being indexed into.
@RGS Well, ⍺≤⍥≢⍴⍵ because ⌷ allows omitting trailing axes. Of course, this means that an empty ⍺ doesn't really index into a scalar, as it leaves any array as-is.
The challenge
Given point and a path of points, say whether or not the point is in the polygon that is created by the path.
Also return true if the point is on an edge of the polygon.
Input
A list of pairs of integers.
The first 2 integers represent the point.
The remaining pairs (3rd and 4th, 5t...
Could you try explaining again what is the relationship between ⊂⍬ and a scalar?
I think there might be some identity(ies) here I am missing
@Adám although this one seems sensible to me
Basically I expect some identity of the form ⍵⌷⍨f⍵, where f makes use of ⍳⍵, such that prior to 13.0 it was broken when ⍵ was a scalar and that now is fixed
I think I got what my problem is: the sentence "The former behaviour was considered a bug because ⎕IO is not a valid index into an array with empty shape (that is, a scalar)." makes it look like ⍳⍬ now is a valid index into an array with empty shape, it just doesn't specify the indexing method for which ⍳⍬ is a valid index
I was assuming such a method would be through use of the ⌷ primitive
but in using ⊃ or [] indexing, ⍳⍬ works as an index to a scalar
Ok, so I think this identity must hold: (⊢≡{⍵[⍳∘⍴⍵]}) array, and it did not hold with the old ⍳⍬ giving ⎕IO:
I ← (⊢≡{⍬≡⍴⍵: ⍵[⎕IO] ⋄ ⍵[⍳∘⍴⍵]})
I ⍳2 2
I 1 2 3
I ⍬
I 3
Hm I thought the bot handled this, but this gives a RANK ERROR on the last one, whereas just using {⍵[⍳∘⍴⍵]} works for all "test cases"
@RGS The depth of ⍳v is 1 if the length ≢v is 1 and 2 otherwise. This inconsistency is caused by the fact that the NARS "extension" of ⍳ to vector arguments isn't actually compatible with the old version: see APL Wiki.
@Adám 'need'? I thought they would be helpful for comparison. ⎕←'' spaces the output pleasantly. Trying to show that =⍨ penetrates structure without boxing looked more confusing than helpful when I attempted it.
@Marshall dzaima/APL improves this by giving a simple array result if the argument has rank 0 (instead of length 1) and a nested one otherwise, so that ≡⍳v ←→ ≢⍴v. BQN fixes it by using single-number indices if the argument isn't an array and vector indices if it is (in which case it must have rank exactly 1), so that ≡↕v ←→ 1+≡v.
@TessellatingHeckler The example is interactive. The user can easily remove the function and reexecute. Btw, you could do 'disp'⎕CY'dfns' in the header and use disp to show structure.
@TessellatingHeckler I often make my PC sleep. No issues here.
@Adám While both those are true, is that not contradictory to suggest both removing and adding unnecessary helper code for clarity in the output, in the same reply?
@Marshall Is there a better way than ⊏⥊ to get the array corresponding to a scalar?
@TessellatingHeckler :-) The helper code would also assist in further experiments, while being non-obvious for the uninitiated to add themselves. I don't really feel strongly about this, so if you do, then I'll just merge it as-is. Better to have more examples than to be overly pedantic about their exact spelling.
Having treated new 18.0 features in the previous lessons, I was thinking to describe some of the language enhancements next. Unless we have other requests.
@RGS The problem you have is that you are detecting if a value belongs to a new segment relative to its neighbour on the left, rather than how many segments ahead it is.
@RGS ah I think I got it! when we had a boolean, a 1 indicated a new partition would start there, or rather, we would have to jump 1 partition to the right; an integer n means we jump n partitions to the right, meaning we create n-1 empty partitions if n≥1
@RGS Yes, you were comparing interval indices, to see if they were growing or not. Instead, - computes the difference in interval index numbers, i.e. how many segments ahead of its neighbour on the left, any given value belongs in. 0 means "in the same segment". 1 means "in the next one". 2 means "skip one".
@ngn It originally used ⎕IO←0 by default, but having the bot use a different default than the main system (however wrong you may thing that default is) would be quite confusing.
Anyway, this shows another extension in 18.0, namely that ⍸⍣¯1 conveniently works, but what you might not notice is that it also shows a further extension of ⊂. Observe:
Another thing that ⎕JSON can now do is to understand and create JSON5: ⋄ (ns←⎕JSON⍠'Dialect' 'JSON5'⊢'{noQuotes: [0xdecaf,0xC0FFEE] /* comment */}').noQuotes ⋄ ⎕JSON⍠'Dialect' 'JSON5'⊢ns
@RGS the couple times i've needed to "solve" some function (not in APL unfortunately), 1) it was complicated enough for wolfram engine to not be able to solve it (definitely too much for me), and 2) i needed (aka wanted) all the solutions (i ended up going with code assuming the solutions are relatively non-hidden)
@RGS as far as i'm considered, single solutions don't give me much. i see they can be useful sometimes, but dyalog's inverses giving just one possible result is a pet peeve of mine
@Razetime BQNs; separating highlighting for code and REPL results is pretty much impossible so i don't do it; feel free to remove #BQN at the end of the URL for no highlighting/font