Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

macro system #26

Open
alandipert opened this issue Nov 26, 2013 · 0 comments
Open

macro system #26

alandipert opened this issue Nov 26, 2013 · 0 comments
Milestone

Comments

@alandipert
Copy link
Owner

TBD, see Notes and Questions

  • Macros are globally-defined functions for which there is an entry in the list gherkin.core/*macros*. Macros are passed their arguments, unevaluated, and whatever they return is evaluated.
(def unless
  (fn (pred conseq alt)
    (list 'if pred alt conseq)))

(set! *macros* (cons 'user/unless *macros*))

(unless t 1 2) ;=> 2
  • Support quasi-quoting via the reader macro, which expands to thesyntax-quote` special form.
  • Elements within a syntax-quoted expression may be selectively unquoted via the ~ reader macro, which expands to the gherkin.core/unquote sentinel.
    • ~ is not valid outside of syntax-quote
(def unless
  (fn (pred conseq alt)
    `(if ~pred ~alt ~conseq)))
  • Support splicing via ~@, the which expands to the gherkin.core/unquote-splicing sentinel.
    • ~@ is not valid outside of syntax-quote
(def unless
  (fn (pred & xs)
    `(if ~pred ~@(reverse xs))))

Notes

  • syntax-quote doesn't need to resolve anything (yet)
  • We can support symbol-macrolet if fns themselves may appear in the *macros* list
    • lexically bind the fn to a name
    • set! *macros* with the fn object
    • evaluate symbol-macrolet body
    • remove the fn object from the *macros* list
  • We already have gensym

Questions

  • property lists on symbols?
    • then we can take the traditional approach of '(macro . t) metadata
    • need property lists on conses to do symbol-macrolet?
      • then, macro meta goes directly on the function object, not its current name
        • as it could be tricky to manage property lists across lexical bindings
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant