[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Guile hooks
From: |
Andy Wingo |
Subject: |
Re: Guile hooks |
Date: |
Fri, 01 Jul 2011 17:19:15 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
Hi :)
On Sun 08 May 2011 15:01, address@hidden 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/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Guile hooks,
Andy Wingo <=