unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guile hooks
@ 2011-05-08 13:01 rm
  2011-07-01 15:19 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: rm @ 2011-05-08 13:01 UTC (permalink / raw)
  To: guile-user

Hello list,

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? 

 TIA Ralf Mattes





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Guile hooks
  2011-05-08 13:01 Guile hooks rm
@ 2011-07-01 15:19 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2011-07-01 15:19 UTC (permalink / raw)
  To: rm; +Cc: guile-user

Hi :)

On Sun 08 May 2011 15:01, rm@tuxteam.de 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/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-01 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-08 13:01 Guile hooks rm
2011-07-01 15:19 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).