« first day (2021 days earlier)      last day (616 days later) » 

7:24 AM
So, Dfns can recurse by calling , but is the same possible using tradfns?
Like, suppose I wanted to convert the following function to a tradfn:

fib←{
⍵≤1:⍵
(∇ ⍵-1)+∇ ⍵-2
}

How would I go about doing that?
 
you just call fib by name
 
I tried that and it gave me an error
.... and now it works
weird
btw, what's the difference between `∇` and `∇∇`?
I'm guessing `∇∇` works like an argument to an operator?
 
7:41 AM
∇∇ is the operator itself; is the derived function, equivalent to either ⍺⍺∇∇ or ⍺⍺∇∇⍵⍵ depending on the number of operands the operator has
 
could you give a more concrete example, I'm not sure I follow
 
also i guess i should've said that ∇∇ is only for operator definitions
you can abstract out the + of that fib definition with fib←{⍵≤1:⍵ ⋄ (∇ ⍵-1) ⍺⍺ ∇ ⍵-2}, now its usage being +fib 10. Equivalently, you can {⍵≤1:⍵ ⋄ (∇ ⍵-1) ⍺⍺ (⍺⍺ ∇∇) ⍵-2}
 
what would be the benefit of writing it (⍺⍺ ∇∇) ⍵-2 over simply ∇ ⍵-2?
 
none; I'm just showing it as an example. You could of course use some other value than ⍺⍺ there, giving a different operand
 
ah, and then it would be re-called but with a different function, whereas calling it with ∇ would just call it with the same function again?
 
7:49 AM
same operand, yes
 
is there a reason to couple the operand to ∇ and not just have it use ∇∇ as the default behaviour?
saves on typing I guess
 
I imagine it's a very common case; and it keeps always being a function, which can ease mental parsing
just like how is the right argument in both functions and operators, operators just get the additional ⍺⍺/⍵⍵
 
right but ⍵⍵ is never a right argument
it's always a right operand
in the case of ∇ vs ∇∇, it still refers to the same object, the dfn itself
while ⍵ and ⍵⍵ refer to different objects
or am I completely missing the big picture?
 
and ∇∇ reference very different things
 
I'm guessing you can't use ∇∇ without the dfn being an operator
 
7:56 AM
I do agree that there is a sense in wanting to always refer the dfn/dop itself without any additions always, but I think the other arguments overpower that
@ElectricCoffee yeah, it makes it become one if there isn't already any ⍺⍺/⍵⍵
 
what's the upshot of having an operator without operands?
I don't assume {⍺ (∇∇) ⍵} makes any sense
 
@ElectricCoffee not much; there's just not much else it could be (other than an error i guess)
 
fair enough
 
@dzaima Uh, no.
 
I can see the case for ∇∇ and ∇ being different would help resolve ambiguities also
 
7:59 AM
@Adám oh, huh. I guess it is an error. ¯\_(ツ)_/¯
 
both mental ones and programmatical ones
 
@dzaima Yes, SYNTAX ERROR at runtime.
 
      foo ← { ⍺ (∇∇) ⍵}
      foo
 ∇foo
is what I get when I try it in RIDE
      2 foo 3
SYNTAX ERROR
foo[0] foo←{⍺(∇∇)⍵}
           ∧
 
right; the dfn "evaluates", but it's an error to use it
 
That's a SYNTAX ERROR at run time for you :-)
@ElectricCoffee Btw, RIDE is "dumb"; it is little more than an HTML renderer connected to the interpreter (which is also the actual IDE), and it knows next to nothing about the language.
 
8:04 AM
hey, it's what I have access to :P
 
Sure. I just wanted to clarify that RIDE isn't part of the equation. The language engine gives you that.
 
yeah I figured as much
but just to get back on topic to see if I got this right
`∇` refers to the dfn as it exists with all operands applied (if any)
`∇∇` refers to the dfn as a naked operator (a dop?), allowing me to change the operands should I need to
 
I'd say that for a dop, refers to its current derived function, while ∇∇ refers to just the dop itself.
 
