p*****2 发帖数: 21240 | |
c******o 发帖数: 1277 | 2 this comparison happens many times, look at the comment, scala has its
greatness.
I am recently just fascinated by scalaz.
btw, how clojure handle stack overflow for complex recursions?
I am recently studying stackless scala, wondering how clojure handle
recursive that is not tail recursive. |
p*****2 发帖数: 21240 | 3
what do you mean complex recursion? Is loop/recur what you want?
【在 c******o 的大作中提到】 : this comparison happens many times, look at the comment, scala has its : greatness. : I am recently just fascinated by scalaz. : btw, how clojure handle stack overflow for complex recursions? : I am recently studying stackless scala, wondering how clojure handle : recursive that is not tail recursive.
|
c******o 发帖数: 1277 | 4 no, not loop, no loop
for example mutual recursion,
or another example just try to write a insertion sort with no loop/no
mutable.
【在 p*****2 的大作中提到】 : : what do you mean complex recursion? Is loop/recur what you want?
|
p*****2 发帖数: 21240 | 5
trampoline
Clojure is not purely functional.
【在 c******o 的大作中提到】 : no, not loop, no loop : for example mutual recursion, : or another example just try to write a insertion sort with no loop/no : mutable. :
|
t****a 发帖数: 1212 | 6 我猜想用lazy sequence(lazy-cat?)可能能做到complex stackless recusion,不过还
没试过。 |
c******o 发帖数: 1277 | 7 yes, basically generalize trampoline
it is easy to do not purely functional in scala, easier than clojure
not purely functional will give up some benefits though.
I want to master both.
sometime, it is not easy to see that happens, as some combinator will in
fact have deep nested calling stack without you know this use case when you
implement the system.
It is mostly fine for app developer, but if you want to develop a library,
it is a must have skill.
【在 p*****2 的大作中提到】 : : trampoline : Clojure is not purely functional.
|
p*****2 发帖数: 21240 | 8
It's awkward once you do Java interop anyway. Everything becomes mutable
immediately. Can't say which one is easier.
【在 c******o 的大作中提到】 : yes, basically generalize trampoline : it is easy to do not purely functional in scala, easier than clojure : not purely functional will give up some benefits though. : I want to master both. : sometime, it is not easy to see that happens, as some combinator will in : fact have deep nested calling stack without you know this use case when you : implement the system. : It is mostly fine for app developer, but if you want to develop a library, : it is a must have skill.
|
t****a 发帖数: 1212 | 9 尝试了,可以的。如果recursion可以表示为sequence的情形下例如fib数列,就可以用
lazy sequence来实现stackless trampline。
(declare fib2)
(defn fib1 [a b]
(lazy-seq (cons a (fib2 b (+ a b)))))
(defn fib2 [a b]
(lazy-seq (cons a (fib1 b (- a b)))))
(def fib-seq2 (fib1 0.0 1.0))
(nth fib-seq2 100000) ; it works
【在 t****a 的大作中提到】 : 我猜想用lazy sequence(lazy-cat?)可能能做到complex stackless recusion,不过还 : 没试过。
|