That last line is the repl printing out the result of the for, which
returns a seq of the return values from the for body (in this case, the
return value of println). If you run this code as part of an
application, you would not see the seq of nils printed. To suppress
printing them in the repl, and instead have it print a single nil,
replace 'doall' with 'dorun'. That will do the same thing, but retain
none of the results.

- Toby

cldwester...@gmail.com writes:

> 2014-04-08 20:49 GMT+02:00 Toby Crawley <t...@tcrawley.org>:
>
>> Does this give you the results you are looking for?
>>
>> (doall
>>   (for [i (range 1 1000)
>>         :let [val (Math/sqrt i)
>>               diff (Math/abs (- (Math/pow val 2) (* val val)))]
>>         :when (> diff 1.1755025E-38)]
>>     (println (format "Different for %d (%e)" i diff))))
>>
>
> It is a lot better. But for every result I get a nil value:
> (doall
>   (for [i (range 1 10000)
>         :let [val (Math/sqrt i)
>               diff (Math/abs (- (Math/pow val 2) (* val val)))]
>         :when (> diff 1.1755025E-38)]
>     (println (format "Different for %d (%e)" i diff))))
>
> Gives:
> Different for 838 (1.136868e-13)
> Different for 3352 (4.547474e-13)
> Different for 3674 (4.547474e-13)
> Different for 5343 (9.094947e-13)
> Different for 7667 (9.094947e-13)
> Different for 7863 (9.094947e-13)
> Different for 9470 (1.818989e-12)
> (nil nil nil nil nil nil nil)
>
>
> Is it possible to get rid of the last line:
> (nil nil nil nil nil nil nil)
>
>
>
>> cldwester...@gmail.com writes:
>>
>> > In common lisp I had the following code:
>> > (let (
>> >       (difference)
>> >       (i)
>> >       (val)
>> >       )
>> >   (loop for i from 1 to 10000000 do
>> >        (setq val (sqrt i))
>> >        (setq difference (abs (- (expt val 2) (* val val))))
>> >        (unless (< difference 1.1755025E-38)
>> >          (print (format nil "Different for ~D (~F)." i difference))
>> >          )))
>> >
>> > Clojure works a little bit different. Until now I have the following with
>> > comes near the above:
>> >   (for [i (range 1 1000)]
>> >        (do
>> >        (def ^:dynamic val (Math/sqrt i))
>> >        (def ^:dynamic difference (Math/abs (- (Math/pow val 2) (* val
>> > val))))
>> >        (when (> difference 1.1755025E-38)
>> >          (println (format "Different for %d (%e)" i difference))
>> >          )))
>> >
>> > But beside that this defines the two variables val and difference, it
>> also
>> > generates a lot of nil values.
>> >
>> > What would be a better way to do this in Clojure?
>> >
>> >
>> > --
>> > Cecil Westerhof
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Cecil Westerhof

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to