how close is that to my understanding?
 
I think it is either very close or identical, but your terminology was a bit off.
 
8:10 AM
I just referred to {...} as a "dfn" regardless of context, even if that mightn't be strictly correct
 
Right, but operands aren't really applied to an operator. They just bind with it to form a derived function (which may or may not be meaningful).
 
I think it is important to understand that internal operator code is never run before the eventual derived function is applied to one or two arguments.
 
I guess that's a matter of semantics, coming from Haskell, writing foo (+) for function foo :: (Int -> Int -> Int) -> Int -> Int is partially applying + to foo
any application is also a type of binding
 
But wouldn't foo could run (or at least be looked at) when you do that?
 
8:14 AM
no
it can't
 
Oh.
 
without all its arguments it'll simply return a new function that awaits the remainder of its inputs
 
OK.
So you can also construct nonsensical things, as long as you don't apply them?
 
besides, Haskell is lazily evaluated, so it doesn't evaluate at all until actually needed
 
In APL, you can construct, name, pass around, deconstruct, and even apply in a matter that doesn't actually use the function.
 
8:15 AM
I can write x = [1..] which generates a list from 1 to infinity
but as long as I don't evaluate x, it's fine
 
Right, but what about x = ["a"..]?
 
can't
.. isn't defined for strings
it'll be a syntax error at compile time
 
x←⊃∘⍳∘'a' is perfectly valid. Picks the nth element of ⍳'a'
 
at least not as far as I remember
 
Only, you can't apply it, because that would cause ⍳'a' to give a DOMAIN ERROR.
 
8:17 AM
Haskell does let you write 'a'..'z' for when you want to generate the alphabet
the difference being chars instead of strings
 
Oh, x = ['a'..] then.
 
I'm not sure
I'll check
 
:-)
 
it might just run out of ASCII characters
 
Hey, Unicode exists.
Anyway, it shouldn't try to collect all those characters until you evaluate it.
 
8:19 AM
it goes into unicode
it runs forever
 
Huh.
 
well not until evaluated I mean
 
@ElectricCoffee Beyond 1114111?
 
yes
Prelude> take 52 ['a'..]
"abcdefghijklmnopqrstuvwxyz{|}~\DEL\128\129\130\131\132\133\134\135\136\137\138\139\140\141\142\143\144\145\146\147\148"
@Adám well maybe not
I stopped it well before that
 
Is it that slow? A million chars shouldn't take very long.
 
8:21 AM
printing is slow
 
Oh.
 
it tries to write everything to the screen when you just evaluate in the repl
 
What if you start at ⎕←⎕UCS 1114000?
 
I can try
 
@Adám 􏾐
 
8:22 AM
Prelude> take 20 ['\1114000'..]
"\1114000\1114001\1114002\1114003\1114004\1114005\1114006\1114007\1114008\1114009\1114010\1114011\1114012\1114013\1114014\1114015\1114016\1114017\1114018\1114019"
I guess it doesn't care
 
Can it actually render those?
 
well it doesn't try
 
:-(
 
dunno if it's due to the given terminal I'm using
but it doesn't seem to render anything unicode
 
@ElectricCoffee that only got to 1114019, the limit is 1114111
 
8:24 AM
I'll push it further!!
 
Start at 1114100
 
Prelude> take 20 ['\1114000'..'\1114112']

<interactive>:8:30: error:
    numeric escape sequence out of range at character '2'
Prelude>
 
:-)
 
Prelude> ['\1114100'..'\1114112']

<interactive>:10:22: error:
    numeric escape sequence out of range at character '2'
Prelude> ['\1114100'..'\1114111']
"\1114100\1114101\1114102\1114103\1114104\1114105\1114106\1114107\1114108\1114109\1114110\1114111"
Prelude>
it knows the upper bound
good to know
 
⎕←{⍺←'' ⋄ 0::⍺ ⋄ (⍺,⎕UCS∇1∘+)⍵}1114100
 
8:26 AM
@Adám 􏿴􏿵􏿶􏿷􏿸􏿹􏿺􏿻􏿼􏿽􏿾􏿿
 
