[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Two optional arguments
From: |
Urs Liska |
Subject: |
Re: Two optional arguments |
Date: |
Wed, 15 Jul 2020 20:53:02 +0200 |
User-agent: |
Evolution 3.36.4-1 |
Hi Aaron,
Am Mittwoch, den 15.07.2020, 07:09 -0700 schrieb Aaron Hill:
> 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?
Thank you, this was a terrific idea which seems to get me over the goal
line.
>
> %%%%
> \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'
>
> %%%%
The actual implementation will be totally different, given what I
already have and that all this happens inside a macro, but I could
translate the idea without problems.
>
> 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.
Yes, this is not my original syntax, but that doesn't matter.
My wish was to spare the user to write a \with block for just that
symbol. But when the user has to write that anyway it's no hassle to
provide that symbol as a regular property within the \with block.
So this solution allows me to work around the fact that I can't use the
two optional arguments.
Best
Urs
>
>
> -- Aaron Hill