On Tue, Feb 19, 2008 at 07:14:07AM -0800, Bob La Quey wrote:

Not necessarily.  Often we simply want to map things onto
other structures. Sometimes that is easier to do recursively
sometimes in some other way. Lots of code gets written that
traverses XML in essentially a pattern matching mode without
much reference to the tree structure. Certainly that is a
natural way for a lot of the Perl guys to do things.

True closures allow this mapping to be done naturally.  The tree traversal
can be written recursively, and the results used linearly in another piece
of code.

Without closures/continuations, there is no way to suspend the "stack"
information from a recursive set of calls to be resumed later (C, C++,
Java, for example).

Well it has been a while but what about jump, setjump in C?

setjmp in C lets you get out of the stack, but not back to where you were.
It is possible to implement coroutines with setjmp, but the code becomes
very system and processor dependent, since you have to setup and manage a
separate stack.

A much easier way to do this is be creating a separate thread to do the
recursive traversal.  Depending on the implementation, this can be quite a
bit of overhead as well, though.

Agree that the nodes are polymorphic but I do _not_ see
what that has to do with static typing. Please explain.

Maybe what you are saying is that if a node were
a single data type then compile time checking
could be imposed?

In a statically typed language, you have to explicitly handle the various
types of values that can be in a node.  For example, C or C++ could use a
union and another field to indicate which element of the union to use.
Other statically typed langauge, such as ML or Haskell have an explicit
type to help with this.

A statically typed language doesn't allow for an array of different-typed
items.  In Java, you can create an array of "object", but then you have to
figure out the types before you can do anything with them.

With a dynamic typed language, each node just stores the object of whatever
type it is.  You can just use them when you know what the type should be.

I posted an earlier example of a piece of XML represented in Lisp.  It was
almost the same as the XML, just slight differences to deal with the syntax
difference.

David

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to