[Top][All Lists]

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

Re: making a thunk out of a list

From: Neil Jerram
Subject: Re: making a thunk out of a list
Date: Tue, 18 Sep 2007 23:16:26 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

"Marco Maggi" <address@hidden> 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,

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?


reply via email to

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