## Help with clojure problem

### Help with clojure problem

sd

Last edited by steve1994 on Sat Nov 14, 2015 2:25 pm, edited 1 time in total.

### Re: Help with clojure problem

This sounds like a recursive homework problem.

Write a recursive function.

When descending the tree,

- if the node is an integer, return it

- if the node is a list, take the operator, recurse into the children, then evaluate the operator, and return the evaluated list

When evaluating the operator, the evaluated argument nodes are either values or lists with the value in the first entry

Write a recursive function.

When descending the tree,

- if the node is an integer, return it

- if the node is a list, take the operator, recurse into the children, then evaluate the operator, and return the evaluated list

When evaluating the operator, the evaluated argument nodes are either values or lists with the value in the first entry

### Re: Help with clojure problem

Hi thanks for your reply.

I'm a complete beginner at this and have no clue how to do any of that. There isn't really much material online to help figure this out. Any chance you could give me a bit more of a push in the right direction on how to do that?

Thanks,

I'm a complete beginner at this and have no clue how to do any of that. There isn't really much material online to help figure this out. Any chance you could give me a bit more of a push in the right direction on how to do that?

Thanks,

### Re: Help with clojure problem

from what you said ive got this:

its incomplete and doesnt work but i have no clue how to go about doing the rest

thanks

(defn evaltree [tree]

(cond (number? tree) tree)

(tree? tree)

(eval (evaltree))

its incomplete and doesnt work but i have no clue how to go about doing the rest

thanks

(defn evaltree [tree]

(cond (number? tree) tree)

(tree? tree)

(eval (evaltree))

### Re: Help with clojure problem

What happened to the original post?

Here are some links that may help.

https://clojuredocs.org/clojure.core/loop

https://clojuredocs.org/clojure.core/recur

https://clojuredocs.org/clojure.core/map

https://clojuredocs.org/clojure.core/reduce

Here are some links that may help.

https://clojuredocs.org/clojure.core/loop

https://clojuredocs.org/clojure.core/recur

https://clojuredocs.org/clojure.core/map

https://clojuredocs.org/clojure.core/reduce