sick that you got tryapl wired into this chat
I guess web hooks make it easy
but it's pretty cool regardless
 
We're gunning for TryAPL everywhere. You can tweet APL code too, and have TryAPL evaluate it.
 
no way
do you have to tag tryapl in the tweet to get it to work?
or does it just rudely leave you a comment either way? ;P
 
@tryaplbot and put backticks around your APL code.
 
that doesn't render well
 
I give up; using APL Over as a shocked face was hilarious in my mind
 
I do that all the time.
 
:D
@Adám that's so cool
 
I have TryAPL in my SE chat input box too:
 
8:33 AM
 
 
2 hours later…
10:07 AM
a lot of stuff I worry about when programming is data representation, as in how data is stored, and more importantly accessed. Is there a general best-practice way to do records/structs in APL? Or is it more of a try-to-cram-it-into-arrays-and-hope-for-the-best like it is in Lisp?
like, suppose I want to make a deck of playing cards. Each card has three different components: A suit, a rank, and (often) a value (like Kings being worth 10 points for example)
 
10:44 AM
@Adám @rak1507 baiting Hettinger; that made my day.
@ElectricCoffee You can use a namespace.
card ← ⎕NS⍬
card.(suit value)  ← '♣' 55.0
 
@ElectricCoffee As an initial model, I'd represent each card as an enclosed vector in the most natural form, using Unicode symbols and a number. Then, when your algorithm is done, convert to all-integer flat representation.
 
10:59 AM
@xpqz would I then need to use 52 namespaces, one for each card?
@Adám could you provide an example?
 
Adám’s approach is better and more idiomatic in every way, but namespaces are the closest concept to a record or named tuple in a traditional language.
 
that reminds me of how Erlang handles records: it's merely a macro which defines a series of tuple accessors. The tuples themselves aren't really named at all. Metaprogramming is cool when it works
 
11:24 AM
@ElectricCoffee I'd represent the cards as ⎕←'♠♡♢♣'∘.,'A123456789XJQK'
 
@Adám
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│♠A│♠1│♠2│♠3│♠4│♠5│♠6│♠7│♠8│♠9│♠X│♠J│♠Q│♠K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♡A│♡1│♡2│♡3│♡4│♡5│♡6│♡7│♡8│♡9│♡X│♡J│♡Q│♡K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♢A│♢1│♢2│♢3│♢4│♢5│♢6│♢7│♢8│♢9│♢X│♢J│♢Q│♢K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♣A│♣1│♣2│♣3│♣4│♣5│♣6│♣7│♣8│♣9│♣X│♣J│♣Q│♣K│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
 
And then have a different lookup table that translates these to values.
 
yeah that was my initial gut instinct as well. I just feel bad about splitting a string every time I want to check the suit or rank of a card
 
That's fine to begin with.
 
that said, I suppose it isn't any different from just indexing an array
 
11:27 AM
Eventually, you can convert them into integers 0–56 and use ⌊14÷⍨ to get the suit and 14| to get the rank.
Maybe faster to use 0 14 28 42⍸ to get the suit.
 
for the integer values you mean
 
Yes.
 
typically I'd want to do this on a card-by-card basis, you're almost never dealing with the entire deck all at once, unless each card has a unique index in the deck
though I'm not sure if representing a hand of cards as a list of indices is more efficient than just a list of strings. I suppose it would be
 
You can do (suit rank)←⍳2 so you can do myCard[suit] and myCard[rank]
 
depends on how APL does allocation behind the scenes
 
11:32 AM
Using two bytes per card is surely less efficient than one byte.
 
it's one byte either way if it's all heap allocated
pointers don't grow any bigger
 
(and even worse if using Unicode symbols, as those would blow up the representation to 4 bytes per card)
 
and then it's not one byte, but four
 
We never share parts of arrays.
 
you wouldn't need to
but I guess that's a fair point
how does indexing into a table work again?
suppose deck ←'♠♡♢♣'∘.,'A123456789XJQK'
how would I get say six of diamonds out?
ravel first, then take flat index? that seems inefficient
 
