When thinking about trees, I find it's often best to start with the most basic case. So in your case, begin by writing a function that deals with a single operator and two numerical arguments:
(f '(* 4 9)) => (36 4 9) (f '(- 6 10)) => (-4 6 10) Next, consider the case where you have two precomputed lists instead. So assume you have list arguments that have already been transformed: (g '(+ (36 4 9) (-4 6 10))) => (32 (36 4 9) (-4 6 10)) Then think on how to create a function that deals with both instances. So: (h '(+ 10 (36 4 9))) => (46 10 (36 4 9)) Once you have a function that can do all that, then think of how you deal with lists that *haven't* been transformed: (i '(+ 10 (* 4 9))) => (46 10 (36 4 9)) And you'll have your answer. Hopefully that's a good enough hint! If you get stuck on any of those steps, try posting the code you have so far. - James On 14 November 2015 at 14:16, <stevegarrid1...@gmail.com> wrote: > I have recently started learning lisp and completed some simple exercises > that are available to me, unfortunately I have got stuck & after spending > hours it seems I don't seem to be getting any closer to a decent solution. > > I am trying to produce a function which takes the expression 'tree' as its > argument and returns the tree with the relevant calculated values in place > of the operators. > > An example of what a tree could look like is: (* (+ 10 (* 4 9)) (- 6 10)) > And the function should return: (-184 (46 10 (36 4 9)) (-4 6 10)) > > > > could anyone help me out with an example to point me in the right > direction with an explanation of how it works? > > > thanks > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.