lilypond-user
[Top][All Lists]
Advanced

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

Re: `ly:context-property` and empty alist


From: Valentin Petzel
Subject: Re: `ly:context-property` and empty alist
Date: Sun, 10 Jul 2022 14:32:42 +0200

Hello Werner,

the problem here is not really ly:context-property, but the C-implementation 
Context::internal_get_property, which uses SCM_EOL as default value. So 
Lilypond’s guile interface cannot know if a NULL is actually set or if the 
context property is not set. It would be possible to check before whether the 
context in question has this property set. Sadly we do not have a scheme 
handle on the here_defined macro, but only on the where defined macro.

Still we can use something like
(eq? (ly:context-property-where-defined context sym) context)
to check if a symbol is defined in a specific context. So we could use 
something 
like:

#(define (context-has-defined? context sym)
   (eq? (ly:context-property-where-defined context sym) context))

#(define* (context-strict-get-property context sym #:optional (def '()))
   (if (context-has-defined? context sym)
       (ly:context-property context sym)
       def))

Cheers,
Valentin

Am Sonntag, 10. Juli 2022, 13:46:58 CEST schrieb Werner LEMBERG:
> The documentation of `ly:context-property` is as follows.
> 
>   -- Function: ly:context-property context sym def
> 
>      Return the value for property SYM in CONTEXT.  If DEF is given,
>      and property value is ‘'()’, return DEF.
> 
> I have a use case where I want to say
> 
> ```
> \set SYM = #'()
> ```
> 
> i.e., I explicitly want to override the default DEF with an empty
> list.  How can I do that?
> 
> 
>     Werner

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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