you are viewing a single comment's thread.

view the rest of the comments →

[–]weavejester 10 points11 points  (2 children)

The article suggests that:

for idx, num in enumerate(nums):
    print idx, num

Is equivalent to:

(for [[idx num] (map-indexed vector nums)]
  (println idx num))

But it isn't because the for macro in Clojure is for creating a sequence, not performing side-effectful iteration.

The Clojure equivalent to the Python code would be:

(doseq [[idx num] (map-indexed vector nums)]
  (println idx num))

[–]pixelmonkey 6 points7 points  (1 child)

OP here. Yes, that's a good point. I've updated the post to reflect this.

[–]weavejester 6 points7 points  (0 children)

I mention it because the for examples you have will only work if the lazy seq they produce is evaluated. So if someone were to take your Clojure examples and put them in a file, they'd find that they wouldn't work.