unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Add procedure list->hook in Guile
@ 2019-08-30  1:52 Amar Singh
  0 siblings, 0 replies; only message in thread
From: Amar Singh @ 2019-08-30  1:52 UTC (permalink / raw)
  To: guile-devel


Scheme procedure - list->hook lst
Convert the procedure list of LST to a hook.

It will compliment the hook->list procedure already there. :)

I found the hook->list procedure in C but I cannot find a good place to add
list->hook.

Thoughts?

Cheers,
amar<nly@disroot.org>


--------------------------------------------------------------------------------
;;; Full procedure
(define (list->hook lst)
  "Convert the procedure list of LST to a hook."
  (define (adder h lst arity)
    (if (null? lst) h
        (let ((proc (car lst)))
          (if (procedure? proc)
              (if (equal? arity (car (procedure-minimum-arity proc)))
                  (begin (add-hook! h proc #t)
                         (adder h (cdr lst) arity))
                  (error (format #f "In procedure list->hook: Wrong number of arguments to ~s, expected arity ~s" proc arity)))
              (error (format #f "In procedure list->hook: Wrong type argument ~s, expecting a procedure." proc))))))
  (if (null? lst) (make-hook)
      (let ((proc (car lst)))
        (if (procedure? proc)
            (let* ((arity (car (procedure-minimum-arity proc)))
                   (hook (make-hook arity)))
              (adder hook lst arity))
            (error (format #f "In procedure list->hook: Wrong type argument: ~s in list, expected a procedure." proc))))))



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-30  1:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30  1:52 Add procedure list->hook in Guile Amar Singh

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).