Re: Detecting null markup in Scheme

2017-09-04 Thread David Kastrup
Graham King  writes:

> On Fri, 2017-09-01 at 20:35 +0200, David Kastrup wrote: 
>> Graham King  writes:
>> 
>> > On Fri, 2017-09-01 at 19:06 +0200, David Kastrup wrote:
>> >> 
>> >> I'd just try (equal? markupContents "") here.  equal? can compare any
>> >> objects for "equality", and at least "" as input should compare equal
>> >> then.
>> >> 
>> > thanks David.  I'm getting "Missing or extra expression in (if (equal?
>> > markupContents ""))"
>> 
>> Well, missing.  You have a condition but no expression to be evaluated
>> depending on it.
>> 
> Thanks again David.  After a long struggle, I've got somewhere.  The 
> result is probably inelegant enough to cause some sucking of teeth 
> among the congnoscenti, but it works for me:
>
> ( if ( equal? #{ \markup #markupContents #}
>   #{ \markup { \concat { "" "" "" } } #} )

Ouch.  I've forgotten that markups are just assembled when you write
them and are only interpreted when using interpret-markup .  Only then
does \markup \line { \concat { "" "" "" } } collapse to an empty
stencil.  So you probably had to mimic the contents of markupContents in
order to get equal? to do something reasonable.

Sorry for that.

>   #{ <> #}
>   (case whereMarkup
>  ((system) #{ \mark #markupContents #})
>  ((staff)  #{ <>^   #markupContents #})
>  (else #{ \mark \markup \color #red #markupContents #})
> ))

-- 
David Kastrup

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


Re: Detecting null markup in Scheme

2017-09-04 Thread Graham King
On Fri, 2017-09-01 at 20:35 +0200, David Kastrup wrote: 
> Graham King  writes:
> 
> > On Fri, 2017-09-01 at 19:06 +0200, David Kastrup wrote:
> >> 
> >> I'd just try (equal? markupContents "") here.  equal? can compare any
> >> objects for "equality", and at least "" as input should compare equal
> >> then.
> >> 
> > thanks David.  I'm getting "Missing or extra expression in (if (equal?
> > markupContents ""))"
> 
> Well, missing.  You have a condition but no expression to be evaluated
> depending on it.
> 
Thanks again David.  After a long struggle, I've got somewhere.  The 
result is probably inelegant enough to cause some sucking of teeth 
among the congnoscenti, but it works for me:

( if ( equal? #{ \markup #markupContents #}
  #{ \markup { \concat { "" "" "" } } #} )
  #{ <> #}
  (case whereMarkup
 ((system) #{ \mark #markupContents #})
 ((staff)  #{ <>^   #markupContents #})
 (else #{ \mark \markup \color #red #markupContents #})
))

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


Re: Detecting null markup in Scheme

2017-09-01 Thread David Kastrup
Graham King  writes:

> I have a monstrous music-function that constructs a markup in Scheme and
> then decides whether to put it at system-level or staff-level, along the
> following lines (much-redacted):
>
> foo = #(define-music-function (args...) (types...)
>   (let* ((markupContents #{
> \markup {
>\concat {
>   #markupOne 
>   #markupTwo
>}}
> #})
>   (case whereMarkup
>  ((system) #{ \mark #markupContents #})
>  ((staff)  #{ <>^   #markupContents #})
>  (else #{ \mark \markup \color #red #markupContents #})
>   ))
> )
>
> The problem is: how best to deal with the case where #markone and
> #markuptwo are both empty, i.e. #{ \markup "" #}, and no markup at all
> should be attempted?
>
> I've tried variations on:
>   ( if ( string=? ( markup->string markupContents ) 
>   ( markup->string empty-markup ))
>  (#{ <> #})
>  (case whereMarkup ...
>
> but my grasp of Scheme, never very firm, is slipping away.
>
> Grateful for any suggestions, pointers to documentation/tutorials,
> etc.

I'd just try (equal? markupContents "") here.  equal? can compare any
objects for "equality", and at least "" as input should compare equal
then.

-- 
David Kastrup

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


Detecting null markup in Scheme

2017-09-01 Thread Graham King
I have a monstrous music-function that constructs a markup in Scheme and
then decides whether to put it at system-level or staff-level, along the
following lines (much-redacted):

foo = #(define-music-function (args...) (types...)
  (let* ((markupContents #{
\markup {
   \concat {
  #markupOne 
  #markupTwo
   }}
#})
  (case whereMarkup
 ((system) #{ \mark #markupContents #})
 ((staff)  #{ <>^   #markupContents #})
 (else #{ \mark \markup \color #red #markupContents #})
  ))
)

The problem is: how best to deal with the case where #markone and
#markuptwo are both empty, i.e. #{ \markup "" #}, and no markup at all
should be attempted?

I've tried variations on:
  ( if ( string=? ( markup->string markupContents ) 
  ( markup->string empty-markup ))
 (#{ <> #})
 (case whereMarkup ...

but my grasp of Scheme, never very firm, is slipping away.

Grateful for any suggestions, pointers to documentation/tutorials, etc.

-- Graham

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