I'm reading the ISO spec on ⍤, in order to implement it. Given the form A (F⍤N) B where F is a function and B is a vale, I don't understand how A is supposed to work. I can't seem to be able to write dyadic invocation that doesn't give me an error in GNU APL, so clearly I haven't understood ho wit's supposed to work.
I was actually logging in to see if xificurC wanted to learn some more when I noticed they pinged us. I don't mind you taking over, whatever you prefer.
Ok, great. Dyalog APL has support for tail recursion as well. If we check the value of ⎕SI during a function call we can check how many things are in the execution stack, e.g.
@xificurC maybe try running fib←{⍵≤1:⍵ ⋄ ⎕←≢⎕SI ⋄ (fib ⍵-1)+(fib ⍵-2)} ⋄ fib 5 in your machine.
(I changed the ⎕←⎕SI to ⎕←≢⎕SI` because ⎕SI contains the names of the functions in the execution stack and we only care about how many are in the stack)
Btw @all, why does ⎕ look so odd to the right of ≢? ≢⎕ ?
@RGS fact←{⍵≤1:⍺⋄(⍺×⍵)fact ⍵-1}. It's dyadic because I don't know if dfns has support for more args. Of course it could be wrapped factorial←{1 fact ⍵}
clearly the best way to do factorial is ⎕CY 'dfns' ⋄ f ← {lisp '(((\(f)(\(x)(cond((=0x)1)(else(* x ((f f)(- x 1)))))))(\(f)(\(x)(cond((=0x)1)(else(* x ((f f)(- x 1))))))))',(⍕⍵),')'}
@xificurC slashes (/\⌿⍀) in APL are known to be "schizophrenic". Really /\⌿⍀ are 8 built-ins (10 if you count monadic and dyadic cases as separate builtins) squeezed into 4 characters.
Defining your own ops in APL is really simple. You can use the same syntax as for dfns (and hence you will be writing dops - direct operators) to enclose the body of the operator with {}
Then, inside {}, you use ⍺⍺ (double ⍺) to refer to the left operand (the left """argument""" of the operator) and use ⍵⍵ to refer to the right operand.
Question: which one of ⍺⍺ or ⍵⍵ is always present in operators?
Go ahead, and define a "filter" monadic operator. It should take a function as left operand, and what it does is, takes a right argument (⍵), applies the operand to it to create a boolean mask, and then returns only the elements for which the boolean mask is 1
@xificurC you usually write it out. (and here the schizophrenia of / gets really annoying as it prefers to be an operator to the compress function you want in some contexts)
Now of course we haven't covered all built-ins, but you have a basic overview of the language. Would you rather be solving some problems now, and get to know the primitives as we go along? Or have a look at some more primitives here?
@xificurC (≤∘1 {⍺/⍵} ⊢) works, but you may notice that useless dfn wrapper around /. Without it, (≤∘1 / ⊢) is interpreted as a ≤∘1-reduce of identity (equal to {{ifAlphaExists:error ⋄ ⍵≤1}/ ⍵}). There exists a slightly shorter working version of (≤∘1 ⊢⍤/ ⊢), but that introduces another operator.
@RGS ah, i may have been overcomplicating things. I also implicitly assumed that the results should be summed, but you're asking for an array of vectors of numbers 1…6
Of the 4 characters in the dfn, 2 must be ⍺ & ⍵, so there a 2 left for somehow making an array of vectors. As a hint, the array of results needn't be a vector
So with ⍳, ⍺ and ⍵ you have 3 of the 4 bytes needed. The remaining byte is a function you have used for the purpose you need in this 4-byte solution :)
@xificurC note that 'abcd'[2 3] extends to higher dimensions - ⋄ (⍳3 3)[1 2;1 3] (this also shows a caveat of (⍳3 3)[1;1] - the result is a rank 0 array containing the vector)
@xificurC for when you get back: in case you have a function that needs to get a lot of things as input, it is common to pack them into one of the arguments, say ⍵, and then unpack them in the beginning of the dfn: roll ← {(sides dice n) ← ⍵ ⋄ ⍳dice⍴sides} works as roll 6 3 0 to roll 3 die with 6 sides.
dyalog.com/uploads/files/student_competition/… question 5 from this is interesting, how would you do it? I have a solution that returns ⊂stuff, and I can't figure out how to unenclose in a train