I tried this:
(declare F)
(defn M [n]
(if (zero? n)
0
(- n (F (M (dec n))
(defn F [n]
(if (zero? n)
1
(- n (M (F (dec n))
and for large n I got the expected stack overflow. Then I tried to
trampoline the functions:
(declare F)
(defn M [n]
(if (zero? n)
0
Thank you for the answers. I now understand why this cannot work with
trampoline.
Is there another way to avoid stack overflow? I'd like to submit the
code to http://rosettacode.org/wiki/Mutual_Recursion to improve the
Clojure coverage and also to learn more stuff myself...
--~--~-~--~
the java provided version, it suffers from the same StackTrace
> problem.
>
> 2009/6/10 arasoft :
>
>
>
> > Thank you for the answers. I now understand why this cannot work with
> > trampoline.
> > Is there another way to avoid stack overflow? I'd like to submit t
When I enter the following function into the REPL it compiles and
works without problems:
(defn harmonic-number [n prec]
(reduce + (map #(with-precision prec (/ 1 (bigdec %))) (range 1 (inc
n
)
After (set! *warn-on-reflection* true), in a normal REPL I get:
Reflection warning, NO_SO
I just wrote my first practice macro, first without and then with
syntax quoting:
(defmacro take-until1 [function sq]
(list 'take-while (list 'fn (vector 'x) (list 'not (list function
'x))) sq))
(defmacro take-until2 [function sq]
`(take-while (fn [x#] (not (~function x#))) ~sq))
Both seem
Thank you for your help. I have posted a message on the Enclojure
group yesterday and I am still waiting for it to show up...
On Jun 22, 5:46 am, "Stephen C. Gilardi" wrote:
> On Jun 21, 2009, at 11:17 PM, arasoft wrote:
>
> > When I enter the following function into th
Clojipsy
clojure-eclipse
On Jun 23, 1:47 pm, Laurent PETIT wrote:
> Hello,
>
> Since the switch to git, there has also been the creation of a mailing list
> called clojure-dev for discussions concerning clojure development, and a
> twitter account also named clojuredev.
>
> While Rich didn't me
Is there a way to avoid having to use a function like this
(defn coerce-primitive-integer [value to-class]
(cond (= to-class java.lang.Byte) (byte value)
(= to-class java.lang.Short) (short value)
(= to-class java.lang.Integer) (int value)
(= to-class java.lang.L
This also works:
(into [-1] [0 1 2 3 4])
but I am more than uncertain whether it is "proper".
On Jun 25, 12:26 am, CuppoJava wrote:
> I personally use (concat [-1] [0 1 2 3 4]), but I've never been happy
> with that either. I would be interested in the proper way of doing
> this also.
> -Patri
Why does this work?
(take-while (complement #{\a\e\i\o\u}) "the-quick-brown-fox")
When I do something similar, like
(take-while (complement #(Character/isWhitespace %)) "the-quick-brown-
fox")
I have to deal with the parameter explicitly ("%"). How is the
parameter hidden in the set/function?
Thank you for a comprehensive explanation!!!
On Jun 25, 1:17 am, Richard Newman wrote:
> > Why does this work?
>
> > (take-while (complement #{\a\e\i\o\u}) "the-quick-brown-fox")
>
> > When I do something similar, like
>
> > (take-while (complement #(Character/isWhitespace %)) "the-quick-brown-
I think you just forgot to return the value itself. This seems to
work:
(defn produce [value predicate generator]
(when (predicate value)
(let [result (generator value)]
(cons result (lazy-seq (produce result predicate
generator)
)
And I would use "quot" instead of "u
At least I believe so: it would allow client code to set the desired
precision once and then be able to invoke functions that take an
optional precision parameter (or none at all) without having to
specify precision every time.
For example:
(set! *default-precision* (. java.math.MathContext/DECIM
is the difference? How is it done right?
On Jun 29, 2:24 pm, Christophe Grand wrote:
> On Mon, Jun 29, 2009 at 1:23 PM, arasoft wrote:
>
> > At least I believe so: it would allow client code to set the desired
> > precision once and then be able to invoke functions that
I'm obviously all for it...
On Jun 29, 5:53 pm, Rich Hickey wrote:
> On Mon, Jun 29, 2009 at 10:51 AM, Stephen C. Gilardi wrote:
>
> > On Jun 29, 2009, at 10:11 AM, Nicolas Oury wrote:
>
> >> I am not sure, but I believe it's due to *warn-on-reflection* being
> >> bound by the compiler/REPL befo
Using a fairly recent 1.1 snapshot, I get an OutOfMemoryError for
this:
(defn fib-seq []
((fn more [a b]
(lazy-seq (cons a (more b (+ a b)
0 1)
)
(nth (fib-seq) 20)
However, this works fine:
(defn xth [coll i]
(if (zero? i) (first coll) (recur (rest coll) (dec i
16 matches
Mail list logo