unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: David Kastrup <dak@gnu.org>
To: Han-Wen Nienhuys <hanwenn@gmail.com>
Cc: guile-devel@gnu.org, lilypond-devel <lilypond-devel@gnu.org>
Subject: Re: unhandled constant?
Date: Sat, 01 Feb 2020 12:36:45 +0100	[thread overview]
Message-ID: <8736buwnci.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <CAOw_e7abf0dRuEGBGFaft+4d8s+LHKekSeXPiOnFneGK+7aQKQ@mail.gmail.com> (Han-Wen Nienhuys's message of "Sat, 1 Feb 2020 12:23:51 +0100")

Han-Wen Nienhuys <hanwenn@gmail.com> writes:

> On Sat, Feb 1, 2020 at 11:11 AM David Kastrup <dak@gnu.org> wrote:
>> >> Here is an example that shows better how things work, and what might
>> >> be the cause of my problems. Is it right that programmatically set
>> >> contents of "current-module" are not serialized into the compiled
>> >> file?
>> >>
>> >>    (define (run-at-compile-time cmd)
>> >>      (module-define! (current-module) (string->symbol cmd) #t)
>> >>      (format (current-error-port) "I-am-called-at-compile-time ~a\n" cmd))
>> >>
>> >>   (define (runtime-call cmd)
>> >>     (format (current-error-port) "I-am-called-at-runtime ~a\n" cmd)
>> >>     (format (current-error-port) "val ~a\n"
>> >>             (module-ref (current-module) (string->symbol cmd))))
>> >>
>> >>   (defmacro foo (cmd . rest)
>> >>   (run-at-compile-time cmd)
>> >>   `(runtime-call ,cmd))
>> >>
>> >>   (foo "xy")
> ..
>> >> ERROR: In procedure scm-error:
>> >> No variable named xy in #<directory (guile-user) 56514b591140>
>> >>
>>
>> But that is not using a local define at all.  Can you point out the
>> actual code that failed for you?
>
> There are two independent problems. One is a problem with inner
> defines, which is addressed by
>
>   https://codereview.appspot.com/553480044/
>
> the symptom is compilation failing with "unhandled constant
> #<procedure ... > "

Ah, ok.  This appears not to signify that anything is wrong with the
code in principle but rather that the byte compiler is not sufficiently
capable for processing it.

> The other is a problem you can reproduce if you check out
>
>   https://github.com/hanwen/lilypond/tree/guile22-experiment
>
> with the symptom being:
>
> ;;; compiling
> /home/hanwen/vc/lilypond/out/share/lilypond/current/scm/define-markup-commands.scm
> fatal error: Not a markup command: line
>
> This is because the LilyPond macro "markup" doesn't recognize markup
> command and aborts in code that is executed at compile-time. The code
> that triggers this are  definitions in scm/define-markup-commands.scm
> that use (mark #:blah .. ) in the function body.

The LilyPond macro "markup" is something I would not mind getting rid of
sooner rather than later.  It's sick.  It is not completely clear to me
why it needs the actual definitions to work with, but it may have
something to do with its partly workable support of markup list commands.

The make-...-markup convenience functions are quite more sane.  Stacking
a lot of them together may incur a bit of runtime overhead since they do
argument checking that the results from markup macro expansion don't.
But markup command processing times are likely quite negligible in the
total scheme of things even if we end up rechecking large markup lists
as they are passed from one function to another.

> You can verify this by rewriting
> https://github.com/lilypond/lilypond/blob/c5ffa540fdbe52486b9575567ede70be575adb47/scm/define-markup-commands.scm#L305
> and seeing how the error message changes.
>
> I still don't understand why some code is executed compile time (the
> expansion of the  markup macro) while other is not (defining the
> make-x-markup function in (current-module))
>
> Since we recognize markup commands by looking them up in
> (current-module), I believe the example I showed here shows that we
> can never make this work, and we  will have to revisit the markup
> macros completely.

My vote is on throwing them out.  But that would affect a whole bunch of
user-level programs.  We could add a macro _function_ that does the hard
work at execution time rather than at expansion time as a backwards
compatibility measure, and discourage using it for new code.

-- 
David Kastrup



  reply	other threads:[~2020-02-01 11:36 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 [this message]
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
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=8736buwnci.fsf@fencepost.gnu.org \
    --to=dak@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=hanwenn@gmail.com \
    --cc=lilypond-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).