i think when defining procedure in a file or even toplevel, the order
is of no importance , but seems not to be the case for macro if i
remember correctly the examples of the discussion threads last
week,and of course, as you mention it, for defining variables
dependant of each others, the order is important.

On Tue, Aug 8, 2023 at 9:38 PM Maxime Devos <maximede...@telenet.be> wrote:
>
>
>
> Op 03-08-2023 om 11:58 schreef Jean Abou Samra:
> >> overload.scm must be before some definitions of scheme-infix.scm even
> >> if it is not used here, it is strange, i do not understand all but it
> >> compiles now
> >
> >
> > A minimal reproducer for your problem is
> >
> > (define (foo)
> >    (bar 'quux))
> > (define-syntax-rule (bar x) x)
> > (display (foo))
> >
> >
> >
> > Let's dissect what happens. At macro expansion time (during byte 
> > compilation),
> > first the definition of foo is expanded. bar is unbound, so it's compiled 
> > as a
> > function call. Then comes the definition of bar as a macro, but foo has 
> > already
> > been expanded without it.
> >
> > At runtime, a macro is bound to a syntax transformer, so the binding for bar
> > that was unresolved at expand time gets resolved to the toplevel binding 
> > that
> > gets defined for bar, and you get this error because a macro transformer 
> > can't
> > be called as  a function.
>
> Also, note that this only applies to top-level definitions (this is
> already referred to by the previous response, but only implicitly and
> perhaps only by accident).  In a lambda/let/define/..., however, you can
> refer to the 'bar' macro before it has been defined:
>
> ;; Evaluates to the symbol 'quux'
> (let ()
>    ;; Note: this 'bar' and 'foo' is only  available inside this 'let'.
>    (define (foo)
>      (bar 'quux))
>    (define-syntax-rule (bar x) x)
>    (foo))
>
> As such, this not working on the top-level seems a bug to me -- after
> all, a module definition is conceptually just a big let:
>
> <enable extra reader syntax> (if applicable)
> (let ()
>    <magic to make imports work>
>    (define ...)
>    (define-syntax-rule ...) ...
>    ;; use a new macro using syntax-local-binding
>    ;; to extract the syntax transformer (*).
>    <insert stuff in hash tables>)
>
> (*) not sure if that precise approach actually works in this context
>
> > i know what disturb me in this error, it is because the order of
> > definitions has effect but i always learn (was it right?) that in
> > scheme the order of definitions should have no effect on the resulting
> > evaluations.
>
> Barring the caveat mentioned in the previous follow-up response and
> barring any mutation (*), I think I learned this too somewhere (though I
> don't recall where), but Guile Scheme apparently doesn't implement this
> completely (i.e. in case of top-level things).
>
> (*) Example:
>
> (define a 0)
> (define (count!)
>    (set! a (+ a 1))
>    a)
> ;; Order of 'a' and 'b' is important!
> ;; I wouldn't rely on Guile doing 'b' before 'c', though.
> (define b (count!))
> (define c (count!))

Reply via email to