This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: guile-vm-0.2
Keisuke Nishida <kxn30@po.cwru.edu> writes:
> > Which other core syntax forms would you like to have support for?
>
> I think that's it for now. I want to have support for generalized
> `set!', but is it possible?
Sure it is---silly me, I've forgotten this completely. This is a bug
and should be fixed ASAP. If anyone provides a patch to psyntax.ss,
I'll happily receive it. Otherwise, I'll do it myself.
> I think it would be the best if I could define my own syntax set
> in a module and use it for expansion. Something like:
>
> ---- vm/syntax.scm ---------------------
> (define-module (vm syntax)
> :use-module (ice-9 syncase))
>
> (define-syntax cond
> (lambda (x)
> (syntax-case ...)))
> ----------------------------------------
Good idea.
(define-syntax cond
(lambda (x)
(syntax-case x ()
((_ m1 m2 ...)
(let f ((clause (syntax m1)) (clauses (syntax (m2 ...))))
(if (null? clauses)
(syntax-case clause (else =>)
((else e1 e2 ...) (syntax (begin e1 e2 ...)))
((e0) (syntax (let ((t e0)) (if t t))))
((e0 => e1) (syntax (let ((t e0)) (if t (e1 t)))))
((e0 e1 e2 ...) (syntax (if e0 (begin e1 e2 ...))))
(_ (syntax-error x)))
(with-syntax ((rest (f (car clauses) (cdr clauses))))
(syntax-case clause (else =>)
((e0) (syntax (let ((t e0)) (if t t rest))))
((e0 => e1) (syntax (let ((t e0)) (if t (e1 t) rest))))
((e0 e1 e2 ...) (syntax (if e0 (begin e1 e2 ...) rest)))
(_ (syntax-error x))))))))))
> ---- vm/compile.scm --------------------
> (define-module (vm compile)
> :use-module (ice-9 syncase))
>
> (define compiler-syntax (module-syntax (resolve-module '(vm syntax))))
>
> (define (compile form . opts)
> (let ((expanded-form (expand form compiler-syntax)))
> ...
> ))
> ----------------------------------------
>
> This is symmetrical to eval and very customizable.
I think something like this is a good idea, but we'll have to
elaborate the details further. When you currently ask for the syntax
of a module, the module is expected to provide a *procedure* which is
the macro expander. So the code above is not correct in this respect.
Actually, what we probably should do is to fix psyntax.ss so that it
starts to cooperate for real with the module system. We can do that
by extending the syntactic environments (the variable `r' in Dybvig's
code) with some object representing the top-level environment. We'll
then extend the expander call with an extra parameter to provide this
object. Also, the top-level lookup hook should be changed from using
the object-property of Guile variable objects to using this syntactic
environment instead.
Once we have made these fixes, we can use the module system in the
usual way and simply "use" exported syntactic bindings.