JohnEarnest / ok

An open-source interpreter for the K5 programming language.
MIT License
588 stars 72 forks source link

Float parsing vs trains #66

Closed leahneukirchen closed 7 years ago

leahneukirchen commented 7 years ago
% k
2016.08.09 (c) arthur whitney
 @ . "6.
`f
% ok
oK v0.1
  @ . "6."
107
JohnEarnest commented 7 years ago

Recently, Arthur's interpreter went from representing typecodes with magic numbers to using symbols. It's an interesting design tradeoff. Magic numbers make it relatively easy to partition things into type classes (for example, checking their sign to distinguish vectors from scalars as in most K dialects), and this is slightly more difficult with symbols. The symbols are, of course, rather less cryptic and create pleasant symmetry with the behavior of dyadic $. This is on my todo list.

(Fun fact: if you dig back through oK's commit history, I actually experimented with this behavior for a while before reverting to magic numbers!)

leahneukirchen commented 7 years ago

Sorry, that's not what I meant. k6 parses 6. as 6.0, ok parses 6. as (6 .)

JohnEarnest commented 7 years ago

Ah, I see. Seems like we just need to tweak the regex used to identify numeric tokens:

https://github.com/JohnEarnest/ok/blob/gh-pages/oK.js#L651