Hi Mikael and welcome back!

*But*, the proper implementation of syntax-toplevel? requires
> modification of psyntax.scm and adding it to the (system syntax)
> module.  I didn't want to do this until I've had your comments, so the
> present patch has its own syntax-object accessors (which breaks
> abstraction and is therefore not a real solution).  I should also say
> that I have not yet fixed the slib interface to the new Guile uniform
> arrays, so there's a lot of slib functionality which won't yet work.
>
> Comments?  Can I add syntax-toplevel? to psyntax.scm and (system
> syntax)?  Do you think it is reasonable to submit something along the
> line of guile.init.diff to slib guile.init?
>
> Best regards,
> Mikael Djurfeldt
>

I can answer with some kind of suggestion here.

in (system syntax) there is syntax-local-binding which you can use for
example as


(define-syntax f
  (lambda (x)
    (syntax-case x ()
      ((_ x)
        (call-with-values (lambda () (syntax-local-binding #'x))
                                (lambda (x y) (pk x) (pk y))) #'#t))))

Then,

scheme@(guile-user) [1]> (f +)

;;; (global)

;;; ((+ guile-user))

And,

scheme@(guile-user) [1]> (let ((s 1)) (f s))

;;; (lexical)

;;; (s-490)

(let ((s 1)) (define-syntax g (lambda (x) #'#f)) (f g))

;;; (displaced-lexical)

;;; (#f)

I'm not sure what exactly syntax-toplevel? does, but can you base it on
syntax-local-binding?
And if not is it possible to change syntax-local-binding so that you can
use it?

Regards
Stefan

Reply via email to