guile-devel
[Top][All Lists]
Advanced

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

continuation efficiency


From: Thomas Bushnell, BSG
Subject: continuation efficiency
Date: 05 Jul 2001 14:50:28 -0700

I have some potential uses of continuations, which will be used in
automatically generated code.  That makes it easier to go ahead and
make the continuations all the time, but only use them once in a
while.  (To only make the continuations when they are needed would
complicate the compiler.)  So this question is for those who
understand guile guts enough to answer sensibly for the particular
implementations guile uses.


I.  Is A substantially worse than B:

    A: (call/cc (lambda (c) (do-something)))
    B: (do-something)

    (Note that the continuation in A is never used.)

II. Is A substantially worse than B:

    A: (call/cc (lambda (c) (do-some-things) (c do-something)))
    B: (begin (do-some-things) (do-something))

    (Note that the escape procedure is only used as a tail call in the
    argument to call/cc.)


If dynamic context is held as a linked list of stack frames, then the
obvious implementation of call/cc makes the answer to question I
"no", even without clever optimizations: because the continuation is
just a simple object creation, which gets gc'd soon enough.  If
dynamic context were real machine stacks, that had to be copied, then
the answer to I would be "yes" unless there were other clever
optimizations going on.  So that means you can't just reason "guile
does no clever optimizations; the answer must be `yes'".

Does the following expression (which runs forever) run forever, or
does it run out of space?  (The astute will notice a connection
between this question and number I above.)

(letrec
  ((whizzie 
   (lambda (argument)
    (argument (call/cc whizzie)))))
  (call/cc whizzie))


Thomas



reply via email to

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