Re: Head retention example

2013-04-22 Thread tyaakow
Thank you for the exhaustive explanation, Michal.


-- 
-- 
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/groups/opt_out.




Re: Head retention example

2013-04-14 Thread tyaakow
Thank you for your response, Marko.
I want to clarify one more thing:

(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count d) (count t)])


does this mean that while (count d) is realizing (range 1e8) seq, it 
becomes (also) realized within t, therefore 
it doubles (range 1e8) in memory causing OOME while (count d) is still not 
finished?

Also, you say "As *count* realizes one element after another, it doesn't on 
its own retain a reference to the past elements."

Does this mean that, eg. in repl, when I do some (count xyz) and it 
realizes xyz, It will later need to be reevaluated (realized again) if I 
require xyz within repl (I presume that if I require xyz later within file, 
it wont be GC due to it and clojure will know it shouldnt be GC)


-- 
-- 
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/groups/opt_out.




Head retention example

2013-04-13 Thread tyaakow
 

I'm reading Clojure Programming book by O'Reilly..

I came over an example of head retention. First example retains reference 
to d (I presume), so it doesnt get garbage collected:

(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count d) (count t)]);= #

While second example doesnt retain it, so it goes with no problem:

(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count t) (count d)]);= [12 9988]

What I don't get here is what exactly is retained in which case and why. If 
I try to return just [(count d)], like this:

(let [[t d] (split-with #(< % 12) (range 1e8))]
[(count d)])

- it seems to create same memory problem. Why is that?

Further, I recall reading that count in every case realizes/evaluates a 
sequence. So, i need that clarified.

If I try to return (count t) first, how is that faster/more memory 
efficient then if I dont return it at all? And what & why gets retained in 
which case?

-- 
-- 
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/groups/opt_out.




Re: Beginners question - emacs & compiling tests

2013-03-20 Thread tyaakow
As Marko has said, this was answered on stackoverflow.
But I appreciate your answers, and the discussion is a joy to read.
Cheers!!

-- 
-- 
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/groups/opt_out.




Beginners question - emacs & compiling tests

2013-03-19 Thread tyaakow
I'm going through clojure & emacs tutorial from clojure-doc.org, and
when compiling
the test as suggested, i get following output in emacs nrepl:


clojure.lang.Compiler$CompilerException:
java.lang.RuntimeException: Unable to resolve symbol: deftest in this
context, compiling:(/home/jakov/dev/PROJECTS/clojure/test2/test/test2/
core_test.clj:1)
 Compiler.java:6281 clojure.lang.Compiler.analyze
 Compiler.java:6223 clojure.lang.Compiler.analyze
 Compiler.java:3497 clojure.lang.Compiler
$InvokeExpr.parse
 Compiler.java:6457 clojure.lang.Compiler.analyzeSeq
 Compiler.java:6262 clojure.lang.Compiler.analyze
 Compiler.java:6223 clojure.lang.Compiler.analyze
 Compiler.java:6515 clojure.lang.Compiler.eval
 Compiler.java:6952 clojure.lang.Compiler.load
 Compiler.java:6912 clojure.lang.Compiler.loadFile
RT.java:307 clojure.lang.RT$3.invoke
   NO_SOURCE_FILE:1 user/eval42
 Compiler.java:6511 clojure.lang.Compiler.eval
 Compiler.java:6477 clojure.lang.Compiler.eval
  core.clj:2797 clojure.core/eval
   main.clj:245 clojure.main/repl[fn]
   main.clj:266 clojure.main/repl[fn]
   main.clj:266 clojure.main/repl
   RestFn.java:1096 clojure.lang.RestFn.invoke
  interruptible_eval.clj:56
clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn]
   AFn.java:159 clojure.lang.AFn.applyToHelper
   AFn.java:151 clojure.lang.AFn.applyTo
   core.clj:601 clojure.core/apply
  core.clj:1771 clojure.core/with-bindings*
RestFn.java:425 clojure.lang.RestFn.invoke
  interruptible_eval.clj:41
clojure.tools.nrepl.middleware.interruptible-eval/evaluate
 interruptible_eval.clj:171
clojure.tools.nrepl.middleware.interruptible-eval/interruptible-
eval[fn]
  core.clj:2278 clojure.core/comp[fn]
 interruptible_eval.clj:138
clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn]
AFn.java:24 clojure.lang.AFn.run
ThreadPoolExecutor.java:895
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
ThreadPoolExecutor.java:918
java.util.concurrent.ThreadPoolExecutor$Worker.run
Thread.java:662 java.lang.Thread.run
Caused by: java.lang.RuntimeException: Unable to resolve symbol:
deftest in this context
  Util.java:170 clojure.lang.Util.runtimeException
 Compiler.java:6766 clojure.lang.Compiler.resolveIn
 Compiler.java:6710 clojure.lang.Compiler.resolve
 Compiler.java:6671
clojure.lang.Compiler.analyzeSymbol
 Compiler.java:6244 clojure.lang.Compiler.analyze

To me, it seems like this line is crucial in the nrepl error output:

Caused by: java.lang.RuntimeException: Unable to resolve symbol:
deftest in this context

Anyway, i am really a clojure & emacs noob, and I dont have much clue
here.
All the emacs slime clojure stuff is installed, `leiningen2` is
installed, java is oracle java 1.6, emacs is emacs 24, and when I run
lein test in projects directory, it goes without errors.

Can anyone help me?


My core_test.clj file:

(deftest pairs-of-values
   (let [args ["--server" "localhost"
   "--port" "8080"
   "--environment" "production"]]
  (is (= {:server "localhost"
  :port "8080"
  :environment "production"}
 (parse-args args)

My core.clj file:

(defn parse-args [args]
  {})

-- 
-- 
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/groups/opt_out.