8 Queens Problem

Justin Sheehy justin at iago.org
Tue Jul 9 12:03:07 EDT 2002


Simon.Foster at smiths-aerospace.com writes:

>     Would this solution qualify as tail-recursive?

Yes.  The only recursive call that you make is in tail position.

(Not that it matters even the slightest bit in Python, of course.)

> What's a closure? 

A closure is a function body together with an environment giving
values for the function's free variables.

In other words, a function's definition combined with the relevant
part of the environment in which it was defined.

> A continuation?

A continuation is a representation of the future of a computation.

If I leave you with just that definition, though, you probably won't
be much better off than when you started, so...

At any given time in program flow, the current continuation can be
thought of as "the rest of the program", with a hole in it for the
thing currently being executed.  For instance, in the code segment:

f(g(x))

g's continuation could be thought of as being f(_) where "_" is to be
filled in when the continuation is run.

Think of your continuation as a function of one argument that will
take your return value as its argument.  It represents everything
that will happen in the program onward from the time that you return.

Even in languages that provide the programmer with direct access to
continuations, it is rare for continuations to be used directly for
something other than implementation of a scheduling system or a new
control-flow construct.  However, implementing such things can be
pretty cool.

Some of the sorts of things that can be done with continuations:

  backtracking
  coroutines
  threading systems
  generators
  cross-tree searches
  recursion exits

If you get really interested in continuations for some reason, you
should probably read up on the papers produced by all of the Scheme
folks at or from the University of Indiana over the past 20 years.

(Dan Friedman, Mitch Wand, Will Clinger, Kent Dybvig, Chris Hanyes,
Bruce Duba, Eugene Kohlbecker, Matthias Felleisen...)

Enjoy, have fun, and good luck.

-Justin

 






More information about the Python-list mailing list