Paste number 80683: Simple binary tree constructor

Paste number 80683: Simple binary tree constructor
Pasted by: gnuvince
When:8 months, 2 weeks ago
Share:Tweet this! | http://paste.lisp.org/+1Q97
Channel:#clojure
Paste contents:
Raw Source | XML | Display As
(def *count* (atom 0))

(defstruct node :children)

(defn make-node [children]
  (swap! *count* inc)
  (struct node children))

(defn make-tree [depth]
  (if (> depth 1)
    (make-node [(make-tree (dec depth)) (make-tree (dec depth))])
    (make-node [])))

(let [depth (if *command-line-args*
              (Integer/parseInt (first *command-line-args*))
              10)]
  (make-tree depth)
  (println @*count*))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.