Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to express tree using CL?

Tags:

common-lisp

I want to convert the following OCaml type (an unbalanced binary tree) to Common Lisp, but as a CL newbie, i donot know how to do it using a dynamic language.

type 'a tree =
    Leaf
  | Node of 'a * 'a tree * 'a tree

Any suggestion is appreciated !

like image 888
z_axis Avatar asked Mar 03 '26 13:03

z_axis


1 Answers

A standard cons is your tree node, car being the left subtree, and cdr the right.

See http://nostoc.stanford.edu/jeff/llisp/13.html (at archive.org now) for more information.

like image 181
kkm Avatar answered Mar 07 '26 17:03

kkm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!