[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Define variable only if it doesn't exist / is unbound
From: |
Richard Shann |
Subject: |
Re: Define variable only if it doesn't exist / is unbound |
Date: |
Fri, 29 Mar 2019 08:58:34 +0000 |
On Thu, 2019-03-28 at 18:22 -0700, Aaron Hill wrote:
> 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
This sounds like a problem I had when Denemo started running under
Guile 2 - I asked on the guile mailing list and got fixed up with
this:
;;; for guile 2.0 compatibility define the define-once procedure to
work in guile 1.8
(cond-expand
(guile-2) ; nothing
(else ; guile < 2.0
(define-macro (define-once sym exp)
`(define ,sym
(if (module-locally-bound? (current-module) ',sym)
,sym
,exp)))))
Apologies in advance if this is un-related, I've not been following
this thread :(
Richard
- Define variable only if it doesn't exist / is unbound, Pedro Pessoa, 2019/03/28
- Re: Define variable only if it doesn't exist / is unbound, Valentin Villenave, 2019/03/28
- Re: Define variable only if it doesn't exist / is unbound, Aaron Hill, 2019/03/28
- Re: Define variable only if it doesn't exist / is unbound, Thomas Morley, 2019/03/28
- Re: Define variable only if it doesn't exist / is unbound, Aaron Hill, 2019/03/28
- Re: Define variable only if it doesn't exist / is unbound,
Richard Shann <=
- Re: Define variable only if it doesn't exist / is unbound, Thomas Morley, 2019/03/29
- Re: Define variable only if it doesn't exist / is unbound, Aaron Hill, 2019/03/29
- Re: Define variable only if it doesn't exist / is unbound, Thomas Morley, 2019/03/29
- Re: Define variable only if it doesn't exist / is unbound, Thomas Morley, 2019/03/29
- Re: Define variable only if it doesn't exist / is unbound, Vaughan McAlley, 2019/03/30
Re: Define variable only if it doesn't exist / is unbound, Pedro Pessoa, 2019/03/28
Re: Define variable only if it doesn't exist / is unbound, David Kastrup, 2019/03/29