chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] define not using define


From: Elf
Subject: Re: [Chicken-users] define not using define
Date: Fri, 25 Jan 2008 07:30:30 -0800 (PST)


(define-macro (setting param . initval)
    (let ((kvar   (gensym)))
        (or (null? initval) (null? (cdr initval))
            (error 'setting "too many args to setting: (cons param initval)))
        `(call-with-current-continuation
            (lambda (,kvar)
                (condition-case ,param
                    (()    (,kvar (lambda ()
                                      (set! ,param
                                            (make-parameter
                                                (and (not (null? ',initval))
                                                     (car ,initval))))))))
                (,param)))))

i think should do the trick.  this will define the given param name to the
optional initval if undefined, or give the current value of the param if it
was previously defined.  this was just a quick throway so there might be an
error.

-elf


On Fri, 25 Jan 2008, minh thu wrote:

Hi,

Is it possible to register symbols in Chicken, just as a global
(define ...) would do from arbitrary code?

I'd like to be able to write (setting 'color '#f32(1 0 0 0)) and have
the same effect
than a (define color (make-parameter '#f32(1 0 0 0)) unless the color procedure
already exists.

Is it possible to define 'setting' as a procedure and not as a macro
(or am I limited to use 'setting' at the top level (I don't mean the
repl))?

The fact color is procedure is nice for me, I'd rather call (color)
than (look-up 'color).

Thanks,
thu


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users





reply via email to

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