On Wed, 2013-02-27 at 08:19 -0500, m...@markwitmer.com wrote: > Richard Shann <richard.sh...@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*)))))) >