Live data from Hacker News

In Lisp, should lists be replaced with trees?

hxa.name

41–43 of 43 posts

Re: In Lisp, should lists be replaced with trees?

#41

You can just build your tree data structure and develop operators to work with them in Lisp. There's nothing that restricts you to using lists. So what's the point of "replacing" them (even if such a thing were possible without "replacing" Lisp)?

Cons cells give you binary trees. It is possible to encode any arbitrary tree as a binary tree. However, this does not mean that the expression of algorithms over such left child right sibling encoded trees is identical to one over trees with some higher branching factor. So the cons/binary situation will at the least require some additional layers of abstraction to simulate various traversal patterns of the n way tree on the encoding binary tree.

There also physical/efficiency concerns. There's a reason databases use highly branching trees.

Re: In Lisp, should lists be replaced with trees?

#42
post #36

This is either a reinvention of ASTs or it's Graph Reduction. http://en.wikipedia.org/wiki/Abstract_syntax_tree http://en.wikipedia.org/wiki/Graph_reduction :)

You provided two things that the original post is a reinvention of. Which is it? Why not read the article enough to decide which it is a reinvention of, then present your thinking in your comment?

Re: In Lisp, should lists be replaced with trees?

#43

You can just build your tree data structure and develop operators to work with them in Lisp. There's nothing that restricts you to using lists. So what's the point of "replacing" them (even if such a thing were possible without "replacing" Lisp)?

Cons cells give you binary trees. It is possible to encode any arbitrary tree as a binary tree. However, this does not mean that the expression of algorithms over such left child right sibling encoded trees is identical to one over trees with some higher branching factor. So the cons/binary situation will at the least require some additional layers of abstraction to simulate various traversal patterns of the n way tr…

And you can create the abstractions necessary to work with such a data structure and add them straight to the regular grammar of the language.

Lisp also has all of the other low-level primitives we're used to when working closer to the machine. Structs, indexed arrays, hashes, etc. If efficiency is a concern, just pick an implementation that compiles to machine code. SBCL is pretty good for this depending on your target platform.

Replacing conses seems like a waste of time.

Post reply on HN