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: Fri, 29 Mar 2019 11:31:56 +0100

Am Fr., 29. März 2019 um 02:23 Uhr schrieb Aaron Hill
<address@hidden>:
>
> On 2019-03-28 3:14 pm, Thomas Morley wrote:
> > 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))
>
> Wouldn't...
>
> (define foo (if (defined? 'foo) foo 123))
>
> ...work?  Since foo is not defined (or redefined) until the S-expression
> is fully evaluated, it should be able to resolve the existing value
> should it exist.  This also keeps the define at the top-level.
>
> -- Aaron Hill

Think so.

Cheers,
  Harm



reply via email to

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