cmh25 / gk

k interpreter
MIT License
18 stars 0 forks source link

length error when doing `y_'x` on a matrix #1

Open vbmithr opened 1 week ago

vbmithr commented 1 week ago
  x:6 3#!18
  y:2
  y_x
(6 7 8
 9 10 11
 12 13 14
 15 16 17)
  y_'x
length error
y_'x
 ^
>  
kafka64 commented 1 week ago

I am still studying parser to see how each-prior is being parsed so have no explanation but it works as expected for explicit lambda. Also train pierces which is cool.

  {2_x}'x
(,2
 ,5
 ,8
 ,11
 ,14
 ,17)

  (y_)'x
type error
x:6 3#!18
^
>  \
  (y_)x
(,2
 ,5
 ,8
 ,11
 ,14
 ,17)
cmh25 commented 1 week ago

@vbmithr, thanks for bringing this up. @kafka64 , thanks for those examples.

The only form of x f' y that gk currently supports is for the slide adverb, which is a generalization of each-prior (see README.md), the case of -1 f' y being the equivalent of k3 each-prior.

  -1 ,'"asdf"
("sa"
 "ds"
 "fd")

The k3 style each you're expecting is still available with square brackets.

  x:6 3#!18
  y:2
  _'[y;x]
(,2
 ,5
 ,8
 ,11
 ,14
 ,17)

Also, note that each-right is preferred for this case.

  y_/x
(,2
 ,5
 ,8
 ,11
 ,14
 ,17)

The really important feature of k3 style each is the conformance. Which is why gk supports it with the square brackets.

  x:("as";"df")
  y:"gh"
  ,'[x;y]
("asg"
 "dfh")

I have several discussions going on related to slide and each. I'm leaning toward making slide a named builtin and bringing back k3 style each. But I'm also waiting to see how this works in k9.