unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Amar Singh <nly@disroot.org>
To: guile-devel@gnu.org
Subject: Add procedure list->hook in Guile
Date: Fri, 30 Aug 2019 07:22:50 +0530	[thread overview]
Message-ID: <85zhjr1kst.fsf@disroot.org> (raw)


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



                 reply	other threads:[~2019-08-30  1:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85zhjr1kst.fsf@disroot.org \
    --to=nly@disroot.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).