This will only give you one nil:
(doseq [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)))))

On Tuesday, April 8, 2014 9:28:44 PM UTC+2, Cecil Westerhof wrote:
>
> 2014-04-08 20:49 GMT+02:00 Toby Crawley <to...@tcrawley.org <javascript:>>
> :
>
>> 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)
>
>
>> cldwes...@gmail.com <javascript:> 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 clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> 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