kevinlawler / kona

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

Define globals as a function is parsed #548

Open tavmem opened 5 years ago

tavmem commented 5 years ago

The k2.8 parser is recursive: k2.8 defines globals that are contained in a function as the function is being parsed. This may not be a bug in Kona, nor a critical difference between k and Kona, but I thought it was worth documenting the difference.

$ rlwrap -n ./k
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
\ for help. \\ to exit.

  abc:{3+def(x)}
  \v
def abc 
  def 5
5
$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  abc:{3+def(x)}
  \v
,`abc
  def 5
value error
def
^
tavmem commented 5 years ago

But, there are boundary cases were k2.8 and Kona both define a global contained in a function. Since "global assignment" (::) is not used, you might guess that "def" is local to the function "abc".

K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
\ for help. \\ to exit.

  abc:{def,:2}
  \v
def abc 
  def
  abc 5
  def
(;2)
$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  abc:{def,:2}
  \v
`abc `def
  def
  abc 5
(;2)             /note:  Kona displays a result here, where k2.8 does not
  def
(;2)