But after reading about NARS's direct def, and contemplating things like BQN's ◶, I'm thinking that maybe a better use of multiple colons in a dfn expression is to choose what to return, so 0: continues with the next statement, 1: returns what's to the right of the : while 2:not this:but this returns the second statement, etc. Thoughts, anyone?
The paper also starts off by proposing function assignment, which I'm thinking NARS didn't support since it's conspicuously absent in their examples. To the point of including D←'⍺÷⍵' ⋄ M←'1_⍵' then 3 (D∇M) 4.
Well, a page name change is in order at least. "Direct definition (operator)" versus "Direct definition (notation)"? Iverson seems to have called the operator "function definition" or "verb definition", but that's ambiguous because of J's :, which I wouldn't consider to be the same thing.
@Marshall Growing up, the term "direct definition" was quite commonly mentioned and always refered to the notation, so I think that page merits being an unqualified name, and then the operator one can be "(operator)" but do we need a "(function)" too for Dictionary's?
> • takes a space-delimited character vector right argument, string
> • returns an array of length N where:
> ⠀○ if N is less than or equal to the number of sub-arrays in string, the first N-1 elements of the result are the first N-1 space-delimited partitions in string.
> The Nᵗʰ element of the result is the remaining portion of string.
> ⠀○ if N is greater than the number of sub-arrays, pad the result with as many empty arrays as necessary to achieve length N.
I did not succeed with this one. Splitting the character vector is no problem and picking the first n is also not difficult. But appending the left over part is.
It could, but it is mostly there for APL2-compatibility.
And further, for some reason, ⊆ treats a 1-element vector left arg as a scalar, while ⊂ didn't. So if we allowed short left args for ⊆ then there'd be an inconsistency at length 1.
@RubenVerg Because of prototypes, you can write ' '⍴⍨' '≠⊃⍤⌽ as ''⍴⍨' '≠⊃⍤⌽
So yeah, I guess this is it. It's been a (110-episode) blast, and I hope everyone found it worthwhile and learned things, and will continue onwards and upwards in their APL journey. Of course, we can all still hang out here and challenge each, not just on Fridays!
not supported: stranding, trains, most primitives (the repl helpfully prints a list)
idk if it works on windows, its unicode support is kinda wonky
supported: * dfns `{...}`, dadvs `_{...}`, dconjs `_{...}_` * guards `cond:executed` * early return statements (`■`) * names and assignment (names must follow the convention: `abc` for arrays, `Abc` for functions, `_Abc` for monadic ops, `_Abc_` for dyadic ops) * complex numbers (`⏨` for exponent notation, `ᴊ` for complex notation) * character literals (`'abc'`) and strings (`"abc"`, plus `⍘` for escapes) * arguments to dfns are `⍺` and `⍵`, left operand is `⍺⍺` if array and `⍶⍶` if function, right operand is `⍵⍵` if array and `⍹⍹` if function
Not especially nice: > (3*⊖1≠⍳3) { array with ⍴ = 3 and , = [3.0000000000000004,3.0000000000000004,1] } although fortunately it'll be accepted as an integer array.
> -{⍶⍶ ⍵} ⍳10
Syntax error:Variable ⍶⍶ does not exist
But I did manage to construct a multiplication table:
> {s←2⍴l←≢⍵⋄((l*⊖1≠⍳3)↑(l+2=⍳3)⍴¯1↓,(l+1=⍳2)⍴⍵)×⍥(s∘⍴)⍵} ⍳4
{ array with ⍴ = 4 4 and , = [1,2,3,4,2,4,6,8,3,6,9,12,4,8,12,16] }
(in just O(n^3) time)
One way to catenate vectors:
> (2×⍳5) {S←(l←⍺+⍥≢⍵)∘⍴⋄m←(≢⍺)<⍳l⋄(S ⍺){⍺+m×⍵-⍺}⊖S⊖⍵} 1+2×⍳3
{ array with ⍴ = 8 and , = [2,4,6,8,10,3,5,7] }
All right I don't think reduction's possible because I don't see a way to call an arithmetic function an arbitrary number of times. But you can sum a vector of natural numbers with ≢⍸a and take its product with ≢,⍳a, or ≢,a⍴0.
Well, I shouldn't throw out recusion so quickly; maybe there's a Z combinator. Although it doesn't seem likely with the array/function/operator system.
⍸{(1↓⍵)-¯1↓⍵}⍸a is prefix sum of a vector of natural numbers, drops the last element although that could be fixed. And {(1↓⍵)-¯1↓⍵}⍸{(1↓⍵)-¯1↓⍵} is ⍸-inverse-ish, also dropping some stuff.
SumRows is +/ on a matrix of natural numbers! Unfortunately the floor function Fl is not terribly accurate, so it's liable to get numbers that don't round to integers and break because of that.
All right, {⍸2=SumRows ⍵{s←⍺⍮⍥≢⍵⋄(Transpose s⊖⊸⍴⍺)=s⍴⍵},Transpose⊸×(2⍴≢⍵)⍴⍵} ⍳n should get primes up to n, but due to numerical issues the largest n I was able to use it with is 2.
I found a floor-less way to do +/ on a boolean matrix, although the shape management gets rather extreme.
T3←{m←≢⍵⋄n←⊃⊖⍴⍵⋄(m⍮3×n)⍴(n Ap m⍮3)↑((n×m)Ap m⍮4)⍴(-n)↓,(n Ap 4⍮m)⍴⍵}
CountRows←{m←≢⍵⋄t←3×n←⊃⊖⍴⍵⋄r←T3 ⍵⋄i←(⍴r)⍴⍸3⍴n⋄(1+n×1-⍨3×⍳m)-,(m⍮1)↑(m⍮-n)↑(m⍮2×n)⍴⍸,(r∧3≠i)≠(0=r)∧1≠i}
The 1D version is just {t←3×n←≢⍵⋄r←t⍴⍵⋄i←⍸3⍴n⋄(1+2×n)-1↑n↓⍸(r∧3≠i)≠(0=r)∧1≠i}.
In SumRows, the whole Pd 1-⍨⍸Pd(≢⍵)Ap thing is more or less ⍸⍣¯1, going around the square of power from "target indices" to "division lengths". So the floor-division thing gives you a list of row indices and this section adds up how many times each row appears.
All right, the version with floor is quite a bit faster.
Also, I noticed there's multidimensional ⍸, so SumRows←{Pd 1-⍨⍸Pd(≢⍵)Ap⊃¨⍸⍵} would work, except, I don't know how to do ⊃¨.