Sunday 15 July 2012

clojure - walk through tree functionally -


I'm trying myself "walk through the tree" function, but I am new to FP

I wrote this function and it works fine, but it looks ugly

  (defrecord tree [value left]] (defn_walk_tree [tree functor] (value: tree) ) (If (: left tree) (break (if (: left tree) (inconsistent item (depth_ walk_tree (left tree))) (list item)) (if (: right tree) (comet left list (depth_wall_tree) ( : Right tree) Factor)) (DERT tree (tree 1 (tree 2 (tree 0 zero zero) (tree 90 blue zero) (tree 3. blue (tree 10 zero zero)) (printlen (depth_value_tree) Tree # (+% 1))   

Program response

  (2 3 194 11 11); OK  < / Pre> 

Can someone advise me how to make this beauty?

I do not have my native language in English.

It looks a bit more functional, IMHO: < (If:: left tree) (depth_wall_tree (left tree))) (if (: right tree) (if (: right tree) () depth_wok_tree (: right tree)))))

and also preserves the original result:

  (depth_walk_tree tree inc) = & gt; (2 3 1 91 4 11)    

No comments:

Post a Comment