unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: "Marco Maggi" <marco.maggi-ipsu@poste.it>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: making a thunk out of a list
Date: Tue, 18 Sep 2007 23:16:26 +0100	[thread overview]
Message-ID: <877imn62md.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <JLOSIV$2E4F7F26CDDA160612B9386C99C412BC@poste.it> (Marco Maggi's message of "Tue, 24 Jul 2007 16:06:31 +0200")

"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:

> Ciao,
>
>   maybe this is simple, but today I cannot find a solution;
> while iterating over the nodes of a graph I can accumulate
> in a list the sequence of function invocations upon each
> node (pseudo-code):
>
>   (let ((result '()))
>      ;; for each node in the iteration:
>      (set! result (cons (list action-upon-node node)
>                         result))
>      ;; at the end
>      (reverse result))
>
> I do it in a method to memoize the iteration; now I
> would like to make a thunk out of the list, the following
> works:
>
>   (lambda () (for-each primitive-eval result))
>
> but I would like a thunk that does not use FOR-EACH. I fail
> to see how to do it with a macro, and I cannot APPLY a
> LAMBDA, for example the following does not work:
>
>     ((list lambda '() result))
>
> Ideas?

You've probably solved this by now, but I found your question curious,
so...

You have a list of nodes, and you have a procedure f that you want to
apply to each node.  So that's just `(map f nodes)', isn't it?

But then you want to delay the f calls, and wrap the whole thing up
in a thunk.  So:

(define (make-delayed-map-thunk f nodes)
  (lambda ()
    (map f nodes)))

I guess it can't really be this simple, so what am I missing?

Regards,
        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


      parent reply	other threads:[~2007-09-18 22:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-24 14:06 making a thunk out of a list Marco Maggi
2007-07-24 14:37 ` Thien-Thi Nguyen
2007-07-24 14:47   ` Thien-Thi Nguyen
2007-09-18 22:16 ` Neil Jerram [this message]

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=877imn62md.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    --cc=marco.maggi-ipsu@poste.it \
    /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).