11:36 AM
2 6⌷deck or deck[2;6] assuming ⎕IO←0
Wait, my deck is messed up. A and 1 are the same.
There are only 52 cards, not 56; adjust 14 to 13 above.
 
@Adám yeah I know, I decided not to correct your inclusion of 1's out of politeness ;P
 
⎕←3 6⌷deck←'♠♡♢♣'∘.,'A23456789XJQK'
 
@Adám
┌──┐
│♢6│
└──┘
 
@ElectricCoffee Please be brutal next time. If caught on time, I can fix my message.
 
that's fair
my version of RIDE doesn't seem to like the red suits
renders them narrower in the boxes than the black ones
so the table looks whack
┌→─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
↓♠A│♠1│♠2│♠3│♠4│♠5│♠6│♠7│♠8│♠9│♠X│♠J│♠Q│♠K│
├─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┤
│♡A│♡1│♡2│♡3│♡4│♡5│♡6│♡7│♡8│♡9│♡X│♡J│♡Q│♡K│
├─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┤
│♢A│♢1│♢2│♢3│♢4│♢5│♢6│♢7│♢8│♢9│♢X│♢J│♢Q│♢K│
├─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┼─→┤
│♣A│♣1│♣2│♣3│♣4│♣5│♣6│♣7│♣8│♣9│♣X│♣J│♣Q│♣K│
└─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┴─→┘
looks fine when pasted
 
11:42 AM
Then use all-black set.
Not sure why this happens, as the font seems to have both.
@ElectricCoffee The red (Unicode white) don't look good by me in chat either.
 
I'm used to work in non-unicode systems, so I usually do it like this instead: ⎕←'chsd'∘.,'A23456789XJQK'
 
@ElectricCoffee
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│cA│c2│c3│c4│c5│c6│c7│c8│c9│cX│cJ│cQ│cK│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│hA│h2│h3│h4│h5│h6│h7│h8│h9│hX│hJ│hQ│hK│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│sA│s2│s3│s4│s5│s6│s7│s8│s9│sX│sJ│sQ│sK│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│dA│d2│d3│d4│d5│d6│d7│d8│d9│dX│dJ│dQ│dK│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
 
@Adám I'm trying to wrap my head around how this is supposed to work. What's the right argument supposed to be here?
 
The card number.
 
11:49 AM
⎕←'♠♡♢♣'∘.,'A123456789XJQK'
 
@Adám
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│♠A│♠1│♠2│♠3│♠4│♠5│♠6│♠7│♠8│♠9│♠X│♠J│♠Q│♠K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♡A│♡1│♡2│♡3│♡4│♡5│♡6│♡7│♡8│♡9│♡X│♡J│♡Q│♡K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♢A│♢1│♢2│♢3│♢4│♢5│♢6│♢7│♢8│♢9│♢X│♢J│♢Q│♢K│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│♣A│♣1│♣2│♣3│♣4│♣5│♣6│♣7│♣8│♣9│♣X│♣J│♣Q│♣K│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
 
⋄ ⎕io←0 ⋄ ⎕←⍳4 13
 
@Adám
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────┬────┬────┐
│0 0│0 1│0 2│0 3│0 4│0 5│0 6│0 7│0 8│0 9│0 10│0 11│0 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│1 0│1 1│1 2│1 3│1 4│1 5│1 6│1 7│1 8│1 9│1 10│1 11│1 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│2 0│2 1│2 2│2 3│2 4│2 5│2 6│2 7│2 8│2 9│2 10│2 11│2 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│3 0│3 1│3 2│3 3│3 4│3 5│3 6│3 7│3 8│3 9│3 10│3 11│3 12│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴────┴────┴────┘
 
⋄ ⎕IO←0 ⋄ ⎕←4 13∘⊥¨⍳4 13
 
@Adám
 0  1  2  3  4  5  6  7  8  9 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47 48 49 50 51
 
11:51 AM
ah yeah using decode was also my thinking here
 
⋄ ⎕IO←0 ⋄ 4 13∘⊤¨4 13⍴⍳52
 
