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: Jean Abou Samra
Subject: Re: ASSIGN_EVENT_ONCE in Scheme
Date: Sun, 20 Feb 2022 19:57:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

Le 20/02/2022 à 19:46, Dan Eble a écrit :
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?



You would have to define it as a macro, a Scheme
procedure (= function) can't set lvalues.

#(define-macro (assign-event-once lvalue rvalue)
  (let ((var (make-symbol "event")))
    `(let ((,var ,rvalue))
       (cond
         ((not ,lvalue)
          (set! ,lvalue ,var))
         ((equal? ,lvalue ,var))
         (else
          (ly:event-warning ,var "conflict bla bla"))))))

However, my personal take is that ASSIGN_EVENT_ONCE
is an attractive nuisance in a number of cases (its
use prevents concurrent events that could very well
be handled), so I would rather take the direction
of reducing its use in C++. That said, if you have
a good reason for it in Scheme, go for it.

HTH

Jean





reply via email to

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