lilypond-devel
[Top][All Lists]
Advanced

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

Re: ASSIGN_EVENT_ONCE in Scheme


From: David Kastrup
Subject: Re: ASSIGN_EVENT_ONCE in Scheme
Date: Sun, 20 Feb 2022 20:21:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Dan Eble <dan@lyric.works> writes:

> ASSIGN_EVENT_ONCE(cur, new) does this:
>
>   - if cur is nullptr: assign cur = new, return true
>   - if *cur and *new are equal: quietly return false
>   - if *cur and *new are unequal: warn and return false 
>
> Would a Scheme analog of ASSIGN_EVENT_ONCE be used like this,
>
>     (let ((my-foo-event #f))
>       ;; . . .
>       (listeners
>         ((foo-event this-engraver event)
>          (if (ly:set-event-once! my-foo-event event)
>            ;; my-foo-event event has been set: handle it
>
> or am I thinking too much like a C++ programmer?

ASSIGN_EVENT_ONCE outputs a warning, doesn't it?  A natural way of
representing this (though with a loss of choosing how to handle spurious
events) would be

       (listeners
         ((foo-event this-engraver event #:once)
           ;; event has been seen the first time: handle it

Now how this would be actually implemented: that's a different question
altogether.  make-engraver could conceivably handle this (though it
currently is a very superficial macro and would need to get smarter) by
inserting the equivalent of your code, or it could just use lambda*
instead of lambda and the generated callback could be smarter.

Yes, this is a lot of hand-waving for a simple question...

-- 
David Kastrup



reply via email to

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