[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Nifty finalizer-related macro
From: |
Ed Watkeys |
Subject: |
[Chicken-users] Nifty finalizer-related macro |
Date: |
Wed, 15 Dec 2004 17:40:38 -0500 |
Hey,
Until I figure out* how to use C_do_register_finalizer(...), I've got
to wrap a bunch of foreign functions that return pointers so that a
finalizer is installed. The enlightened lazy person in me first thought
to write a function:
(define (make-finalizing proc finalizer)
(lambda args
(let ((result (apply proc args)))
(set-finalizer! result finalizer))))
With it, you can write the following:
(define make-thing
(make-finalizing
make-thing-in-c
finalize-thing))
Yeah, that was good, but the really lazy person in me said, "Hey, you
can do better; don't make me work!" So I thought for a bit and came up
with this:
(define-macro (define-finalizing name proc finalizer)
`(define (,name . args)
(let ((result (apply ,proc args)))
(set-finalizer! result ,finalizer)
result)))
With this macro, you can now type a little less:
(define-finalizing
make-thing
make-thing-in-c
finalize-thing)
I don't know if this will be useful to anyone, but given that I'm going
to implement glue to a large-ish API three times, I'm looking to save
keystrokes wherever possible.
Regards,
Ed
* I've already asked too many questions today.
--
Watkeys Product Design -- http://watkeys.com/
- [Chicken-users] Nifty finalizer-related macro,
Ed Watkeys <=