Hi!

Andy Wingo <[email protected]> writes:

> On Tue 08 Feb 2011 23:58, Andy Wingo <[email protected]> writes:
>
>> On Thu 03 Feb 2011 20:18, Mark Harig <[email protected]> writes:
>>
>>> scheme@(guile-user)> ,re (ice-9 readline)
>>
>> Actually now this causes an infinite loop.  Doh.  We need defvar,
>> somehow...
>
> What do people think about this:
>
>     (define-syntax define-once
>       (syntax-rules ()
>         ((_ sym val)
>          (define sym (if (defined? 'sym) sym val)))))

Looks cool!

How about this variant?

    (define-syntax define-once
      (syntax-rules ()
        ((_ sym val)
         (define sym (if (defined? 'sym) sym val)))
        ((_ sym val docstring)
         (begin
           (define-once sym val)
           (set-doc-property! (module-variable (current-module) 'sym)
                              docstring)))))

Ludo’.


Reply via email to