[plt-scheme] Generating top-level definitions from inner syntax
On Oct 9, Lauri Alanko wrote:
> Ah. I wasn't aware that this was readable syntax. How do I generate
> such a syntax object from a string?
Just like numbers or strings -- use (regexp "foo") as the new syntax
result. In other words, my `regexp*' macro used to be:
| ;; Warning: hack regexps in source code
| (defsyntax (regexp* stx)
| (syntax-case stx ()
| ((_ re)
| (let ((x (syntax-object->datum #'re)))
| (if (string? x)
| (quasisyntax/loc stx (#%datum . #,(regexp x)))
| (syntax/loc stx (regexp re)))))))
now it is exactly one line shorter:
| (defsyntax (regexp* stx)
| (syntax-case stx ()
| ((_ re)
| (let ((x (syntax-object->datum #'re)))
| (if (string? x)
| (quasisyntax/loc stx (#%datum . #,(regexp x)))
| (syntax/loc stx (regexp re)))))))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!