unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Taylan Kammer <taylan.kammer@gmail.com>
To: guile-devel@gnu.org
Subject: Re: unhandled constant?
Date: Sat, 1 Feb 2020 22:55:15 +0100	[thread overview]
Message-ID: <e1269c28-0990-eefa-f92d-454d0208b96a@gmail.com> (raw)
In-Reply-To: <CAOw_e7ax50qMu5F6Sb5qiD4F+xvYfi_-JrrtP0kd3tGVU=UM-Q@mail.gmail.com>

> (defmacro define-session (name value)
>   (define (inner n v)
>     (set! decl
>         (cons
>          (make-var n v)
>          decl))
>     )
>   `(,inner ',name ,value))

The problem here is that the macro output

  `(,inner ',name ,value)

would include a #<procedure> object, because it evaluates 'inner', which
has been defined as a procedure.  The raw output would look something
like this:

  (#<procedure inner (a b)> 'foo "bar)

And the compiler tries to put that into a file.  But procedure objects
cannot be put into a file.

(They cannot be "serialized" i.e. turned back into text.  Hence the
clumsy "#<procedure ...>" thing which tells us a bit about the procedure
like its name and the number of arguments it takes but doesn't actually
include its code.)

That's why the compiler chokes.  It could put a constant like the number
982346 or the string "foo" or the vector #(x 4 "blah") into the output
it generates, because all those objects can be serialized, but a
procedure object cannot be truly serialized.

Note that something like (lambda () ...) is NOT a procedure; it's a
list.  Such a list can be evaluated as Scheme code, within a larger
context (an "environment"), which then yields a procedure object, but
that resulting procedure object cannot be turned back into text, because
it might be relying on the environment in which it was defined.

Like others pointed out, there's a couple of ways to rewrite that code
to avoid putting a procedure object straight into the macro output.  For
instance, you could put the definition of the procedure into the output,
so it will be evaluated (turned into a procedure) at run-time:

  (defmacro define-session (name value)
    `(begin
       (define (inner n v)
         (set! decl
             (cons
              (make-var n v)
              decl))
         )
       (inner ',name ,value)))

I'm not sure if this code will work verbatim in 1.8 and 2.2, but you get
the idea: don't put procedures into macro output.

- Taylan


On 29.01.2020 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?
> 



  parent reply	other threads:[~2020-02-01 21:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28 23:08 unhandled constant? Han-Wen Nienhuys
2020-01-29 15:06 ` Ricardo Wurmus
2020-01-30  8:05   ` Han-Wen Nienhuys
2020-01-31 10:49     ` Han-Wen Nienhuys
2020-01-31 11:17     ` Ricardo Wurmus
2020-02-02 19:30     ` Jan Nieuwenhuizen
2020-01-31 14:57 ` Linus Björnstam
2020-01-31 15:16   ` Han-Wen Nienhuys
2020-01-31 17:50   ` Han-Wen Nienhuys
2020-01-31 18:19     ` Linus Björnstam
2020-01-31 19:17       ` Han-Wen Nienhuys
2020-01-31 19:52         ` Linus Björnstam
2020-01-31 20:01         ` Linus Björnstam
2020-02-01  9:54           ` Han-Wen Nienhuys
2020-02-01  9:56             ` Han-Wen Nienhuys
2020-02-01 10:10               ` David Kastrup
2020-02-01 11:23                 ` Han-Wen Nienhuys
2020-02-01 11:36                   ` David Kastrup
2020-02-01 13:12             ` Linus Björnstam
2020-02-01 11:09   ` David Kastrup
2020-02-01 13:16     ` Linus Björnstam
2020-02-01 14:23       ` David Kastrup
2020-02-01 15:21         ` Linus Björnstam
2020-02-01 21:55 ` Taylan Kammer [this message]
2020-02-01 21:58   ` Fwd: " Taylan Kammer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1269c28-0990-eefa-f92d-454d0208b96a@gmail.com \
    --to=taylan.kammer@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).