guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add procedure list->hook in Guile


From: Amar Singh
Subject: Add procedure list->hook in Guile
Date: Fri, 30 Aug 2019 07:22:50 +0530

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<address@hidden>


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]