[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Two optional arguments
From: |
Aaron Hill |
Subject: |
Re: Two optional arguments |
Date: |
Wed, 15 Jul 2020 07:09:23 -0700 |
User-agent: |
Roundcube Webmail/1.4.2 |
On 2020-07-15 3:07 am, Urs Liska wrote:
It would be nice if the user could write each of these (all in the
context of my other discussion about presets/configuration/subsets):
\myFrame c'
\myFrame analogy c'
\myFrame \with { color = #red } c'
\myFrame analogy \with { color = #red } c'
It seems I would have to put a mandatory argument between the symbol
and the \with block here, which seems like a bad interface.
The solution I'll probably have to take is pulling the symbol inside
the \with block:
\myFrame \with {
configuration = analogy
color = #red
}
This forces the user to write a \with block when all they want is to
load a configuration. But that's not a *bad* interface, only
inconvenient, so clearly the lesser evil.
What about using a compound type predicate with alteration?
%%%%
\version "2.20.0"
asdf =
#(begin
(define (context-mod-assign-alist context-mod)
(map
(lambda (mod) (cons (cadr mod) (caddr mod)))
(filter
(lambda (mod) (eq? 'assign (car mod)))
(ly:get-context-mods context-mod))))
(define (symbol-or-context-mod? arg)
(or (symbol? arg)
(ly:context-mod? arg)))
(define-scheme-function
(opt-arg mus-arg)
((symbol-or-context-mod? #{ \with {} #})
ly:music?)
(if (symbol? opt-arg)
(set! opt-arg
#{ \with { symbol = $opt-arg } #}))
#{
\markup \column {
\line { \bold \typewriter "\asdf" invoked: }
$@(map
(lambda (elem) #{ \markup {
with \bold #(symbol->string (car elem)) =
\typewriter #(format #f "~s" (cdr elem)) } #})
(context-mod-assign-alist opt-arg))
\line { \score { #mus-arg } }
}
#}))
hline =
\markup \column {
\vspace #0.5
\override #'(span-factor . 1/4) \draw-hline
\vspace #0.5
}
\asdf g' \hline
\asdf foo g' \hline
\asdf \with { baz = 2/3 } g' \hline
\asdf \with { symbol = foo baz = 2/3 } g'
%%%%
While not exactly your original syntax, this does permit a user to
shorthand "\with { symbol = foo }" as simply "foo" providing they do not
need to use the \with block.
-- Aaron Hill
opt-args.cropped.png
Description: PNG image