Skip to content

Instantly share code, notes, and snippets.

@zallarak
Created January 9, 2012 16:38
Show Gist options
  • Save zallarak/1583757 to your computer and use it in GitHub Desktop.
Save zallarak/1583757 to your computer and use it in GitHub Desktop.
Creating a tree in Scheme (Lisp)
; This creates a simple tree
(define tree-1 (cons (list 1 2) (list 3 4)))
; Quick linked list review
(list 1 2 3 4) ;is equivalent to:
(cons 1 (cons 2 (cons 3 (cons 4 ()))))
; And here is some interpreter action
; just for practice:
(define tree-1 (cons (list 1 2) (list 3 4)))
;Value: tree-1
;tree-1
;Value 11: ((1 2) 3 4)
(car tree-1)
;Value: (1 2)
; Using car on the tree doesn't return the first element
; We have hierarchy, hence the tree
(cdr tree-1)
;Value: (3 4)
(define linked-list-1 (list 1 2 3 4))
;Value: linked-list-1
(car linked-list-1)
;Value: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment