kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Feature in k2.8 not in Kona #642

Open gitonthescene opened 1 year ago

gitonthescene commented 1 year ago

I know the goal is to have Kona match K2 and possibly K3. Here's something I discovered when trying to parse sql.k

  abc[`f`g`h`i`j]:(0 1 2 10 20 30;101 102 103 104 3 4;`f`e`d`c`b`a;2 3 8 2 9 0;1 2 1 2 2 2)
  t:`abc
  @[t;"+[f;1]"]
1 2 3 11 21 31

I.e. it's evaluating +[f;1] where f is taken as from the table abc. (Since t is the symbol `abc it's acting on the global.)

This seems like a pretty advanced feature and I was a little surprised to find this worked like this. It feels like it's an early incarnation of expressions in K9.

gitonthescene commented 1 year ago

One way to make this work is to simply replace f with abc[`f] and reevaluate it. I haven't thought through how to fully test how this feature actually works in k2.8.

gitonthescene commented 1 year ago

Interestingly, if I try to access a global in this expression it errors:

  b:7
  @[t;"+[f;b]"]
  @[t;"+[f;b]"]
value error
b

It feels like if Amend is given a string, then that string is passed through the parser again, but with the dictionary itself replacing "globals".