[Top][All Lists]

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

Re: Having trouble understanding optional and variable amount of argumen

From: Urs Liska
Subject: Re: Having trouble understanding optional and variable amount of arguments
Date: Fri, 9 Mar 2018 08:29:44 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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
      (let ((props (context-mod->props rules #t opts)))
        . ,body)))

testRules =
#(define-void-function-with-options () ()
   `((ind ,number? 5)
     (target ,symbol?)
     (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.

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.


reply via email to

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