Re: ANN: Clojure live-repl

2009-10-30 Thread Jeff Rose
Awesome! Thanks a lot. I've been needing this. -Jeff P.S. Maven is annoying. On Oct 18, 6:53 pm, "David Powell" wrote: > Hi, > > I just posted a project at . > > It uses the Java Attach API to let you connect a Clojure REPL to any running > Java or Clojur

Re: ANN: Clojure live-repl

2009-10-30 Thread Rick Moynihan
2009/10/18 David Powell : > > Hi, > > I just posted a project at . > > It uses the Java Attach API to let you connect a Clojure REPL to any running > Java or Clojure process, without them requiring any special startup. > This is really cool and seems very usef

Re: Newcomer's question about Clojure's compatibility with common lisp

2009-10-30 Thread Stefan Fehrenbach
Hi Julien. On Thursday 29 October 2009 bal...@gmail.com wrote: > Hello, > > Next is my question: can I run common lisp programs on the jvm using > clojure? I was thinking specifically to Maxima - (the formal calculus > program)? > Clojure is not source compatible to Common Lisp (and not intended

Clojure contrib http-agent hangs when making a POST request

2009-10-30 Thread Alex
Hi, I'm getting some strange errors when trying to make a POST request using the Clojure contrib http-agent library (http:// richhickey.github.com/clojure-contrib/http.agent-api.html). When I run: (use 'clojure.contrib.http.agent) (println (string (http-agent "http://www.google.com"; :method "

Periodic tasks

2009-10-30 Thread Stefan Arentz
What is a good and simple way to run periodic tasks in Clojure? I need to run a simple function every couple of minutes. And make sure that if it throws an exception that it won't kill the periodic task. I come from a Spring world where XML, Timers, Jobs and Quartz rule the world, so am hop

Generating Java and C# wrappers

2009-10-30 Thread John Ky
Hello, I've been wondering if there was a way to specify the Java and C# wrapper classes/interfaces to wrap Clojure code in Clojure, and then writing out them to a file so that they can ge compiled by their respective compilers. I'm asking this because in my work, I need to support these two lang

Re: invoking macros from Java

2009-10-30 Thread Rich Hickey
On Wed, Oct 28, 2009 at 12:21 AM, Alex Osborne wrote: > > Jeff Brown wrote: > >> I can invoke a function using Java code that looks something like this... >> >> Reader reader = new FileReader("clj/demo.clj"); >> Compiler.load(reader); >> Var var = RT.var("demo", "add_numbers"); >> Object result =

Re: Observations from a real-world Clojure project

2009-10-30 Thread Rich Hickey
On Thu, Oct 29, 2009 at 11:57 AM, Jamie wrote: > > First, thank you Rich & Co for doing Clojure. > > We've been using Clojure for a real-world project, and I thought I'd > share some observations. > Thanks - these kinds of experience reports are very useful. Rich --~--~-~--~~--

Re: Constructing Java Interop calls

2009-10-30 Thread Tiago Antão
On Thu, Oct 29, 2009 at 1:38 PM, Meikel Brandmeyer wrote: >> All good here, but, if I do the eval variation, >> user=> (eval (list (symbol ".setFileSelectionMode") jfc 1)) > > Another example which shows that eval is not worth the trouble. It is > better to use reflection. You cannot embed the JF

How to make lazy seq from socket input?

2009-10-30 Thread timc
Can someone suggest how to make the packets received on a socket into a lazy sequence? The application I'm making is a log file parser. A (Java) program is producing log output using log4j, the output can go to file(s) or be sent to a socket. So, the program has this outline: (defn fileLines [fil

Re: Newcomer's question about Clojure's compatibility with common lisp

2009-10-30 Thread Tassilo Horn
Daniel Simms writes: > On Thu, Oct 29, 2009 at 4:34 PM, Rayne wrote: >> but I would highly recommend that you just pull it from the github >> repository. > > Especially if you're going to use clojure-contrib ...or is there some > "release" of contrib synch'd to clojure releases that I missed >

Re: How to make lazy seq from socket input?

2009-10-30 Thread Alex Osborne
timc wrote: > I think I know how to do fileLines, but not socketLines. (Each > received packet should contain one line as it would have been written > to a file, I think). Something like this? (use 'clojure.contrib.duck-streams) (read-lines (.getInputStream socket)) > My problem is not how to

Re: Periodic tasks

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 12:05 AM, Stefan Arentz wrote: > What is a good and simple way to run periodic tasks in Clojure? I need > to run a simple function every couple of minutes. And make sure that > if it throws an exception that it won't kill the periodic task. > > I come from a Spring world w

Re: Generating Java and C# wrappers

2009-10-30 Thread Stuart Sierra
On Oct 30, 6:18 am, John Ky wrote: > I've been wondering if there was a way to specify the Java and C# wrapper > classes/interfaces to wrap Clojure code in Clojure, and then writing out > them to a file so that they can ge compiled by their respective compilers. I'm not sure I understand your qu

Re: How to make lazy seq from socket input?

2009-10-30 Thread Meikel Brandmeyer
Hi, if you have a stream, you can basically do: (defn stream-seq [stream] (take-while #(<= 0 %) (repeatedly #(.read stream This will give a character at a time. From there you can build the lines and turn it into a seq of lines. Or can you can to the lower level and use lazy-seq directl

Is running a script without leaving Clojure?

2009-10-30 Thread Arie van Wingerden
Hi, when I run a Clojure script Clojure ends directly when the script is finished. I would like an option to keep the Clojure REPL open when the script has finished. Is this possible somehow? Currently I use something like this (in WinXP): set jar1="C:\Clojure\clojure.jar" set jar2="C:\Clo

Re: Periodic tasks

2009-10-30 Thread Albert Cardona
How about: (import '(java.util.concurrent Executors TimeUnit)) (let [s (Executors/newSingleThreadScheduledExecutor)] (.scheduleAtFixedRate s #(try (println "I did it again") (catch Exception e (.printStackTrace e))) (long 0) (long 1) TimeUnit/SECONDS)) Adm

Implementation of zipmap

2009-10-30 Thread John Harrop
What's up with this? (defn zipmap "Returns a map with the keys mapped to the corresponding vals." [keys vals] (loop [map {} ks (seq keys) vs (seq vals)] (if (and ks vs) (recur (assoc map (first ks) (first vs)) (next ks) (nex

Re: Implementation of zipmap

2009-10-30 Thread Alex Osborne
John Harrop wrote: > Was something wrong with this?: > > (defn my-zipmap > "Returns a map with the keys mapped to the corresponding vals." > [keys vals] > (into {} (map vec (partition 2 (interleave keys vals) > > :) One reason might be that the original zipmap is 5-10 times faster for

Re: Implementation of zipmap

2009-10-30 Thread Chouser
On Fri, Oct 30, 2009 at 11:30 AM, Alex Osborne wrote: > > John Harrop wrote: >> Was something wrong with this?: >> >> (defn my-zipmap >>   "Returns a map with the keys mapped to the corresponding vals." >>   [keys vals] >>   (into {} (map vec (partition 2 (interleave keys vals) >> >> :) > > O

Re: Implementation of zipmap

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 11:37 AM, Chouser wrote: > On Fri, Oct 30, 2009 at 11:30 AM, Alex Osborne wrote: > > > > John Harrop wrote: > >> Was something wrong with this?: > >> > >> (defn my-zipmap > >> "Returns a map with the keys mapped to the corresponding vals." > >> [keys vals] > >> (int

Re: Implementation of zipmap

2009-10-30 Thread Chouser
On Fri, Oct 30, 2009 at 11:44 AM, John Harrop wrote: > On Fri, Oct 30, 2009 at 11:37 AM, Chouser wrote: >> >> On Fri, Oct 30, 2009 at 11:30 AM, Alex Osborne wrote: >> > >> > John Harrop wrote: >> >> Was something wrong with this?: >> >> >> >> (defn my-zipmap >> >>   "Returns a map with the keys

Re: Implementation of zipmap

2009-10-30 Thread Alex Osborne
Chouser wrote: > On Fri, Oct 30, 2009 at 11:30 AM, Alex Osborne wrote: >> John Harrop wrote: >>> Was something wrong with this?: >>> >>> (defn my-zipmap >>> "Returns a map with the keys mapped to the corresponding vals." >>> [keys vals] >>> (into {} (map vec (partition 2 (interleave keys va

Seq wrappers for arrays can morph

2009-10-30 Thread John Harrop
user=> (def x (int-array 3)) #'user/x user=> x [0, 0, 0] user=> (def y (seq x)) #'user/y user=> (first y) 0 user=> (aset x 1 3) 3 user=> x [0, 3, 0] user=> (second y) 3 user=> (aset x 0 2) 2 user=> x [2, 3, 0] user=> (first y) 2 Here, (first y) returned first 0, then 2 without y being rebound in b

Re: How to make lazy seq from socket input?

2009-10-30 Thread timc
Thanks for the help. On Oct 30, 1:23 pm, Meikel Brandmeyer wrote: > Hi, > > if you have a stream, you can basically do: > > (defn stream-seq >   [stream] >   (take-while #(<= 0 %) (repeatedly #(.read stream > > This will give a character at a time. From there you can build the > lines and tu

Re: Newcomer's question about Clojure's compatibility with common lisp

2009-10-30 Thread Rayne
No, I didn't. On Oct 30, 8:28 am, Tassilo Horn wrote: > Daniel Simms writes: > > On Thu, Oct 29, 2009 at 4:34 PM, Rayne wrote: > >> but I would highly recommend that you just pull it from the github > >> repository. > > > Especially if you're going to use clojure-contrib ...or is there some >

Re: Is running a script without leaving Clojure?

2009-10-30 Thread Chouser
On Fri, Oct 30, 2009 at 10:23 AM, Arie van Wingerden wrote: > Hi, > > when I run a Clojure script Clojure ends directly when the script is > finished. > > I would like an option to keep the Clojure REPL open when the script has > finished. Is this possible somehow? > > Currently I use something l

Re: Constructing Java Interop calls

2009-10-30 Thread Kevin Downey
eval calls read for somethings. 2009/10/30 Tiago Antão : > > On Thu, Oct 29, 2009 at 1:38 PM, Meikel Brandmeyer wrote: >>> All good here, but, if I do the eval variation, >>> user=> (eval (list (symbol ".setFileSelectionMode") jfc 1)) >> >> Another example which shows that eval is not worth the

Running out of memory when using loop/recur and destructuring

2009-10-30 Thread Paul Mooser
I was working with a large data set earlier today, and I had written a loop/recur where I was passing in a huge seq to the first iteration, and I was surprised when I ran out of heap space, because I was very careful not to hold on to the head of the seq, and I though that loop ended up rebinding

Re: Observations from a real-world Clojure project

2009-10-30 Thread Spencer Schumann
On Oct 29, 9:57 am, Jamie wrote: > 5. The functionality of the docs hasn't kept up with Clojure.  We > often resorted to text searches of the various sources.  Need links > and see-also's.  Clojure has grown/matured so much that it needs a doc > system of some sort. I recently started learning C

Re: Periodic tasks

2009-10-30 Thread AndrewC.
On 30 Oct, 16:18, Albert Cardona wrote: > How about: > > (import '(java.util.concurrent Executors TimeUnit)) .. > Admittedly very java-ish. Personally, I think Java-ish is the way to go here. John's actor lib is pretty nifty, but it is relying on implementation details of the threading o

Re: Newcomer's question about Clojure's compatibility with common lisp

2009-10-30 Thread rob
Clojure is actually an entirely different language in the Lisp family of languages. In addition to ABCL (Common Lisp on the JVM), there are also 2 or 3 Scheme implementations on the JVM. On Oct 29, 8:09 am, "bal...@gmail.com" wrote: > Hello, > > First let me congratulate the clojure team on thi

Re: Seq wrappers for arrays can morph

2009-10-30 Thread John Newman
When someone knowingly dips into arrays, though, aren't doing so because they require java's semantics? For speed, interop, or whatever? We want to champion functional programming, but on the other hand we want to preserve the smooth java-interop use-cases. Not an easy balancing act, I suppose.

Re: Newcomer's question about Clojure's compatibility with common lisp

2009-10-30 Thread Daniel Simms
On Thu, Oct 29, 2009 at 5:18 PM, Alex Osborne wrote: > There's a 1.0 compatible branch on github.  [...] Thanks, I missed that branch. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: Clojure contrib http-agent hangs when making a POST request

2009-10-30 Thread Rob Wolfe
Alex writes: > Hi, > > I'm getting some strange errors when trying to make a POST request > using the Clojure contrib http-agent library (http:// > richhickey.github.com/clojure-contrib/http.agent-api.html). > > When I run: > > (use 'clojure.contrib.http.agent) > > (println (string (http-agent "

Re: Observations from a real-world Clojure project

2009-10-30 Thread Tom Faulhaber
> > 5. The functionality of the docs hasn't kept up with Clojure.  We > often resorted to text searches of the various sources.  Need links > and see-also's.  Clojure has grown/matured so much that it needs a doc > system of some sort. > This has been recognized for awhile now. I have promised

Re: How to make lazy seq from socket input?

2009-10-30 Thread Tom Faulhaber
One thing to keep in mind, when using sockets, is that TCP does not guarantee to keep packetization across the network. That is, just because you're writing lines, doesn't mean that read will return lines. TCP can put writes together or break them into parts or some combination of both. So if you

idiom questions

2009-10-30 Thread Chick Corea
Is everything in Clojure immutable? For example, w/ this code-snippet (let [x nil] ;; do something and modify 'x' ) how does one modify the value of 'x' ? (let [x nil] (def x true)) this doesn't work. the "def' interns and defines a (dynamic) root- b

Re: Is running a script without leaving Clojure?

2009-10-30 Thread Chick Corea
On Oct 30, 1:37 pm, Chouser wrote: > On Fri, Oct 30, 2009 at 10:23 AM, Arie van Wingerden > wrote: > > > Hi, > > > when I run a Clojure script Clojure ends directly when the script is > > finished. > > > java -cp ~/build/clojure/clojure.jar clojure.main -i some_script.clj -r > Where are thos

can I make this faster (and leaner) ?

2009-10-30 Thread Chick Corea
How do I make this code faster? And leaner, i.e., use less memory ? It's a simple function to generate NUMKEYS strings of length KEYLENGTH, store them in a Java array then store them in a HashMap hash-map. [it doesn't store them in the hash-map yet; but it allocates it] (set! *warn-on-reflecti

Re: idiom questions

2009-10-30 Thread David Nolen
On Fri, Oct 30, 2009 at 4:42 PM, Chick Corea wrote: > > Is everything in Clojure immutable? For example, w/ this code-snippet > > (let [x nil] > ;; do something and modify 'x' > ) > > how does one modify the value of 'x' ? > >(let [x nil] (def x true)) > >

Re: idiom questions

2009-10-30 Thread Howard Lewis Ship
When I first looked at Clojure, I didn't get it (I scanned the docs for 10 - 15 minutes). A few month later, Stu Halloway said to give it a second look and boy am I glad I did. Go read Stu's book, or at least the first couple of chapters online at Manning. Digest for a bit. It'll be an eye opene

Re: Is running a script without leaving Clojure?

2009-10-30 Thread Chouser
On Fri, Oct 30, 2009 at 4:44 PM, Chick Corea wrote: > > Where are those and other CLI options documented?  I have not found > them. > > A "usage" or "help" message could help w/ this, too. java -cp clojure.jar clojure.main --help --Chouser --~--~-~--~~~---~--~~

Re: can I make this faster (and leaner) ?

2009-10-30 Thread David Nolen
The better question to ask is this real code you intend on using? Are you really going to generate 100,000 random keys of 1024 chars each all at once in a real running program? (def *valid-chars* [\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \u \z \0 \1 \2 \3 \4

Re: Seq wrappers for arrays can morph

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 12:40 PM, John Harrop wrote: > (defn lazy-array-seq > ([arr] > (lazy-array-seq arr 0)) > ([arr from-idx] > (lazy-array-seq arr 0 (count arr))) > ([arr from-idx end-idx] > (if-not (= from-idx end-idx) > (lazy-seq (aget arr from-idx) (lazy-array-seq a

Re: idiom questions

2009-10-30 Thread Alex Osborne
Chick Corea wrote: > Is everything in Clojure immutable? Most things. Clojure tries very hard to be thread-safe by default. > how does one modify the value of 'x' ? > > (let [x nil] (def x true)) One does not, at least not in a let-binding. If you really want a lexical variable you

Re: idiom questions

2009-10-30 Thread Alex Osborne
Alex Osborne wrote: > Chick Corea wrote: >> If I understand correctly, the "(binding ...)" macro specifically >> applies to >> "Variables", one of Clojure's STM types, thus has dynamic, thead-local >> scope. Is that right? In which case, it may hide a lexical binding ? > > Yes, I think you are

Re: Running out of memory when using loop/recur and destructuring

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 3:15 PM, Paul Mooser wrote: > Is this behavior due to some artifact of destructuring I'm not aware > of (or something else I'm missing), or is there a bug? If it sounds > like a bug, can anyone else reproduce? > > Thanks! I vaguely remember something like this coming up

Re: can I make this faster (and leaner) ?

2009-10-30 Thread Alex Osborne
Chick Corea wrote: > The corresponding Java code (w/ the hash-insert omitted in the clojure > version) > runs in 5.5sec and uses 290MB. > > This code runs (which omits the hash-insert) runs in 17.8sec and uses > 353MB. > > I thought that I added all of the casts and "warn-on-reflections" that >

Re: Seq wrappers for arrays can morph

2009-10-30 Thread Josh Daghlian
During the Boston Lisp Users meeting last November (?) I asked Rich about whether seq's on mutable java.util.Collections were really immutable if the underlying object (the Collection) was mutable. He emphatically said that no, the seq is still immutable, and that it caches values as it sees them.

Re: Seq wrappers for arrays can morph

2009-10-30 Thread Josh Daghlian
Although I suppose this isn't too surprising: user> (second y) --> ConcurrentModificationException --josh On Oct 30, 9:31 pm, Josh Daghlian wrote: > During the Boston Lisp Users meeting last November (?) I asked Rich > about whether seq's on mutable java.util.Collections were really > immutabl

Re: Seq wrappers for arrays can morph

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 9:31 PM, Josh Daghlian wrote: > During the Boston Lisp Users meeting last November (?) I asked Rich > about whether seq's on mutable java.util.Collections were really > immutable if the underlying object (the Collection) was mutable. He > emphatically said that no, the seq

Re: Seq wrappers for arrays can morph

2009-10-30 Thread John Harrop
On Fri, Oct 30, 2009 at 9:36 PM, Josh Daghlian wrote: > > Although I suppose this isn't too surprising: > > user> (second y) > --> ConcurrentModificationException Eeeuw. Guess it uses an Iterator to generate the elements for the lazy seq. For ArrayList, walking it by index would avoid this. For

Re: can I make this faster (and leaner) ?

2009-10-30 Thread DavidF
Try this: (def *valid-chars* [ \a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \u \z \0 \1 \2 \3 \4 \5 \6 \7 \8 \9 ] ) (defn generate-key [keylength] (for [x (range keylength)] (nth *valid-chars* (rand-int (count *valid- c

Memoize improvement

2009-10-30 Thread Stefan Arentz
This is some of my first Clojure code so it might not be the greatest ... yet! Here is an improved memoize function that also takes a time-to-live argument. Useful when you want to expire results from the cache. I'm using it to cache query results from a database. This probably breaks som

Re: idiom questions

2009-10-30 Thread Adrian Cuthbertson
> (let [x nil] > ;; do something and modify 'x' > ) > >how does one modify the value of 'x' ? Hi Chick, there's nothing stopping you re-binding x within the let construct, eg; (defn myfn [x] (let [x (if (or (nil? x) (< x 0.2)) 0.0 x) x (if (>= x 0.8) 1.0 x)]

Re: bugs in cl-format.clj

2009-10-30 Thread Tom Faulhaber
Hey Carlos, Thanks for noticing these. I'll take a look. I think cl-format has the most tests of anything in Clojure and it still has lousy test coverage of all the cases it's supposed to cover. Tom On Oct 28, 4:53 pm, carlitos wrote: > Hello, > > I've encountered a couple of issues with the

Re: bugs in cl-format.clj

2009-10-30 Thread Tom Faulhaber
I've added assembla ticket #40 for these issues: https://www.assembla.com/spaces/clojure-contrib/tickets/40-bugs-in-cl-format --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send

Re: bugs in cl-format.clj

2009-10-30 Thread Richard Newman
> I think cl-format has the most tests of anything in Clojure and it > still has lousy test coverage of all the cases it's supposed to cover. Don't be too hard on yourself... FORMAT and LOOP are amongst the scarier corners of Common Lisp, and even battle-hardened CL implementations sometimes