@Adám
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬────┬────┬────┐
│0 0│0 1│0 2│0 3│0 4│0 5│0 6│0 7│0 8│0 9│0 10│0 11│0 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│1 0│1 1│1 2│1 3│1 4│1 5│1 6│1 7│1 8│1 9│1 10│1 11│1 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│2 0│2 1│2 2│2 3│2 4│2 5│2 6│2 7│2 8│2 9│2 10│2 11│2 12│
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼────┼────┼────┤
│3 0│3 1│3 2│3 3│3 4│3 5│3 6│3 7│3 8│3 9│3 10│3 11│3 12│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴────┴────┴────┘
 
⋄ ⎕IO←0 ⋄ 13|4 13⍴⍳52
 
@Adám
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5 6 7 8 9 10 11 12
 
⋄ ⎕IO←0 ⋄ ⌊13÷⍨4 13⍴⍳52
 
11:52 AM
@Adám
0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3
 
(message flood done)
 
I wonder
      4 13∘⊥¨⍳4 13
14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65
my IO is set to 1, is that why it does this?
 
Yes.
 
      render_card ← {(4 13∘⊤ ⍵) ⌷ deck}
      render_card 51
┌──┐
│♣K│
└─→┘
I like it
 
Or simply render_card ← 4 13∘⊤⌷deck⍨
 
12:02 PM
could you break down how that works?
omega vanished and a selfie appeared, but I'm not sure how selfie works in this context to replace omega
 
It is a fork (3-train). The three parts are 4 13∘⊤ and and deck⍨
 
4 13∘⊤ and deck⍨ are applied to the argument, and their results become the arguments to
array⍨ is a constant function.
 
I see I see
very cool and not at all obvious
 
By the way, you can stick a on the far left of render_card to avoid the box.
 
12:10 PM
@xpqz was a serious suggestion to look into APL for those sorts of things like jeremy howard is doing
apparently the kid was using excel to start, APL is pretty similar so it'd probably be easier for them than python
 
@Adám very nice
how would I do the inverse of render_card?
iota doesn't seem to be doing much
 
One way is to do card_number←13⊥∘⊃∘⍸deck≡¨⊆
But (,deck)⍳⊆ is much better.
 
how does nest differ from enclose?
 
It only encloses if the argument is simple.
I did that to handle both the ⊂'♣K' result of your original render_card and the simple result when amending with a leading
 
ah
so it turns out my initial idea deck ⍳ '♠K' was almost right; I just forgot to ravel first
oops sorry
wrong snippet
 
12:22 PM
@rak1507 I'd love to see what Raymond could do with APL if he tried. But I'm not holding my breath.
 
deck⍳⊂'♠K'
 
@ElectricCoffee card_number←(,deck)⍳⊂ ⋄ render_card←card_number⍣¯1
 
honestly, the fact that you can just invert functions like that is probably the coolest feature in APL
what if the function isn't trivially invertible, is there a way to define an inversion?
so that it works with the ⍣¯1 syntax
 
Not yet. We are considering adding an operator to pair up f and its inverse.
So you can do things like FFT⍫iFFT
 
I see
considered doing it similar to how J does it?
afaik it lets you add a line in the verb definition for an inverse
for tradfns I mean
 
12:36 PM
@ElectricCoffee This is how J does it. NARS2000 uses system labels.
 
ah
goes to show how far merely skimming the nuvoc gets me
unrelated: is there a better way of doing this: `+/∨⌿1 3∘.=roll`?
my initial idea was to use an inner product, but it doesn't work with vectors of uneven length
counting the number of dice rolls that are either 1s or 3s, where roll is a vector containing the outcomes of n rolled dice
 
+/roll∊1 3
 
thanks
can I unassign a definition?
I want to recycle a variable name, but I get a "cannot change nameclass on assignment"
 
1:12 PM
)erase varname
 
thanks!
 
1:43 PM
@ElectricCoffee What did you search APLcart for?
 
 
7 hours later…

« first day (2021 days earlier)      last day (616 days later) »