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
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 p
Sorry I'm a complete rookie at this that didn't make a bit of sense to me. So
far I have this:
(def a '(* (+ 5 (* 3 7)) (- 6 8)) )
(defn evaltree [tree] (cons (eval (first (rest tree))) tree))
all i have so far which evals the first part of list but doesn't recurse
through to do the rest
So start with something like:
(def a '(+ 3 9))
Then write a function where:
(evaltree a)
=> (12 3 9)
Don't worry about recursion to start with. Just get the simplest case
working first.
- James
On 14 November 2015 at 17:46, wrote:
> Sorry I'm a complete rookie at this that didn'
Ok by starting with the basic (Def a '(+ 3 9))
I have
(Defn evaltree [tree]
(Cons (eval tree) tree))
But I can't seem to get it to work or drop the plus from the list. I'm really
struggling with this
Thanks for your help
--
You received this message because you are subscribed to the Goo
Hey there,
>
Congratulations on getting this far. It took me a long time too to be able
to do something this complicated. I think it's cool that you're thinking
about this kind of problem. This is essentially a small recursive
interpreter, which is a neat problem.
How do you drop the first ele
Okay, so:
(defn evaltree [tree]
(cons (eval tree) (rest tree)))
That evaluates the tree, assuming that (rest tree) only contains numbers.
(eval-tree '(+ 3 9))
However, we also want to evaluate the arguments in the same way. The
arguments are a list, and when we want to do somethin
I'm using clojure version: Clojure 1.1.0-alpha-SNAPSHOT and I'm trying
to get slime and clojure to work on OS X.
slime works with my sbcl install without any problems. I installed
all of the packages and I'm getting an error while starting slime -
clojure:
1. I go into clojure mode (M-x clojur
2009/8/30 mlm :
> (setq swank-clojure-extra-
> classpaths
> (list
> "/opt/clojure/clojure-contrib/clojure-contrib.jar:/opt/clojure/swan\
> k-clojure/swank/swank.clj"))
Try changing the swank-clojure bit to point to the directory rather
than the .clj file, i.e. either /opt/clojure/swank-clo