|
From: | Jean Abou Samra |
Subject: | Re: `ly:context-property` and empty alist |
Date: | Sun, 10 Jul 2022 17:38:33 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 |
Le 10/07/2022 à 14:32, Valentin Petzel a écrit :
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))
That differs in semantics from ly:context-property not just with the handling of '(). Normally, context properties are inherited. If the property is not defined in the context, it is read from its parent, or the parent of the parent, etc. How about this instead:
#(define* (context-strict-property context property #:optional (default '()))
(if (null? (ly:context-property-where-defined context property)) default (ly:context-property context property))) Best, Jean
[Prev in Thread] | Current Thread | [Next in Thread] |