Re: Streams work
On 22.01.2009, at 19:50, Rich Hickey wrote: Does that mean that calling seq on a stream converts the stream into a seq for all practical purposes? That sounds a bit dangerous considering that so many operations in Clojure call seq implicitly. One can easily have a seq steal a stream and not notice it before all memory is used up by the seq. Calling seq on a stream yields a seq that will forever own the stream - if you think about it a bit, you'll see why that has to be the case. OTOH, that seq is lazy, so I'm not sure what the memory issue is. If my understanding is correct, then (def rand-stream (stream (fn [_] (rand (take 5 rand-stream) will create a seq on the stream that is referenced by the stream. As long as the stream is referenced by a var, the seq will remain referenced as well. Seqs being cached, this means that the whole random number sequence will be kept in memory. The only way to avoid this seems to be not calling any sequence function on a stream. I could use for example (defn take-stream [n s] (let [iter (stream-iter s) eos (Object.) vs (doall (for [_ (range n)] (next! iter eos)))] (do (detach! iter) vs))) (take-stream 5 rand-stream) Writing take-stream made me discover another pitfall: the stream seems to keep a reference to its iter object as well, meaning that is never released without an explicit call to detach!. I had expected to be able to create a local iter in a let and have it disappear and release the stream when it goes out of scope. I guess that would require the stream not to keep a reference to the iter, but just a flag that an iter exists. Which in turn requires that the iter resets the flag when it goes out of scope. I don't even know if that is doable in the JVM. Again, I don't see the enormous side effect. Steams form a safe, stateful pipeline, you'll generally only call seq on the end of the pipe. If you ask for a seq on a stream you are asking for a (lazy) reification. That reification and ownership is what makes the pipeline safe. Then why not make a pipeline using lazy sequences right from the start? I don't see anything that I could do better with streams than with lazy sequences. Konrad. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
A nil puzzle
The power set of a set S is defined as the set of all subsets of S. Here is one possible implementation of a powerset function. To stay true to the spirit of the above definition, I've written it in a way that manipulates the sets in set form as much as possible (not quite an easy task since things like rest and map return sequences, not sets). (defn powerset [s] (if (empty? s) #{#{}} (let [element (first s), rest-s (disj s element), powerset-rest-s (powerset rest-s)] (clojure.set/union powerset-rest-s (into #{} (map #(conj % element) powerset-rest-s)) Example: (powerset #{1 2 3}) prints as #{#{} #{1} #{2} #{3} #{1 2} #{1 3} #{2 3} #{1 2 3}} Now, here's the puzzle. Let's say you want to convert this idea over to working with lists, or perhaps sequences in general. Should (powerset '(1 2 3)) print as: (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) or (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) I can think of several excellent arguments for and against each option. I'd like to know whether the Clojure community is as conflicted on this point as I am. I think that the way you reason about this question says a lot about how you view the relationship between lists and sequences and the role of nil and the empty list, so I look forward to hearing the responses. Let the debating begin! --~--~-~--~~~---~--~~ 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 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: Any way we can get this in clojure-contrib?
Interesting. Are u sure joda-time is so widely in usage among java developers ? Anyway, as far as I remember, one of the benefits of clojure running on an existing VM (the JVM) is to leverage all the existing APIs. Since the date/time support would be in clojure-contrib (and not clojure-core), couldn't it make sense to have joda jar as an explicitly required dependency. And the design of you lib could carefully avoid exposing joda internals, so that joda could remain an implementation detail (and eventually be thrown away when you have the time to rewrite it) ? My 0,02€, -- Laurent On 23 jan, 06:25, Matt Moriarity matt.moriar...@gmail.com wrote: We discussed Joda Time, but it was decided that it wasn't a good idea to add another dependency, since this is something so integral to the language. I don't know what other people think, though. This was just an informal decision on #clojure. On Jan 23, 12:05 am, Nick Vogel voge...@gmail.com wrote: That sounds interesting; you might take a look at Joda Timehttp://joda-time.sourceforge.net/. Although I've never used it myself, from what I've heard it's the Java library that people actually use for dates/times (I do know that Google uses it). Doing a quick search, it looks like Mark McGranaghan is working on a Clojure wrapper for Joda Time herehttp://github.com/mmcgrana/clj-garden/tree/masterunderclj-time. On Thu, Jan 22, 2009 at 11:51 PM, Matt Moriarity matt.moriar...@gmail.comwrote: By the way, I'm in the process of sending in my contributor agreement. Just so you know :) --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
dot and nums in keywords
Hello, As per the docs for keywords ( http://clojure.org/reader ), keywords cannot contain '.'. They cannot contain '.' or name classes. However, the following works on the repl: user= :.. :.. user= (keyword? :..) true Are '.'s allowed and the docs need updating? Or should we see an exception? Also, would a keyword with only numbers be a valid keyword? e.g. : Thanks. Parth --~--~-~--~~~---~--~~ 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 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: A nil puzzle
On 23.01.2009, at 09:35, Mark Engelberg wrote: Now, here's the puzzle. Let's say you want to convert this idea over to working with lists, or perhaps sequences in general. Should (powerset '(1 2 3)) print as: (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) or (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) My vote is for (), because it specifically represents the empty subset of a list, rather than a generic nothing in here value, which is my interpretation of nil. between lists and sequences and the role of nil and the empty list, so I look forward to hearing the responses. Let the debating begin! This reminds me of the long debates in the APL community about the shapes of empty nested arrays :-) Konrad. --~--~-~--~~~---~--~~ 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 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: Agent as a processing queue
On Jan 23, 11:24 am, e evier...@gmail.com wrote: wow. I wonder if I could use this for the quicksort I was talking about. Interesting question. I can't think of an elegant way to implement an agent based parallel quicksort because await cannot be used recursively. So I implemented a version using Futures instead. Now you wont be able to run this unless you modify Agent.java, search for soloExectuor, make it public, and recompile Clojure. http://groups.google.com/group/clojure/web/pquicksort.clj Using futures like this seems convenient to me, I think it has some benefits over just using a Thread (two pools to choose from, you can wait for a return, you can cancel it) and making a one-shot agent just feels a bit messy. On Jan 23, 4:06 am, Emeka emekami...@gmail.com wrote: Could you explain atoms the way you explained agents?\ Atoms provide a place to put some data. Multiple threads can update or read this data without fear of it be 'half' updated by two threads accessing it at once. Further more, modification of Atoms is only available via supplying a function which takes the current value and returns a new value. The reason for this is that even with a piece of atomic data, if you had two threads execute A = A + A * A at the same time, one might update A while the other was half way through its calculation, so on the second thread it might be something like this: Anew = Abefore + Abefore * Aafter That would be really confusing! So instead you update atoms by providing a fuction (swap! A (fn [x] (x + x * x)) A will only be set when the entire calculation has been made without A changing in the meantime. This is in contrast to Refs, which use transactions to coordinate access. Regards, Tim. --~--~-~--~~~---~--~~ 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 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: Streams work
Rich Hickey a écrit : Again, I don't see the enormous side effect. Steams form a safe, stateful pipeline, you'll generally only call seq on the end of the pipe. If you ask for a seq on a stream you are asking for a (lazy) reification. That reification and ownership is what makes the pipeline safe. I am working on seq/stream api unification right now, and we will see how often we'll be calling seq fns yet subsequently using as a stream. Many of those places where seq is called will now call stream instead (e.g. sequence fn entry points), and there may be a non-generator- capturing function for determining eos. I undesrtand but I found this behaviour surprising : user= (defn take1 [s] (let [i (stream-iter s) n (next! i nil)] (detach! i) n)) (defn touch [s] (seq s) s) (def s1 (stream (range 10))) user= (take1 s1) 0 user= (take1 s1) 1 user= (take1 s1) 2 user= (touch s1) #AStream clojure.lang.astr...@19ee8a user= (take1 s1) 3 user= (take1 s1) 3 user= (take1 s1) 3 ; s1 is stuck on 3 because stream-iter returns a new iter on a new stream on the canonical seq for s1 With the attached patch, you get: user= (defn take1 [s] (let [i (stream-iter s) n (next! i nil)] (detach! i) n)) (def s1 (stream (range 10))) user= (take1 s1) 0 user= (take1 s1) 1 user= (take1 s1) 2 user= (seq s1) (3 4 5 6 7 8 9) user= (identical? (seq s1) (seq s1)) true user= (take1 s1) 3 user= (take1 s1) 4 user= (first s1) 5 ;; seq lookup or realization don't consume the stream: user= (seq s1) (5 6 7 8 9) user= (identical? (seq s1) (seq s1)) true user= (first s1) 5 user= (take1 s1) 5 user= (take1 s1) 6 I relaxed the constraint saying that a stream ensures that /*every call to seq on a stream will return the same seq to be */a stream ensures that /*every call to seq on a stream will return the same seq as long as the stream state doesn't change.*/ /*What did I lose? Christophe */ --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~--- Index: C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/AStream.java === --- C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/AStream.java (revision 1222) +++ C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/AStream.java (working copy) @@ -16,28 +16,44 @@ static final ISeq NO_SEQ = new Cons(null, null); -ISeq seq = NO_SEQ; +boolean coseq; +AStream seqstream = null; final IFn src; Cons pushed = null; Iter iter = null; public AStream(IFn src) { +this(src, false); +} + +public AStream(IFn src, boolean coseq) { this.src = src; +this.coseq = coseq; } final synchronized public ISeq seq() { -if (seq == NO_SEQ) + if (coseq) + try { +return (ISeq) src.invoke(); + } catch (Exception e) { +throw new RuntimeException(e); + } + if (seqstream == null) { iter(); -seq = Seq.create(pushed,src); +try { +seqstream = RT.stream(Seq.create(pushed,src)); + } catch (Exception e) { +throw new RuntimeException(e); + } } -return seq; +return seqstream.seq(); } final synchronized public AStream stream() throws Exception { -if (seq == NO_SEQ) +if (seqstream == null) return this; -return RT.stream(seq); +return seqstream; } final synchronized public Iter iter() { Index: C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/RT.java === --- C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/RT.java (revision 1222) +++ C:/Documents and Settings/Christophe/workspaces/clojure/clojure-streams/src/jvm/clojure/lang/RT.java (working copy) @@ -244,6 +244,10 @@ } static final public IFn EMPTY_GEN = new AFn(){ +synchronized public Object invoke() throws Exception { +return null; +} + synchronized public Object invoke(Object eos) throws Exception { return eos; } @@ -461,7 +465,7 @@ static public AStream stream(final Object coll) throws Exception{ if(coll == null) - return new AStream(EMPTY_GEN); + return new AStream(EMPTY_GEN, true); else if(coll instanceof Streamable) return ((Streamable) coll).stream(); else if(coll instanceof Fn) Index:
Re: Streams work
Christophe Grand a écrit : I relaxed the constraint saying that a stream ensures that /*every call to seq on a stream will return the same seq to be */a stream ensures that /*every call to seq on a stream will return the same seq as long as the stream state doesn't change.*/ /*What did I lose? Christophe */ /* and */ are by courtesy of Thunderbird :-( I relaxed the constraint saying that a stream ensures that every call to seq on a stream will return the same seq to be a stream ensures that every call to seq on a stream will return the same seq as long as the stream state doesn't change. What did I lose? Christophe --~--~-~--~~~---~--~~ 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 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: Streams work
Christophe Grand a écrit : I relaxed the constraint saying that a stream ensures that every call to seq on a stream will return the same seq to be a stream ensures that every call to seq on a stream will return the same seq as long as the stream state doesn't change. Well currently it's stronger than that: If you call seq on a stream, consume one item, call seq again then the second seq is the rest of the first one. This property being transitive you get: ser= (def s1 (stream (range 10))) #'user/s1 user= (take1 s1)(take1 s1)(take1 s1) 0 1 2 user= (def seq1 (seq s1)) #'user/seq1 user= seq1 (3 4 5 6 7 8 9) user= (take1 s1)(take1 s1)(take1 s1) 3 4 5 user= (identical? (seq s1) (drop 3 seq1)) true --~--~-~--~~~---~--~~ 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 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: dot and nums in keywords
Parth Malwankar a écrit : Hello, As per the docs for keywords ( http://clojure.org/reader ), keywords cannot contain '.'. They cannot contain '.' or name classes. http://groups.google.com/group/clojure/msg/eac27b0bd6f823f7 Rich Hickey: As far as '.', that restriction has been relaxed. I'll try to touch up the docs for the next release. Christophe --~--~-~--~~~---~--~~ 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 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: what when (some identity maps) mean?
I don't think the function passed to some should be called a predicate, since it is not constrained to true/false. The docstring agrees with you, however. Stuart Hi, It means that some of the maps can be nil, but at least one of them has to be non-nil. some requires a predicate, but since nil is logical false, we can just use identity. Here's the behavior: user (merge nil nil nil) nil user (merge {:a 1} nil {:b 2}) {:b 2, :a 1} -Stuart Sierra On Jan 22, 7:16 pm, wubbie sunj...@gmail.com wrote: Hi, Here is def of merge: (defn merge [ maps] (when (some identity maps) (reduce #(conj (or %1 {}) %2) maps))) How can I interpret when (some identity maps)? Thanks -sun --~--~-~--~~~---~--~~ 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 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: A nil puzzle
The power set function for lists should use () as the empty set. If you use nil, then it seems that you would have (powerset nil) = (nil) but this is wrong, since the only subset of an empty set is the empty set. You could try to fix this by making (powerset nil) = nil but then your function would return a list for all cases except when presented with the empty set, which doesn't seem right. For sequences in general, Rich has said there is no such thing as an empty seq: http://groups.google.com/group/clojure/browse_thread/thread/966bd0d4bb18a4a2/b56470cbc8b4123e?lnk=raotfwc=1 so I think you couldn't use seqs to represent sets (unless there is a notion of sets where there is no empty set). --~--~-~--~~~---~--~~ 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 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: Any way we can get this in clojure-contrib?
On Jan 23, 8:41 am, lpetit laurent.pe...@gmail.com wrote: Interesting. Are u sure joda-time is so widely in usage among java developers ? I use it and so do all my friends :) I believe there are moves afoot to get it included in the JDK sooner or later. https://jsr-310.dev.java.net/ --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
why does this work?
This is just something contrived I was playing around with and I know it is silly. I just have a couple of questions about it. (defn create-a [firstName lastName] (defn getFirstName [] firstName) (defn getLastName [] lastName) (fn [operator operands] (apply operator operands))) (def t (create-a Kurt Z)) ;How or why does this next line work? What is getFirstName in this context? (t getFirstName) ;I'm not surprised this doesn't work. (t 'getFirstName) ;And I'm not surprised this doesn't work. (defn getLastName blah) (t getLastName) Kurt --~--~-~--~~~---~--~~ 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 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: Agent as a processing queue
Thanks. I really appreciate seeing that example. There are more answers there than even the original question . . . like how easily you time the performance and how easily you make random lists of values. . . .also the use of remove in that code you grabbed to avoid having two filters is totally slick. I agree that agents seemed a little heavy-weight, too. Just to understand ... 'send-future' works too but you don't think that's the way to go? Also, I need to see if the Java code has a place for a user to specify the thread pool size. Otherwise is that best handled by send-off-future wrapping a generator that can throttle or something? Thanks again. On Fri, Jan 23, 2009 at 4:35 AM, Timothy Pratley timothyprat...@gmail.comwrote: On Jan 23, 11:24 am, e evier...@gmail.com wrote: wow. I wonder if I could use this for the quicksort I was talking about. Interesting question. I can't think of an elegant way to implement an agent based parallel quicksort because await cannot be used recursively. So I implemented a version using Futures instead. Now you wont be able to run this unless you modify Agent.java, search for soloExectuor, make it public, and recompile Clojure. http://groups.google.com/group/clojure/web/pquicksort.clj Using futures like this seems convenient to me, I think it has some benefits over just using a Thread (two pools to choose from, you can wait for a return, you can cancel it) and making a one-shot agent just feels a bit messy. On Jan 23, 4:06 am, Emeka emekami...@gmail.com wrote: Could you explain atoms the way you explained agents?\ Atoms provide a place to put some data. Multiple threads can update or read this data without fear of it be 'half' updated by two threads accessing it at once. Further more, modification of Atoms is only available via supplying a function which takes the current value and returns a new value. The reason for this is that even with a piece of atomic data, if you had two threads execute A = A + A * A at the same time, one might update A while the other was half way through its calculation, so on the second thread it might be something like this: Anew = Abefore + Abefore * Aafter That would be really confusing! So instead you update atoms by providing a fuction (swap! A (fn [x] (x + x * x)) A will only be set when the entire calculation has been made without A changing in the meantime. This is in contrast to Refs, which use transactions to coordinate access. Regards, Tim. --~--~-~--~~~---~--~~ 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 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: why does this work?
Hi Kurt, Am 23.01.2009 um 05:23 schrieb zoglma...@gmail.com: (defn create-a [firstName lastName] (defn getFirstName [] firstName) (defn getLastName [] lastName) (fn [operator operands] (apply operator operands))) It's important to note that, regardless of the lexical context, def(n) creates global/top-level definitions (contrary to scheme, i believe). (def t (create-a Kurt Z)) Upon calling create-a, getFirstName and getLastName become globally defined functions. getFirstName will always return Kurt, getLastName will always return Z. ;How or why does this next line work? What is getFirstName in this context? (t getFirstName) The value of t is the function (fn [operator operands] (apply operator operands))), which is called with getFirstName as the operator arg. Since there are no further operands, applying operator to nothing just calls it and returns Kurt. Hope this helps. Kind Regards, achim --~--~-~--~~~---~--~~ 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 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: Any way we can get this in clojure-contrib?
On Fri, Jan 23, 2009 at 5:30 AM, AndrewC. mr.bl...@gmail.com wrote: On Jan 23, 8:41 am, lpetit laurent.pe...@gmail.com wrote: Interesting. Are u sure joda-time is so widely in usage among java developers ? I use it and so do all my friends :) I believe there are moves afoot to get it included in the JDK sooner or later. https://jsr-310.dev.java.net/ That's right. So eventually it won't be an extra dependency. For that reason I think it would be much better to make the contrib date/time functions delegate to the Joda Time library. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: A nil puzzle
+1. #{} is the empty set, () is the empty list, {} is the empty map. Cheers, -- Laurent On 23 jan, 10:17, Konrad Hinsen konrad.hin...@laposte.net wrote: On 23.01.2009, at 09:35, Mark Engelberg wrote: Now, here's the puzzle. Let's say you want to convert this idea over to working with lists, or perhaps sequences in general. Should (powerset '(1 2 3)) print as: (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) or (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) My vote is for (), because it specifically represents the empty subset of a list, rather than a generic nothing in here value, which is my interpretation of nil. between lists and sequences and the role of nil and the empty list, so I look forward to hearing the responses. Let the debating begin! This reminds me of the long debates in the APL community about the shapes of empty nested arrays :-) Konrad. --~--~-~--~~~---~--~~ 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 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: Basic about setting upp Clojure and editor enviroment
Or try the IntelliJ plugin, if you like that IDE http://code.google.com/p/clojure-intellij-plugin/ It works fine on Windows and Linux. We are currently fixing the Mac. P Matt Clark wrote: If you're not already an emacs user, I found it can be quite the learning curve getting into it. So I'd recommend you also give the eclipse clojure-dev plugin a shot. It now has a REPL, namespace browser, syntax highlighting, etc and works fine on windows. http://code.google.com/p/clojure-dev/ On Jan 21, 10:05 am, anderspe anders.u.pers...@gmail.com wrote: Hello, i am waiting for the book Programming Clojure by Stuart Halloway, I have set upp a enviroment that i can run a REPL and load script. But i am looking for som basic info about sett upp interaction to a editor, EMACS or... I have tryed Plugin to Netbeans but it was Alpha and have som problem running Windows. Tutorials, Links, tips would be nice // Anders --~--~-~--~~~---~--~~ 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 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: Calling Clojure from Java (again)
Hi, On 23 jan, 01:43, Peter Wolf opus...@gmail.com wrote: Hi Laurent, 1) Does Eclipse use the server for resolving references? Currently, the only resolved references are those that come from a clojure environment launched by the user. So yes. When time comes to resolve references for the needs of the editor, then, indeed, we will have to make a choice : a) rely on the fact that the user has launched an environment, and on the fact that this environment and the editor are sufficiently in sync with each other (that's what slime does, AFAIK, and that's probably what clojuredev will do first). b) or have the clojuredev plugin launch, behind the scene, a environment just for its own needs. 2) Is the server visible to the user, or hidden inside Eclipse? I think 1) answered to that. 3) Does the server call load-file? Not yet. It calls 'load-string for the correct execution, in the environment launched by the user (if any, 'cause if none, nothing happens, or maybe a warning popup, I don't remember), of the command string. The next step for clojuredev will be to leverage auto-build, but it's not been done yet. 4) Can the user break the server with bogus code in a file? Not the server in the sense the clojuredev environment, and so the running eclipse. But the server that every launch made by the user triggers automatically. 5) What happens if a file has top level code that pops up a window/starts a process? This is exactly the same question that makes me think twice about how to do auto-build. At first, I thought I had found the solution by restricting the problem to only do auto-build by compiling files that represent libs. But this too won't work as expected, because 'compile will also load the code in the environment that does the compilation (was the subject of another e-mail). 6) How does the user know when the server is broken? For the moment, he knows immediately, because the only server clojudev talks to is the one embedded in a configuration launched by him = his REPL ... will be broken also. When time comes to have an under the hoods server just for clojuredev's purpose, then I think I'll implement some 'ping remote function that would return true or false or ... nothing at all if it's dead, and make clojuredev restart a new one if that happens. Thanks, this is very helpful to me Yes, to me too, -- Laurent P ... skipping the top This bridge function runs on the eclipse JVM, and calls a server we systematically install in the remote JVM when the user launches his project. The code for the client part is here : http://code.google.com/p/clojure-dev/source/browse/clojuredev/trunk/s... The code for the server part is here : http://code.google.com/p/clojure-dev/source/browse/clojuredev/trunk/s... (and yes, it's yet another variation on the repl over socket) Thanks, I shall take a look at this. However, if there is only one Clojure image used for references and the like, what happens if someone calls an infinite loop, or infinite recursion, in a file. Does the Clojure server hang/blow up? How do you detect it/protect from it? No, currently, clojuredev's dynamism is tied to an existing (and visible via its REPL console) launched configuration. It is this configuration that is used. So the user has only access to the launched JVM, and if he breaks it, then he just has to click on the stop VM button on the classic console view. Was that your question ? For example, I was using the SmallSnake code for testing, and when that file is loaded, it pops up a window and runs a process forever. I don't want that to happen, just because someone included that file in their IntelliJ project. This must be a problem common to all Swank based IDEs. What is the Clojure way here? --~--~-~--~~~---~--~~ 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 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: Calling Clojure from Java (again)
On 23 jan, 03:00, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Jan 22, 6:51 pm, Peter Wolf opus...@gmail.com wrote: However, if there is only one Clojure image used for references and the like, what happens if someone calls an infinite loop, or infinite recursion, in a file. Does the Clojure server hang/blow up? If you code an infinite loop, the SWANK server will run an infinite loop. The only solution is to kill off the Java process. If you wanted to get clever, you could load the file in a separate thread and just kill off that thread. For example, I was using the SmallSnake code for testing, and when that file is loaded, it pops up a window and runs a process forever. That's an unfortunate side effect of using Clojure as a scripting language like Perl or Python. Perhaps it would be more proper for the distributed file to define a function that will run the application. If only lib compilation could not automatically load the lib in the environment that calls 'compile (or could provide an option for that) , it would be much safer to implement an auto-build functionality in IDEs. I don't know if its primarily a technical consideration, so if it's feasible at all without having to rewrite a bunch of classes or even the whole 'compile thing ? Alas, I'm not currently in a position to give help on this, I haven't sufficiently studied clojure's internals. -- Do you know if getting a version of 'compile that would not also load the lib is feasible ? Thanks in advance, -- Laurent -Stuart Sierra --~--~-~--~~~---~--~~ 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 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: why does this work?
Hi Achim, I think I understand now. It's important to note that, regardless of the lexical context, def(n) creates global/top-level definitions (contrary to scheme, i believe). (defn create-a [firstName lastName] (defn getFirstName [] firstName) (defn getLastName [] lastName) (fn [operator operands] (apply operator operands))) (def t (create-a Kurt Z)) (def r (create-a Bob hope)) (t getFirstName) -- returns Bob instead of Kurt And this is the case because despite where defn is declared, it is a top level definition in the current name space. Thus calling def r above redefines getFirstName and getLastName. Thanks for clearing this up. --~--~-~--~~~---~--~~ 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 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: Streams work
On Jan 23, 3:31 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On 22.01.2009, at 19:50, Rich Hickey wrote: Does that mean that calling seq on a stream converts the stream into a seq for all practical purposes? That sounds a bit dangerous considering that so many operations in Clojure call seq implicitly. One can easily have a seq steal a stream and not notice it before all memory is used up by the seq. Calling seq on a stream yields a seq that will forever own the stream - if you think about it a bit, you'll see why that has to be the case. OTOH, that seq is lazy, so I'm not sure what the memory issue is. If my understanding is correct, then (def rand-stream (stream (fn [_] (rand (take 5 rand-stream) will create a seq on the stream that is referenced by the stream. As long as the stream is referenced by a var, the seq will remain referenced as well. Seqs being cached, this means that the whole random number sequence will be kept in memory. Creating stateful streams and leaving them lying around in named globals is not the intended use case. They are for immediate use in computational pipelines. They are even less collections than are seqs, i.e. not at all. The only way to avoid this seems to be not calling any sequence function on a stream. I could use for example (defn take-stream [n s] (let [iter (stream-iter s) eos (Object.) vs (doall (for [_ (range n)] (next! iter eos)))] (do (detach! iter) vs))) (take-stream 5 rand-stream) Writing take-stream made me discover another pitfall: the stream seems to keep a reference to its iter object as well, meaning that is never released without an explicit call to detach!. I had expected to be able to create a local iter in a let and have it disappear and release the stream when it goes out of scope. Were that the case, then the map* and filter* examples wouldn't work, The most common idiom is to obtain an iter on the incoming stream, create a computational stage with a generator that wraps that iter, and returns a stream that owns that generator. So certainly it can't go out of scope at the end of the let. I guess that would require the stream not to keep a reference to the iter, but just a flag that an iter exists. Which in turn requires that the iter resets the flag when it goes out of scope. I don't even know if that is doable in the JVM. Nope. You can't tie things like this to the lifetime of GC-able entities, nor would you want to try to understand a system that did. Again, I don't see the enormous side effect. Steams form a safe, stateful pipeline, you'll generally only call seq on the end of the pipe. If you ask for a seq on a stream you are asking for a (lazy) reification. That reification and ownership is what makes the pipeline safe. Then why not make a pipeline using lazy sequences right from the start? I don't see anything that I could do better with streams than with lazy sequences. There are a couple of advantages. First, streams are faster, at least 2x faster. Since a lazy sequence must allocate per stage, a multi- stage pipeline would incur multiple allocations per step. A stream could be built that has no allocation other than the results. If your calculations per step are significant, they'll dominate the time. but when they are not, this allocation time matters. Second, streams are fully lazy. Seqs could be made fully lazy, but currently are not. Third, stream iters currently provide transparent MT access. Doing the same for a seq means wrapping it in a ref. 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 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: Any way we can get this in clojure-contrib?
On Fri, Jan 23, 2009 at 7:20 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 23, 2009 at 5:30 AM, AndrewC. mr.bl...@gmail.com wrote: On Jan 23, 8:41 am, lpetit laurent.pe...@gmail.com wrote: Interesting. Are u sure joda-time is so widely in usage among java developers ? I use it and so do all my friends :) I believe there are moves afoot to get it included in the JDK sooner or later. https://jsr-310.dev.java.net/ That's right. So eventually it won't be an extra dependency. For that reason I think it would be much better to make the contrib date/time functions delegate to the Joda Time library. It looks to me like this lib as it stands would allow me to go from a date string (from a file or user input) or from the current date, through some minimal calculations, and back out to a formatted string without ever touching the underlying Java object directly. Why do I care if Joda time is inside or not. ...except of course that every external dependency is an increased burden on the users of any code I write. It seems likely that a pretty substantial percentage of use cases could be handled in a way that would allow either Java lib to be used underneath. That way I would have no extra dependency now, or if I need Joda features could use that instead. --Chouser --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
evalOnlyDefs
Looking for opinions from Clojure internals Wizards... I am thinking about safe loading for IDEs (see other thread). IDEs need a way to load and resolve code, without calling script code that might be in the file. I was looking the code called by load-file and load. Here is Compiler.eval() public static Object eval(Object form) throws Exception{ boolean createdLoader = false; if(!LOADER.isBound()) { Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); createdLoader = true; } try { if(form instanceof IPersistentCollection !(RT.first(form) instanceof Symbol ((Symbol) RT.first(form)).name.startsWith(def))) { FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), eval); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); } else { Expr expr = analyze(C.EVAL, form); return expr.eval(); } } catch(Throwable e) { if(!(e instanceof CompilerException)) throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e); else throw (CompilerException) e; } finally { if(createdLoader) Var.popThreadBindings(); } } I notice that it already checks for def being the first of the form, and does something different in that case. How do Wizards feel about adding evalOnlyDefs() like below, to be called by load-file-only-defs to be used by IDEs. Would this do the right thing? public static Object evalOnlyDefs(Object form) throws Exception{ boolean createdLoader = false; if(!LOADER.isBound()) { Var.pushThreadBindings(RT.map(LOADER, RT.makeClassLoader())); createdLoader = true; } try { if(form instanceof IPersistentCollection !(RT.first(form) instanceof Symbol ((Symbol) RT.first(form)).name.startsWith(def))) { FnExpr fexpr = (FnExpr) analyze(C.EXPRESSION, RT.list(FN, PersistentVector.EMPTY, form), eval); IFn fn = (IFn) fexpr.eval(); return fn.invoke(); } } catch(Throwable e) { if(!(e instanceof CompilerException)) throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e); else throw (CompilerException) e; } finally { if(createdLoader) Var.popThreadBindings(); } } --~--~-~--~~~---~--~~ 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 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: why does this work?
On Fri, Jan 23, 2009 at 7:56 AM, zoglma...@gmail.com zoglma...@gmail.com wrote: It's important to note that, regardless of the lexical context, def(n) creates global/top-level definitions (contrary to scheme, i believe). (defn create-a [firstName lastName] (defn getFirstName [] firstName) (defn getLastName [] lastName) (fn [operator operands] (apply operator operands))) It's also worth noting that this is very much discouraged, as it means that create-a has poorly controlled global side-effects. If you want locals named 'getFirstName' and 'getLastName', please use 'let' instead of 'defn': (defn create-a [firstName lastName] (let [getFirstName (fn [] firstName) getLastName (fn [] lastName)] ...)) However, if you mean to be changing global state, look into using any of the well-managed state mechanisms, such as 'ref', 'agent', 'atom', or Vars: http://clojure.org/concurrent_programming Also, CamelCase is discouraged unless required for interop with Java or something else. Clojure allows names like first-name and get-last-name, so that format is preferred. --Chouser --~--~-~--~~~---~--~~ 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 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: Streams work
On Jan 23, 4:53 am, Christophe Grand christo...@cgrand.net wrote: Christophe Grand a écrit : I relaxed the constraint saying that a stream ensures that /*every call to seq on a stream will return the same seq to be */a stream ensures that /*every call to seq on a stream will return the same seq as long as the stream state doesn't change.*/ /*What did I lose? Christophe */ /* and */ are by courtesy of Thunderbird :-( I relaxed the constraint saying that a stream ensures that every call to seq on a stream will return the same seq to be a stream ensures that every call to seq on a stream will return the same seq as long as the stream state doesn't change. What did I lose? I think you lose the game overall. The entire point of this mechanism is to prevent the dissemination of stateful things. seq being a true (referentially transparent) function of a stream is a critical part of that. It ensures that when you've got a seq on a stream, you have exclusive access to a pipe with no leaks. Inside the pipe, there may be mutation and state, but no one can see them, since the end, seq, view is persistent and immutable. With what you are proposing: (if (seq astream) (do-something-with (first astream)) is broken. More generally, I guess I simply don't understand these use cases for treating the stream as a seq and subsequently mutating it. Maybe I should rename them pipes and it would be less likely people would expect them to divide and run all over the mountain :) Seriously, is there a real use case for (first astream) ... (take1 astream) ? You should presume there will be stream version of all the sequence fns. 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 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: Streams work
On Jan 22, 11:17 am, Konrad Hinsen konrad.hin...@laposte.net wrote: On 22.01.2009, at 16:27, Rich Hickey wrote: Now it works - fine. But what happened to the seq that now owns the stream? Nothing refers to it, so it should be gone. No, the stream must refer to it, in order to keep its promise to return the same seq every time. OK. Did it perhaps liberate the stream, so that I can create an iter again? Let's try: (def rand-iter (stream-iter rand-stream)) (next! rand-iter nil) (next! rand-iter nil) What you've created an iter on the second time is the seq of the stream. Right now, once you've treated a stream as a seq it will always behave like one. So this second stream-iter call actually creates an iter on a stream on that seq. Does that mean that calling seq on a stream converts the stream into a seq for all practical purposes? That sounds a bit dangerous considering that so many operations in Clojure call seq implicitly. One can easily have a seq steal a stream and not notice it before all memory is used up by the seq. I understand this may not be intuitive or clear yet from the docs. Nor am I set in this being the behavior. The case I am looking towards is this one: (def s (stream (range 10))) (if (seq s) (take 4 (map-stream inc s)) A stream is used as a seq and then passed to a stream function. Without this seqed-stream-behaves-as-seq capability, this will fail with Already iterating, and would have to be written: (if (seq s) (take 4 (map-stream inc (seq s I think the second is in fact clearer. I've made (stream astream) identity in SVN 1228 - that's easy to understand, and I'm not sure my case will be all that common. 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 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: Any way we can get this in clojure-contrib?
On Fri, Jan 23, 2009 at 7:12 AM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 7:20 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 23, 2009 at 5:30 AM, AndrewC. mr.bl...@gmail.com wrote: On Jan 23, 8:41 am, lpetit laurent.pe...@gmail.com wrote: Interesting. Are u sure joda-time is so widely in usage among java developers ? I use it and so do all my friends :) I believe there are moves afoot to get it included in the JDK sooner or later. https://jsr-310.dev.java.net/ That's right. So eventually it won't be an extra dependency. For that reason I think it would be much better to make the contrib date/time functions delegate to the Joda Time library. It looks to me like this lib as it stands would allow me to go from a date string (from a file or user input) or from the current date, through some minimal calculations, and back out to a formatted string without ever touching the underlying Java object directly. Why do I care if Joda time is inside or not. ...except of course that every external dependency is an increased burden on the users of any code I write. It seems likely that a pretty substantial percentage of use cases could be handled in a way that would allow either Java lib to be used underneath. That way I would have no extra dependency now, or if I need Joda features could use that instead. I think some reasons to use Joda Time instead of new code for data/time calculations include: 1) Joda Time is already very well tested, so it's known to be good code. 2) Joda Time has much more functionality than what has been implemented so far in Clojure. Having the Clojure code delegate to Joda Time paves the way to easily add more of that functionality later. 3) When Joda Time becomes a standard part of Java, the extra dependency will go away. 4) Reimplementing Joda Time functionality consumes time that could be better spent on other things. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Streams work
Rich Hickey a écrit : I think you lose the game overall. I'm sorry if I sounded provocative, I was trying to better understand the model you propose with streams. Thanks for your answer: it made thinks clearer to me. With what you are proposing: (if (seq astream) (do-something-with (first astream)) is broken. Indeed you're right: astream can change between the two calls to (seq astream). More generally, I guess I simply don't understand these use cases for treating the stream as a seq and subsequently mutating it. It's not a use case, it's the mere angst of nasty bugs basically due to: (seq astream) ... (stream-iter astream) not raising an exception when someone inadvertently mixing seq fns and stream fns. Now (rev 1228) I get an Already iterating exception so I'm happy. Christophe --~--~-~--~~~---~--~~ 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 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: function that takes primitives?
On Jan 22, 6:16 pm, Korny Sietsma ko...@sietsma.com wrote: Hi folks, Is there any way to make a function that takes primitive parameters? It seems you can't, but I might be missing something. I have the following code (a start to playing with mandelbrot sets): (defn step [x0, y0, xn, yn] (let [xm (+(-(* xn xn)(* yn yn)) x0) ym (+(* 2 xn yn) y0) ] [xm ym] ) ) (defn try_to_solve [x0, y0, xn, yn, n, max_n] (let [m (+ n 1) [xm ym] (step x0 y0 xn yn) zm (+(* xm xm)(* ym ym)) ] (cond ( zm 2.0) m (= n max_n) [x0, y0, xm, ym, m, max_n] true (recur x0, y0, xm, ym, m, max_n) ) ) ) This works fine (it's my first clojure code, so I'm sure there are things I could do better, but I'm happy with it as a start) However, I want to do this a lot, so I was trying to coerce the paramters to primitive doubles. It seems you can't write: (defn step [#^double x0, #^double y0, #^double xn, #^double yn] and from comments I've seen before, I get the impression if I use type hinting, clojure will use Doubles and boxing, which is a speed overhead I don't want. I get the impression I can rewrite try_to_solve to use a loop/recur, and then can use primitives - but I can't see any way to make calls to step use primitives, short of inlining the function... Currently, there is no way to write a function that takes/returns primitives, all of the signatures are Object based. 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 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 -~--~~~~--~~--~--~---
Joda Time library
Since we've been discussing using the Joda Time library from Clojure ... if anyone is interested in a quick intro. to the Joda Time library, I have a PDF of some slides I put together for a recent project at http://www.ociweb.com/mark/programming/JodaTime.pdf. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Any way we can get this in clojure-contrib?
Joda Time is also a good fit for Clojure because all features in the library have a functional implementation, whereas the current built-in Java classes tend to use non-functional/non-threadsafe mechanisms. - Mark M. On Fri, Jan 23, 2009 at 9:14 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 23, 2009 at 7:12 AM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 7:20 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 23, 2009 at 5:30 AM, AndrewC. mr.bl...@gmail.com wrote: On Jan 23, 8:41 am, lpetit laurent.pe...@gmail.com wrote: Interesting. Are u sure joda-time is so widely in usage among java developers ? I use it and so do all my friends :) I believe there are moves afoot to get it included in the JDK sooner or later. https://jsr-310.dev.java.net/ That's right. So eventually it won't be an extra dependency. For that reason I think it would be much better to make the contrib date/time functions delegate to the Joda Time library. It looks to me like this lib as it stands would allow me to go from a date string (from a file or user input) or from the current date, through some minimal calculations, and back out to a formatted string without ever touching the underlying Java object directly. Why do I care if Joda time is inside or not. ...except of course that every external dependency is an increased burden on the users of any code I write. It seems likely that a pretty substantial percentage of use cases could be handled in a way that would allow either Java lib to be used underneath. That way I would have no extra dependency now, or if I need Joda features could use that instead. I think some reasons to use Joda Time instead of new code for data/time calculations include: 1) Joda Time is already very well tested, so it's known to be good code. 2) Joda Time has much more functionality than what has been implemented so far in Clojure. Having the Clojure code delegate to Joda Time paves the way to easily add more of that functionality later. 3) When Joda Time becomes a standard part of Java, the extra dependency will go away. 4) Reimplementing Joda Time functionality consumes time that could be better spent on other things. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Binding values in a list of symbols and evaluating as code
I'm trying my hand at genetic programming. (Full post about why and how, with code coming soon - I promise.) My current technique uses a genetic algorithm to generate a list of symbols, numbers and other lists of the same form. The head is the name of any of several functions. I'm trying to figure out a good way to bind the symbols that appear in these lists and evaluate them as code. My current technique looks like this: (def a) (def b) (defn try-rule [r val-a val-b] (binding [a val-a b val-b] (eval r))) and an example call looks like: (try-rule '(+ a b) 2 4) I know that calls to eval are discouraged outside of writing something like a REPL. I'm looking for a better way to do this. Note that binding a and b when the rules are generated or using actual values instead of symbols won't work because each rule actually needs to be tested against hundreds of possible values. --~--~-~--~~~---~--~~ 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 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: Joda Time library
On Fri, Jan 23, 2009 at 9:41 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Since we've been discussing using the Joda Time library from Clojure ... if anyone is interested in a quick intro. to the Joda Time library, I have a PDF of some slides I put together for a recent project at http://www.ociweb.com/mark/programming/JodaTime.pdf. That's a nice summary, thanks. Joda Time's API looks good enough it may not need any wrapper at all to work nicely in Clojure: Immutable types, low-ceremony interactions, etc. --Chouser --~--~-~--~~~---~--~~ 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 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: A nil puzzle
There was a recent suggestion here: http://groups.google.com/group/clojure/msg/32d323e15f8ce624 about the proper value of: (clojure.contrib.lazy-seqs/combinations) (and perhaps by extension (clojure.contrib.lazy-seqs/combinations '()) (or any number of empty seq arguments)) Does a decision to use empty collections in the powerset case fit well with the suggestion that (clojure.contrib.lazy-seqs/combinations) return ([]) or are they in conflict or unrelated? --Steve On Jan 23, 2009, at 7:20 AM, lpetit wrote: +1. #{} is the empty set, () is the empty list, {} is the empty map. Cheers, -- Laurent On 23 jan, 10:17, Konrad Hinsen konrad.hin...@laposte.net wrote: On 23.01.2009, at 09:35, Mark Engelberg wrote: Now, here's the puzzle. Let's say you want to convert this idea over to working with lists, or perhaps sequences in general. Should (powerset '(1 2 3)) print as: (() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) or (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) My vote is for (), because it specifically represents the empty subset of a list, rather than a generic nothing in here value, which is my interpretation of nil. between lists and sequences and the role of nil and the empty list, so I look forward to hearing the responses. Let the debating begin! This reminds me of the long debates in the APL community about the shapes of empty nested arrays :-) Konrad. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~--- smime.p7s Description: S/MIME cryptographic signature
Re: why does this work?
Thanks Chouser, No, I really didn't have any intentions with this example. I was merely exploring around. In hindsight it is also obvious why this works. (defn foo[] (defn bar [x] (* x 2)) nil) (foo) (bar 2)--- returns 4 I just didn't realize initially what was going on... that defn binds globally. And yeah, this could be abused to allow some kind of weird mutability. I was't going for that. :) What I originally wrote was this (with camel case corrected) (defn create-a [first-name last-name] (let [fnc-map {'type (fn [] person) 'get-first-name (fn [] first-name) 'get-last-name (fn [] last-name) 'name-length (fn [] (+ (count first-name) (count last-name)))}] (fn [fnc-symbol args] (apply (fnc-map fnc-symbol) args ((create-a Kurt Z) 'get-first-name) (def bob-vance (create-a Bob Vance)) (bob-vance 'name-length) (bob-vance 'get-first-name) I wasn't completely satisfied with the example because it seemed I could make it a bit more abstract. Before I went down the path of writing a macro, I ended up stumbling on some strangeness with defn. If you are curious as to my intentions, I have been watching the SICP lecture series. And I was a bit intrigued in alternative ways of implenting simple types in a lisp instead of having a lookup table. Kurt --~--~-~--~~~---~--~~ 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 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: Binding values in a list of symbols and evaluating as code
Hi Zak, I think this is a reasonable use of eval, since you're evaluating an expression that is generated at run-time. The alternatives are messy. -Stuart Sierra On Jan 23, 10:20 am, Zak Wilson zak.wil...@gmail.com wrote: I'm trying my hand at genetic programming. (Full post about why and how, with code coming soon - I promise.) My current technique uses a genetic algorithm to generate a list of symbols, numbers and other lists of the same form. The head is the name of any of several functions. I'm trying to figure out a good way to bind the symbols that appear in these lists and evaluate them as code. My current technique looks like this: (def a) (def b) (defn try-rule [r val-a val-b] (binding [a val-a b val-b] (eval r))) and an example call looks like: (try-rule '(+ a b) 2 4) I know that calls to eval are discouraged outside of writing something like a REPL. I'm looking for a better way to do this. Note that binding a and b when the rules are generated or using actual values instead of symbols won't work because each rule actually needs to be tested against hundreds of possible values. --~--~-~--~~~---~--~~ 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 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: evalOnlyDefs
On Jan 23, 2009, at 8:38 AM, Peter Wolf wrote: Looking for opinions from Clojure internals Wizards... I can think of only one Clojure internals Wizard, but I have some thoughts. I am thinking about safe loading for IDEs (see other thread). IDEs need a way to load and resolve code, without calling script code that might be in the file. That's interesting and it seems arguments along these lines touch on topics like functional vs. imperative as well with functional having many of its usual advantages here as well. I recently changed my user.clj file to be purely full of definitions. I think it fits well with the require/use model that reloading ought to only affect what's available to call after the load, not actually do (in the Clojure side-effecting sense) anything. Some questions this raises: - Should libs be restricted to definitions (and lib support things like ns and (some kind of) load-resource) only? - Should the appearance of an ns form automatically make that restriction enforced for the rest of this file (as it's being loaded). - Do we need a mechanism like java's main method where we could put any scripting code (things intended to do something when the lib is used as a script) rather than allowing non-definitions everywhere? We could by convention call a particularly named function or we could provide the name (or signature?) of a designated function in the ns form and call that when calling (effectively) a namespace as a program rather than using it as a library: (ns my-simulator (:require 'clojure.contrib.lazy-seqs) (:main do-simulation [circuit inputs])) This seems an attractive model for libs independent of its usefulness for IDEs and with IDEs benefiting so much from it, I like it a lot. --Steve smime.p7s Description: S/MIME cryptographic signature
Embed Clojure in OSGi Bundles
Hi everybody, I am working in a software company specialized in Eclipse based product development (and member of the Eclipse Fundation). We are very interesting in clojure features and we plan to use it in some of our products. I am currently working on clojure integration in OSGi Bundles in order to embed code in Eclipse plugins. As mentioned in some posts the biggest problems is class loading. Indeed in OSGi each bundle has its own class loader and class loading is not based on the application classpath or on the current thread class loader. Consequently, it is very difficult to make clojure work with java code and to use OSGi visibility and dependencies system inside clojure. I think the best solution is to use bundles class loader inside clojure class loading system. I developed a proof of concept that uses a new class loader that extends clojure.lang.DynamicClassLoader with bundle class loading capability. To know which bundle use to load classes or script file the class loader uses the current namespace which has to reflect the bundle name (this is the java convention for bundles). In order to use this new class loader I had to modified clojure.lang.RT#baseLoader and makeClassLoader and clojure.lang.core#import. Moreover to test this I made a experimental Eclipse Builder that enable AOT compilation of mixed clojure and java plugin. So far it seems to work well: clojure and java interact seamlessly and it is very fun to interact dynamically with an Eclipse instance! I had some questions to the clojure community: * Whether it is possible to overload clojure class loading without introducing dependencies in clojure's core? * If their are some people interested in this application of clojure? (I can made my sources available) Moreover I will made a post on Eclipse E4 project mailing list (work on the future of Eclipse) as they are very interested in dynamic languages. BR, Gaetan --~--~-~--~~~---~--~~ 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 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: evalOnlyDefs
On Jan 23, 2009, at 17:15, Stephen C. Gilardi wrote: I recently changed my user.clj file to be purely full of definitions. I think it fits well with the require/use model that reloading ought to only affect what's available to call after the load, not actually do (in the Clojure side-effecting sense) anything. I do the same. Some questions this raises: - Should libs be restricted to definitions (and lib support things like ns and (some kind of) load-resource) only? - Should the appearance of an ns form automatically make that restriction enforced for the rest of this file (as it's being loaded). That would require an operational definition of what counts as a definition, which moreover can be verified by the compiler. I am not sure that is realistic. Pretty much any Clojure function except for I/O can be used in definitions, so your suggestion comes down to making the compiler recognize any attempt to do I/O, even indirectly, and even then make an exception for things like load-file. As a guideline your sugggestions seem fine though. I wouldn't like to work with libraries whose mere import does something magical. - Do we need a mechanism like java's main method where we could put any scripting code (things intended to do something when the lib is used as a script) rather than allowing non-definitions everywhere? We could by convention call a particularly named function or we could provide the name (or signature?) of a designated function in the ns form and call that when calling (effectively) a namespace as a program rather than using it as a library: (ns my-simulator (:require 'clojure.contrib.lazy-seqs) (:main do-simulation [circuit inputs])) That sounds nice. Konrad. --~--~-~--~~~---~--~~ 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 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: Embed Clojure in OSGi Bundles
Hello Gaetan, I'm one of the core developers of clojuredev, an open source project whose goal is to provide clojure support for the Eclipse IDE. What you say below is interesting, please see what I have noted inline -- 2009/1/23 gaetan gaetan.mor...@gmail.com Hi everybody, I am working in a software company specialized in Eclipse based product development (and member of the Eclipse Fundation). We are very interesting in clojure features and we plan to use it in some of our products. I am currently working on clojure integration in OSGi Bundles in order to embed code in Eclipse plugins. As mentioned in some posts the biggest problems is class loading. Indeed in OSGi each bundle has its own class loader and class loading is not based on the application classpath or on the current thread class loader. Consequently, it is very difficult to make clojure work with java code and to use OSGi visibility and dependencies system inside clojure. For mere mortals like me, could you explain the problem via an example ? (I understand there is a problem, I don't exactly understand what it really is) Concerning clojuredev, we provide clojure as a separate plugin, which exposes everything to plugins that depend on it. Currently, clojuredev plugin is successful in calling clojure core functions defined in clojure plugin, as well as loading new functions and namespaces from clojuredev plugin. I think the best solution is to use bundles class loader inside clojure class loading system. I developed a proof of concept that uses a new class loader that extends clojure.lang.DynamicClassLoader with bundle class loading capability. To know which bundle use to load classes or script file the class loader uses the current namespace which has to reflect the bundle name (this is the java convention for bundles). In order to use this new class loader I had to modified clojure.lang.RT#baseLoader and makeClassLoader and clojure.lang.core#import. Moreover to test this I made a experimental Eclipse Builder that enable AOT compilation of mixed clojure and java plugin. So far it seems to work well: clojure and java interact seamlessly and it is very fun to interact dynamically with an Eclipse instance! I had some questions to the clojure community: * Whether it is possible to overload clojure class loading without introducing dependencies in clojure's core? * If their are some people interested in this application of clojure? (I can made my sources available) We currently don't have made the AOT version of the eclipse builder, so if you could publish what you've done so far that would be great, because we could work on it, or it could give us some hints to make our own. Is it possible for you to publish it, maybe via the EPL, which seems to be the 'defacto' Open source license to use when creating code around clojure ? Regards, -- Laurent Moreover I will made a post on Eclipse E4 project mailing list (work on the future of Eclipse) as they are very interested in dynamic languages. BR, Gaetan --~--~-~--~~~---~--~~ 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 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: Binding values in a list of symbols and evaluating as code
On Jan 23, 2009, at 16:20, Zak Wilson wrote: that appear in these lists and evaluate them as code. My current technique looks like this: (def a) (def b) (defn try-rule [r val-a val-b] (binding [a val-a b val-b] (eval r))) and an example call looks like: (try-rule '(+ a b) 2 4) I know that calls to eval are discouraged outside of writing something like a REPL. Depending on how flexible your code generator has to be, this may be the only way to do it, which only shows that eval has its good uses, even if they are few in number. One approach without eval, but also a less flexible one, would use rules made up of functions instead of arbitrary expression forms. You would then have something like (try-rule + 2 4) meaning that the first argument, the function +, is applied to the remaining ones: (defn try-rule [f args] (apply f args)) You can have a more complex, but still rigid, definition of rules, e.g. (try-rule f g 2 6 4 h 1 9) meaning apply f to the results of calling g and h, where g is a function of two arguments (as indicated by the 2 following g) and h a function of one argument. If you can come up with some scheme general enough for all your rules, this approach is likely to be safer and more efficient than the one using eval. Konrad. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
IntelliJ Plugin Pre-Alpha 0.03 Available
For those who like IntelliJ, a new version of the plugin is available. This one has numerous fixes, but is mostly interesting because the Debugger and Profiler work (or at least JProfiler). The Debugger and Profiler currently treat Clojure as compiled Java, and don't know how to go from byte code location to source code. But there is enough information that one can figure out what is going on. Note that Mac users still have to build it themselves. If someone would build it, so we can post a Mac jar that would be great. http://code.google.com/p/clojure-intellij-plugin/ Enjoy! P --~--~-~--~~~---~--~~ 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 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: IntelliJ Plugin Pre-Alpha 0.03 Available
Hello, Could you place some screenshots in a wiki page ? I'm too lazy to install IntelliJ yet, but maybe with some appealing screenshots I could change my mind ;-) Thanks, -- Laurent 2009/1/23 Peter Wolf opus...@gmail.com For those who like IntelliJ, a new version of the plugin is available. This one has numerous fixes, but is mostly interesting because the Debugger and Profiler work (or at least JProfiler). The Debugger and Profiler currently treat Clojure as compiled Java, and don't know how to go from byte code location to source code. But there is enough information that one can figure out what is going on. Note that Mac users still have to build it themselves. If someone would build it, so we can post a Mac jar that would be great. http://code.google.com/p/clojure-intellij-plugin/ Enjoy! P --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Installing SLIME and friends
So I've noticed one of the most common questions in #clojure from beginners is how to install SLIME. Working with SLIME can be messy work[1], so I've written some functionality to help out with that. If you check out my installer branch of clojure-mode[2] you can see the clojure-install command that checks out clojure, clojure-contrib, slime, and swank-contrib, then configures Emacs to use these libraries. I've tested it and it works fine on my machine, but I'm wondering a couple things: 0) Would it be a useful thing to include in mainline clojure-mode to get beginners started? It's rather unconventional, but it seems like it could address a very common problem. 1) How well does it work for others? -Phil [1] - har har. [2] - http://github.com/technomancy/clojure-mode/blob/0f28b61de90ce8a09d75bf1668ef3f1c200f9c52/clojure-mode.el#L560 --~--~-~--~~~---~--~~ 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 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: Streams work
people who love doing stream processing would attack an extra allocation. On Fri, Jan 23, 2009 at 12:09 PM, Konrad Hinsen konrad.hin...@laposte.netwrote: On Jan 23, 2009, at 14:04, Rich Hickey wrote: Then why not make a pipeline using lazy sequences right from the start? I don't see anything that I could do better with streams than with lazy sequences. There are a couple of advantages. First, streams are faster, at least 2x faster. Since a lazy sequence must allocate per stage, a multi- stage pipeline would incur multiple allocations per step. A stream could be built that has no allocation other than the results. If your calculations per step are significant, they'll dominate the time. but when they are not, this allocation time matters. Second, streams are fully lazy. Seqs could be made fully lazy, but currently are not. Third, stream iters currently provide transparent MT access. Doing the same for a seq means wrapping it in a ref. Thanks for those explanations, that makes a lot of sense. I just wonder about the performance aspect. If I have a pipeline stage with very little computational cost, say adding 1 to every element, the I would expect the overhead of the iter layer and the thread-safeness to dominate CPU time anyway. Does an allocation really add that much on top of that that it makes a difference? Konrad. --~--~-~--~~~---~--~~ 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 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: A nil puzzle
On Jan 23, 7:34 am, Stephen C. Gilardi squee...@mac.com wrote: There was a recent suggestion here: http://groups.google.com/group/clojure/msg/32d323e15f8ce624 about the proper value of: (clojure.contrib.lazy-seqs/combinations) (and perhaps by extension (clojure.contrib.lazy-seqs/combinations '()) (or any number of empty seq arguments)) No no no :). (combinations '()) should be nil/empty coll, but (combinations) should be a [[]] (or any coll/seq containing only an nil/empty coll, I don't care which types). This can be argued several ways, but the clearest is to think about the length of the sequence returned by combinations. It should be the product of the lengths of the input sequences. Thus, if any of the inputs to combinations are empty lists, (* ? 0 ? ?) == 0, the return value should be nil. But, if the input is *no lists at all*, then we have (*) == 1 and the output should be a list containing the empty list. Does a decision to use empty collections in the powerset case fit well with the suggestion that (clojure.contrib.lazy-seqs/combinations) return ([]) or are they in conflict or unrelated? Well, you can reason in the same way about power-set; if the input has n elements, the output should have 2^n elements. Thus, (power-set nil) should return [[]] as well (or, again, any coll/seq containing only an empty coll/seq, I don't care which type). Or, you could just look at Wiki: the power set of the empty set is the set containing the empty set http://en.wikipedia.org/wiki/Power_set -Jason --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
newbie Q: what's wrong with this?
Hi, I got the following and don't know what's wrong with it. thanks in advance. user= (defn sum [ more ] ((fn [total other] (if other (recur (+ total (first other)) (rest(other))) total)) 0 more)) #'user/sum user= (sum [1 2 3 4]) java.lang.ClassCastException: clojure.lang.LazilyPersistentVector cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) --~--~-~--~~~---~--~~ 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 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: Another socket repl
Craig McDaniel craig...@gmail.com writes: I wonder if it wouldn't be a good idea to move the call to binding fromsocket-replinto accept-fn. It seems like a reasonable default to rebind *in* and *out* for the duration of the accepting function; the example uses this as does my application. I'm not sure that rebinding *in* and *out* is something that every socket server app would want to do. And couldn't it interfere with debugging? You may not want that println you put in there for debugging to go out the socket to the other side. Well, I think the rebinding should be what _most_ users of the function should want to do rather than _every_ use. The atypical uses can require a little more work if it streamlines the common cases IMHO. You could always write to *err* for debugging. But I guess I can't assume my own use of the function is all that typical. -Phil --~--~-~--~~~---~--~~ 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 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: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?
Just to clarify: I dont' care what the type of the output is. I guess (seq [[]]) would actually be more consistent with the existing function. The point is that the output of 0-arg combinations should be a seq containing an empty vector (or whatever other types, I don't care), not an empty seq. Anyone willing to sign off?? On Jan 21, 5:34 pm, Jason Wolfe jawo...@berkeley.edu wrote: I just got bit by (clojure.contrib.lazy-seqs/combinations) returning nil, not [[]] as I expected. I could see arguments for either being the correct output, but let me give my case for [[]]. In my mind, asking what the output of (combinations) should be is completely analogous to asking what the value of 0^0 should be. Either 0 or 1 seems defensible, but the accepted answer is 1 (for reasons I won't go into here). Similarly, Clojure (*) == 1. If you don't see the connection, note that for all non-empty seqs of seqs args, (= (count (apply combinations args)) (apply * (map count args))). If (= (combinations) [[]]), then this would hold always. Plus, this is what would make it work in my application. I can go into more details if you like, but the basic idea use case is finding the set of all allowed variable bindings, given a possible set of possible values for each variable. If there are no variables, this set should consist of the single empty binding rather than no bindings possible. Will anyone sign off on adding this as a clojure.contrib issue? Thanks, Jason --~--~-~--~~~---~--~~ 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 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: newbie Q: what's wrong with this?
Thanks Jason. Anyway I'd like to have (sum) returns 0 so I used [ more]. Is there any way to specify 0 or more args? -sun On Jan 23, 12:49 pm, Jason Wolfe jawo...@berkeley.edu wrote: Two mistakes: First, if you want sum to take a vector, you should remove the from the arglist. Second, (rest(other)) should be (rest other). This buys you: user (defn sum [more ] ((fn [total other] (if other (recur (+ total (first other)) (rest other)) total)) 0 more)) #'user/sum user (sum [1 2 3 4]) 10 (of course, sum could also be defined as just (apply + more) or (reduce + more)). -Jason --~--~-~--~~~---~--~~ 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 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: evalOnlyDefs
On Jan 23, 2009, at 11:52 AM, Konrad Hinsen wrote: Some questions this raises: - Should libs be restricted to definitions (and lib support things like ns and (some kind of) load-resource) only? - Should the appearance of an ns form automatically make that restriction enforced for the rest of this file (as it's being loaded). That would require an operational definition of what counts as a definition, which moreover can be verified by the compiler. I am not sure that is realistic. Pretty much any Clojure function except for I/O can be used in definitions, so your suggestion comes down to making the compiler recognize any attempt to do I/O, even indirectly, and even then make an exception for things like load-file. Good point. I had been thinking mostly of definition of functions where in the simple case, all actual operation is deferred until the function is called. One basic way to view what counts as a definition is something that ultimately invokes def. On the way to invoking def, one could also allow compiling code, but not running it, deferring initializers until some kind of load time. Macros present a problem with this strategy, of course, and I gather they're the primary reason why code has to be loaded as well as compiled in Clojure's same world compilation process currently. Would some kind of Java sandbox to compile in be an effective way to implement a (macroscopically) more functional way to use the existing compiler to accomplish goals along these lines? Certainly if a different JVM instance were used, that should be an effective way to separate what happens at compile time from the operation of Clojure instance supporting an IDE session. The familiar compile/load/run separation in Java and C++ (where compile is purely functional and load calls static initializers) has some nice benefits. I'm guessing if it were easy to accomplish with Clojure, Rich might have gone that way initially. As a guideline your suggestions seem fine though. I wouldn't like to work with libraries whose mere import does something magical. Thanks. - Do we need a mechanism like java's main method where we could put any scripting code (things intended to do something when the lib is used as a script) rather than allowing non-definitions everywhere? We could by convention call a particularly named function or we could provide the name (or signature?) of a designated function in the ns form and call that when calling (effectively) a namespace as a program rather than using it as a library: (ns my-simulator (:require 'clojure.contrib.lazy-seqs) (:main do-simulation [circuit inputs])) That sounds nice. One further thought on that is that an argument to :main should probably just be a name rather than a name and argument list because the argument list(s) will already appear along with the defn of the name. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?
On Jan 23, 2009, at 12:53 PM, Jason Wolfe wrote: Just to clarify: I dont' care what the type of the output is. I guess (seq [[]]) would actually be more consistent with the existing function. The point is that the output of 0-arg combinations should be a seq containing an empty vector (or whatever other types, I don't care), not an empty seq. Anyone willing to sign off?? Please do enter it as an issue. I'd be interested in hearing from Chouser before making the change. He added combinations to lazy-seqs. Thanks! --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Basic about setting upp Clojure and editor enviroment
Thanks for clojure-dev that was exaktly what i was looking for. I have first a problem get it running, the reason was i download EasyEclipse-JavaDesktop on Vista it have problem both with clojure-dev and internal update, and still i dide't install it in Program Files I removed it and download Normal Version and added clojure-dev I found 1 thing, if i make a error in my code the process hangs after error and a have to press STOP button this was a suprice becurse i could not find way my correction in the code didn't got thure, may this is a Eclipse way. // Anders On 23 Jan, 13:33, Peter Wolf opus...@gmail.com wrote: Or try the IntelliJ plugin, if you like that IDE http://code.google.com/p/clojure-intellij-plugin/ It works fine on Windows and Linux. We are currently fixing the Mac. P Matt Clark wrote: If you're not already an emacs user, I found it can be quite the learning curve getting into it. So I'd recommend you also give the eclipse clojure-dev plugin a shot. It now has a REPL, namespace browser, syntax highlighting, etc and works fine on windows. http://code.google.com/p/clojure-dev/ On Jan 21, 10:05 am, anderspe anders.u.pers...@gmail.com wrote: Hello, i am waiting for the book Programming Clojure by Stuart Halloway, I have set upp a enviroment that i can run a REPL and load script. But i am looking for som basic info about sett upp interaction to a editor, EMACS or... I have tryed Plugin to Netbeans but it was Alpha and have som problem running Windows. Tutorials, Links, tips would be nice // Anders --~--~-~--~~~---~--~~ 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 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: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?
On Jan 23, 2009, at 1:11 PM, Stephen C. Gilardi wrote: I'd be interested in hearing from Chouser before making the change. He added combinations to lazy-seqs. I think it's quite cool that simply removing the when accomplishes this. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Embed Clojure in OSGi Bundles
Hello Laurent, thank you for your interest. 2009/1/23 Laurent PETIT laurent.pe...@gmail.com Hello Gaetan, I'm one of the core developers of clojuredev, an open source project whose goal is to provide clojure support for the Eclipse IDE. What you say below is interesting, please see what I have noted inline -- 2009/1/23 gaetan gaetan.mor...@gmail.com Hi everybody, I am working in a software company specialized in Eclipse based product development (and member of the Eclipse Fundation). We are very interesting in clojure features and we plan to use it in some of our products. I am currently working on clojure integration in OSGi Bundles in order to embed code in Eclipse plugins. As mentioned in some posts the biggest problems is class loading. Indeed in OSGi each bundle has its own class loader and class loading is not based on the application classpath or on the current thread class loader. Consequently, it is very difficult to make clojure work with java code and to use OSGi visibility and dependencies system inside clojure. For mere mortals like me, could you explain the problem via an example ? (I understand there is a problem, I don't exactly understand what it really is) Concerning clojuredev, we provide clojure as a separate plugin, which exposes everything to plugins that depend on it. Currently, clojuredev plugin is successful in calling clojure core functions defined in clojure plugin, as well as loading new functions and namespaces from clojuredev plugin. I will try to give an example (I hope it will be understandable). First has you may now in OSGi (and therefor in Eclipse) each bundle declare its dependencies toward others in the MANIFEST.MF file. If you are developing a bundle a that needs a class in a bundle b you have to update the MANIFEST.MF file of a to said that it depends on b and b has to export the package that contains the class (this information is in the MANIFEST.MF file of b). Under the hood, each bundle has its own class loader that is fully aware of the dependencies and export of the plugin. So in the example above, at runtime the class loader of a will be able to use the class loader of b (thanks to the dependency declaration) and this one will be able to load the class for an external bundle (thanks to the export declaration). Now if you want to use clojure code in your OSGi instead of java. First you will embed clojure core in a specific bundle called c. You write a clojure lib in a that use another clojure lib in b. What will happen? To load code of b the lib in a will use the use (or require) function of clojure core. This function use a specific class loader (called DynamicClassLoader) that use the class path of the bootstrapping thread. However this class path is not aware of the bundles inside the application and so the clojure class loader will not be able to find the lib in b. Another case is if you want to use clojure code in a that use java code in b. In this case clojure code use the import function of clojure core. This function use the Class#forName method that is based on the caller class loader. In this case the caller is clojure core and so its class loader is the class loader of c. As this class loader as no dependencies toward b, it will not be able to load the java class. As you can see the problem is a little tricky :-). That's why I think the best way to use clojure in OSGi bundles is to enable clojure to use bundles' class loader, it is flawless and understandable as it mimics java behavior. To do this I use clojure namespaces. In the example above the clojure lib in a must have a namespace that start with a so the clojure class loader can find and use the class loader of bundle a to load its dependencies. I think the best solution is to use bundles class loader inside clojure class loading system. I developed a proof of concept that uses a new class loader that extends clojure.lang.DynamicClassLoader with bundle class loading capability. To know which bundle use to load classes or script file the class loader uses the current namespace which has to reflect the bundle name (this is the java convention for bundles). In order to use this new class loader I had to modified clojure.lang.RT#baseLoader and makeClassLoader and clojure.lang.core#import. Moreover to test this I made a experimental Eclipse Builder that enable AOT compilation of mixed clojure and java plugin. So far it seems to work well: clojure and java interact seamlessly and it is very fun to interact dynamically with an Eclipse instance! I had some questions to the clojure community: * Whether it is possible to overload clojure class loading without introducing dependencies in clojure's core? * If their are some people interested in this application of clojure? (I can made my sources available) We currently don't have made the AOT version of the eclipse builder, so if you could publish what you've done so far that would be great,
bug? tree-seq assumes the root is a branch
tree-seq assumes the root is a branch: user= (tree-seq (constantly false) seq [1 2 3]) ([1 2 3] 1 2 3) ; I expected ([1 2 3]) Is this a bug? Christophe --~--~-~--~~~---~--~~ 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 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: bug? tree-seq assumes the root is a branch
Christophe Grand a écrit : tree-seq assumes the root is a branch: user= (tree-seq (constantly false) seq [1 2 3]) ([1 2 3] 1 2 3) ; I expected ([1 2 3]) Is this a bug? I know it's documented but I don't understand why. --~--~-~--~~~---~--~~ 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 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: newbie Q: what's wrong with this?
Hi Wubble, Looking at the code you have above I thought I might point out that rather than create an anonymous function inside of sum and then call it immediately after finishing its description, you could just use the loop/recur construct which is much more idiomatic clojure code. If you decide to go that route, your code would look like the following: (defn sum [ more] (loop [total 0 other more] (if other (recur (+ total (first other)) (rest other)) total))) loop essentially works the same as the anonymous function you've got in your sum function, but it allows you to set the parameters when you define the loop just as you would in a let. Then when you call recur, the code within the loop is called again, but this time with the bindings that you supply to the recur statement. This just shortens the code you wrote and makes it a bit more understandable. Of course, Jason's suggestions above of using the apply method or 'folding' the list with the reduce command is the most straightforward (and, I assume, most performant) method for computing the sum, outside of just using the '+' function directly of course ;-) To execute the function above you could either use (sum 1 2 3 4 5) or---if you are absolutely dead set on passing a vector to the function---you could use (apply sum [1 2 3 4 5]). Hope that helps. Christopher --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Regarding (.keySet {:a :map})
I type this expression in the REPL (trunk 1228): user= (let [s (.keySet {:a 1})] [(set? s) (ifn? s)]) [false false] But I expected it to return [true true]. Is this an oversight, or is there a good reason for this behavior? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Printing Strings in Lists
Below are two operations that print (1 2 3 4). How can I do something similar to print (1 2 3 4) to standard out? (println '(1 2 3 4)) - (1 2 3 4) (def x 1 2 3) (println `(~x 4)) - (1 2 3 4) --Kevin Albrecht --~--~-~--~~~---~--~~ 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 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: newbie Q: what's wrong with this?
Clojure supports functions with multiple arities (http://clojure.org/ functional_programming). Assuming you don't actually care if you call the function with a vector, you can do something like this: (defn sum ([] 0) ([acc r] (if (nil? r) acc (recur (+ acc (first r)) (rest r) Not sure if that is precisely what you want or not. On Jan 23, 9:58 am, wubbie sunj...@gmail.com wrote: Thanks Jason. Anyway I'd like to have (sum) returns 0 so I used [ more]. Is there any way to specify 0 or more args? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Possible feature: consider aliases when reading namespace-qualified keywords.
On Jan 19, 4:29 pm, Jason Wolfe jawo...@berkeley.edu wrote: I've been doing some OO-type Clojure programming, and have run into the following (quite minor) annoyance: I've defined a struct with a :class of ::Foo in namespace my.long.namespace.foo. In another namespace my.long.namespace.bar, I want to define a subclass of this struct. In this namespace, I require [...foo :as foo], so that I can refer to multimethods like foo/method1. However, it seems I'm still required to write (derive ::Bar :my.long.namespace.foo/Foo) when I'd like to write (derive ::Bar :foo/Foo) On IRC, duck1123 just showed me that this is already implemented; you just have to use the :: form. (derive ::Bar ::foo/Foo) You learn something new every day... -Jason --~--~-~--~~~---~--~~ 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 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: Printing Strings in Lists
prn On Fri, Jan 23, 2009 at 11:00 AM, Kevin Albrecht onlya...@gmail.com wrote: Below are two operations that print (1 2 3 4). How can I do something similar to print (1 2 3 4) to standard out? (println '(1 2 3 4)) - (1 2 3 4) (def x 1 2 3) (println `(~x 4)) - (1 2 3 4) --Kevin Albrecht -- 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 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 -~--~~~~--~~--~--~---
reader macros
Are all of these considered reader macros? ; (comment) @ (deref) ^ (get metadata) #^ (add metadata) ' (quote) #... (regex) ` (syntax quote) ~ (unquote) ~@ (unquote splicing) #' (var quote) #{...} (set) #(...) (anonymous function) Is it correct that these are not considered reader macros? \ (character literal) , (readability whitespace) [...] (vector) {...} (map) (in arg list to gather a variable number of them) Did I miss any? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Printing Strings in Lists
Ah, exactly what I was looking for, thanks. On Jan 23, 11:15 am, Kevin Downey redc...@gmail.com wrote: prn On Fri, Jan 23, 2009 at 11:00 AM, Kevin Albrecht onlya...@gmail.com wrote: Below are two operations that print (1 2 3 4). How can I do something similar to print (1 2 3 4) to standard out? (println '(1 2 3 4)) - (1 2 3 4) (def x 1 2 3) (println `(~x 4)) - (1 2 3 4) --Kevin Albrecht -- 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 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: Streams work
I work for NVIDIA doing 3d graphics engines and editor platforms on both PC and embedded platforms. Konrad, the extra memory allocation is often the difference between something fitting inside a cache line on a CPU and hitting main ram. Last time I looked, I believe the difference is a factor of 100. This is exacerbated on embedded platforms such as ARM where your on-chip cache is anemic and you CPU is still quite bandwidth starved in terms of main-memory. The inability to exactly position datasets in memory is the key performance difference between c++ and java in my book. Creating some piece of information lazily that sits outside my current dataset for no reason is absolutely not acceptable. I have pretty full confidence that I could produce a java-based graphics runtime that would work fine on most cell-phones, android or otherwise and produce graphics on par with anything currently done in C or any other language *if* I can pack objects into distinct contiguous blocks of memory that I will then run through and sequentially access each render step. Currently Java doesn't give me this ability (for no obvious reason) and thus I can't easily produce very performant code. Lazy sequences hurt my limited ability (due to their extra memory allocation) to control memory layout and access semantics of what I am doing and thus have an extremely serious impact on what I am doing. C# and Mono, btw, do allow this as their generics implementation is allows their struct datatypes in lists. Should clojure provide a wrapper on the trusty old int array that allows me to use it like an array of structures then we would be at least halfway there, assuming I could force JVM to put the array into contiguous memory. Closures and runtime-generated code in general, btw, represent a possible way for me to beat a C based runtime as I can create specialized functions instead of having a bunch of branches and if- statements. So there is a tradeoff going the other way. Anyway, any extra memory allocation I don't specifically require is going to have severe impacts if I can't disable it. So streams fit the bill *much* better than lazy seqs. I am apparently someone who loves doing stream processing. Chris On Jan 23, 10:34 am, e evier...@gmail.com wrote: people who love doing stream processing would attack an extra allocation. On Fri, Jan 23, 2009 at 12:09 PM, Konrad Hinsen konrad.hin...@laposte.netwrote: On Jan 23, 2009, at 14:04, Rich Hickey wrote: Then why not make a pipeline using lazy sequences right from the start? I don't see anything that I could do better with streams than with lazy sequences. There are a couple of advantages. First, streams are faster, at least 2x faster. Since a lazy sequence must allocate per stage, a multi- stage pipeline would incur multiple allocations per step. A stream could be built that has no allocation other than the results. If your calculations per step are significant, they'll dominate the time. but when they are not, this allocation time matters. Second, streams are fully lazy. Seqs could be made fully lazy, but currently are not. Third, stream iters currently provide transparent MT access. Doing the same for a seq means wrapping it in a ref. Thanks for those explanations, that makes a lot of sense. I just wonder about the performance aspect. If I have a pipeline stage with very little computational cost, say adding 1 to every element, the I would expect the overhead of the iter layer and the thread-safeness to dominate CPU time anyway. Does an allocation really add that much on top of that that it makes a difference? Konrad. --~--~-~--~~~---~--~~ 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 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: Basic about setting upp Clojure and editor enviroment
2009/1/23 anderspe anders.u.pers...@gmail.com Thanks for clojure-dev that was exaktly what i was looking for. I have first a problem get it running, the reason was i download EasyEclipse-JavaDesktop on Vista it have problem both with clojure-dev and internal update, and still i dide't install it in Program Files I removed it and download Normal Version and added clojure-dev I found 1 thing, if i make a error in my code the process hangs after error and a have to press STOP button this was a suprice becurse i could not find way my correction in the code didn't got thure, may this is a Eclipse way. I'm not sure I understand correctly. Did you encounter the problem in the REPL ? If so, I think that's nothing special to clojure-dev, but due to the fact that clojure reader was still waiting for the current s-expr to be terminated (e.g. by a closing paren, a closing doublequote ..) ? // Anders On 23 Jan, 13:33, Peter Wolf opus...@gmail.com wrote: Or try the IntelliJ plugin, if you like that IDE http://code.google.com/p/clojure-intellij-plugin/ It works fine on Windows and Linux. We are currently fixing the Mac. P Matt Clark wrote: If you're not already an emacs user, I found it can be quite the learning curve getting into it. So I'd recommend you also give the eclipse clojure-dev plugin a shot. It now has a REPL, namespace browser, syntax highlighting, etc and works fine on windows. http://code.google.com/p/clojure-dev/ On Jan 21, 10:05 am, anderspe anders.u.pers...@gmail.com wrote: Hello, i am waiting for the book Programming Clojure by Stuart Halloway, I have set upp a enviroment that i can run a REPL and load script. But i am looking for som basic info about sett upp interaction to a editor, EMACS or... I have tryed Plugin to Netbeans but it was Alpha and have som problem running Windows. Tutorials, Links, tips would be nice // Anders -- Cordialement, Laurent PETIT --~--~-~--~~~---~--~~ 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 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: Embed Clojure in OSGi Bundles
OK, I understand better now, I think. Did you experience the problems you have exposed ? Or is it an anticipation of problems ? If so, can you expose the tests data, so that one can also experiment with them ? 2009/1/23 Gaetan Morice gaetan.mor...@gmail.com Hello Laurent, thank you for your interest. 2009/1/23 Laurent PETIT laurent.pe...@gmail.com Hello Gaetan, I'm one of the core developers of clojuredev, an open source project whose goal is to provide clojure support for the Eclipse IDE. What you say below is interesting, please see what I have noted inline -- 2009/1/23 gaetan gaetan.mor...@gmail.com Hi everybody, I am working in a software company specialized in Eclipse based product development (and member of the Eclipse Fundation). We are very interesting in clojure features and we plan to use it in some of our products. I am currently working on clojure integration in OSGi Bundles in order to embed code in Eclipse plugins. As mentioned in some posts the biggest problems is class loading. Indeed in OSGi each bundle has its own class loader and class loading is not based on the application classpath or on the current thread class loader. Consequently, it is very difficult to make clojure work with java code and to use OSGi visibility and dependencies system inside clojure. For mere mortals like me, could you explain the problem via an example ? (I understand there is a problem, I don't exactly understand what it really is) Concerning clojuredev, we provide clojure as a separate plugin, which exposes everything to plugins that depend on it. Currently, clojuredev plugin is successful in calling clojure core functions defined in clojure plugin, as well as loading new functions and namespaces from clojuredev plugin. I will try to give an example (I hope it will be understandable). First has you may now in OSGi (and therefor in Eclipse) each bundle declare its dependencies toward others in the MANIFEST.MF file. If you are developing a bundle a that needs a class in a bundle b you have to update the MANIFEST.MF file of a to said that it depends on b and b has to export the package that contains the class (this information is in the MANIFEST.MF file of b). Under the hood, each bundle has its own class loader that is fully aware of the dependencies and export of the plugin. So in the example above, at runtime the class loader of a will be able to use the class loader of b (thanks to the dependency declaration) and this one will be able to load the class for an external bundle (thanks to the export declaration). Now if you want to use clojure code in your OSGi instead of java. First you will embed clojure core in a specific bundle called c. You write a clojure lib in a that use another clojure lib in b. What will happen? To load code of b the lib in a will use the use (or require) function of clojure core. This function use a specific class loader (called DynamicClassLoader) that use the class path of the bootstrapping thread. However this class path is not aware of the bundles inside the application and so the clojure class loader will not be able to find the lib in b. Another case is if you want to use clojure code in a that use java code in b. In this case clojure code use the import function of clojure core. This function use the Class#forName method that is based on the caller class loader. In this case the caller is clojure core and so its class loader is the class loader of c. As this class loader as no dependencies toward b, it will not be able to load the java class. As you can see the problem is a little tricky :-). That's why I think the best way to use clojure in OSGi bundles is to enable clojure to use bundles' class loader, it is flawless and understandable as it mimics java behavior. To do this I use clojure namespaces. In the example above the clojure lib in a must have a namespace that start with a so the clojure class loader can find and use the class loader of bundle a to load its dependencies. Thanks, I now see what you mean. I think the best solution is to use bundles class loader inside clojure class loading system. I developed a proof of concept that uses a new class loader that extends clojure.lang.DynamicClassLoader with bundle class loading capability. To know which bundle use to load classes or script file the class loader uses the current namespace which has to reflect the bundle name (this is the java convention for bundles). In order to use this new class loader I had to modified clojure.lang.RT#baseLoader and makeClassLoader and clojure.lang.core#import. Moreover to test this I made a experimental Eclipse Builder that enable AOT compilation of mixed clojure and java plugin. So far it seems to work well: clojure and java interact seamlessly and it is very fun to interact dynamically with an Eclipse instance! I had some questions to the clojure community: * Whether it is possible to
Not nil and 'true' with conditional functions
Here is some code, my question relates to '(not (nil?...': (if (not (nil? (regex-search-keyword (regex-get-text) line))) (add-select-style styles-vec all-bold) (add-select-style styles-vec light))) Could I have done the following or is (not (nil? ... a better approach. (if (regex-search-keyword (regex-get-text) line))) What are the differences between the two. --~--~-~--~~~---~--~~ 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 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: Not nil and 'true' with conditional functions
The only two false values in Clojure are false and nil. Everything else is logically true. If your function returns nil/false or a result, you don't need (not (nil? (...))) On Jan 23, 2:59 pm, BerlinBrown berlin.br...@gmail.com wrote: Here is some code, my question relates to '(not (nil?...': (if (not (nil? (regex-search-keyword (regex-get-text) line))) (add-select-style styles-vec all-bold) (add-select-style styles-vec light))) Could I have done the following or is (not (nil? ... a better approach. (if (regex-search-keyword (regex-get-text) line))) What are the differences between the two. --~--~-~--~~~---~--~~ 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 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: Not nil and 'true' with conditional functions
Is every function supposed to return something? Of course, except for pure side-effects. -sun On Jan 23, 3:02 pm, Vincent Foley vfo...@gmail.com wrote: The only two false values in Clojure are false and nil. Everything else is logically true. If your function returns nil/false or a result, you don't need (not (nil? (...))) On Jan 23, 2:59 pm, BerlinBrown berlin.br...@gmail.com wrote: Here is some code, my question relates to '(not (nil?...': (if (not (nil? (regex-search-keyword (regex-get-text) line))) (add-select-style styles-vec all-bold) (add-select-style styles-vec light))) Could I have done the following or is (not (nil? ... a better approach. (if (regex-search-keyword (regex-get-text) line))) What are the differences between the two. --~--~-~--~~~---~--~~ 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 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: Proposal: smarter set operations that take size into account for speed
OK, if these are not wanted in core right now, will anyone sign off for adding them to clojure.contrib? I can't say I like the idea of having two sets of functions that do exactly the same thing, but ... sometimes you just don't want things to run ~1000 times slower than they should. -Jason --~--~-~--~~~---~--~~ 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 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: IntelliJ Plugin Pre-Alpha 0.03 Available
I installed it and it works really well, -- thanks to the authors for their work. btw, I installed it directly on my mac, without building it. Francesco On Jan 23, 6:08 pm, Peter Wolf opus...@gmail.com wrote: For those who like IntelliJ, a new version of the plugin is available. This one has numerous fixes, but is mostly interesting because the Debugger and Profiler work (or at least JProfiler). The Debugger and Profiler currently treat Clojure as compiled Java, and don't know how to go from byte code location to source code. But there is enough information that one can figure out what is going on. Note that Mac users still have to build it themselves. If someone would build it, so we can post a Mac jar that would be great. http://code.google.com/p/clojure-intellij-plugin/ Enjoy! P --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
contains
This must be something I learned months ago and then forgot ... embarassing! What's the easiest way to determine if a sequence contains a given value? I thought there would be something like this: (include? [2 4 7] 4) - true That doesn't exist. I know I can do this: (some #{4} [2 4 7]) Having to create a set seems overkill. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote: This must be something I learned months ago and then forgot ... embarassing! What's the easiest way to determine if a sequence contains a given value? I thought there would be something like this: (include? [2 4 7] 4) - true That doesn't exist. I know I can do this: (some #{4} [2 4 7]) Having to create a set seems overkill. user= (contains? [1 2 3] 1) true --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 3:39 PM, Justin Johnson ajustinjohn...@gmail.com wrote: On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: This must be something I learned months ago and then forgot ... embarassing! What's the easiest way to determine if a sequence contains a given value? I thought there would be something like this: (include? [2 4 7] 4) - true That doesn't exist. Sure it does: user= (require 'clojure.contrib.seq-utils) nil user= (clojure.contrib.seq-utils/includes? [2 4 7] 4) true :-) I know I can do this: (some #{4} [2 4 7]) Having to create a set seems overkill. It's not! It's beautiful and succinct. And it let's you test for any of several values, and then tells you which it found: user= (some #{3 4 5} [2 4 7]) 4 user= (contains? [1 2 3] 1) true This is doing something different: user= (contains? [2 4 7] 7) false That's telling you that the vector has no value at index 7. The docs try to explain this: user= (doc contains?) - clojure.core/contains? ([coll key]) Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'. --Chouser --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 2:39 PM, Justin Johnson ajustinjohn...@gmail.com wrote: On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: This must be something I learned months ago and then forgot ... embarassing! What's the easiest way to determine if a sequence contains a given value? I thought there would be something like this: (include? [2 4 7] 4) - true That doesn't exist. I know I can do this: (some #{4} [2 4 7]) Having to create a set seems overkill. user= (contains? [1 2 3] 1) true That doesn't do what you think it does. For example, (contains? [2 4 7] 4) - false The doc string includes this: Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. So it doesn't compare the values. I'd like to use it with strings like this to determine if a letter is a vowel: (contains? aeiou letter) but that doesn't work either. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: License of/permission for Clojure's logo
And Rich Hickey writes: You can use the logo on the wikipedia article on Clojure, but only if you spell my name correctly :) May I use the logo for the identi.ca group? ( http://identi.ca/group/clj ) Jason --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: (contains? aeiou letter) but that doesn't work either. user= (some (set aeiou) dn'tndthsstinkngvwls) \i Or, if you must, user= (clojure.contrib.seq-utils/includes? aeiou \o) true --Chouser --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 2:45 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 3:39 PM, Justin Johnson ajustinjohn...@gmail.com wrote: On Fri, Jan 23, 2009 at 2:32 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: This must be something I learned months ago and then forgot ... embarassing! What's the easiest way to determine if a sequence contains a given value? I thought there would be something like this: (include? [2 4 7] 4) - true That doesn't exist. Sure it does: user= (require 'clojure.contrib.seq-utils) nil user= (clojure.contrib.seq-utils/includes? [2 4 7] 4) true :-) Thanks! It's too bad something this basic isn't in the core. I know I can do this: (some #{4} [2 4 7]) Having to create a set seems overkill. It's not! It's beautiful and succinct. And it let's you test for any of several values, and then tells you which it found: user= (some #{3 4 5} [2 4 7]) 4 Well ... I agree that it's beautiful and succinct IF you want to test multiple values. I just think there should be a simpler way to test for one value that is in the core. user= (contains? [1 2 3] 1) true This is doing something different: user= (contains? [2 4 7] 7) false That's telling you that the vector has no value at index 7. Yeah, I just figured that out while you were composing your reply. Thanks! -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Proposal: smarter set operations that take size into account for speed
On Fri, Jan 23, 2009 at 12:23 PM, Jason Wolfe jawo...@berkeley.edu wrote: OK, if these are not wanted in core right now, will anyone sign off for adding them to clojure.contrib? Well, *I* want these changes you've proposed in the core, but of course, I'm not in charge. I guess the real question is, what is the process to ensure that Rich sees and considers a potential core improvement like this? I think the main mechanism for this is to post it as an issue on google code, but I'm not certain whether you're supposed to post an issue unless he's seen the newsgroup thread and says, Yes, that sounds good, please post it as an issue. But if he misses the thread for some reason, that will never happen. So it's a bit of a catch-22. Anyway, maybe someone can clarify the procedure. --~--~-~--~~~---~--~~ 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 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: reader macros
On Fri, Jan 23, 2009 at 2:17 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Are all of these considered reader macros? [snip] Is it correct that these are not considered reader macros? I don't see any distinction made in the code: http://code.google.com/p/clojure/source/browse/trunk/src/jvm/clojure/lang/LispReader.java?r=1202#64 Why does it matter if it's called a reader macro or not? --Chouser --~--~-~--~~~---~--~~ 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 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: Proposal: smarter set operations that take size into account for speed
On Fri, Jan 23, 2009 at 2:52 PM, Mark Engelberg mark.engelb...@gmail.comwrote: On Fri, Jan 23, 2009 at 12:23 PM, Jason Wolfe jawo...@berkeley.edu wrote: OK, if these are not wanted in core right now, will anyone sign off for adding them to clojure.contrib? Well, *I* want these changes you've proposed in the core, but of course, I'm not in charge. I guess the real question is, what is the process to ensure that Rich sees and considers a potential core improvement like this? I think the main mechanism for this is to post it as an issue on google code, but I'm not certain whether you're supposed to post an issue unless he's seen the newsgroup thread and says, Yes, that sounds good, please post it as an issue. But if he misses the thread for some reason, that will never happen. So it's a bit of a catch-22. Anyway, maybe someone can clarify the procedure. In a previous thread Rich suggested that additions to clojure-contrib be discussed here and lacking any objections they should be posted as issues with attached patches on the clojure-contrib project. From what I've seen in the past clojure-contrib is the place for functions like the fast set operations discussed here. This gives people a chance to use them and identify any problems, etc before being considered for a move into clojure core. -- Cosmin Stejerean http://offbytwo.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 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: function that takes primitives?
Currently, there is no way to write a function that takes/returns primitives, all of the signatures are Object based. And please keep them so! Turtles all the way down solves many, many problems. For performance, whoever in need, just cache the int/float/double/etc. values locally. Albert -- Albert Cardona http://albert.rierol.net --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 2:51 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: (contains? aeiou letter) but that doesn't work either. user= (some (set aeiou) dn'tndthsstinkngvwls) \i Why does this work (some (set aeiou) e) but this doesn't (some #{aeiou} e) I thought (set ...) was equivalent to #{...}. Or, if you must, user= (clojure.contrib.seq-utils/includes? aeiou \o) true -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Binding values in a list of symbols and evaluating as code
It does seem like a legitimate use for eval, at least at first glance. The biggest problem is that using eval this way is really slow when each rule is being tested on hundreds of inputs. Interesting alternative, Konrad. I can probably take advantage of the fact that all of the functions I'm calling (unchecked math and bitwise operators) take exactly two arguments. I might give something like that a try. I'd rather not though, if I can avoid it. It seems like there ought to be a way to make a function out of a list of symbols that would be a valid function body and then call it repeatedly. I was playing around with that approach at first, but never managed to get it right. I strongly suspect creating a function once and calling it 400 times will be faster than calling eval 400 times. --~--~-~--~~~---~--~~ 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 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: contains
Hi Mark, set takes a single argument, a coll, and #{} is a literal form that can have a variable number of args. To make them equivalent: (set aeiou) - #{\a \e \i \o \u} #{(seq aeiou)} - #{(\a \e \i \o \u)} Stuart On Fri, Jan 23, 2009 at 2:51 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: (contains? aeiou letter) but that doesn't work either. user= (some (set aeiou) dn'tndthsstinkngvwls) \i Why does this work (some (set aeiou) e) but this doesn't (some #{aeiou} e) I thought (set ...) was equivalent to #{...}. Or, if you must, user= (clojure.contrib.seq-utils/includes? aeiou \o) true -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: contains
#{aeiou} is the set containing the String aeiou. You want #{\a \e \i \o \u} On Jan 23, 4:04 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 23, 2009 at 2:51 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 3:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: (contains? aeiou letter) but that doesn't work either. user= (some (set aeiou) dn'tndthsstinkngvwls) \i Why does this work (some (set aeiou) e) but this doesn't (some #{aeiou} e) I thought (set ...) was equivalent to #{...}. Or, if you must, user= (clojure.contrib.seq-utils/includes? aeiou \o) true -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: IntelliJ Plugin Pre-Alpha 0.03 Available
You are more than welcome. Enjoy! I am interested that it works on your Mac. Others have reported problems (but not with this particular JAR). What version of Mac and IntelliJ are you using? Peter Francesco Bellomi wrote: I installed it and it works really well, -- thanks to the authors for their work. btw, I installed it directly on my mac, without building it. Francesco On Jan 23, 6:08 pm, Peter Wolf opus...@gmail.com wrote: For those who like IntelliJ, a new version of the plugin is available. This one has numerous fixes, but is mostly interesting because the Debugger and Profiler work (or at least JProfiler). The Debugger and Profiler currently treat Clojure as compiled Java, and don't know how to go from byte code location to source code. But there is enough information that one can figure out what is going on. Note that Mac users still have to build it themselves. If someone would build it, so we can post a Mac jar that would be great. http://code.google.com/p/clojure-intellij-plugin/ Enjoy! P --~--~-~--~~~---~--~~ 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 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: evalOnlyDefs
On 23.01.2009, at 19:04, Stephen C. Gilardi wrote: is something that ultimately invokes def. On the way to invoking def, one could also allow compiling code, but not running it, deferring initializers until some kind of load time. Macros present a problem with this strategy, of course, and I gather they're the primary reason why code has to be loaded as well as compiled in Clojure's same world compilation process currently. How about something like (let [my-factor (* 3 (. Math sqrt 2) (. Math log 42.))] (defn foo [x] (* my-factor x))) where the let outside of the definition makes sure the constant factor is evaluated only once? Konrad. --~--~-~--~~~---~--~~ 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 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: contains
I'm trying to implement pig latin using only what's in core in the simplest way possible. Does anyone see a simpler way? I'm not happy with using three functions (some, set and str) to determine if a letter is a vowel. (defn pig-latin [word] (let [first-letter (first word)] (if (some (set aeiou) (str first-letter)) (str word ay) (str (subs word 1) first-letter ay (println (pig-latin red)) - edray (println (pig-latin orange)) - orangeay -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: contains
On Fri, Jan 23, 2009 at 4:04 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Why does this work (some (set aeiou) e) but this doesn't (some #{aeiou} e) I thought (set ...) was equivalent to #{...}. (hash-set ...) is equivalent to #{...} 'set' takes a single collection as an argument, which it will treat as a seq and pour into a hash-set, so above the string behaves as a seq of chars, and each char becomes an item in the set: user= (set aeiou) #{\a \e \i \o \u} On the other hand, hash-set and #{} expect several args, each of which becomes an item in the set: user= (hash-set aeiou) #{aeiou} --Chouser --~--~-~--~~~---~--~~ 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 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: reader macros
On Fri, Jan 23, 2009 at 3:00 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 23, 2009 at 2:17 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Are all of these considered reader macros? [snip] Is it correct that these are not considered reader macros? I don't see any distinction made in the code: http://code.google.com/p/clojure/source/browse/trunk/src/jvm/clojure/lang/LispReader.java?r=1202#64 Why does it matter if it's called a reader macro or not? I guess it doesn't matter when writing code. I'm just trying to make sure I grasp the terminology used in the documentation and reader macro is a term that appears often. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: Binding values in a list of symbols and evaluating as code
instead of using binding and eval, you can generate a (fn ) form, eval it, keep the result function stuffed away somewhere and apply it instead of calling eval all the time On Fri, Jan 23, 2009 at 1:10 PM, Zak Wilson zak.wil...@gmail.com wrote: It does seem like a legitimate use for eval, at least at first glance. The biggest problem is that using eval this way is really slow when each rule is being tested on hundreds of inputs. Interesting alternative, Konrad. I can probably take advantage of the fact that all of the functions I'm calling (unchecked math and bitwise operators) take exactly two arguments. I might give something like that a try. I'd rather not though, if I can avoid it. It seems like there ought to be a way to make a function out of a list of symbols that would be a valid function body and then call it repeatedly. I was playing around with that approach at first, but never managed to get it right. I strongly suspect creating a function once and calling it 400 times will be faster than calling eval 400 times. -- 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 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: Proposal: smarter set operations that take size into account for speed
On Fri, Jan 23, 2009 at 12:23 PM, Jason Wolfe jawo...@berkeley.edu wrote: OK, if these are not wanted in core right now, will anyone sign off for adding them to clojure.contrib? Well, *I* want these changes you've proposed in the core, but of course, I'm not in charge. Thanks. I guess the real question is, what is the process to ensure that Rich sees and considers a potential core improvement like this? I think the main mechanism for this is to post it as an issue on google code, but I'm not certain whether you're supposed to post an issue unless he's seen the newsgroup thread and says, Yes, that sounds good, please post it as an issue. But if he misses the thread for some reason, that will never happen. So it's a bit of a catch-22. Anyway, maybe someone can clarify the procedure. Yes, it is not supposed to be posted as a core issue unless Rich OK's it here. I just had a discussion about just this meta-issue on IRC. Chouser says that Rich still reads every message on the group. See also the further-up discussion in [1] for more procedural details, where it is also suggested that an explicit sign-off here should be required for posting clojure.contrib issues. [1] http://groups.google.com/group/clojure/msg/657291bc62c48f32?hl=en Anyway, I'm feeling quite frustrated and won't try to push this (or any other) issue further. I know Rich and the team are very busy, but it really saps my will to contribute when I have to keep pushing to get an authoritative answer (be it yes or no) on even (what seems to me to be) a fairly uncontroversial change like this one, or [2]. [2] http://groups.google.com/group/clojure/browse_thread/thread/5d11bc0da25a7ecc?hl=en# Sorry for taking your question as a jumping off point for whining about not getting attention. I guess my short answer is: the policy is fairly clear, but its current implementation may be discouraging potential contributors like myself. -Jason --~--~-~--~~~---~--~~ 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 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: Possible feature: consider aliases when reading namespace-qualified keywords.
Nice :) On Fri, Jan 23, 2009 at 2:10 PM, Jason Wolfe jawo...@berkeley.edu wrote: On Jan 19, 4:29 pm, Jason Wolfe jawo...@berkeley.edu wrote: I've been doing some OO-type Clojure programming, and have run into the following (quite minor) annoyance: I've defined a struct with a :class of ::Foo in namespace my.long.namespace.foo. In another namespace my.long.namespace.bar, I want to define a subclass of this struct. In this namespace, I require [...foo :as foo], so that I can refer to multimethods like foo/method1. However, it seems I'm still required to write (derive ::Bar :my.long.namespace.foo/Foo) when I'd like to write (derive ::Bar :foo/Foo) On IRC, duck1123 just showed me that this is already implemented; you just have to use the :: form. (derive ::Bar ::foo/Foo) You learn something new every day... -Jason --~--~-~--~~~---~--~~ 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 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: Not nil and 'true' with conditional functions
Every clojure function returns a value. Even if it is only used for side effects, it still has to return something (probably nil). -Jason On Jan 23, 12:17 pm, wubbie sunj...@gmail.com wrote: Is every function supposed to return something? Of course, except for pure side-effects. -sun On Jan 23, 3:02 pm, Vincent Foley vfo...@gmail.com wrote: The only two false values in Clojure are false and nil. Everything else is logically true. If your function returns nil/false or a result, you don't need (not (nil? (...))) On Jan 23, 2:59 pm, BerlinBrown berlin.br...@gmail.com wrote: Here is some code, my question relates to '(not (nil?...': (if (not (nil? (regex-search-keyword (regex-get-text) line))) (add-select-style styles-vec all-bold) (add-select-style styles-vec light))) Could I have done the following or is (not (nil? ... a better approach. (if (regex-search-keyword (regex-get-text) line))) What are the differences between the two. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Simple lisp like idiom in clojure, call function and keep the result
What is an idiom to call a function and also retain the result. For example, I see myself doing this a lot, but it seems to more code than would be needed. (let [a (some-func)] (when a (println (a dosomething - I wish I could avoid having to use the 'let' in this case I guess in python/ruby, this is something like this. print a.dosomething() ; if a --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---