Skip to content

Instantly share code, notes, and snippets.

@rocketnia
Created February 2, 2011 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocketnia/808357 to your computer and use it in GitHub Desktop.
Save rocketnia/808357 to your computer and use it in GitHub Desktop.
An example FleetDB syntax sugar DSL.
; example-fleetdb-dsl.arc
;
; Copyright 2011 Ross Angle. However, you can use this for whatever
; you want. Don't bother giving me credit.
;
;
; This is an example of an extensible syntax sugar DSL for a
; hypothetical combinator library, together with a couple of
; definitions specifically for thaddeus's FleetDB interface. This was
; posted as an example in a comment at
; <http://arclanguage.org/item?id=13602>.
(= dsl-macs* (table))
(mac dsl-mac (name parms . body)
`(= (dsl-macs* ',name) (fn ,parms ,@body)))
(def expand-dsl (expr)
(if atom.expr
expr
(let (op . args) expr
(aif dsl-macs*.op
(apply it args)
expr))))
(mac dsl (expr)
expand-dsl.expr)
; FleetDB combinator
(def fleetdb-or args
(cons "or" args))
; FleetDB DSL extension using that combinator
(dsl-mac or args
`(fleetdb-or ,@(map expand-dsl args)))
; Test this with:
;
; (iso (dsl:or '("<" "foo" 1)
; (or '("=" "bar" "woof") '(">" "foo" 11))))
; '("or" ("<" "foo" 1)
; ("or" ("=" "bar" "woof") '(">" "foo" 11)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment