spy16 / sabre

Sabre is highly customisable, embeddable LISP engine for Go. :computer:
GNU General Public License v3.0
28 stars 5 forks source link

Support for macros & special forms #2

Closed spy16 closed 4 years ago

spy16 commented 4 years ago
spy16 commented 4 years ago

@lthibault Macro support has been added in 83f8103 . It's not well tested yet. But seems to work 😄 . Do try it out and let me know when you get a chance.

lthibault commented 4 years ago

@spy16 Very cool!

I've had a look, but I'm not sure what kind of useful feedback I can give, as I'm not very knowledgable in the nuances of macro systems (or lisp in general, for that matter).

In lieu of a thoughtful critique, here's a list of questions that popped into my mind as I was reading. Some of these are probably very basic.

  1. What does the terminating-* convention signify? I'm familiar with the meaning of the "earmuffs" convention (e.g. *ns*), but not of e.g. let*.

  2. What is the relationship between macro*, fn, defn and defmacro?

  3. What is the meaning of &, and where is it defined? (e.g.: (def defn (macro* defn [name & fdecl] ...)

  4. What's the rationale behind the SpecialForm type versus binding a user-defined native Go type to a scope?

In general, I think I'm looking for some insight into the design choices at play. Understanding intent will help use this correctly.

spy16 commented 4 years ago
  1. * I thought of making all special forms have this actually but haven't done that yet. I was thinking of having an alias in lisp code for these special forms that add some documentation also (since no doc string is added from go code. So fn* would be pure go form and fn would be wrapped version with documentation. Idea taken from clojure)
  2. fn* and macro* define a anonymous function and macro respectively. defn and defmacro define a function and bind It to a name in the root scope. macro* might go away.
  3. & is for variadic arguments similar to clojure. After & there can be only one arg which will be assigned the list of all remaining arguments.
  4. SpecialForm has a special treatment in List.Eval(). I might merge SpecialForm into Fn to reduce number of types. This is the intermediate parse step I was talking about.
lthibault commented 4 years ago

Makes sense, thanks for the explanation! This all seems sensible and I don't see anything missing.

I'm currently integrating the changes to Sabre in my project, after which I'll start focusing on the language. I'm certain I'll have some feedback at this point (albeit from the trenches!)