I have written the following syntax rule:
(define-syntax match-rewriter
(syntax-rules ()
((_ (patt body) ...)
(λ (x) (match x (patt body) ... (_ x))))))
which is essentially match-lambda except that it returns its argument if no match is found rather than throwing an exception.
Now I want to write a function, let_as_lambda, that will take strings of source code as input and rewrite the let statements as the new let_as_lambda function. This is what I have:
(define let_as_lambda
(match-rewriter (`(let((,<var> ,<val>)) ... ,<expressions>)
`((lambda (,<var> ...) ,<expressions>) ,<val> ...))))
It is clearly wrong as:
(let_as_lambda '(let((x 3)) (+ x 2)))
returns:
'((λ ((x) ...) (+ x 2)) (3) ...)
still showing the ellipses and with the "3" in parentheses. I believe my problem is that I don't understand the proper usage of the symbols `, ., and , in pattern matching.
If someone could show me the correct way to do this it would be greatly appreciated.
Thanks.