[Top][All Lists]

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

Effective use of destructive functions

From: address@hidden
Subject: Effective use of destructive functions
Date: 11 Apr 2007 16:42:42 -0700
User-agent: G2/1.0

Here's some code....

(setq doc '(root (child 1 2) (child 3 4)))
(setq editable-child (car (cdr doc)))
;; (setq editable-child (mapcan (lambda (x)
;;                     (cons x nil)) editable-child))

(setcdr editable-child '(10 11))

It seems that in the commented sexp, altering the symbol
editable-child using setcdr has no effect on doc because the contents
of editable-child is a copy of the contents of doc rather than a
direct reference to a particular `place' in doc.

This is a stripped down version of my real problem which is to
creating a number of widgets out of the data in doc.  I want to make
a :notify function for each widget that updates doc when an element of
the tree is edited.

My question is...How can you run the contents of editable-child
through a mapping function, and keep the structure so that any changes
to the return value carry on up to doc?

Many Thanks,
Andy Chambers

reply via email to

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