Trying to understand the "rx" macro.
"Igor Hjelmstrom Vinhas Ribeiro" <[email protected]> Sun, 2 Nov 2008 17:59:22 -0200
| Newsgroups | gmane.lisp.scheme.scsh |
|---|---|
| Message-ID | <[email protected]> |
All,
First of all: thanks for Scsh. I used it for over a year now, and it is a
really nice tool - SRE's, specifically, are wonderful.
Second, I am trying to understand the "rx" macro that can be found
in SCSH, with the purpose of porting it and the associated
functionality over to another Scheme system.
I don't understand how its declaration and use
are working. In packages.scm I found the following line:
(define-syntax rx expand-rx)
Then, expand-rx is declared in re-syntax.scm like this:
(define (expand-rx exp r c)...
How can this be? How can it simply associate define-syntax with
a procedure like this? Did I miss anything in the source code? In
R5RS itself? Is this something Scheme48 specific?
Here is a test I did. I changed Scsh source code so that the expand-rx
definition starts like this:
(define (expand-rx exp r c)
(display "\nexpand-rx: p1=")(display exp)(display "\n")
(display "\nexpand-rx: p2=")(display r)(display "\n")
(display "\nexpand-rx: p3=")(display c)(display "\n")
(let ((re (simplify-regexp (parse-sres (cdr exp) r c))))
...
When I run (rx (| "a" "x")) I get the following output:
expand-rx: p1=(#{Name rx} (| a x))
expand-rx: p2=#{Procedure 2610 (unnamed in make-name-generator in names)}
expand-rx: p3=#{Procedure 2607 (unnamed in make-keyword-comparator in
names)}
'#{re-char-set}
The two procedures (p2 and p3) - where did they came from? And how
did my (rx ...) ended up translated to this expand-rx call?
Any help / pointers to assist me in understanding all of this will be
much appreciated.
Regards,
Igor.