Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread Werner LEMBERG

>> I want to write a user-friendly markup command that can accept either
>> a markup or a markup list as arguments.  Example:
>>
>> ```
>> % \ornament   
>> \markup \ornament \number ♭
>>   \musicglyph "scripts.turn"
>>   \number ♮
>> \markup \ornament { \number ♭ \number ♭ }
>>   \musicglyph "scripts.turn"
>>   \number ♮
>> ```
> 
> So if you give a markup list here, is this supposed to be stacked
> horizontally or vertically?

Vertically.

> If horizontally, adding \line does not seem all that terrible.

Yep.

> And it will be hard to explain what
> 
> \markup \ornament \with-color #red { \number ♭ \number ♭ } ...
> 
> is supposed to do: is \with-color #red applied to the numbers or to
> the whole list?

I would rather write either

  \markup \with-color #red \ornament { \number ♭ \number ♭ } ...

or 

  \markup \ornament { \with-color #red \number ♭
  \with-color #red \number ♭ } ...

so I don't mind if

  \markup \ornament \with-color #red { \number ♭ \number ♭ } ...

is probably not well defined.


Werner


Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread David Kastrup
Werner LEMBERG  writes:

>> The real question is what you actually are trying to achieve here.
>
> I want to write a user-friendly markup command that can accept either
> a markup or a markup list as arguments.  Example:
>
> ```
> % \ornament   
> \markup \ornament \number ♭
>   \musicglyph "scripts.turn"
>   \number ♮
> \markup \ornament { \number ♭ \number ♭ }
>   \musicglyph "scripts.turn"
>   \number ♮
> ```

So if you give a markup list here, is this supposed to be stacked
horizontally or vertically?  If horizontally, adding \line does not seem
all that terrible.

And it will be hard to explain what

\markup \ornament \with-color #red { \number ♭ \number ♭ } ...

is supposed to do: is \with-color #red applied to the numbers or to the
whole list?

-- 
David Kastrup



Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread Werner LEMBERG

> The documentation clearly states:
> 
> 
> 
>Arguments are distinguished according to their type:
>• a markup, corresponding to type predicate ‘markup?’;
>• a list of markups, corresponding to type predicate
>  ‘markup-list?’;
>• any other scheme object, corresponding to type predicates such
>  as ‘list?’, ‘number?’, ‘boolean?’, etc.
>
> You use a predicate other than markup? or markup-list?, so this
> counts as any other scheme object.

OK.

> The real question is what you actually are trying to achieve here.

I want to write a user-friendly markup command that can accept either
a markup or a markup list as arguments.  Example:

```
% \ornament   
\markup \ornament \number ♭
  \musicglyph "scripts.turn"
  \number ♮
\markup \ornament { \number ♭ \number ♭ }
  \musicglyph "scripts.turn"
  \number ♮
```


Werner


Re: markup function accepting either markup or markup list as argument

2024-06-22 Thread David Kastrup
Werner LEMBERG  writes:

> Folks,
>
>
> I would like to write a markup function that can either accept a
> markup or a markup list as an argument.

You mean, a markup command.

> The code below works fine, reporting
>
> ```
> bar: (#)
> baz: 1
> bar: ((#)
>   (#))
> baz: 1
> ```
>
> as expected.  (The `baz` argument is inserted in the demo code to
> avoid interference with LilyPond's special handling of a markup
> function's last argument, which can be either a markup or a markup
> list, for example, `\bold foo` or `\bold { foo bar }`.)
>
> However, if I activate the commented-out code, LilyPond aborts with
>
> ```
> error: syntax error, unexpected MARKUP_FUNCTION
> \markup \fooEither 
>\flat #1
> ```
>
> It seems to me that this is a limitation built into LilyPond's parser,
> and it is not possible to do what I would like to achieve, probably
> due to the above-mentioned special handling of the last argument.  Has
> someone more insight?

The documentation clearly states:



   Arguments are distinguished according to their type:
   • a markup, corresponding to type predicate ‘markup?’;
   • a list of markups, corresponding to type predicate ‘markup-list?’;
   • any other scheme object, corresponding to type predicates such as
 ‘list?’, ‘number?’, ‘boolean?’, etc.

You use a predicate other than markup? or markup-list?, so this counts
as any other scheme object.

The real question is what you actually are trying to achieve here.

-- 
David Kastrup



markup function accepting either markup or markup list as argument

2024-06-22 Thread Werner LEMBERG


Folks,


I would like to write a markup function that can either accept a
markup or a markup list as an argument.  The code below works fine,
reporting

```
bar: (#)
baz: 1
bar: ((#)
  (#))
baz: 1
```

as expected.  (The `baz` argument is inserted in the demo code to
avoid interference with LilyPond's special handling of a markup
function's last argument, which can be either a markup or a markup
list, for example, `\bold foo` or `\bold { foo bar }`.)

However, if I activate the commented-out code, LilyPond aborts with

```
error: syntax error, unexpected MARKUP_FUNCTION
\markup \fooEither 
   \flat #1
```

It seems to me that this is a limitation built into LilyPond's parser,
and it is not possible to do what I would like to achieve, probably
due to the above-mentioned special handling of the last argument.  Has
someone more insight?


Werner


==


\version "2.24.0"

#(define-markup-command (foo layout props bar baz)
   (markup? number?)
   (ly:message "bar: ~a" bar)
   (ly:message "baz: ~a" baz)
   (interpret-markup layout props bar))

\markup \foo \flat #1


#(define-markup-command (fooList layout props bar baz)
   (markup-list? number?)
   (ly:message "bar: ~a" bar)
   (ly:message "baz: ~a" baz)
   (interpret-markup layout props (car bar)))

\markup \fooList { \sharp \sharp } #1


% #(define (markup-or-markup-list? x)
%(or (markup? x) (markup-list? x)))
%
% #(define-markup-command (fooEither layout props bar baz)
%(markup-or-markup-list? number?)
%(ly:message "bar: ~a" bar)
%(ly:message "baz: ~a" baz)
%(interpret-markup layout props (if (markup-list? bar) (car bar) bar)))
%
% \markup \fooEither \flat #1
% \markup \fooEither { \sharp \sharp } #1