Created
February 2, 2011 20:24
-
-
Save rocketnia/808357 to your computer and use it in GitHub Desktop.
An example FleetDB syntax sugar DSL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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