guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unhandled constant?


From: Linus Björnstam
Subject: Re: unhandled constant?
Date: Fri, 31 Jan 2020 19:19:52 +0100
User-agent: Cyrus-JMAP/3.1.7-781-gfc16016-fmstable-20200127v1

I'm not very familiar with how guile 1.8 works since my first guile version was 
2.2, but I remember hearing Andy talk about how macro expansion was done at 
runtime, due to guile not being compiled.

I just put one and one together and figured that the reason the macro you 
posted works in 1.8 must be because of what basically rounds down to no 
separation between runtime and expand time.

Defmacro is expanded to a regular syntax case macro that first strips all 
syntax information and passes it to the defmacro body and the re-introduces the 
result. Regarding your other question: any literal string in the defmacro body 
is moved to the correct define-syntax placement.

I don't really understand your question. With defmacro and syntax-case you can 
run arbitrary code. If you just output code that does module-define! that won't 
be run until runtime, and thus you cannot depend on the result of that 
module-define! during expansion. You can however wrap it in an eval-when to 
solve that issue. That allows you to specify when code gets run. With 
module-define! I personally find it all a bit icky, but I usually stay as far 
away from phasing as I can :)



-- 
  Linus Björnstam

On Fri, 31 Jan 2020, at 18:50, Han-Wen Nienhuys wrote:
> On Fri, Jan 31, 2020 at 3:58 PM Linus Björnstam
> <address@hidden> wrote:
> >
> > Guile1.8's macros are run-time macros: they are executed directly and not 
> > transformed to output code that is then compiled. That is the reason why 
> > your code works: to newer guiles the (inner ...) is only available at 
> > expansion time. The macro output is trying to call code that does not exist 
> > at runtime!
> 
> When is the code executed?  If have complex set of macros to define a
> special type of functions (so called markup commands).  Some of these
> refer to other markup commands through a macro.
> 
> What I can observe that some of the functions involved are not called
> during the compilation, but others are.
> 
> In particular, the function that registers a markup command using something 
> like
> 
>   (module-define! (current-module)
>       (string->symbol (format #f "~a-markup" name))   defn))
> 
> but this function is not called during the compile
> 
> There is a convenience macro that is called within some function
> bodies, that does get called. Unfortunately, the latter convenience
> macro is expanded and then executed; the execution tries to then do
> 
>    (module-ref (current-module)
>       (string->symbol (format #f "~a-markup" name)
> 
> which fails.
> 
> 
> 
> > For this to be working code the (inner ...) function needs to be available 
> > in the macro expansion. I didn't read through exactly what you are trying 
> > to do, but try outputting a let:
> >
> > `(let ((inner (lambda (n v) (set ! ...))))
> >   (inner ,name ,value))
> >
> > I doubt you can make the old code work in newer guiles, since I doubt any 
> > scheme is a s lax about expansion time and macro time separation.
> > --
> >   Linus Björnstam
> >
> > On Wed, 29 Jan 2020, at 00:08, Han-Wen Nienhuys wrote:
> > > Some of the lilypond Scheme files do the following:
> > >
> > >
> > > (define decl '())
> > > (define (make-var n v) (list "var" n v))
> > > (defmacro define-session (name value)
> > >   (define (inner n v)
> > >     (set! decl
> > >         (cons
> > >          (make-var n v)
> > >          decl))
> > >     )
> > >   `(,inner ',name ,value))
> > > (define-session foo 1)
> > > (display decl)
> > > (newline)
> > >
> > > In GUILE 2.2, this yields
> > >
> > > ;;; WARNING: compilation of /home/hanwen/vc/lilypond/q.scm failed:
> > > ;;; unhandled constant #<procedure inner (a b)>
> > >
> > > What does this error message mean, and what should I do to address the 
> > > problem?
> > > --
> > > Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen
> > >
> > >
> 
> 
> 
> -- 
> Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]