Hi :)
On Sun 08 May 2011 15:01, [email protected] writes:
> just a short question: in guile it's possible to have C-hooks of
> different type (HOOK_NORMAL, HOOK_OR, HOOK_AND). Is there similar
> functionality for scheme level hooks? Can I create a scheme hook
> where hooks are only run until one returns a value other than
> undefined?
Guile's Scheme hooks don't support this out of the box, so to speak, but
it's quite easy to build what you need.
For example:
(use-modules (srfi srfi-9))
(define-record-type <hook>
(%make-hook procs runner)
hook?
(procs hook-procs set-hook-procs!)
(runner hook-runner))
(define (add-hook! hook proc)
(set-hook-procs! hook (append (hook-procs hook) (list proc))))
(define (make-or-hook)
(%make-hook '()
(lambda (procs args)
(or-map (lambda (proc) (apply proc args))
procs))))
(define (run-hook hook . args)
((hook-runner hook) (hook-procs hook) args))
(define h (make-or-hook))
(add-hook! h (lambda () (pk 'a #f)))
(add-hook! h (lambda () (pk 'b #t)))
(add-hook! h (lambda () (pk 'c #f)))
(run-hook h)
;;; (a #f)
;;; (b #t)
=> #t
Andy
--
http://wingolog.org/