Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Functional > newbie question
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 2780 of 2841
Post > Topic >>

newbie question

by justincorn@[EMAIL PROTECTED] Feb 26, 2008 at 05:15 PM

Hi, I'm new to lisp and trying to get a feel for things in CL. To that
end, I'm trying to write a binary tree, but I can't figure out how to
do it the way I'd like.  Given nodes in the form of (key left-child
right-child . data), I'd prefer to write something like

<code>
(defun insert (key data &optional (node *root*))
  (progn
    (if (null *root*)
        (setf *root* (make-node key data)))
    (destructuring-bind (k l r . d) node
      (if (funcall test k key)
          (setf node (make-node key data l r))
          (insert key data (if (funcall cmp k key)
                               l
                               r))))))
</code>

for the insert function, but obviously this isn't working.  As you can
see, in two places I'm trying to set the <i>place</i> of a variable
I'm passing into the function, but all I'm really doing is clobbering
the version in the local scope.

I guess what I'm kind of trying to do is a bit like passing around
handles (pointers to pointers) in c.  Is there some nice way to do
something like this in CL?




 2 Posts in Topic:
newbie question
justincorn@[EMAIL PROTECT  2008-02-26 17:15:23 
Re: newbie question
forkiliens <forkiliens  2008-03-01 15:03:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun May 11 19:58:12 CDT 2008.