* More Guile 1.8 code failing in 2.x
@ 2013-02-27 10:07 Richard Shann
2013-02-27 13:19 ` mark
2013-02-27 14:50 ` Stefan Israelsson Tampe
0 siblings, 2 replies; 10+ messages in thread
From: Richard Shann @ 2013-02-27 10:07 UTC (permalink / raw)
To: guile-user
We have one more construct being refused as we upgrade to guile 2.0 in
GNU/Denemo
(if (not (defined? 'ToggleTripleting::InsideTriplet))
(define ToggleTripleting::InsideTriplet #t))
It is intended to set up a flag which toggles between true and false on
each call. If already set up, the flag is not altered.
Apparently (I haven't been able to check) Guile 2.0 gives an error.
#f definition in expression context, where definitions are not allowed, ((line . 2) (column . 4) (filename . #f)) (define ToggleTripleting::InsideTriplet #t) #f)
Can anyone suggest what could replace that? I would prefer to to replace
it with something that has the same semantics, rather than setting up
some alternative method of handling the situation - registering all such
variables on program startup, or some such - as at the moment this code
only evaluated if used and doesn't require any mechanism to get
initialized, other than this construct.
Richard Shann
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 10:07 More Guile 1.8 code failing in 2.x Richard Shann
@ 2013-02-27 13:19 ` mark
2013-02-27 14:22 ` Richard Shann
2013-02-27 14:50 ` Stefan Israelsson Tampe
1 sibling, 1 reply; 10+ messages in thread
From: mark @ 2013-02-27 13:19 UTC (permalink / raw)
To: Richard Shann; +Cc: guile-user
Richard Shann <richard.shann@virgin.net> writes:
> We have one more construct being refused as we upgrade to guile 2.0 in
> GNU/Denemo
>
> (if (not (defined? 'ToggleTripleting::InsideTriplet))
> (define ToggleTripleting::InsideTriplet #t))
>
> It is intended to set up a flag which toggles between true and false on
> each call. If already set up, the flag is not altered.
>
> Apparently (I haven't been able to check) Guile 2.0 gives an error.
>
> #f definition in expression context, where definitions are not
> allowed, ((line . 2) (column . 4) (filename . #f)) (define
> ToggleTripleting::InsideTriplet #t) #f)
>
> Can anyone suggest what could replace that? I would prefer to to replace
> it with something that has the same semantics, rather than setting up
> some alternative method of handling the situation - registering all such
> variables on program startup, or some such - as at the moment this code
> only evaluated if used and doesn't require any mechanism to get
> initialized, other than this construct.
>
> Richard Shann
>
>
>
>
Hi Richard,
You can probably just replace your code with
(define-once ToggleTripleting::InsideTriplet #t)
(define-once ...) works like defvar in Common Lisp and will not
redefine a variable once it has been defined. You can read about it at
the bottom of the node "Top Level Variable Definitions" in the Guile
manual.
I'm still learning the ins and outs of procedural macros, but I think
that if you need to include (define ...) in a conditional like that for
more complicated purposes, you can use syntax-case like this:
(define-syntax conditional-define
(lambda (x)
(syntax-case x ()
((conditional-define arg val)
(let ((arg-datum (syntax->datum #'arg)))
(if (not (defined? arg-datum))
#'(define arg val)
#'*unspecified*))))))
--
Mark Witmer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 13:19 ` mark
@ 2013-02-27 14:22 ` Richard Shann
2013-02-27 14:28 ` Ludovic Courtès
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Richard Shann @ 2013-02-27 14:22 UTC (permalink / raw)
To: mark; +Cc: guile-user
On Wed, 2013-02-27 at 08:19 -0500, mark@markwitmer.com wrote:
> Richard Shann <richard.shann@virgin.net> writes:
>
> > We have one more construct being refused as we upgrade to guile 2.0 in
> > GNU/Denemo
> >
> > (if (not (defined? 'ToggleTripleting::InsideTriplet))
> > (define ToggleTripleting::InsideTriplet #t))
> >
> > It is intended to set up a flag which toggles between true and false on
> > each call. If already set up, the flag is not altered.
> >
> > Apparently (I haven't been able to check) Guile 2.0 gives an error.
> >
> > #f definition in expression context, where definitions are not
> > allowed, ((line . 2) (column . 4) (filename . #f)) (define
> > ToggleTripleting::InsideTriplet #t) #f)
> >
> > Can anyone suggest what could replace that? I would prefer to to replace
> > it with something that has the same semantics, rather than setting up
> > some alternative method of handling the situation - registering all such
> > variables on program startup, or some such - as at the moment this code
> > only evaluated if used and doesn't require any mechanism to get
> > initialized, other than this construct.
> >
> > Richard Shann
> >
> >
> >
> >
>
> Hi Richard,
>
> You can probably just replace your code with
>
> (define-once ToggleTripleting::InsideTriplet #t)
Thanks for this - it seems define-once is not defined in guile 1.8
however, so while some systems only have guile 2.0 (Fedora) and others
only have guile 1.8 (Debian stable) I would need something more.
I wonder if I can test if define-once is defined and if not evaluate a
string which has the dis-allowed syntax in it?
(if (defined? 'define-once)
(define-once ToggleTripleting::InsideTriplet #t)
(eval-string "(if (not (defined? 'ToggleTripleting::InsideTriplet))
(define ToggleTripleting::InsideTriplet #t))"))
or will the guile 2.0 compiler try and compile the string being passed to eval-string?
Richard
>
> (define-once ...) works like defvar in Common Lisp and will not
> redefine a variable once it has been defined. You can read about it at
> the bottom of the node "Top Level Variable Definitions" in the Guile
> manual.
>
> I'm still learning the ins and outs of procedural macros, but I think
> that if you need to include (define ...) in a conditional like that for
> more complicated purposes, you can use syntax-case like this:
>
> (define-syntax conditional-define
> (lambda (x)
> (syntax-case x ()
> ((conditional-define arg val)
> (let ((arg-datum (syntax->datum #'arg)))
> (if (not (defined? arg-datum))
> #'(define arg val)
> #'*unspecified*))))))
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 14:22 ` Richard Shann
@ 2013-02-27 14:28 ` Ludovic Courtès
2013-02-27 14:48 ` Mike Gran
2013-02-27 15:08 ` Andy Wingo
2 siblings, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2013-02-27 14:28 UTC (permalink / raw)
To: guile-user
Richard Shann <richard.shann@virgin.net> skribis:
> (if (defined? 'define-once)
> (define-once ToggleTripleting::InsideTriplet #t)
> (eval-string "(if (not (defined? 'ToggleTripleting::InsideTriplet))
> (define ToggleTripleting::InsideTriplet #t))"))
Rather something along these lines:
(cond-expand ((not guile-2)
(define-macro (define-once var expr)
`(if (not (defined? ',var))
(define ,var ,expr))))
(guile-2 #t))
This will do nothing on Guile 2.0, and will define ‘define-once’ on 1.8.
HTH,
Ludo’.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 14:22 ` Richard Shann
2013-02-27 14:28 ` Ludovic Courtès
@ 2013-02-27 14:48 ` Mike Gran
2013-02-27 17:54 ` Richard Shann
2013-02-27 15:08 ` Andy Wingo
2 siblings, 1 reply; 10+ messages in thread
From: Mike Gran @ 2013-02-27 14:48 UTC (permalink / raw)
To: Richard Shann, mark@markwitmer.com; +Cc: guile-user@gnu.org
> From: Richard Shann <richard.shann@virgin.net>
>
> Thanks for this - it seems define-once is not defined in guile 1.8
> however, so while some systems only have guile 2.0 (Fedora) and others
> only have guile 1.8 (Debian stable) I would need something more.
Just as an aside... Fedora doesn't have Guile 2.0 at all, except in its
experimental Rawhide distro. It still ships with 1.8. Still about
half of the Guile-using programs in Fedora can't compile with 2.0, so
Fedora will be shipping with both guile-1.8 and 2.0 in the next version,
Fedora 19. Maintainers will be able to link their packages to
either one. The executable for Guile 2.0 will likely be called
/usr/bin/guile2.
-Mike
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 10:07 More Guile 1.8 code failing in 2.x Richard Shann
2013-02-27 13:19 ` mark
@ 2013-02-27 14:50 ` Stefan Israelsson Tampe
1 sibling, 0 replies; 10+ messages in thread
From: Stefan Israelsson Tampe @ 2013-02-27 14:50 UTC (permalink / raw)
To: guile-user; +Cc: Richard Shann
Can you wrap the code in a cond-expand form no?
/Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 14:22 ` Richard Shann
2013-02-27 14:28 ` Ludovic Courtès
2013-02-27 14:48 ` Mike Gran
@ 2013-02-27 15:08 ` Andy Wingo
2013-02-27 15:13 ` Andy Wingo
2 siblings, 1 reply; 10+ messages in thread
From: Andy Wingo @ 2013-02-27 15:08 UTC (permalink / raw)
To: Richard Shann; +Cc: mark, guile-user
Hi Richard,
On Wed 27 Feb 2013 15:22, Richard Shann <richard.shann@virgin.net> writes:
> On Wed, 2013-02-27 at 08:19 -0500, mark@markwitmer.com wrote:
>> Richard Shann <richard.shann@virgin.net> writes:
>>
>> > (if (not (defined? 'ToggleTripleting::InsideTriplet))
>> > (define ToggleTripleting::InsideTriplet #t))
I'm sorry we were not able to make this case work in Guile 2; it's quite
complicated actually.
>> You can probably just replace your code with
>>
>> (define-once ToggleTripleting::InsideTriplet #t)
>
> Thanks for this - it seems define-once is not defined in guile 1.8
> however
You could define it in a prelude somewhere:
(cond-expand
(guile-2) ; nothing
(else ; guile < 2.0
(define-macro (define-once sym exp)
`(if (not (defined? ',sym)) (define ,sym ,exp)))))
Then you could change all uses of this idiom to use define-once.
Note that Guile 2.'s `define-once' is slightly different; it always
declares a local definition, and it uses the existing value only if
there is already a local definition. In this way imported values get
overridden by define-once.
Here is a Guile 2-compatible version:
(cond-expand
(guile-2) ; nothing
(else ; guile < 2.0
(define-macro (define-once sym exp)
`(define ,sym (if (module-locally-bound? ',sym) ,sym ,val)))))
Finally in Guile 2 there is also the `define!' procedure, which makes
top-level definitions programmatically. Use it if you need it. But if
you can, better to rewrite to use standard Scheme.
In general I recommend adding shims to Denemo to make it
forward-compatible -- like adding define-once if needed so that it uses
the Guile 2.0 idioms, even on 1.8.
Good luck, and let us know how it goes.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 15:08 ` Andy Wingo
@ 2013-02-27 15:13 ` Andy Wingo
2013-02-27 17:59 ` Richard Shann
0 siblings, 1 reply; 10+ messages in thread
From: Andy Wingo @ 2013-02-27 15:13 UTC (permalink / raw)
To: Richard Shann; +Cc: mark, guile-user
On Wed 27 Feb 2013 16:08, Andy Wingo <wingo@pobox.com> writes:
> Here is a Guile 2-compatible version:
>
> (cond-expand
> (guile-2) ; nothing
> (else ; guile < 2.0
> (define-macro (define-once sym exp)
> `(define ,sym (if (module-locally-bound? ',sym) ,sym ,val)))))
Sorry, thinko+typo. Should be:
(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)))))
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 14:48 ` Mike Gran
@ 2013-02-27 17:54 ` Richard Shann
0 siblings, 0 replies; 10+ messages in thread
From: Richard Shann @ 2013-02-27 17:54 UTC (permalink / raw)
To: Mike Gran; +Cc: mark@markwitmer.com, guile-user@gnu.org
On Wed, 2013-02-27 at 06:48 -0800, Mike Gran wrote:
> > From: Richard Shann <richard.shann@virgin.net>
> >
> > Thanks for this - it seems define-once is not defined in guile 1.8
> > however, so while some systems only have guile 2.0 (Fedora) and others
> > only have guile 1.8 (Debian stable) I would need something more.
>
> Just as an aside... Fedora doesn't have Guile 2.0 at all, except in its
> experimental Rawhide distro.
Yes, it was the maintainer of Denemo for Fedora that raised a bug about
the lack of guile 2.0 support. I guess he was unable to test it for the
upcoming release...
Richard
> It still ships with 1.8. Still about
> half of the Guile-using programs in Fedora can't compile with 2.0, so
> Fedora will be shipping with both guile-1.8 and 2.0 in the next version,
> Fedora 19. Maintainers will be able to link their packages to
> either one. The executable for Guile 2.0 will likely be called
> /usr/bin/guile2.
>
> -Mike
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: More Guile 1.8 code failing in 2.x
2013-02-27 15:13 ` Andy Wingo
@ 2013-02-27 17:59 ` Richard Shann
0 siblings, 0 replies; 10+ messages in thread
From: Richard Shann @ 2013-02-27 17:59 UTC (permalink / raw)
To: Andy Wingo; +Cc: mark, guile-user
On Wed, 2013-02-27 at 16:13 +0100, Andy Wingo wrote:
> On Wed 27 Feb 2013 16:08, Andy Wingo <wingo@pobox.com> writes:
>
> > Here is a Guile 2-compatible version:
> >
> > (cond-expand
> > (guile-2) ; nothing
> > (else ; guile < 2.0
> > (define-macro (define-once sym exp)
> > `(define ,sym (if (module-locally-bound? ',sym) ,sym ,val)))))
>
> Sorry, thinko+typo. Should be:
>
> (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)))))
>
This works a treat (well, of course I didn't actually get to test on
guile 2.0 myself, but I will doubtless hear about it if it should fail
there :)
Thank you all who responded.
Richard
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-02-27 17:59 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-27 10:07 More Guile 1.8 code failing in 2.x Richard Shann
2013-02-27 13:19 ` mark
2013-02-27 14:22 ` Richard Shann
2013-02-27 14:28 ` Ludovic Courtès
2013-02-27 14:48 ` Mike Gran
2013-02-27 17:54 ` Richard Shann
2013-02-27 15:08 ` Andy Wingo
2013-02-27 15:13 ` Andy Wingo
2013-02-27 17:59 ` Richard Shann
2013-02-27 14:50 ` Stefan Israelsson Tampe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).