Re: Map literal with keys generated by function cause "Duplicate key" exception

2012-09-12 Thread Stefan Kamphausen
Hi,

On Thursday, September 13, 2012 7:37:09 AM UTC+2, bsmith.occs wrote:
>
>
> Consider a simpler example with a vector, which doesn't produce an 
> error since it's allowed to have duplicates: 
>
> (def k (atom 0)) 
> (defn generate-id [] (swap! k inc)) 
>
> Now when the reader reads this: 
>
> [(generate-id) (generate-id)] 
>
> It returns a vector containing two lists, each of which contains the 
> symbol generate-id. 
>
> It's only when this data structure is evaluated, that the functions 
> generate-id get called. In some order. I wouldn't rely on getting [1 
> 2] and not [2 1]. 
>
>
you can examine, what the reader returns by using read-string, e.g.

user=> (read-string "[1 2]")
[1 2]

OK

user=> (read-string "[(+ 1 2) 2]")
[(+ 1 2) 2]

Oops?!

user=> (eval (read-string "[(+ 1 2) 2]"))
[3 2]

Aha. :-)

And, of course, the same for maps with gensym:

user=> (read-string "{(gensym) :value}")
{(gensym) :value}
user=> (eval (read-string "{(gensym) :value}"))
{G__333 :value}


Regards,
Stefan

-- 
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

Re: Map literal with keys generated by function cause "Duplicate key" exception

