-
-
Save dherman/1886598 to your computer and use it in GitHub Desktop.
(define-syntax or | |
(syntax-rules () | |
[(or e) | |
e] | |
[(or e1 es ...) | |
(let ([x e1]) | |
(if x x (or es ...)))])) |
I could then generate impls that define a tr
method for all the types I might need.
Now to the gen_map_fn
macro, you might do something like:
def_structural_map gen_map_fn(type_name, method_name, arg_name, arg_type) { v =>
v.$method_name($arg_name)
}
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.
what I would like to write:
which would generate code like: