[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
advice on how to use syntax transformers
From: |
Federico Beffa |
Subject: |
advice on how to use syntax transformers |
Date: |
Fri, 6 Mar 2015 15:51:46 +0100 |
Hi,
I'm writing to ask for help in understanding syntax
transformers. Specifically, I'm trying to construct a function of the
following form
(define (key->value meta)
(match meta
(() '())
(((("name") value) rest ...)
value)
(((k value) rest ...)
(key->value (cdr meta)))
(_ "key Not fount")))
where I would like the ability to program the actual form of the ("name")
pattern with a second function argument. I've tried with the following
(define (key->value meta key)
(define-syntax match-key
;;(let ((key '("name")))
(lambda (x)
(syntax-case x ()
((_ e
(((k v) r ...) b ...) c ...)
#`(match e
(((#,key v) r ...)
v)
(((k v) r ...) b ...) c ...)))));)
(match-key meta
(((k v) r ...)
(key->value (cdr meta) key))
(_ "key not fount")))
which however, doesn't work and gives the following error:
---------------------------------------------------------
ice-9/psyntax.scm:1274:12: In procedure #<procedure 29405a0 (val key m)>:
ice-9/psyntax.scm:1274:12: Syntax error:
unknown location: reference to identifier outside its scope in form key
In ice-9/psyntax.scm:
1274:12 0 (#<procedure 29405a0 (val key m)> #(syntax-object key
((top) #(# …) …) …) …)
---------------------------------------------------------
If however I make key a local variable with the commented let expression, then
it works (but I loose the programming feature that I'm trying to implement).
I would greatly appreciate an hint on why the above is incorrect and what is
the correct form.
Thanks you in advance for your help.
Regards,
Fede
- advice on how to use syntax transformers,
Federico Beffa <=