JohnEarnest / ok

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

Odd error with taking more elements in list #13

Closed refi64 closed 9 years ago

refi64 commented 9 years ago

Just try:

2#""

It gives:

Cannot read property 't' of undefined
JohnEarnest commented 9 years ago

Looks like the oK bug is simply for the case where you're trying to "take" from an empty list. Should be a straightforward fix.

The official K5 interpreter produces a few surprising results, mainly the behavior for 3#"":

 3#""
"   "
 3#()
("";"";"")
 3#0N
0N 0N 0N
refi64 commented 9 years ago

I believe it goes like this (in a Python-like pseudocode):

a (#) b =
 if a > len(b)
  if b == "" then return 'a' spaces
  else return b repeated 'a' times
 else take a elements from b
JohnEarnest commented 9 years ago

Fixed the surface level problem. As mentioned in the commit, the special case for strings will have to wait, since oK presently does not carry type information along with vectors- a zero length vector is just a zero-length vector:

  0#""
()
  5#""
(()
 ()
 ()
 ()
 ())