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: Graham Fawcett
Subject: Re: [Chicken-users] define not using define
Date: Fri, 25 Jan 2008 10:48:53 -0500

On Jan 25, 2008 10:32 AM, Elf <address@hidden> wrote:
>
> on that note, something that does work in the general case:
>
> (define-macro (define-if-undefined name . val)
>      `(condition-case ,name
>          (()    (define ,name ,@val))))

Thanks, Elf, I missed the "unless already exists" requirement.
(define-if-undefined) is reminiscent of DEFVAR in Common Lisp.

On a tangent, this reminds me of a macro I use. I wanted to introduce
formal hook-points in the main program, and let the run-script inject
hook-procedures into the main code if desired. The macro

(define-macro (hook-point hook-name)
  (let ((hook (gensym "hook")))
    `(and-let* ((,hook (condition-case ,hook-name (() #f))))
       (,hook))))

is used in the main program like this:

(use ...)
(hook-point pre-init)
(initialize)
(hook-point post-init)
(main-loop)
(hook-point pre-shutdown)
(shutdown)

if the runscript defines a (pre-init) thunk, it's called at the right
moment; if not, no error is thrown, and the program continues. And I
like the way the main program reads; it's clear where the optional
behaviour might occur.

Graham




reply via email to

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