Wednesday, July 13, 2016

J provokes self-talk (2)

OK, so I've managed to deal a deck. Now, suits and ranks for the cards. Courtesy the same source as the deal;

t12  =. <. t1 % 13) 'SHDC'

CHSSDCDSSHHSH
CDHSCDDCHSDHC
HSCCDDDSSHDSC

CDSSHCHDCCDHH

Not that it happened quite this easily. After my early success (ignoring its somewhat derivative quality) I figured I had this J under sufficient control to write something myself. I tried:

{'SHDC' <. t1%13
|domain error

...figuring that since J's OOO(1) is right to left, this would work fine. First divide (%) the matrix by 13, then round down (<.) the chuck the result into the indexing ({) thingy. As I write this I shudder at my stupidity, but at the  time I was shuddering over the extreme uselessness of the error message. WTF is a 'domain error'?

In fact, there's a lot going on here.

  1. Iteration. Something like a "for-matrix" loop is built into J. Neat. (Wait, there's more)
  2. Vocabulary. { is NOT called index. It's called 'catalogue/from'. The vocab of J is huge, and you need to have it right to navigate the documentation. I usually make up names for everything, typically translating into some amalgam of the first two or three programming languages I ever learnt, and this 'knack' has not been helpful
  3. J doesn't have helpful error messages for a beginner.
  4. a J 'verb' accepts either one or two inputs (typically - I haven't finished understanding this yet, and I dimly recall reading somewhere that you can handle three inputs) conceptually called 'x' and 'y', as in:                                                 x verb y
    • since J is right-to-left, this means that y  is the primary input. Now, quite frankly, this is whack. When I learned algebra - and I bet I'm not alone in the universe in this - x  came before y.  I did a lot of exercises with x before y ever turned up. And I don't want to be rude, but x comes before y in the alphabet. Since, in J, right comes before left, what the hell is wrong with 'verb x' ? OK, in the end it's all arbitrary, and I'm getting the hang of it now, but is the motivation for this worth the intuitive cost? Or did Roger Hui(2) start his algebraic career with y ?
    • what I now think the error means is that I wasn't providing an x for ...in other words, the output of a function only gets passed to the y input, without some advanced cleverness.
I didn't work any of this out at the time, mind you. I just stopped thinking so much, and went back to direct plagiarism.

t11  =.  (13 t1) 'AKQJT98765432'

A9242389TA786
JT267QK9T5AQK
JQ6Q964AK5J75
85J334472T3K8

I haven't bothered to highlight the parentheses, because they're not on the J vocab page. This last expression adds assignment (=., or =:) and remainder (|).

It still doesn't look much like a deck of cards. Back to Alvord & Thomson to find that they 'laminate' (,;) the suits and the ranks together.
t11 ,: t12
A9242389TA786
JT267QK9T5AQK
JQ6Q964AK5J75
85J334472T3K8

CHSSDCDSSHHSH
CDHSCDDCHSDHC
HSCCDDDSSHDSC

CDSSHCHDCCDHH

Yuk. OK, research in the vocab book gives 'append' (,) and 'stitch' (,.)

 t11 t12
A9242389TA786
JT267QK9T5AQK
JQ6Q964AK5J75
85J334472T3K8
CHSSDCDSSHHSH
CDHSCDDCHSDHC
HSCCDDDSSHDSC

CDSSHCHDCCDHH

t11 ,. t12
A9242389TA786CHSSDCDSSHHSH
JT267QK9T5AQKCDHSCDDCHSDHC
JQ6Q964AK5J75HSCCDDDSSHDSC

85J334472T3K8CDSSHCHDCCDHH

Guess Alvord and Thomson aren't card players. A lesser man would stop here and find out exactly what is going on, but it doesn't look worth the investment of time to me. I checked the vocab page for 'interleave' but didn't find it. Plan B.

Sitting on the bus I've been trying to memorise the vocab from a handy pocket cheat sheet. One of the things I have found is that you can get a row from a matrix with { . This doesn't seem to gel all that obviously with what i know about { (3), but OK. I can try.
0 { t11
A9242389TA786
0 t12

CHSSDCDSSHHSH

Good. And laminate.
 (0{t11) ,: (0{t12)
A9242389TA786

CHSSDCDSSHHSH

Do not think that will work without the parentheses, and don't think I'm going to explain why yet, either. It aligns if I 'box' (<) it.

 < (0{t11) ,: (0{t12)
┌─────────────┐
│A9242389TA786         │
│CHSSDCDSSHHSH   │

└─────────────┘but it doesn't cut and paste very well. How about
<"0 (0{t11) ,: (0{t12)
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│A│9 │2 │4 │2│3 │8 │9 │T│A│7 │8 │6 │
├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤
│C│H│S │S│D│C│D│S │S │H│H│S│H│

└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘Likewise. Well, I can ignore the design for now. There's rather a startling amount going on. Plus, this is just an unsorted hand, virtually no use at all. A lot to do yet.


(1) Order of Operations
(2) A very important person in the invention of J

No comments:

Post a Comment