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 > Re: newbie ques...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 2780 of 2842
Post > Topic >>

Re: newbie question

by forkiliens <forkiliens@[EMAIL PROTECTED] > Mar 1, 2008 at 03:03 PM

On Feb 27, 2:15 am, justinc...@[EMAIL PROTECTED]
 wrote:
> 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?


Hi,

I'm new to Lisp too, but here is what a google search on
'binary tree lisp'
yields:

http://www.cs.sfu.ca/CC/310/pwfong/Lisp/3/tutorial3.html

It seems like it is not so trivial.

Good Luck




 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 Sat May 17 8:43:17 CDT 2008.