JohnEarnest / ok

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

[question] which of the various K implementations use lexical scope? #75

Closed hoosierEE closed 5 years ago

hoosierEE commented 6 years ago

Playing with iKe it appears (to my delight!) to support lexically-scoped closures:

greet:{[lang]
 greeting: $[lang~"eng";"hello ";"hola "]
 {greeting,x}}

hi:greet["eng"]
hey:greet["asdf"]

hey["bob"] / "hello bob"
hi["bob"]  / "hola bob"

Is this a first for K implementations? I was under the impression that Whitney's K and Q implementations used dynamic scoping and did not support closures.

ngn commented 6 years ago

I think you swapped hi and hey in the last two lines.

Terminology nitpick: lack of closures doesn't mean dynamic scoping. Dynamic scoping is when the callee can see variables from the caller's context. That's not the case in k. In (the original) k functions can see only local and global variables and nothing in between, so scoping is still lexical, albeit restricted.

hoosierEE commented 6 years ago

Thanks for the clarification, I was indeed conflating the two concepts.