@Urs
I've thought about this some more. I don't know if you were interested in wrapping the functions that use opts and props in a macro, but I noticed a lot of redundancy so I gave it a try.

    \version  "2.19.80" \include  "oll-core/package.ily" #(define-macro  
(define-void-function-with-options vars preds rulings . body)
        `(define-void-function  ,(append  '(opts) vars) ,(append  
'(ly:context-mod?) preds)
           (define  rules
             ,rulings)
           (let  ((props (context-mod->props rules #t opts)))
             . ,body)))

    testRules =
    #(define-void-function-with-options () ()
        `((ind ,number?  5)
          (target ,symbol?)
          (payload)
          (accepted-arg ,fraction?  opt)
          (accepted-without-type opt)
          (msg ,string?  "No message given"))
        (pretty-print  props))

    \testRules  \with  { msg ="Something" unk ="Unknown option" target = 
something
    % accepted-arg = 7/4 % accepted-without-type = #(ly:make-moment
    3/16) }

Again, tell me if you find it convenient.


Hm.
The definition of testRules looks pretty good. What I'm not so sure about is that this would actually imply creating -with-options variants of *all* define- macros, and I'm not sure if that would add unnecessary complexity compared to "simply" calling context-mod->props within a function definition.

Actually, I start thinking if this doesn't call for a "proper" solution to be added to LilyPond itself. Of course I'm hijacking ly:context-mod? which is semantically there for a different purpose. What I would like to see is a different predicate, say, ly:properties? that internally is a simple key-value alist but that can be entered with the same \with {} syntax.

Urs
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to