2012-09-12 Thread Ben Smith-Mannschott
On Thu, Sep 13, 2012 at 12:02 AM, Matthew O.  Smith  wrote:
>
> On Wednesday, September 12, 2012 8:03:58 AM UTC-6, jarppe wrote:
>>
>> I have a function that generatwed unique ID's, something like this:
>>
>>   (def k (atom 0))
>>   (defn generate-id [] (swap! k inc))
>>
>>  and I try to use it like this:
>>
>>{(generate-id) "foo"
>> (generate-id) "bar"}
>>
>> How ever, I get
>>
>>IllegalArgumentException Duplicate key: (generate-id)
>> clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)
>>
>>
>> This works as expected.
>>
>>   (let [id1 (generate-id)
>> id2 (generate-id)]
>> {id1 "foo" id2 "bar})
>>
>> Should I be able to call generate-id in map literal?
>>
>> --
>> -jarppe
>>
>
> This also fails:
>
>  {  (gensym) "foo"
> (gensym) "bar" }
>
> From the stack trace I get it looks like the reader macro that handles map
> literals is only looking at the function call, not the result of the
> function call.  This makes sense as it is the reader, not the evaluator.

Figuring out what is and what isn't a compile time constant is tricky,
huh? *headdesk*...

But, what's really going on is that you're running into a consequence
of how Clojure and other lisps work. The first thing they do is
'read', which means
converting the text of the program into data structures. Then it
evaluates those data structures as a program. Then it prints the
result. (REPL)

So, here it's building a map which contains the key "a list containing
the symbol gensym" twice. Clearly, that can't work.

It's only *after* the reader has done its work, and returned the map
that compilation/evaluation take place.

Consider a simpler example with a vector, which doesn't produce an
error since it's allowed to have duplicates:

(def k (atom 0))
(defn generate-id [] (swap! k inc))

Now when the reader reads this:

[(generate-id) (generate-id)]

It returns a vector containing two lists, each of which contains the
symbol generate-id.

It's only when this data structure is evaluated, that the functions
generate-id get called. In some order. I wouldn't rely on getting [1
2] and not [2 1].

// Ben

-- 
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


Re: [ANN] rubydoc 0.3.0

2012-09-12 Thread Gabriel Horner


On Monday, September 10, 2012 7:24:15 AM UTC-4, Denis Labaye wrote:
>
>
>
> On Mon, Sep 10, 2012 at 4:10 AM, Gabriel Horner 
> 
> > wrote:
>
>> rubydoc  is a project aimed at 
>> helping rubyists find clojure equivalents. There are now over 200+ 
>> ruby-clojure comparisons. 0.3.0 comes with some new features:
>>
>> * A comparison is not just limited to functions/methods. With the 
>> introduction of a :type field, comparisons between libraries, constants, 
>> special forms, variables, and general code are encouraged.
>> * Records can be individually display
>> * :raw option was added to just return records instead of printing them.
>> * :ruby field can take multiple values (for method aliases).
>> * :ruby-lib field was added for adding library names to methods
>>
>> More clojure-ruby comparisons welcome! For more info on contributing see 
>> here .
>>
>> Thanks,
>> Gabriel
>>
>
> Thanks, that's very cool:
>
>- To have a grasp on comparing Ruby and Clojure
>- But also for people knowing Clojure well and using Ruby without 
>knowing it well (like me) or the other way around, we can use it as a 
> quick 
>translator from one language to the other.
>
> Being a beginner clojurist, I haven't put much effort into the experienced 
clojurist to novice ruby use case. I'd definitely welcome any such 
contributions. Seeing that edn is shaping out 
well, https://github.com/relevance/edn-ruby, the translation file rubydoc 
uses could be used by clojurists in ruby.


>
> By the way the "direct link" to the Clojure / Ruby side by side 
> comparison: http://langref.org/clojure+ruby/files
>
> Cheers, 
>
> Denis
>  
>
>>
>>
>>  -- 
>> 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
>> 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 
>> 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 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

Re: Literate Programming in org-babel (ob-clojure.el) is broken under nrepl.el

2012-09-12 Thread Ben Mabey

On 9/12/12 9:29 PM, Ben Mabey wrote:
Thanks for the great example Gary! I've been meaning to try org-babel 
out for a while but never got around to it.


I just tried your example and when I run org-babel-tangle the code 
blocks are not expanded into the source file, but rather the code 
block names are just inserted into the source destination (e.g. 
<> instead of the actual function).  Any 
ideas on what may be wrong?  Do you have global settings that are 
perhaps making the tangle work differently on your setup?  I was able 
to export the document to HTML just fine and execute the clojure code, 
so the only issue appears to be tangling.


I found the problem was a missing :noweb argument:

https://github.com/lambdatronic/org-babel-example/pull/1

--
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

Re: Literate Programming in org-babel (ob-clojure.el) is broken under nrepl.el

2012-09-12 Thread Ben Mabey
Thanks for the great example Gary! I've been meaning to try org-babel 
out for a while but never got around to it.


I just tried your example and when I run org-babel-tangle the code 
blocks are not expanded into the source file, but rather the code block 
names are just inserted into the source destination (e.g. 
<> instead of the actual function).  Any ideas 
on what may be wrong?  Do you have global settings that are perhaps 
making the tangle work differently on your setup?  I was able to export 
the document to HTML just fine and execute the clojure code, so the only 
issue appears to be tangling.


I'm using Emacs 24 and the only org specific code I have is applying 
your provided patch after requiring ob-clojure.


Thanks again for the example,
Ben

On 9/11/12 2:13 PM, Gary Johnson wrote:
I just put together a simple example repo on GitHub, containing a 
literate programming solution to the Potter Kata 
(http://codingdojo.org/cgi-bin/wiki.pl?KataPotter) using Emacs' 
org-babel mode. You can check it out here:


  https://github.com/lambdatronic/org-babel-example

Also be sure to take a look at the canonical online org-babel docs:

  http://orgmode.org/worg/org-contrib/babel/

In particular the intro section:

  http://orgmode.org/worg/org-contrib/babel/intro.html

And even though it's a little bit dated w.r.t. the current org-mode 
version in Emacs 24, this journal article on Org-Mode's literate 
programming and reproducible research features is really, really cool 
to work through (lots of nice code examples):


  http://www.jstatsoft.org/v46/i03

Happy hacking,
  ~Gary

On Saturday, September 8, 2012 4:24:38 AM UTC-4, Denis Labaye wrote:



On Thu, Sep 6, 2012 at 6:42 PM, lambdatronic > wrote:

For those people (like myself) who do a lot of Literate
Programming in Emacs using Clojure and org-babel, migrating to
nrepl and nrepl.el is somewhat non-trivial. This is because
the existing Clojure support in org-babel (ob-clojure.el)
relies on slime and swank-clojure when running
org-babel-execute-src-block (which redirects to
org-babel-execute:clojure in ob-clojure.el).

So clearly this is actually an issue for both nrepl.el and
ob-clojure.el, not simply one or the other. All the same, I've
hacked together a simple workaround that fixes the problem and
makes Literate Programming under nrepl possible once again. If
there is some slick way this could be worked into nrepl.el's
codebase that wouldn't break its existing behavior (as this
does), I'd be excited to see it.

Here we go:

;; Patch result table rendering bug in ob-clojure (NREPL version)
(defun nrepl-send-request-sync (request)
  "Send a request to the backend synchronously (discouraged).
The result is a plist with keys :value, :stderr and :stdout."
  (with-current-buffer "*nrepl-connection*"
(setq nrepl-sync-response nil)
(nrepl-send-request request (nrepl-sync-request-handler
(current-buffer)))
(while (not (plist-get nrepl-sync-response :done))
  (accept-process-output))
nrepl-sync-response))

(defun org-babel-execute:clojure (body params)
  "Execute a block of Clojure code with Babel."
  (let ((result-plist (nrepl-send-string-sync
(org-babel-expand-body:clojure body params) nrepl-buffer-ns))
(result-type  (cdr (assoc :result-type params
(org-babel-script-escape
 (cond ((eq result-type 'value)  (plist-get result-plist
:value))
   ((eq result-type 'output) (plist-get result-plist
:value))
   (t(message "Unknown
:results type!"))

Have fun!


It seems to be very interesting, I am already using Emacs /
org-mode / clojure a lot, I was aware of org-babel, but never used it.
Would you have a simple example project (on github, ...) on how to
bootstrap this ?

Thanks,

Denis

-- 
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

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 
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 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

Re: How do I get the total memory used by the app?

2012-09-12 Thread Sean Corfield
On Wed, Sep 12, 2012 at 7:12 PM, larry google groups
 wrote:
> I notice that on my server, if at the command line I simply run "top" I see
> CPU load averages .5 or .6, but this function gives me numbers around 40.
> Could you point me to some information about what the JVM is really
> reporting with this number?

How many cores do you have?
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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


Re: How do I get the total memory used by the app?

2012-09-12 Thread larry google groups
Shantanu,

Thank you. That is great information.


On Wednesday, September 12, 2012 1:50:32 PM UTC-4, Shantanu Kumar wrote:
>
> Also look at java.lang.Runtime class methods maxMemory, freeMemory and 
> totalMemory: 
>
> http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html 
>
> Shantanu 
>
> On Sep 12, 10:45 pm, larry google groups  
> wrote: 
> > Thank you much! 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > On Wednesday, September 12, 2012 1:21:20 PM UTC-4, Sean Corfield wrote: 
> > 
> > > Here's some code we use to get memory and CPU usage in a displayable 
> form: 
> > 
> > > (defn- as-megabytes 
> > >   "Given a sequence of byte amounts, return megabyte amounts 
> > >as string, with an M suffix." 
> > >   [memory] 
> > >   (map #(str (int (/ % 1024 1024)) "M") memory)) 
> > 
> > > (defn- as-percentage 
> > >   "Given a pair of values, return the percentage as a string." 
> > >   [[a b]] 
> > >   (str (int (* 100 (/ a b))) "%")) 
> > 
> > > (defn- memory-bean 
> > >   "Return the MemoryMXBean." 
> > >   [] 
> > >   (java.lang.management.ManagementFactory/getMemoryMXBean)) 
> > 
> > > (defn- heap-usage 
> > >   "Given a MemoryMXBean, return the heap memory usage." 
> > >   [^java.lang.management.MemoryMXBean bean] 
> > >   (.getHeapMemoryUsage bean)) 
> > 
> > > (defn- heap-used-max 
> > >   "Given heap memory usage, return a pair of used/max values." 
> > >   [^java.lang.management.MemoryUsage usage] 
> > >   [(.getUsed usage) (.getMax usage)]) 
> > 
> > > (defn memory-usage 
> > >   "Return percentage, used, max heap as strings." 
> > >   [] 
> > >   (let [used-max (-> (memory-bean) (heap-usage) (heap-used-max))] 
> > > (cons (as-percentage used-max) 
> > >   (as-megabytes used-max 
> > 
> > > (defn- operating-system-bean 
> > >   "Return the OperatingSystemMXBean." 
> > >   [] 
> > >   (java.lang.management.ManagementFactory/getOperatingSystemMXBean)) 
> > 
> > > (defn- cpus 
> > >   "Given an OSMXBean, return the number of processors." 
> > >   [^java.lang.management.OperatingSystemMXBean bean] 
> > >   (.getAvailableProcessors bean)) 
> > 
> > > (defn- load-average 
> > >   "Given an OSMXBean, return the load average for the last minute." 
> > >   [^java.lang.management.OperatingSystemMXBean bean] 
> > >   (.getSystemLoadAverage bean)) 
> > 
> > > (defn- cpu-percentage 
> > >   "Given the number of CPUs and the load-average, return the 
> > >percentage utilization as a string." 
> > >   [[cpus load-average]] 
> > >   (str (int (* 100 (/ load-average cpus))) "%")) 
> > 
> > > (defn cpu-usage 
> > >   "Return utilization (as a string) and number of CPUs and load 
> average." 
> > >   [] 
> > >   (let [bean (operating-system-bean) 
> > > data ((juxt cpus load-average) bean)] 
> > > (cons (cpu-percentage data) 
> > >   data))) 
> > 
> > > On Wed, Sep 12, 2012 at 10:12 AM, larry google groups 
> > > > wrote: 
> > > > I need to know how much memory my app is using (it is a long running 
> > > > service). I see that some people have asked about how to measue 
> memory 
> > > use. 
> > > > Robert McIntyre asked, "get the total memory used by a data 
> structure?" 
> > > Some 
> > > > of the answers imply that it is easy to get the total memory use of 
> the 
> > > app 
> > > > (much easier than getting the memory used by a particular data 
> > > structure?). 
> > > > I am ignorant of the JVM. How can I find the total memory used at 
> any 
> > > given 
> > > > moment by my app? 
> > 
> > > > Goal: I wrote a small app that uses Ring and Moustache and Enlive. 
> It 
> > > lives 
> > > > on my server and runs perpetually. I worry about it crashing, or 
> > > becoming 
> > > > overloaded. I am setting up some ping services (not sure which yet, 
> > > Nagios, 
> > > > or Puppet or something) to ask the app "Are you still alive?" I've 
> > > > established a special Moustache route just for the ping. It occurred 
> to 
> > > me 
> > > > that the ping could get some useful info, like memory, and save that 
> to 
> > > a 
> > > > file. That would give me the a good time series about the real world 
> > > memory 
> > > > use, maybe every 5 minutes. 
> > 
> > > > I established the app with this JVM setting: 
> > 
> > > >  :jvm-opts ["-Xmx4000m"] 
> > 
> > > > Within that limit, I'd like to know what is going on. 
>

-- 
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

Re: How do I get the total memory used by the app?

2012-09-12 Thread larry google groups
Sean, 

Thank you much for this. I am curious about this:

(defn cpu-usage 
  "Return utilization (as a string) and number of CPUs and load average." 
  [] 
  (let [bean (operating-system-bean) 
data ((juxt cpus load-average) bean)] 
(cons (cpu-percentage data) 
  data))) 


I notice that on my server, if at the command line I simply run "top" I see 
CPU load averages .5 or .6, but this function gives me numbers around 40. 
Could you point me to some information about what the JVM is really 
reporting with this number? 



On Wednesday, September 12, 2012 1:21:20 PM UTC-4, Sean Corfield wrote:
>
> Here's some code we use to get memory and CPU usage in a displayable form: 
>
> (defn- as-megabytes 
>   "Given a sequence of byte amounts, return megabyte amounts 
>as string, with an M suffix." 
>   [memory] 
>   (map #(str (int (/ % 1024 1024)) "M") memory)) 
>
> (defn- as-percentage 
>   "Given a pair of values, return the percentage as a string." 
>   [[a b]] 
>   (str (int (* 100 (/ a b))) "%")) 
>
> (defn- memory-bean 
>   "Return the MemoryMXBean." 
>   [] 
>   (java.lang.management.ManagementFactory/getMemoryMXBean)) 
>
> (defn- heap-usage 
>   "Given a MemoryMXBean, return the heap memory usage." 
>   [^java.lang.management.MemoryMXBean bean] 
>   (.getHeapMemoryUsage bean)) 
>
> (defn- heap-used-max 
>   "Given heap memory usage, return a pair of used/max values." 
>   [^java.lang.management.MemoryUsage usage] 
>   [(.getUsed usage) (.getMax usage)]) 
>
> (defn memory-usage 
>   "Return percentage, used, max heap as strings." 
>   [] 
>   (let [used-max (-> (memory-bean) (heap-usage) (heap-used-max))] 
> (cons (as-percentage used-max) 
>   (as-megabytes used-max 
>
> (defn- operating-system-bean 
>   "Return the OperatingSystemMXBean." 
>   [] 
>   (java.lang.management.ManagementFactory/getOperatingSystemMXBean)) 
>
> (defn- cpus 
>   "Given an OSMXBean, return the number of processors." 
>   [^java.lang.management.OperatingSystemMXBean bean] 
>   (.getAvailableProcessors bean)) 
>
> (defn- load-average 
>   "Given an OSMXBean, return the load average for the last minute." 
>   [^java.lang.management.OperatingSystemMXBean bean] 
>   (.getSystemLoadAverage bean)) 
>
> (defn- cpu-percentage 
>   "Given the number of CPUs and the load-average, return the 
>percentage utilization as a string." 
>   [[cpus load-average]] 
>   (str (int (* 100 (/ load-average cpus))) "%")) 
>
> (defn cpu-usage 
>   "Return utilization (as a string) and number of CPUs and load average." 
>   [] 
>   (let [bean (operating-system-bean) 
> data ((juxt cpus load-average) bean)] 
> (cons (cpu-percentage data) 
>   data))) 
>
> On Wed, Sep 12, 2012 at 10:12 AM, larry google groups 
> > wrote: 
> > I need to know how much memory my app is using (it is a long running 
> > service). I see that some people have asked about how to measue memory 
> use. 
> > Robert McIntyre asked, "get the total memory used by a data structure?" 
> Some 
> > of the answers imply that it is easy to get the total memory use of the 
> app 
> > (much easier than getting the memory used by a particular data 
> structure?). 
> > I am ignorant of the JVM. How can I find the total memory used at any 
> given 
> > moment by my app? 
> > 
> > Goal: I wrote a small app that uses Ring and Moustache and Enlive. It 
> lives 
> > on my server and runs perpetually. I worry about it crashing, or 
> becoming 
> > overloaded. I am setting up some ping services (not sure which yet, 
> Nagios, 
> > or Puppet or something) to ask the app "Are you still alive?" I've 
> > established a special Moustache route just for the ping. It occurred to 
> me 
> > that the ping could get some useful info, like memory, and save that to 
> a 
> > file. That would give me the a good time series about the real world 
> memory 
> > use, maybe every 5 minutes. 
> > 
> > I established the app with this JVM setting: 
> > 
> >  :jvm-opts ["-Xmx4000m"] 
> > 
> > Within that limit, I'd like to know what is going on. 
>

-- 
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

Re: Sort and Java 1.7

2012-09-12 Thread Armando Blancas
You must be referring to the detection of contract violations. It shouldn't 
be an issue; on the contrary, that seems useful info. And those who depend 
on legacy or third-party code can always stick to the old behavior.

Area: API: Utilities
Synopsis: Updated sort behavior for Arrays and Collections may throw an 
IllegalArgumentException
Description: The sorting algorithm used by java.util.Arrays.sort and 
(indirectly) by java.util.Collections.sort has been replaced. The new sort 
implementation may throw an IllegalArgumentException if it detects a 
Comparable that violates the Comparable contract. The previous 
implementation silently ignored such a situation.
If the previous behavior is desired, you can use the new system property, 
java.util.Arrays.useLegacyMergeSort, to restore previous mergesort behavior.
Nature of Incompatibility: behavioral
RFE: 6804124

http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source

On Wednesday, September 12, 2012 5:54:22 AM UTC-7, Canonical.Chris wrote:
>
> Clojure's sort just trampolines down to the Java sort implementation. 
> Between 1.6 and 1.7, the Java guys have really cracked down on the 
> interface that people must satisfy with their comparators. LISP is much 
> looser with its sorting requirements. I just wanted to know how people felt 
> about these changes.

-- 
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

Re: Is anyone relying on the js* special form?

2012-09-12 Thread Brandon Bloom
Interesting. Would that use case be covered by an implementation of the 
proxy macro, et al? Said implementation could produce proper Google Closure 
javadocs with @extends / @implements, as well as calls to goog.inherit

On Wednesday, September 12, 2012 4:56:24 PM UTC-7, red...@gmail.com wrote:
>
> I've used it to make ClojureScript functions in to javascript object 
> constructors 
>
> (defn Foo [] (js* "/*") (js* "*/")) 
>
> results in the generated return being commented out, so (Foo.) works 
>
> I use this in a macro for creating new types that are based on 
> existing Google Closure types 
>
>
> On Wed, Sep 12, 2012 at 4:12 PM, Brandon Bloom 
> > 
> wrote: 
> > I'm exploring some changes to the ClojureScript compiler backend and am 
> > curious if anyone is using one particular implementation detail: The js* 
> > special form. 
> > 
> > Note that I'm not asking about the js/ pseudo-namespace, only the js* 
> > special form. 
> > 
> > Are you using it in your ClojureScript projects? If so, what for? 
> > 
> > -- 
> > 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 
> > 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  
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
>
>
>
> -- 
> And what is good, Phaedrus, 
> And what is not good— 
> Need we ask anyone to tell us these things? 
>

-- 
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

Re: Is anyone relying on the js* special form?

2012-09-12 Thread Kevin Downey
I've used it to make ClojureScript functions in to javascript object
constructors

(defn Foo [] (js* "/*") (js* "*/"))

results in the generated return being commented out, so (Foo.) works

I use this in a macro for creating new types that are based on
existing Google Closure types


On Wed, Sep 12, 2012 at 4:12 PM, Brandon Bloom  wrote:
> I'm exploring some changes to the ClojureScript compiler backend and am
> curious if anyone is using one particular implementation detail: The js*
> special form.
>
> Note that I'm not asking about the js/ pseudo-namespace, only the js*
> special form.
>
> Are you using it in your ClojureScript projects? If so, what for?
>
> --
> 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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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


Is anyone relying on the js* special form?

2012-09-12 Thread Brandon Bloom
I'm exploring some changes to the ClojureScript compiler backend and am 
curious if anyone is using one particular implementation detail: The js* 
special form.

Note that I'm not asking about the js/ pseudo-namespace, only the js* 
special form.

Are you using it in your ClojureScript projects? If so, what for?

-- 
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

Re: ClojureDocs and Clojure 1.4

2012-09-12 Thread Andy Fingerhut
Your offers of help are certainly welcome, but I think the kinds of changes 
desired require the help of the ClojureDocs site creators to make.  That is, 
they do, unless you want to take a copy of their code from github and create 
another site with a different name running the same code, then modify the code 
running on that new site.

CCing Zachary Kim, in hopes he will reply and let us know what he would 
recommend.

Andy

On Sep 12, 2012, at 8:35 AM, Eric MacAdie wrote:

> I am also interested in helping out with ClojureDocs.
> 
> - Eric MacAdie
> 
> On Wed, Sep 12, 2012 at 10:17 AM, cej38  wrote:
> I am interested in updating the clojure.contrib section.

-- 
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

Re: Using function that returns unique keys in map literals causes an

2012-09-12 Thread Sean Corfield
On Wed, Sep 12, 2012 at 10:38 AM, jarppe  wrote:
> user=> {(generate-id) "foo" (generate-id) "bar"}
> IllegalArgumentException Duplicate key: (generate-id)
> clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)

This is treated as a literal so the reader sees (generate-id) in both
key positions and considers it an error. Essentially, the reader
attempts to construct the map with two entries first and after that
the expressions are evaluated. As Jim suggests, use hash-map instead
and you'll be fine.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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


Re: Map literal with keys generated by function cause "Duplicate key" exception

2012-09-12 Thread Matthew O. Smith

On Wednesday, September 12, 2012 8:03:58 AM UTC-6, jarppe wrote:
>
> I have a function that generatwed unique ID's, something like this:
>
>   (def k (atom 0))
>   (defn generate-id [] (swap! k inc))
>
>  and I try to use it like this:
>
>{(generate-id) "foo"
> (generate-id) "bar"}
>
> How ever, I get
>
>IllegalArgumentException Duplicate key: (generate-id)  
> clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)
>
> This works as expected.
>
>   (let [id1 (generate-id)
> id2 (generate-id)]
> {id1 "foo" id2 "bar})
>
> Should I be able to call generate-id in map literal?
>
> -- 
> -jarppe
>
>  
This also fails:

 {  (gensym) "foo"
(gensym) "bar" }

>From the stack trace I get it looks like the reader macro that handles map 
literals is only looking at the function call, not the result of the 
function call.  This makes sense as it is the reader, not the evaluator.

-- 
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

Re: Sort and Java 1.7

2012-09-12 Thread Alan Malloy
Vote to close as "not a real question". The signature of 
java.util.Collections/sort hasn't changed since 1.5, when generics were 
introduced, and it should still be basically compatible with what it was 
when it was introduced in 1.2.

On Wednesday, September 12, 2012 5:54:22 AM UTC-7, Canonical.Chris wrote:
>
> Clojure's sort just trampolines down to the Java sort implementation. 
> Between 1.6 and 1.7, the Java guys have really cracked down on the 
> interface that people must satisfy with their comparators. LISP is much 
> looser with its sorting requirements. I just wanted to know how people felt 
> about these changes.

-- 
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

Re: Lazy sequences to replace looping?

2012-09-12 Thread gaz jones
You may find this useful:

http://blog.fogus.me/2010/01/22/de-chunkifying-sequences-in-clojure/

loop-recur might be the best way to do it.

On Tue, Sep 11, 2012 at 11:16 PM, Geo  wrote:
> Hello,
>
> I am just getting started with Clojure and I had a question. I have to
> following code:
>
> (get-rss-entry (get-rss-feeds h-res) url)
>
> The call to get-rss-feeds returns a lazy sequence of URLs of feeds that I
> need to examine.
>
> The call to get-rss-entry looks for a particular entry (whose :link field
> matches the second argument of get-rss-entry). It examines, one-by-one, the
> lazy sequence returned by get-rss-feeds. Evaluate each item requires an http
> request across the network to fetch a new rss feed. Therefore, to minimize
> the number of http requests it's important to examine the sequence
> one-by-one and stop as soon as there is a match.
>
> Here is the code:
>
> (defn get-rss-entry
>   [feeds url]
>   (first (drop-while empty? (map #(entry-with-url % url) feeds
>
> entry-with-url returns a lazy sequence of matches or an empty sequence if
> there is no match.
>
> First, I want to make sure I understood lazy evaluation correctly and that I
> did this right. I tested this and it seems to work correctly.
>
> Second, not sure if I am solving this problem idiomatically. In Java, for
> example, this would likely be solved with a loop examining some data
> structure. At first I did it with a loop/recur but that didn't seem like the
> right way to do it. Also I saw somewhere that looping in considered low
> level in Clojure or something to that effect. I would appreciate your
> feedback.
>
> Thanks for your help.
>
> --
> 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 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


Re: Using function that returns unique keys in map literals causes an

2012-09-12 Thread Jim - FooBar();
There is a long discussion about how maps and sets should behave (throw 
on dups or not) (see ''question about sets on the mailing list)for 
the moment try using the constructor fn hash-map rather than the map 
literal...so basically do this:


(hash-map (generate-id) "foo"
   (generate-id) "bar")

hope that helps

Jim


On 12/09/12 18:38, jarppe wrote:
I have a function that returns unique ID every time it is called. If I 
try to create a new map with two entries, both having a unique
key generated by that function, I get IllegalArgumentException 
Duplicate key exception. For example:


user=> *(def id (atom 0))*
user=> *(defn generate-id [] (swap! id inc))*
user=>
user=> *{(generate-id) "foo" (generate-id) "bar"}*
IllegalArgumentException Duplicate key: (generate-id)
 clojure.lang.PersistentArrayMap.createWithCheck
(PersistentArrayMap.java:70)


How ever, it works just fine if I do it like this:

user=> *(let [id1 (generate-id) id2 (generate-id)]  {id1 "foo" id2
"bar"})*
{3 "foo", 4 "bar"}


Is this a bug, or am I doing something wrong here?

I'm using Clojure 1.4.

--
-jarppe

--
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 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

Lazy sequences to replace looping?

2012-09-12 Thread Geo
Hello,

I am just getting started with Clojure and I had a question. I have to 
following code:

(get-rss-entry (get-rss-feeds h-res) url)

The call to get-rss-feeds returns a lazy sequence of URLs of feeds that I 
need to examine. 

The call to get-rss-entry looks for a particular entry (whose :link field 
matches the second argument of get-rss-entry). It examines, one-by-one, the 
lazy sequence returned by get-rss-feeds. Evaluate each item requires an 
http request across the network to fetch a new rss feed. Therefore, to 
minimize the number of http requests it's important to examine the 
sequence one-by-one and stop as soon as there is a match.

Here is the code:
 
(defn get-rss-entry
  [feeds url]
  (first (drop-while empty? (map #(entry-with-url % url) feeds

entry-with-url returns a lazy sequence of matches or an empty sequence if 
there is no match.

First, I want to make sure I understood lazy evaluation correctly and that 
I did this right. I tested this and it seems to work correctly. 

Second, not sure if I am solving this problem idiomatically. In Java, for 
example, this would likely be solved with a loop examining some data 
structure. At first I did it with a loop/recur but that didn't seem like 
the right way to do it. Also I saw somewhere that looping in considered low 
level in Clojure or something to that effect. I would appreciate your 
feedback.

Thanks for your help.

-- 
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

Sort and Java 1.7

2012-09-12 Thread Canonical.Chris
Clojure's sort just trampolines down to the Java sort implementation. 
Between 1.6 and 1.7, the Java guys have really cracked down on the 
interface that people must satisfy with their comparators. LISP is much 
looser with its sorting requirements. I just wanted to know how people felt 
about these changes.

-- 
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

Map literal with keys generated by function cause "Duplicate key" exception

2012-09-12 Thread jarppe
I have a function that generatwed unique ID's, something like this:

  (def k (atom 0))
  (defn generate-id [] (swap! k inc))

 and I try to use it like this:

   {(generate-id) "foo"
(generate-id) "bar"}

How ever, I get

   IllegalArgumentException Duplicate key: (generate-id)  
clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)

This works as expected.

  (let [id1 (generate-id)
id2 (generate-id)]
{id1 "foo" id2 "bar})

Should I be able to call generate-id in map literal?

-- 
-jarppe

-- 
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

Re: ClojureDocs and Clojure 1.4

2012-09-12 Thread Eric MacAdie
I am also interested in helping out with ClojureDocs.

- Eric MacAdie

On Wed, Sep 12, 2012 at 10:17 AM, cej38  wrote:

> I am interested in updating the clojure.contrib section.
>
> --
> 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 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

Using function that returns unique keys in map literals causes an

2012-09-12 Thread jarppe
I have a function that returns unique ID every time it is called. If I try 
to create a new map with two entries, both having a unique
key generated by that function, I get IllegalArgumentException Duplicate 
key exception. For example:

user=> *(def id (atom 0))*
user=> *(defn generate-id [] (swap! id inc))*
user=> 
user=> *{(generate-id) "foo" (generate-id) "bar"}*
IllegalArgumentException Duplicate key: (generate-id) 
 clojure.lang.PersistentArrayMap.createWithCheck 
(PersistentArrayMap.java:70)


How ever, it works just fine if I do it like this:

user=> *(let [id1 (generate-id) id2 (generate-id)]  {id1 "foo" id2 "bar"})*
{3 "foo", 4 "bar"}


Is this a bug, or am I doing something wrong here?

I'm using Clojure 1.4.

-- 
-jarppe

-- 
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

Re: Ideas for interactive tasks

2012-09-12 Thread Nikita Beloglazov
Zmitro: I'll definitely use 4clojure in teaching, but I'm looking for more
interactive tasks so I can use graphics/sound/charts/something else to
visualize them.

Murtaza: It's a great idea, but I'm experienced enough to take such task :)

Thank you,
Nikita

On Wed, Sep 12, 2012 at 8:43 AM, Murtaza Husain <
murtaza.hus...@sevenolives.com> wrote:

>
> Thinking aloud, clojure could be used to create a DSL using which the
> students can experiment with concepts from different sciences, and see the
> results / effects in a graphical manner !!
>
>
> On Wednesday, September 12, 2012 11:03:04 AM UTC+5:30, Murtaza Husain
> wrote:
>>
>>
>> This is really interesting. I am wondering if the idea could be broadened
>> to not just teach CS, but also maths, physics and chemistry.
>>
>> A curriculum in which programming is used as a tool to explore the
>> different sciences. An integrated curriculum to teach the different
>> sciences.
>>
>> Please keep us posted on your progress.
>>
>> On Tuesday, September 11, 2012 6:00:43 PM UTC+5:30, Zmitro Lapcjonak
>> wrote:
>>>
>>>
>>> On Aug 9, 6:21 pm, Nikita Beloglazov  wrote:
>>> > I'm going to organize little clojure course at my university this
>>> year. For
>>> > this I want to implement set of tasks that hopefully will help to
>>> practise
>>> > clojure.
>>>
>>> Some tasks you may find at 4clojure:
>>> https://www.4clojure.com/**problems 
>>> Sort by "topic" and select "games, graph, data-analysis"
>>>
>>> "Project Euler" has some interesting problems that you
>>> may use to teach Clojure and train math theory also.
>>>
>>>
>>> > Thank you,
>>>
>>> Thank you and good luck!
>>>
>>> --
>>> Zmitro Lapcionak
>>>
>>  --
> 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 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

Re: Help - I am doing something wrong (lein cljsbuild fails)

2012-09-12 Thread Thomas
Found the problem. I needed to update to the latest version of Noir 
("1.3.0-beta10") and that solved my problem. 

Thanks everyone
Thomas

-- 
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

Clojurescript/facebook JS-SDK

2012-09-12 Thread Mimmo Cosenza
Hi everyone, I'm pretty new with cljs and perhaps I'm asking something very 
stupid. I'd like to know if integrating facebook js-sdk with cljs could be 
a feaseable approach to be able to write fb app using clojure on both fe 
and be side. I don't know if fb js-sdk is google-closure compatible with 
:advance closure compilation option (I even don't hope that), but by what I 
understood about external js library it should be possible anyway. 
I'm completely out of my mind?

thanx for you attention

Mimmo


-- 
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

Re: How do I get the total memory used by the app?

2012-09-12 Thread Shantanu Kumar
Also look at java.lang.Runtime class methods maxMemory, freeMemory and
totalMemory:

http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html

Shantanu

On Sep 12, 10:45 pm, larry google groups 
wrote:
> Thank you much!
>
>
>
>
>
>
>
> On Wednesday, September 12, 2012 1:21:20 PM UTC-4, Sean Corfield wrote:
>
> > Here's some code we use to get memory and CPU usage in a displayable form:
>
> > (defn- as-megabytes
> >   "Given a sequence of byte amounts, return megabyte amounts
> >    as string, with an M suffix."
> >   [memory]
> >   (map #(str (int (/ % 1024 1024)) "M") memory))
>
> > (defn- as-percentage
> >   "Given a pair of values, return the percentage as a string."
> >   [[a b]]
> >   (str (int (* 100 (/ a b))) "%"))
>
> > (defn- memory-bean
> >   "Return the MemoryMXBean."
> >   []
> >   (java.lang.management.ManagementFactory/getMemoryMXBean))
>
> > (defn- heap-usage
> >   "Given a MemoryMXBean, return the heap memory usage."
> >   [^java.lang.management.MemoryMXBean bean]
> >   (.getHeapMemoryUsage bean))
>
> > (defn- heap-used-max
> >   "Given heap memory usage, return a pair of used/max values."
> >   [^java.lang.management.MemoryUsage usage]
> >   [(.getUsed usage) (.getMax usage)])
>
> > (defn memory-usage
> >   "Return percentage, used, max heap as strings."
> >   []
> >   (let [used-max (-> (memory-bean) (heap-usage) (heap-used-max))]
> >     (cons (as-percentage used-max)
> >           (as-megabytes used-max
>
> > (defn- operating-system-bean
> >   "Return the OperatingSystemMXBean."
> >   []
> >   (java.lang.management.ManagementFactory/getOperatingSystemMXBean))
>
> > (defn- cpus
> >   "Given an OSMXBean, return the number of processors."
> >   [^java.lang.management.OperatingSystemMXBean bean]
> >   (.getAvailableProcessors bean))
>
> > (defn- load-average
> >   "Given an OSMXBean, return the load average for the last minute."
> >   [^java.lang.management.OperatingSystemMXBean bean]
> >   (.getSystemLoadAverage bean))
>
> > (defn- cpu-percentage
> >   "Given the number of CPUs and the load-average, return the
> >    percentage utilization as a string."
> >   [[cpus load-average]]
> >   (str (int (* 100 (/ load-average cpus))) "%"))
>
> > (defn cpu-usage
> >   "Return utilization (as a string) and number of CPUs and load average."
> >   []
> >   (let [bean (operating-system-bean)
> >         data ((juxt cpus load-average) bean)]
> >     (cons (cpu-percentage data)
> >           data)))
>
> > On Wed, Sep 12, 2012 at 10:12 AM, larry google groups
> > > wrote:
> > > I need to know how much memory my app is using (it is a long running
> > > service). I see that some people have asked about how to measue memory
> > use.
> > > Robert McIntyre asked, "get the total memory used by a data structure?"
> > Some
> > > of the answers imply that it is easy to get the total memory use of the
> > app
> > > (much easier than getting the memory used by a particular data
> > structure?).
> > > I am ignorant of the JVM. How can I find the total memory used at any
> > given
> > > moment by my app?
>
> > > Goal: I wrote a small app that uses Ring and Moustache and Enlive. It
> > lives
> > > on my server and runs perpetually. I worry about it crashing, or
> > becoming
> > > overloaded. I am setting up some ping services (not sure which yet,
> > Nagios,
> > > or Puppet or something) to ask the app "Are you still alive?" I've
> > > established a special Moustache route just for the ping. It occurred to
> > me
> > > that the ping could get some useful info, like memory, and save that to
> > a
> > > file. That would give me the a good time series about the real world
> > memory
> > > use, maybe every 5 minutes.
>
> > > I established the app with this JVM setting:
>
> > >  :jvm-opts ["-Xmx4000m"]
>
> > > Within that limit, I'd like to know what is going on.

-- 
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


Re: How do I get the total memory used by the app?

2012-09-12 Thread larry google groups
Thank you much!

On Wednesday, September 12, 2012 1:21:20 PM UTC-4, Sean Corfield wrote:
>
> Here's some code we use to get memory and CPU usage in a displayable form: 
>
> (defn- as-megabytes 
>   "Given a sequence of byte amounts, return megabyte amounts 
>as string, with an M suffix." 
>   [memory] 
>   (map #(str (int (/ % 1024 1024)) "M") memory)) 
>
> (defn- as-percentage 
>   "Given a pair of values, return the percentage as a string." 
>   [[a b]] 
>   (str (int (* 100 (/ a b))) "%")) 
>
> (defn- memory-bean 
>   "Return the MemoryMXBean." 
>   [] 
>   (java.lang.management.ManagementFactory/getMemoryMXBean)) 
>
> (defn- heap-usage 
>   "Given a MemoryMXBean, return the heap memory usage." 
>   [^java.lang.management.MemoryMXBean bean] 
>   (.getHeapMemoryUsage bean)) 
>
> (defn- heap-used-max 
>   "Given heap memory usage, return a pair of used/max values." 
>   [^java.lang.management.MemoryUsage usage] 
>   [(.getUsed usage) (.getMax usage)]) 
>
> (defn memory-usage 
>   "Return percentage, used, max heap as strings." 
>   [] 
>   (let [used-max (-> (memory-bean) (heap-usage) (heap-used-max))] 
> (cons (as-percentage used-max) 
>   (as-megabytes used-max 
>
> (defn- operating-system-bean 
>   "Return the OperatingSystemMXBean." 
>   [] 
>   (java.lang.management.ManagementFactory/getOperatingSystemMXBean)) 
>
> (defn- cpus 
>   "Given an OSMXBean, return the number of processors." 
>   [^java.lang.management.OperatingSystemMXBean bean] 
>   (.getAvailableProcessors bean)) 
>
> (defn- load-average 
>   "Given an OSMXBean, return the load average for the last minute." 
>   [^java.lang.management.OperatingSystemMXBean bean] 
>   (.getSystemLoadAverage bean)) 
>
> (defn- cpu-percentage 
>   "Given the number of CPUs and the load-average, return the 
>percentage utilization as a string." 
>   [[cpus load-average]] 
>   (str (int (* 100 (/ load-average cpus))) "%")) 
>
> (defn cpu-usage 
>   "Return utilization (as a string) and number of CPUs and load average." 
>   [] 
>   (let [bean (operating-system-bean) 
> data ((juxt cpus load-average) bean)] 
> (cons (cpu-percentage data) 
>   data))) 
>
> On Wed, Sep 12, 2012 at 10:12 AM, larry google groups 
> > wrote: 
> > I need to know how much memory my app is using (it is a long running 
> > service). I see that some people have asked about how to measue memory 
> use. 
> > Robert McIntyre asked, "get the total memory used by a data structure?" 
> Some 
> > of the answers imply that it is easy to get the total memory use of the 
> app 
> > (much easier than getting the memory used by a particular data 
> structure?). 
> > I am ignorant of the JVM. How can I find the total memory used at any 
> given 
> > moment by my app? 
> > 
> > Goal: I wrote a small app that uses Ring and Moustache and Enlive. It 
> lives 
> > on my server and runs perpetually. I worry about it crashing, or 
> becoming 
> > overloaded. I am setting up some ping services (not sure which yet, 
> Nagios, 
> > or Puppet or something) to ask the app "Are you still alive?" I've 
> > established a special Moustache route just for the ping. It occurred to 
> me 
> > that the ping could get some useful info, like memory, and save that to 
> a 
> > file. That would give me the a good time series about the real world 
> memory 
> > use, maybe every 5 minutes. 
> > 
> > I established the app with this JVM setting: 
> > 
> >  :jvm-opts ["-Xmx4000m"] 
> > 
> > Within that limit, I'd like to know what is going on. 
>

-- 
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

Re: How do I get the total memory used by the app?

2012-09-12 Thread Dave Ray
You can connect jconsole or visualvm to your running app to monitor memory
usage, GC, threads, etc, etc. On my machine, jconsole lives in
$JAVA_HOME/bin/jconsole.

Cheers,

Dave

On Wed, Sep 12, 2012 at 10:12 AM, larry google groups <
lawrencecloj...@gmail.com> wrote:

> I need to know how much memory my app is using (it is a long running
> service). I see that some people have asked about how to measue memory use.
> Robert McIntyre asked, "get the total memory used by a data structure?"
> Some of the answers imply that it is easy to get the total memory use of
> the app (much easier than getting the memory used by a particular data
> structure?). I am ignorant of the JVM. How can I find the total memory used
> at any given moment by my app?
>
> Goal: I wrote a small app that uses Ring and Moustache and Enlive. It
> lives on my server and runs perpetually. I worry about it crashing, or
> becoming overloaded. I am setting up some ping services (not sure which
> yet, Nagios, or Puppet or something) to ask the app "Are you still alive?"
> I've established a special Moustache route just for the ping. It occurred
> to me that the ping could get some useful info, like memory, and save that
> to a file. That would give me the a good time series about the real world
> memory use, maybe every 5 minutes.
>
> I established the app with this JVM setting:
>
>  :jvm-opts ["-Xmx4000m"]
>
> Within that limit, I'd like to know what is going on.
>
>  --
> 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 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

Re: How do I get the total memory used by the app?

2012-09-12 Thread Sean Corfield
Here's some code we use to get memory and CPU usage in a displayable form:

(defn- as-megabytes
  "Given a sequence of byte amounts, return megabyte amounts
   as string, with an M suffix."
  [memory]
  (map #(str (int (/ % 1024 1024)) "M") memory))

(defn- as-percentage
  "Given a pair of values, return the percentage as a string."
  [[a b]]
  (str (int (* 100 (/ a b))) "%"))

(defn- memory-bean
  "Return the MemoryMXBean."
  []
  (java.lang.management.ManagementFactory/getMemoryMXBean))

(defn- heap-usage
  "Given a MemoryMXBean, return the heap memory usage."
  [^java.lang.management.MemoryMXBean bean]
  (.getHeapMemoryUsage bean))

(defn- heap-used-max
  "Given heap memory usage, return a pair of used/max values."
  [^java.lang.management.MemoryUsage usage]
  [(.getUsed usage) (.getMax usage)])

(defn memory-usage
  "Return percentage, used, max heap as strings."
  []
  (let [used-max (-> (memory-bean) (heap-usage) (heap-used-max))]
(cons (as-percentage used-max)
  (as-megabytes used-max

(defn- operating-system-bean
  "Return the OperatingSystemMXBean."
  []
  (java.lang.management.ManagementFactory/getOperatingSystemMXBean))

(defn- cpus
  "Given an OSMXBean, return the number of processors."
  [^java.lang.management.OperatingSystemMXBean bean]
  (.getAvailableProcessors bean))

(defn- load-average
  "Given an OSMXBean, return the load average for the last minute."
  [^java.lang.management.OperatingSystemMXBean bean]
  (.getSystemLoadAverage bean))

(defn- cpu-percentage
  "Given the number of CPUs and the load-average, return the
   percentage utilization as a string."
  [[cpus load-average]]
  (str (int (* 100 (/ load-average cpus))) "%"))

(defn cpu-usage
  "Return utilization (as a string) and number of CPUs and load average."
  []
  (let [bean (operating-system-bean)
data ((juxt cpus load-average) bean)]
(cons (cpu-percentage data)
  data)))

On Wed, Sep 12, 2012 at 10:12 AM, larry google groups
 wrote:
> I need to know how much memory my app is using (it is a long running
> service). I see that some people have asked about how to measue memory use.
> Robert McIntyre asked, "get the total memory used by a data structure?" Some
> of the answers imply that it is easy to get the total memory use of the app
> (much easier than getting the memory used by a particular data structure?).
> I am ignorant of the JVM. How can I find the total memory used at any given
> moment by my app?
>
> Goal: I wrote a small app that uses Ring and Moustache and Enlive. It lives
> on my server and runs perpetually. I worry about it crashing, or becoming
> overloaded. I am setting up some ping services (not sure which yet, Nagios,
> or Puppet or something) to ask the app "Are you still alive?" I've
> established a special Moustache route just for the ping. It occurred to me
> that the ping could get some useful info, like memory, and save that to a
> file. That would give me the a good time series about the real world memory
> use, maybe every 5 minutes.
>
> I established the app with this JVM setting:
>
>  :jvm-opts ["-Xmx4000m"]
>
> Within that limit, I'd like to know what is going on.

-- 
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


How do I get the total memory used by the app?

2012-09-12 Thread larry google groups
I need to know how much memory my app is using (it is a long running 
service). I see that some people have asked about how to measue memory use. 
Robert McIntyre asked, "get the total memory used by a data structure?" 
Some of the answers imply that it is easy to get the total memory use of 
the app (much easier than getting the memory used by a particular data 
structure?). I am ignorant of the JVM. How can I find the total memory used 
at any given moment by my app?

Goal: I wrote a small app that uses Ring and Moustache and Enlive. It lives 
on my server and runs perpetually. I worry about it crashing, or becoming 
overloaded. I am setting up some ping services (not sure which yet, Nagios, 
or Puppet or something) to ask the app "Are you still alive?" I've 
established a special Moustache route just for the ping. It occurred to me 
that the ping could get some useful info, like memory, and save that to a 
file. That would give me the a good time series about the real world memory 
use, maybe every 5 minutes. 

I established the app with this JVM setting:

 :jvm-opts ["-Xmx4000m"]

Within that limit, I'd like to know what is going on. 

-- 
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

Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread Jim - FooBar();

On 12/09/12 16:23, gaz jones wrote:

I find myself having to make similar choices quite often in my own
Clojure code - do I create perhaps a map of things that represent some
kind of 'state' and pass that around to each function that needs it,
or do I do what has been done above and create some vars in a ns where
most (all?) the functions that use this data live.


I must clarify that I'm only doing this with guis...I try to avoid this 
stuff in regular namespaces,

unless you're referring to immutable things...

Jim

--
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


Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread Jim - FooBar();

On 12/09/12 16:29, the80srobot wrote:
What I usually do when I want to avoid passing these implicit 
parameters is just use thread-local bindings with ^:dynamic vars. From 
the point to rebind them using (bindings), every function called from 
within the binding block sees the same value; you can combine them 
with atoms/agents/refs for even greater flexibility, and still avoid 
polluting your namespace. One way to think about that, in my opinion, 
is that by having your namespace top-level vars hold references to 
state, you are effectively turning your namespace into a singleton 
object, which is typically not a good idea even in Java. Starting with 
Clojure 1.3.0, I believe pmap and some other core functions that work 
with threads even take care of propagating your thread-local bindings 
to child threads for you.


dealing with lots of dynamic vars can be tricky and makes the code less 
readable...can also introduce bugs...the purpose of dynamic vars is not 
to model state...we've got reference types for that...


yes, binding conveyance makes sure your dynamic bindings are propagated 
appropriately...still don't like them!


Jim

--
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


Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread the80srobot
What I usually do when I want to avoid passing these implicit parameters is 
just use thread-local bindings with ^:dynamic vars. From the point to 
rebind them using (bindings), every function called from within the binding 
block sees the same value; you can combine them with atoms/agents/refs for 
even greater flexibility, and still avoid polluting your namespace. One way 
to think about that, in my opinion, is that by having your namespace 
top-level vars hold references to state, you are effectively turning your 
namespace into a singleton object, which is typically not a good idea even 
in Java. Starting with Clojure 1.3.0, I believe pmap and some other core 
functions that work with threads even take care of propagating your 
thread-local bindings to child threads for you.

Anyway, I can see that there really isn't a consensus on this.

On Wednesday, September 12, 2012 5:23:32 PM UTC+2, Gaz wrote:
>
> I find myself having to make similar choices quite often in my own 
> Clojure code - do I create perhaps a map of things that represent some 
> kind of 'state' and pass that around to each function that needs it, 
> or do I do what has been done above and create some vars in a ns where 
> most (all?) the functions that use this data live. 
>
> I think either can be the right choice in different circumstances. For 
> example, I always store configuration data in a var that has a few 
> functions using it rather than passing a config map to every function 
> in the application that needs access to it. I just use those functions 
> throughout the codebase instead. 
>
> I'm not at all familiar with noir so cannot answer your question 
> regarding that specifically, but I would say using your own judgement 
> is a "Clojure best practice" :) 
>
> On Wed, Sep 12, 2012 at 9:30 AM, the80srobot 
> > 
> wrote: 
> > Is this a Clojure best practice? 
>

-- 
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

Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread gaz jones
I find myself having to make similar choices quite often in my own
Clojure code - do I create perhaps a map of things that represent some
kind of 'state' and pass that around to each function that needs it,
or do I do what has been done above and create some vars in a ns where
most (all?) the functions that use this data live.

I think either can be the right choice in different circumstances. For
example, I always store configuration data in a var that has a few
functions using it rather than passing a config map to every function
in the application that needs access to it. I just use those functions
throughout the codebase instead.

I'm not at all familiar with noir so cannot answer your question
regarding that specifically, but I would say using your own judgement
is a "Clojure best practice" :)

On Wed, Sep 12, 2012 at 9:30 AM, the80srobot  wrote:
> Is this a Clojure best practice?

-- 
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


Re: ClojureDocs and Clojure 1.4

2012-09-12 Thread cej38
I am interested in updating the clojure.contrib section.

-- 
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

Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread Jim foo.bar
aaa ok I see what you mean...well, yes everything starting with def can 
be considered a 'global' var or even better a namespaced var (not really 
a variable in the traditional sense)...In Noir's case most of the atoms 
are maps so it could be that each Noir app registers its specific routes 
on a specific key in the map...wildly guessing here...perhaps someone 
else can provide more details...


In general however, this is how you would model small pieces of state in 
Clojure...for example, designing a gui includes a lot of state 
usually...so for example in most of my guis i have an atom at the top 
which holds a map with all he stateful aspects of the gui...but you're 
right - it's generally best to limit the amount of state in your program...


Jim

ps: defonce is not really related with singletons...there was a 
clojure.contrib ns for singletons wasn't there?



On 12/09/12 15:54, the80srobot wrote:
Sorry I wasn't more clear - I'm not talking about defonce, but about 
having refs (atoms) defined at the top level. When they're defined 
like this, they basically become global variables, don't they? Having 
two Noir apps would then mean they share the same routes, among other 
things. Or am I missing something?


On Wednesday, September 12, 2012 4:49:34 PM UTC+2, Jim foo.bar wrote:

defonce simply means "do not bind the var if it already has a root
value"... I think it only applies when reloading your
namespace...to be
honest, I'm not sure why Chris has coded it like that (creating an
atom
is not really expensive), but i find it hard to believe that you
can' t
have 2 Noir apps on the same project...basically defonce it is the
same
as def unless there is already a root value for that var...

can anyone else add anything?

Jim


On 12/09/12 15:30, the80srobot wrote:
> Hello,
>
> So I've been working on a project at work, that required me to
code a
> simple web interface. I considered going with Noir, and while
reading
> the code, I noticed a pattern that seems to repeat throughout
most of
> the code that Chris Granger has published in Clojure. This is
what I'm
> referring to:
>
> ; these are at the top level in (ns noir.core)
> (defonce noir-routes (atom {}))
> (defonce route-funcs (atom {}))
> (defonce pre-routes (atom (sorted-map)))
> (defonce post-routes (atom []))
> (defonce compojure-routes (atom []))
>
> Now, I am new to Clojure, but I am not new to (functional)
programming
> and I'd like to think that I know a singleton when I see one. Is
that
> really what these are? If I'm right then defining your 'globals'
(for
> lack of a better word) like this would mean, among other things,
that
> you really can't have two independent Noir apps defined/running
in the
> same project - is that a correct assessment?
>
> Can someone more experienced shed some light on why it's done this
> way? My experience in functional programming has taught me to
always
> limit my scope - I would think that either using thread-local
bindings
> (and then rebinding them to child threads) or relying on lexical
scope
> would be preferable to polluting the global state. Is this a
Clojure
> best practice?
>
> Thanks. I'm looking to use Clojure a lot at work, and I'm trying to
> really understand the language before I throw it our production
problems.
>
> ~Adam
> --
> 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

> 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 
> 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 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 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

Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread the80srobot
Sorry I wasn't more clear - I'm not talking about defonce, but about having 
refs (atoms) defined at the top level. When they're defined like this, they 
basically become global variables, don't they? Having two Noir apps would 
then mean they share the same routes, among other things. Or am I missing 
something?

On Wednesday, September 12, 2012 4:49:34 PM UTC+2, Jim foo.bar wrote:
>
> defonce simply means "do not bind the var if it already has a root 
> value"... I think it only applies when reloading your namespace...to be 
> honest, I'm not sure why Chris has coded it like that (creating an atom 
> is not really expensive), but i find it hard to believe that you can' t 
> have 2 Noir apps on the same project...basically defonce it is the same 
> as def unless there is already a root value for that var... 
>
> can anyone else add anything? 
>
> Jim 
>
>
> On 12/09/12 15:30, the80srobot wrote: 
> > Hello, 
> > 
> > So I've been working on a project at work, that required me to code a 
> > simple web interface. I considered going with Noir, and while reading 
> > the code, I noticed a pattern that seems to repeat throughout most of 
> > the code that Chris Granger has published in Clojure. This is what I'm 
> > referring to: 
> > 
> > ; these are at the top level in (ns noir.core) 
> > (defonce noir-routes (atom {})) 
> > (defonce route-funcs (atom {})) 
> > (defonce pre-routes (atom (sorted-map))) 
> > (defonce post-routes (atom [])) 
> > (defonce compojure-routes (atom [])) 
> > 
> > Now, I am new to Clojure, but I am not new to (functional) programming 
> > and I'd like to think that I know a singleton when I see one. Is that 
> > really what these are? If I'm right then defining your 'globals' (for 
> > lack of a better word) like this would mean, among other things, that 
> > you really can't have two independent Noir apps defined/running in the 
> > same project - is that a correct assessment? 
> > 
> > Can someone more experienced shed some light on why it's done this 
> > way? My experience in functional programming has taught me to always 
> > limit my scope - I would think that either using thread-local bindings 
> > (and then rebinding them to child threads) or relying on lexical scope 
> > would be preferable to polluting the global state. Is this a Clojure 
> > best practice? 
> > 
> > Thanks. I'm looking to use Clojure a lot at work, and I'm trying to 
> > really understand the language before I throw it our production 
> problems. 
> > 
> > ~Adam 
> > -- 
> > 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 
> > 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  
> > 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 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

Re: Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread Jim foo.bar
defonce simply means "do not bind the var if it already has a root 
value"... I think it only applies when reloading your namespace...to be 
honest, I'm not sure why Chris has coded it like that (creating an atom 
is not really expensive), but i find it hard to believe that you can' t 
have 2 Noir apps on the same project...basically defonce it is the same 
as def unless there is already a root value for that var...


can anyone else add anything?

Jim


On 12/09/12 15:30, the80srobot wrote:

Hello,

So I've been working on a project at work, that required me to code a 
simple web interface. I considered going with Noir, and while reading 
the code, I noticed a pattern that seems to repeat throughout most of 
the code that Chris Granger has published in Clojure. This is what I'm 
referring to:


; these are at the top level in (ns noir.core)
(defonce noir-routes (atom {}))
(defonce route-funcs (atom {}))
(defonce pre-routes (atom (sorted-map)))
(defonce post-routes (atom []))
(defonce compojure-routes (atom []))

Now, I am new to Clojure, but I am not new to (functional) programming 
and I'd like to think that I know a singleton when I see one. Is that 
really what these are? If I'm right then defining your 'globals' (for 
lack of a better word) like this would mean, among other things, that 
you really can't have two independent Noir apps defined/running in the 
same project - is that a correct assessment?


Can someone more experienced shed some light on why it's done this 
way? My experience in functional programming has taught me to always 
limit my scope - I would think that either using thread-local bindings 
(and then rebinding them to child threads) or relying on lexical scope 
would be preferable to polluting the global state. Is this a Clojure 
best practice?


Thanks. I'm looking to use Clojure a lot at work, and I'm trying to 
really understand the language before I throw it our production problems.


~Adam
--
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 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


ANN: 25 September London Clojure Dojo at Thoughtworks

2012-09-12 Thread Bruce Durling
Roll up! Roll up!

After being hosted by Forward in Camden Town our lovely friends at
Thoughtworks are going to host us at the end of the month for our next
London Clojure Dojo.

It will start at 7PM at Thoughtworks London.

Details and sign up are here:

http://late-september-2012-ldnclj-dojo.eventbrite.co.uk/

Also, we'll be having an evening talk event with Stefan Hubner of the
Berlin Clojure User Group on Cascalog = Hadoop + Sanity on 2 October.
Details and sign up for that event are here:

http://skillsmatter.com/event/clojure/cascalog-hadoop-sanity

I hope to see you all there!

cheers,
Bruce

-- 
@otfrom | CTO & co-founder @MastodonC | mastodonc.com

-- 
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


Question: Looking at Noir code - hey, are those singletons?

2012-09-12 Thread the80srobot
Hello,

So I've been working on a project at work, that required me to code a 
simple web interface. I considered going with Noir, and while reading the 
code, I noticed a pattern that seems to repeat throughout most of the code 
that Chris Granger has published in Clojure. This is what I'm referring to:

; these are at the top level in (ns noir.core)
(defonce noir-routes (atom {}))
(defonce route-funcs (atom {}))
(defonce pre-routes (atom (sorted-map)))
(defonce post-routes (atom []))
(defonce compojure-routes (atom []))

Now, I am new to Clojure, but I am not new to (functional) programming and 
I'd like to think that I know a singleton when I see one. Is that really 
what these are? If I'm right then defining your 'globals' (for lack of a 
better word) like this would mean, among other things, that you really 
can't have two independent Noir apps defined/running in the same project - 
is that a correct assessment?

Can someone more experienced shed some light on why it's done this way? My 
experience in functional programming has taught me to always limit my scope 
- I would think that either using thread-local bindings (and then rebinding 
them to child threads) or relying on lexical scope would be preferable to 
polluting the global state. Is this a Clojure best practice?

Thanks. I'm looking to use Clojure a lot at work, and I'm trying to really 
understand the language before I throw it our production problems.

~Adam

-- 
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

Re: Question about sets

2012-09-12 Thread Rich Hickey

On Sep 8, 2012, at 7:38 PM, Andy Fingerhut wrote:

> Rich:
> 
> I'm not sure what you mean by the not-fastest-path possible that exists in 
> today's Clojure code, so if you get a chance, see if the below is what you 
> mean.
> 
> As far as I can tell (i.e. putting debug println's in the Java code of 
> RT.map), when someone enters a map literal in, say, a function definition, 
> and all keys *and* values are compile time constants, it calls RT.map() while 
> the function is being compiled, but never again when the function is called.
> 
> If I make a similar function with run-time variable keys or values, RT.map() 
> is called every time the function is invoked.  Each of these calls repeats 
> the check that the keys are unique.
> 
> Do you mean that you want a new code path where if the keys are compile time 
> constants, but the values are variables at compile-time, then at run time 
> this map should be created with a method that avoids the unnecessary check 
> for unique keys?
> 

Exactly.

> And by the word "restore" do you mean to imply that it was this way at one 
> time before?
> 

Nope. It was that fast, but did no compile-time checks.

Thanks

Rich

> 

-- 
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


Re: Literate Programming in org-babel (ob-clojure.el) is broken under nrepl.el

2012-09-12 Thread Denis Labaye
On Tue, Sep 11, 2012 at 10:13 PM, Gary Johnson  wrote:

> I just put together a simple example repo on GitHub, containing a literate
> programming solution to the Potter Kata  (
> http://codingdojo.org/cgi-bin/wiki.pl?KataPotter) using Emacs' org-babel
> mode. You can check it out here:
>
>   https://github.com/lambdatronic/org-babel-example
>
> Also be sure to take a look at the canonical online org-babel docs:
>
>   http://orgmode.org/worg/org-contrib/babel/
>
> In particular the intro section:
>
>   http://orgmode.org/worg/org-contrib/babel/intro.html
>
> And even though it's a little bit dated w.r.t. the current org-mode
> version in Emacs 24, this journal article on Org-Mode's literate
> programming and reproducible research features is really, really cool to
> work through (lots of nice code examples):
>
>   http://www.jstatsoft.org/v46/i03
>
> Happy hacking,
>   ~Gary
>


That's very cool, great example !

Thanks


>
> On Saturday, September 8, 2012 4:24:38 AM UTC-4, Denis Labaye wrote:
>>
>>
>>
>> On Thu, Sep 6, 2012 at 6:42 PM, lambdatronic  wrote:
>>
>>> For those people (like myself) who do a lot of Literate Programming in
>>> Emacs using Clojure and org-babel, migrating to nrepl and nrepl.el is
>>> somewhat non-trivial. This is because the existing Clojure support in
>>> org-babel (ob-clojure.el) relies on slime and swank-clojure when running
>>> org-babel-execute-src-block (which redirects to org-babel-execute:clojure
>>> in ob-clojure.el).
>>>
>>> So clearly this is actually an issue for both nrepl.el and
>>> ob-clojure.el, not simply one or the other. All the same, I've hacked
>>> together a simple workaround that fixes the problem and makes Literate
>>> Programming under nrepl possible once again. If there is some slick way
>>> this could be worked into nrepl.el's codebase that wouldn't break its
>>> existing behavior (as this does), I'd be excited to see it.
>>>
>>> Here we go:
>>>
>>> ;; Patch result table rendering bug in ob-clojure (NREPL version)
>>> (defun nrepl-send-request-sync (request)
>>>   "Send a request to the backend synchronously (discouraged).
>>> The result is a plist with keys :value, :stderr and :stdout."
>>>   (with-current-buffer "*nrepl-connection*"
>>> (setq nrepl-sync-response nil)
>>> (nrepl-send-request request (nrepl-sync-request-handler
>>> (current-buffer)))
>>> (while (not (plist-get nrepl-sync-response :done))
>>>   (accept-process-output))
>>> nrepl-sync-response))
>>>
>>> (defun org-babel-execute:clojure (body params)
>>>   "Execute a block of Clojure code with Babel."
>>>   (let ((result-plist (nrepl-send-string-sync
>>> (org-babel-expand-body:clojure body params) nrepl-buffer-ns))
>>> (result-type  (cdr (assoc :result-type params
>>> (org-babel-script-escape
>>>  (cond ((eq result-type 'value)  (plist-get result-plist :value))
>>>((eq result-type 'output) (plist-get result-plist :value))
>>>(t(message "Unknown :results
>>> type!"))
>>>
>>> Have fun!
>>>
>>
>> It seems to be very interesting, I am already using Emacs / org-mode /
>> clojure a lot, I was aware of org-babel, but never used it.
>> Would you have a simple example project (on github, ...) on how to
>> bootstrap this ?
>>
>> Thanks,
>>
>> Denis
>>
>>
>>
>>>  --
>>> 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
>>>
>>> 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
>>>
>>> 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 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 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