On 24.07.2024 03:06, spacecadet wrote:
> Hi, I didn't see a help-guile list, I hope this isn't out of place

I think the guile-user list might be more appropriate.

> I'm trying to lexically bind a macro to a lexically bound transformer 
> procedure
> 
> (let ((outer (lambda (x) #''())))
>   (let-syntax ((inner outer))
>     inner))
> 
> This is producing an error
> "reference to identifier outside its scope in form outer"
> 
> My goal is to load external macros without any top-level definitions
> I don't know if the way the macro expander works will allow this
> Any help appreciated, thanks!

Scheme evaluation could be considered to happen in two parts, regardless of 
whether the implementation actually has a compiler:

1. The compile-time execution of code

2. The run-time execution of code

(Guile actually has a compiler so it's definitely like this in practice too.)

The 'let' form works in the context of run-time execution, whereas 'let-syntax' 
works in compile-time execution. Although compile-time code can "see" that a 
variable called 'outer' is bound in the lexical scope, the actual value of the 
binding will only exist at run-time, so you can't rely on it during 
compile-time execution.

The following works:

  (let-syntax ((outer (lambda (x) #'(+ 1 2))))
    (let-syntax ((inner (lambda (x) (outer x))))
      (inner)))

The 'inner' has to be a lambda too, and can't be bound to 'outer' directly. I'm 
not sure why.

-- 
Taylan


Reply via email to