Created
February 22, 2012 18:46
-
-
Save dherman/1886598 to your computer and use it in GitHub Desktop.
simple macro-by-example macro
This file contains hidden or 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
(define-syntax or | |
(syntax-rules () | |
[(or e) | |
e] | |
[(or e1 es ...) | |
(let ([x e1]) | |
(if x x (or es ...)))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now to the
gen_map_fn
macro, you might do something like:obviously this is not real syntax. but the idea is something like "generate a pattern that uses alt or whatever to iterate over the members of an instance of the type
type_name
. For each member, generate the code shown (in this case, a call to a method)"I see three similar patterns:
--- visit: walks and invokes the method but does not build a result
--- map: expects each method to generate a new instance of the given type
Deserialization is kind of a different kind of map where the input data is not an instance of the given type but rather a byte-stream...
...anyway, maybe this cannot be done or maybe macros are not the right tool. but it seems like it'd be useful to me.
...the advantage of this approach is that there is no need for any kind of AST API.