lilypond-user
[Top][All Lists]
Advanced

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

Re: Define variable only if it doesn't exist / is unbound


From: Thomas Morley
Subject: Re: Define variable only if it doesn't exist / is unbound
Date: Thu, 28 Mar 2019 23:14:52 +0100

Am Do., 28. März 2019 um 22:22 Uhr schrieb Aaron Hill
<address@hidden>:
>
> On 2019-03-28 2:18 pm, Valentin Villenave wrote:
> > On 3/28/19, Pedro Pessoa <address@hidden> wrote:
> >> I imagined something like:
> >>
> >> %%% pseudo
> >> #(define var
> >>     (not (is-bound? var) 0))
> >> %%%
> >
> > I’d probably probably do something like
> >
> > (null? (ly:parser-lookup 'var))
> >
> > But I’m sure there are better ways :-)
>
> ;;;;
> (if (not (defined? 'foo)) (define foo 47))
> ;;;;
>
>
> -- Aaron Hill

It's worth mentioning, the above will throw an error in guilev2:

error: GUILE signaled an error for the expression beginning here
#
 (if (not (defined? 'foo)) (define foo 47))
definition in expression context, where definitions are not allowed

Probably better get used to below:

#(if (not (defined? 'foo)) (ly:parser-define! 'foo 47))

Cheers,
  Harm



reply via email to

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