Common Lisp "do" equivalent?

3 views
Skip to first unread message

Parth Malwankar

unread,
Aug 14, 2008, 9:03:38 AM8/14/08
to Clojure
Hello,

I just added a table on CL -> Clojure mapping to the wiki section
http://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_Lisp_Programmers
Please feel free to make addition / correction. I am just trying to
document as I learn Clojure.

Now for my question.
As I made the entry for "progn -> do", the next logical thing
a CL programmer would as is : what about Common Lisp "do"?

I sort of feel that its not needed here as the sequences are
lazy and immutable, and we have map, filter etc. but would
like more accurate comments by Clojure gurus here so that
an accurate explanation can be put up on the wiki.

One a side note, just curious, what was the rationale on the
selection
of "do" as the name instead of "progn"?

Thanks.
Parth


Stuart Sierra

unread,
Aug 14, 2008, 10:08:00 AM8/14/08
to Clojure
The closest match to CL "do" is probably loop/recur.

CL (copied from the HyperSpec):
(do ((temp-one 1 (1+ temp-one))
(temp-two 0 (1+ temp-one)))
((= 3 temp-two) temp-one))
; => 3

Clojure:
(loop [temp-one 1
temp-two 0]
(if (= 3 temp-two)
temp-one
(recur (inc temp-one) (inc temp-one))))
; => 3

-Stuart


On Aug 14, 9:03 am, Parth Malwankar <parth.malwan...@gmail.com> wrote:
> Hello,
>
> I just added a table on CL -> Clojure mapping to the wiki sectionhttp://en.wikibooks.org/wiki/Clojure_Programming#Clojure_for_Common_L...
Reply all
Reply to author
Forward
0 new messages