Re: cons cells



Peter Keller <psilord@xxxxxxxxxxx> writes:

Andrew Reilly <areilly---@xxxxxxxxxxxxxx> wrote:
On Mon, 04 Apr 2011 16:14:59 -0700, TheFlyingDutchman wrote:

Where is the dotted pair(s)?

Here's something more obviously tree-shaped (in scheme, but I'm sure the
same thing works similarly in CL) that I've used from time to time:

(define (maptree f t) ; apply f to leaves of tree t, returning a new
tree of same shape as t
(cond
((null? t) t)
((pair? t) (cons (maptree f (car t)) (maptree f (cdr t))))
(else (f t))))

Out of curiosity, how would you do a mapgraph that preserves the graph
structure?

If the mapping functions preserve it, then it's trivial:

(defun mapgraph (node-fun edge-fun graph)
(make-graph :nodes (mapcar (function node-fun) (graph-nodes graph))
:edges (mapcar (function edge-fun) (graph-edges graph))))

But in all probability, node-fun or edge-fun won't be bijections, so
there's little point in defining such a mapgraph function.


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
.