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