unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* making a thunk out of a list
@ 2007-07-24 14:06 Marco Maggi
  2007-07-24 14:37 ` Thien-Thi Nguyen
  2007-09-18 22:16 ` Neil Jerram
  0 siblings, 2 replies; 4+ messages in thread
From: Marco Maggi @ 2007-07-24 14:06 UTC (permalink / raw)
  To: guile-user

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?

--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"




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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: making a thunk out of a list
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Thien-Thi Nguyen @ 2007-07-24 14:37 UTC (permalink / raw)
  To: Marco Maggi; +Cc: guile-user

() "Marco Maggi" <marco.maggi-ipsu@poste.it>
() Tue, 24 Jul 2007 16:06:31 +0200

     (lambda () (for-each primitive-eval result))

   Ideas?

(lambda () (primitive-eval `(begin ,@result)))

thi


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: making a thunk out of a list
  2007-07-24 14:37 ` Thien-Thi Nguyen
@ 2007-07-24 14:47   ` Thien-Thi Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Thien-Thi Nguyen @ 2007-07-24 14:47 UTC (permalink / raw)
  To: Marco Maggi; +Cc: guile-user

() Thien-Thi Nguyen <ttn@gnuvola.org>
() Tue, 24 Jul 2007 16:37:49 +0200

   () "Marco Maggi" <marco.maggi-ipsu@poste.it>
   () Tue, 24 Jul 2007 16:06:31 +0200

        (lambda () (for-each primitive-eval result))

      Ideas?

   (lambda () (primitive-eval `(begin ,@result)))

however, this just produces the thunk form, if you want
to really produce a thunk, you'd use:

(primitive-eval `(lambda () ,@result))

thi


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: making a thunk out of a list
  2007-07-24 14:06 making a thunk out of a list Marco Maggi
  2007-07-24 14:37 ` Thien-Thi Nguyen
@ 2007-09-18 22:16 ` Neil Jerram
  1 sibling, 0 replies; 4+ messages in thread
From: Neil Jerram @ 2007-09-18 22:16 UTC (permalink / raw)
  To: Marco Maggi; +Cc: guile-user

"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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-09-18 22:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).