Popular Post

Rabu, 16 Maret 2011

Recursion is a low-level operation wn fun

Yesterday I demonstrated how to transform a mundane recursive function tail recursive function. However, I received some criticism for that position, because there are better ways to implement run-length encoding with Clojure. While true, I think some of my critics1 missed the point of the exercise. ;-)

That said, your points are valid because in Clojure (and probably most if not all functional languages) resources should be seen as a low level 2 operation and to avoid if possible. The best way is to study the various functions of higher order and connect them together to create new functions. We go through great lengths to stress in this joy of Clojure, so do not retrace threshing floor. Instead, note the following:

(S def '[aaabcca email ede])

(Package definition (partial partition identity))

(Package S)
((A a a) (b) (c c) (a un) (d) (e e e e))" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">;; => ((A at a) (b) (c c) (a) (d) (e e e e))

(Definition rle (comp (partial map (count Juxt First)) package))

(S RLE)
([4 bis] [1 b] [c 2] [2 a] [1 d] [4 e])" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">=> ([4 a] [1 b] [c 2] [2 a] [1 d] [4 e])

(Definition RLD (mapcat part (corresponding partial repetition)))

RLD)" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">(- Rle S> RLD)
(A aabcca un correo electrónico ede)" onmouseover="this.style.backgroundColor='#ebeff9'" onmouseout="this.style.backgroundColor='#fff'">;; => (A aabcca an email ede)

As a nice bonus, the point definitions3 above are free.

: F

1.

Criticism is probably not a fair statement. A better term would be Kritik.
2.

Low compared with levels of abstraction and also very much the same way that hedonism is low.
3.

Thank you very much Christophe Gran Malloy Alan, and Alan Dipert motivating4 ideas for this post.
4.

That is, he stole their ideas and made them free point. cough. cough.

Tidak ada komentar:

Posting Komentar