glycerine / zygomys

Zygo is a Lisp interpreter written in 100% Go. Central use case: dynamically compose Go struct trees in a zygo script, then invoke compiled Go functions on those trees. Makes Go reflection easy.
https://github.com/glycerine/zygomys/wiki
BSD 2-Clause "Simplified" License
1.71k stars 81 forks source link

How do I export functions from go into a package. #29

Open ericfode opened 6 years ago

ericfode commented 6 years ago

I get how to wrap functions with the Sexp type, but when i add them to the zygo i don't want them all in the top level namespace, it makes listing the symbols not super useful and makes me worry about name collisions. What might you suggest?

glycerine commented 6 years ago

Zygo does have packages:

https://github.com/glycerine/zygomys/blob/master/tests/package.zy

https://github.com/glycerine/zygomys/blob/master/tests/import.zy

update: within Go, a package is represented as a Stack (don't ask me why) https://github.com/glycerine/zygomys/blob/master/zygo/stack.go#L12

Further, the import code shows how the import function creates a package: https://github.com/glycerine/zygomys/blob/master/zygo/import.go#L8

So following the import code as an example, and calling env.LexicalBindSymbol to inject your package into the environment, as import does, should get you started.