Re: code review:replace-first
You're scanning the list twice, first to find the element position, and then to do the split; it's better to do it all at once. Here's a simple version: (defn replace-first [from to in] (cond (empty? in) in (= (first in) from) (cons to (rest in)) :else (cons (first in) (replace-first from to (rest in) And here's one rewritten to take advantage of tail recursion: (defn replace-first [from to in prefix] (cond (empty? in) prefix (= (first in) from) (concat prefix (list to) (rest in)) :else (recur from to (rest in) (concat prefix (list (first in))) But there are no doubt better ways to do it, probably built in or in clojure.core. On Sat, May 8, 2010 at 4:24 AM, ken.coba ken.c...@gmail.com wrote: Hi,there! I need a function that replaces a first found element of list. like that, (replace-first :a :b [:c :c :a :c :a] [:c :c :b :c :a] ~~ ;replace first :a to :b and my code is as follows. ---code begin-- (use '[clojure.contrib.seq-utils]) (defn position [x coll] (first (positions #(= x %) coll))) (defn replace-first [s r coll] (let [idx (position s coll) splitted (split-at idx coll)] (concat (first splitted) (list r) (rest (fnext splitted) ---code end-- I'd like to see how the replase-first could be improved, especially concatination of elements. Thanks for your insights. Kenichi Kobayashi -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
I think you want this: (defn pairup [a b rest] (cons [a b] (if rest (apply pairup rest) []))) On Thu, Apr 29, 2010 at 3:32 PM, john.holland jbholl...@gmail.com wrote: I'm pounding my head against the wall trying to understand how to do a simple task. What I want to do is write a function that will take a even-numbered set of numbers and split them into pairs. What I have right now is the following user (defn pairup ([a b] [a b])([a b rest] (cons (pairup a b) (apply pairup rest))) ([] [] )) #'user/pairup user (pairup 1 2 3 4 5 6 7 8) ([1 2] [3 4] [5 6] 7 8) user I can't get the last pair into a vector like the others. Can someone tell me what I am doing wrong? I know there is probably a way using the language to do this but I ended up trying to do it from scratch as a learning exercise. Thanks John -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
Sorry, let me try answering your questions instead of just proposing an alternative. :) As written, your base case and your recursive call are inconsistent. If you want (pairup 1 2 3 4) to return ([1 2] [3 4]), then you need to wind up calling (cons [1 2] [[3 4]]). What you're calling instead is (cons [1 2] [3 4]), because (pairup 3 4) returns a lone pair instead of a list containing a single pair. Basically, you can't call (cons (pairup) (pairup)) because the two arguments to (cons) are different: the first is an item, and the second is a list to cons the item onto. So the fix is to make the base case return ([a b]) instead of just [a b], and not to use recursion in the first argument to cons in your recurse case: (defn pairup ([a b] (list [a b])) ([a b rest] (cons [a b] (apply pairup rest I got an error when I tried ([a b]) instead of (list [a b]), by the way: Clojure 1.1.0 user= (cons [1 2] ([3 4])) java.lang.IllegalArgumentException: Wrong number of args passed to: PersistentVector (NO_SOURCE_FILE:0) On Thu, Apr 29, 2010 at 3:32 PM, john.holland jbholl...@gmail.com wrote: I'm pounding my head against the wall trying to understand how to do a simple task. What I want to do is write a function that will take a even-numbered set of numbers and split them into pairs. What I have right now is the following user (defn pairup ([a b] [a b])([a b rest] (cons (pairup a b) (apply pairup rest))) ([] [] )) #'user/pairup user (pairup 1 2 3 4 5 6 7 8) ([1 2] [3 4] [5 6] 7 8) user I can't get the last pair into a vector like the others. Can someone tell me what I am doing wrong? I know there is probably a way using the language to do this but I ended up trying to do it from scratch as a learning exercise. Thanks John -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
On Fri, Apr 30, 2010 at 12:25 PM, Mark J. Reed markjr...@gmail.com wrote: I got an error when I tried ([a b]) instead of (list [a b]), by the way: Clojure 1.1.0 user= (cons [1 2] ([3 4])) java.lang.IllegalArgumentException: Wrong number of args passed to: PersistentVector (NO_SOURCE_FILE:0) To be clear, that's because vectors are functions on their indices; I meant to explain why I had to use the (list) form. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
Of course. Which is what I would have done automatically with a Lispier construct. Just still not used to seeing literal vectors as functions. :) On Friday, April 30, 2010, Michael Wood esiot...@gmail.com wrote: On 30 April 2010 18:25, Mark J. Reed markjr...@gmail.com wrote: [...] (defn pairup ([a b] (list [a b])) ([a b rest] (cons [a b] (apply pairup rest I got an error when I tried ([a b]) instead of (list [a b]), by the way: Clojure 1.1.0 user= (cons [1 2] ([3 4])) java.lang.IllegalArgumentException: Wrong number of args passed to: PersistentVector (NO_SOURCE_FILE:0) Well, you didn't *have* to call list. You could have quoted the literal list: (defn pairup ([a b] '([a b])) ([a b rest] (cons [a b] (apply pairup rest -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
Ok, so I was right the first time. It think it's past everyone's bedtime. :) On Fri, Apr 30, 2010 at 5:49 PM, Douglas Philips d...@mac.com wrote: On 2010 Apr 30, at 5:45 PM, Mark J. Reed wrote: Of course. Which is what I would have done automatically with a Lispier construct. Just still not used to seeing literal vectors as functions. :) On Friday, April 30, 2010, Michael Wood esiot...@gmail.com wrote: Well, you didn't *have* to call list. You could have quoted the literal list: (defn pairup ([a b] '([a b])) ([a b rest] (cons [a b] (apply pairup rest Hmmm, that quotes the entire form: user= '([a b]) ([a b]) -Doug -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: something stupid I'm trying to do
0On Fri, Apr 30, 2010 at 8:41 PM, Michał Marczyk michal.marc...@gmail.comwrote: That will overflow the stack when you do, say, (last (apply pairup (range 2))) That can be fixed by wrapping (cons ...) in lazy-seq. Sure. Laziness good. Another version: (defn pairup [ args] (map vector args (rest args))) Nope, that doubles the middle elements: user= (pairup 1 2 3 4) ([1 2] [2 3] [3 4]) -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure 1.2 seq fn enhancement FAQ
I like this proposal. I'd make contains? an alias for contains-key? with a deprecation warning, and just forget about seq-contains? in favor of contains-val? On Thursday, April 29, 2010, ataggart alex.tagg...@gmail.com wrote: I know it won't matter, but for posterity if nothing else... Functions named contains-key? and contains-val? would make a lot more sense to me than the current contains? and new seq-contains?. Anyone looking at contains-val? should expect it to be O(n). The only effective difference would be that the test value for contains-val? is consistently a single value rather than a [key value] tuple for maps. Lists: (contains-key? '(:foo :bar) 0) Exception (contains-val? '(:foo :bar) :foo) true Vectors: (contains-key? [:foo :bar] 0) true (get [:foo :bar] 0) :foo (contains-key? [:foo :bar] 2) false (contains-val? [:foo :bar] :foo) true (contains-val? [:foo :bar] :baz) false Maps: (contains-key? {:foo :bar} :foo) true (get {:foo :bar} :foo) :bar (contains-key? {:foo :bar} :baz) false (contains-val? {:foo :bar} :bar) true (contains-val? {:foo :bar} :baz) false Sets: (contains-key? #{:foo :bar} :foo) true (get #{:foo :bar} :foo) :foo (contains-key? #{:foo :bar} :baz) false (contains-val? #{:foo :bar} :foo) true (contains-val? #{:foo :bar} :baz) false -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure 1.2 seq fn enhancement FAQ
Iterating through the pairs is useful. Asking if a given [k, v] is included is not - you can just ask if (= (assoc k) v) instead. It'd be nice if (contains-val) returned the key(s) as its true result, but probably not useful enough to warrant the complexity of dealing with false keys, explicit true checks, etc. In CL I would totally return the key list as a multivalue on top of t, though. :) On Thursday, April 29, 2010, Boris Mizhen - 迷阵 bo...@boriska.com wrote: +1. I can't imagine any use case for looking up a whole [key, value] pair in a hash-map. Actually this is quite useful when you want to do something for each value and need to know the key as well - for example copy some key/value pairs to another map Boris -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Insert into an indexed seq
I'm a bit surprised that it's not there already, at least in clojure.contrib, but it's not hard to write, at least for vectors: (defn insert [vec pos item] (apply merge (subvec vec 0 pos) item (subvec vec pos))) On Tue, Apr 27, 2010 at 2:45 PM, Sean Devlin francoisdev...@gmail.comwrote: You're right, inserting into a vector is fundamentally slow. Inserting into a list (must traverse elements) or String (Char Array) isn't any better. I get why Clojure doesn't include certain operations on certain data structures (e.g. assoc on a list), because it's the wrong tool for the job. However, there are still problems that require me to use an expensive operation. Maybe I'm too focused on my current project, and wrong about how much a typical person would use insert. Still, its absence seems like an oversight. Sean On Apr 27, 2:05 pm, Chouser chou...@gmail.com wrote: On Tue, Apr 27, 2010 at 1:31 PM, Sean Devlin francoisdev...@gmail.com wrote: Is there a built in to insert a value into an indexed seq? For example: user= (insert [:a :b :c :d] 2 :q) (:a :b :q :c :d) Not sure if I'm missing something simple... That's a vector, which cannot efficiently splice internally, so it's not supported directly. However, you can build a new vector with your value included: (apply conj [:a :b] :q [:c :d]) ;= [:a :b :q :c :d] Also, why does this work: user= (assoc [:a :b :c :d] 2 :q) [:a :b :q :d] And this doesn't: user= (dissoc [:a :b :c :d] 2) #CompilerException java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.IPersistentMap (NO_SOURCE_FILE:286) Annoying. Again, vectors cannot efficiently insert or remove items except from the right-hand end, though as you note items can replaced internally. (let [v [:a :b :c :d]] (into (subvec v 0 2) (subvec v 3))) ;= [:a :b :d] There are immutable collections that support both numeric-indexed lookups and internal splicing, they're just not currently included with Clojure. See for example finger trees: http://functionaljava.googlecode.com/svn/artifacts/2.21/javadoc/fj/da... --Chouserhttp://joyofclojure.com/ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group athttp:// groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Insert into an indexed seq
On Tue, Apr 27, 2010 at 3:41 PM, Mark J. Reed markjr...@gmail.com wrote: I'm a bit surprised that it's not there already, at least in clojure.contrib, but it's not hard to write, at least for vectors: (defn insert [vec pos item] (apply merge (subvec vec 0 pos) item (subvec vec pos))) Er, that should be conj, not merge. Though, perhaps surprisingly, it works as written. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Try + finally question
On Wed, Apr 21, 2010 at 9:37 AM, Laurent PETIT laurent.pe...@gmail.comwrote: Hi, Something I don't understand: if the call to (API/getConnection ...) fails, there is nothing to close, right ? So for the problem of ensuring that any open connection is always closed, the following pattern seems enough: (try (let [conn (API/getConnection ..)] XXX) (finally (API/closeConnection conn))) That would be great, but it doesn't work, because conn doesn't exist any more by the time you get to the finally block. That's the problem being addressed in this thread. So you can do this: (let [conn (API/getConnection ...)] (try XXX (finally (API/closeConnection conn But then any exception thrown by API/getConnection is not caught. So you have to do this: (try (let [conn (API/getConnection ...)] (try XXX (finally (API/closeConnection conn (catch ...)) But that still won't work if the catch block also needs access to conn. So you wind up with something like this: (try (let [conn (API/getConnection ...)] (try XXX (catch ExceptionAfterConnect x (do-something-with conn)) (finally (API/closeConnection conn (catch .ExceptionDuringConnect x (do-something-without-conn -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Try + finally question
this group athttp:// groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: removing parethesis
On Mon, Apr 12, 2010 at 11:15 PM, Alan Busby thebu...@gmail.com wrote: On Tue, Apr 13, 2010 at 11:54 AM, Douglas Philips d...@mac.com wrote: On 2010 Apr 12, at 10:48 PM, Glen Rubin wrote: I am working with a collection of integer sequences ...(e.g. coll: ((3 7 3 5 9 2 0 8 4 0 1 2323 4 11...) (243 4 664 478 3948...) (6 3 7 4 3335 2 4 5 7 6...)...) I want to create an average sequence such that all of the first elements are averaged, all of the second elements, etc However, I am unable to manipulate the collection. If I try something simple like: (map + coll) I get java.lang.ClassCastException Take a look at apply, it sounds as if you want something akin to: (apply map + coll) --Doug Or maybe? Further help lurking in Clojure IRC. ;) user= (use '[clojure.contrib.seq-utils :only (flatten)]) nil user= (map + (flatten '((1 2 3) (4 5 6 (1 2 3 4 5 6) I don't even understand that result.. but what the OP asked for is for a function foo such that (foo '((1 2 3) (4 5 6))) returns (5 7 9) - a list of the sums in order. (apply map +) does that. Except what the OP really wants the average instead of the sum.. there's probably an arithmetic mean function in contrib somewhere, but it's easy to roll your own: (defn mean [ rest] (/ (apply + reset) (count rest))) And then use the same trick with it in place of +: (apply map mean '((1 2 4) (2 4 6) (1 3 5))) which yields (4/3 3 5) -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
Re: , is REAL whitespace...
try this one: (list,1,2,3) :) Per: I'd say it's also weird if you're coming from a Lisp background - just weird in the opposite direction. But not so weird that it's not useful, mostly for separating key/value pairs from other key/value pairs in a map. It's like Perl's fat comma arrow operator in that sense - syntactically no different from comma, but stylistically helpful. On Fri, Apr 2, 2010 at 1:52 AM, Per Vognsen per.vogn...@gmail.com wrote: It doesn't feel right only if you still think you are programming in an Algol-style language where , is a separator token. I can't imagine this is going to change. -Per On Fri, Apr 2, 2010 at 12:37 PM, Frank Siebenlist frank.siebenl...@gmail.com wrote: Even though the specs clearly say that commas are whitespace, the following repl session doesn't feel intuitively right: ... user (list 1 2 3) (1 2 3) user (list 1, 2, 3) (1 2 3) user (list 1, 2, , 3) (1 2 3) user (list 1, 2, nil , 3) (1 2 nil 3) ... , is same as , , is same as ... big gotcha for beginning clojurians... Enjoy, Frank. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: formatting hex string
On Wed, Mar 31, 2010 at 7:22 PM, Glen Rubin rubing...@gmail.com wrote: I have a sequence of hex strings, e.g. ff43 0032 ... (you get the idea) I want to use clojure's short form on them, but short expects an authentic hex input, e.g. (short 0xff43) it will not accept something like (short 0xff43) Right. When you type (short 0xff43), the reader converts that into an actual number before the function (short) is ever actually called; all it ever sees is a number, and has no idea if you typed 0xff43, 653477, or 0177503, or (+ 0xff40 3)). You could prepend 0x to your strings and manually invoke the reader on them (after clearing the unsafe evaluation flags), but using parseInt as suggested by Richard is probably cleaner. However: On Wed, Mar 31, 2010 at 7:58 PM, Richard Newman holyg...@gmail.com wrote: ur= (map #(Integer/parseInt % 16) [ff43 0032]) (65347 50) ...that yields, not shorts. You could try this: (map #(short (Integer/parseInt % 16)) [ff43 0032]) Which works fine in 1.1. But starting in 1.2 that runs into the range problem we talked about with respect to (byte) in another thread. (And that's true of literals as well; (short 0xff43) will throw an IllegalArgumentException. So manually invoking the reader is not a solution.) The full, future-proof solution is something like this: (map #(let [n (Integer/parseInt % 16)] (short (if (bit-test n 15) (bit-or n -65536) (bit-and n 65535 [ff43 0032]) although of course factoring some of that out into named functions is probably not the worst idea. On a related note: if I have the symbol for a type, like short or int or byte, is there a way to ask Clojure what size word that represents? -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
Re: formatting hex string
On Thu, Apr 1, 2010 at 12:29 AM, Armando Blancas armando_blan...@yahoo.com wrote: But if numbers should default to positive but not be coerced to negative, e.g., a -189 just for (short -0xBD) this might work, using nil for out of range values: Yeah, but I was assuming (insert standard caveat here) that the goal is to treat the hex values as bit patterns and return whatever numeric value Clojure requires to get the corresponding bit pattern, hence -1 for 0x, etc. I don't know if there's anything predefined, but you can always fall back to using (Short/MIN_VALUE), (Short/MAX_VALUE), etc. Yeah, I was hoping for something predefined. Failing that, I used the /SIZE field, and came up with the below. The fn name unsigned might seem backwards (truncating-cast would be more descriptive), but I called it that because it lets you use (unsigned byte 255) to mean the same thing as (byte -1). (defn box-type [s] (class (s 0))) (defn bit-size [s] (eval (read-string (str (.getName (box-type s)) /SIZE (defn unsigned [type value] (let [size (bit-size type) sign-bit (- size 1) negative-mask (bit-shift-left -1 size) positive-mask (- (bit-shift-left 1 size) 1)] (type (if (bit-test value sign-bit) (bit-or value negative-mask) (bit-and value positive-mask) -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe, reply using remove me as the subject.
Re: Getting started with open source Clojure projects
On Mon, Mar 29, 2010 at 11:39 PM, Daniel cotter.dan...@gmail.com wrote: Is there a less cumbersome way to get a load of files on the classpath than manually editing the .clojure file? Well, I have a ~/lib/clojure directory and a clj script that automatically puts that directory and all .jar's in it on the classpath. Linux version: #!/bin/bash : ${CLOJURE_LIB:=${HOME}/lib/clojure} export CLASSPATH=${CLASSPATH:+$CLASSPATH:}$HOME/lib/java/clojure.jar:$CLOJURE_LIB if [ -d $CLOJURE_LIB ]; then for f in $CLOJURE_LIB/*.jar; do if [ -r $f ]; then CLASSPATH=$CLASSPATH:$f fi done fi rlwrap java clojure.main $@ The actual java invocation can of course be replaced to e.g. use JLine instead of rlwrap; I use the latter because JLine doesn't seem to have a vi mode. (Yes, I know, vi user in a Lispy language - heretical!) -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: regular expression sequence
Parentheses capture - anything that matches a parenthesized portion of a regular expression is returned as part of the result of the match: user= (re-seq #a(.)c abc) ([abc b]) If you don't want that behavior, you can use the special non-capturing syntax, (?:...): user= (re-seq #a(?:.)c abc) (abc) You don't have to escape pipes or any other special characters inside a character class (that is, between [...]), because characters lose their special meanings there: [.*] matches either a period or an asterisk and has no relationship to the any character symbol or zero or more repetition operator. The only special things inside a character class are a leading '^', which negates the class, and a '-' in the middle, which makes a range: [^a-z] matches any single character that is not a lowercase letter (of the English alphabet). Position matters: [-^] matches a literal hyphen or caret, and [] is not an empty character class but a syntax error (an unclosed character class that so far includes a literal ']' character). On Tue, Mar 30, 2010 at 12:37 PM, Glen Rubin rubing...@gmail.com wrote: The result is a little bit strange still, since I am getting dupliates. First, it returns the string I want 49|00|12 12|a9|a4|ff but then it also returns the same string without the first and last 4 characters, e.g. 12|12|a9| Also, how come I don't need to escape the | inside the parenthesis? thanks Meikel!! On Mar 30, 10:59 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you have to escape the |. user= (re-seq #49\|00\|([0-9a-f|]+)\|a4\|ff a5|a5|49|23|49|00|12| fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff|ae) ([49|00|12|fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff 12|fc|5e|a4|ff|a7|49|00| ee|d3]) However this will be greedy... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: regular expression sequence
Addendum: I highly recommend Jeffrey Friedl's book _Mastering_Regular_Expressions_ if you want to learn how to use regexes well. There are also a number of introductions/tutorials online, but I'm not familiar enough with them to recommend any. On Tue, Mar 30, 2010 at 12:50 PM, Mark J. Reed markjr...@gmail.com wrote: Parentheses capture - anything that matches a parenthesized portion of a regular expression is returned as part of the result of the match: user= (re-seq #a(.)c abc) ([abc b]) If you don't want that behavior, you can use the special non-capturing syntax, (?:...): user= (re-seq #a(?:.)c abc) (abc) You don't have to escape pipes or any other special characters inside a character class (that is, between [...]), because characters lose their special meanings there: [.*] matches either a period or an asterisk and has no relationship to the any character symbol or zero or more repetition operator. The only special things inside a character class are a leading '^', which negates the class, and a '-' in the middle, which makes a range: [^a-z] matches any single character that is not a lowercase letter (of the English alphabet). Position matters: [-^] matches a literal hyphen or caret, and [] is not an empty character class but a syntax error (an unclosed character class that so far includes a literal ']' character). On Tue, Mar 30, 2010 at 12:37 PM, Glen Rubin rubing...@gmail.com wrote: The result is a little bit strange still, since I am getting dupliates. First, it returns the string I want 49|00|12 12|a9|a4|ff but then it also returns the same string without the first and last 4 characters, e.g. 12|12|a9| Also, how come I don't need to escape the | inside the parenthesis? thanks Meikel!! On Mar 30, 10:59 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you have to escape the |. user= (re-seq #49\|00\|([0-9a-f|]+)\|a4\|ff a5|a5|49|23|49|00|12| fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff|ae) ([49|00|12|fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff 12|fc|5e|a4|ff|a7|49|00| ee|d3]) However this will be greedy... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: regular expression sequence
Leaving out the parentheses changes the meaning because they group as well as capture. #a(b|c)d matches either abd or acd. #ab|cd matches either ab or cd. On Tuesday, March 30, 2010, Glen Rubin rubing...@gmail.com wrote: thx that works great! i guess I can also just leave out the parenthesis all together. but, what if i wanted just the portion inside?? the duplicate I wanted to get rid of? also any way to return the sequence without all those bars or do i have to use a seperate regex and or filter? On Mar 30, 12:52 pm, Mark J. Reed markjr...@gmail.com wrote: Addendum: I highly recommend Jeffrey Friedl's book _Mastering_Regular_Expressions_ if you want to learn how to use regexes well. There are also a number of introductions/tutorials online, but I'm not familiar enough with them to recommend any. On Tue, Mar 30, 2010 at 12:50 PM, Mark J. Reed markjr...@gmail.com wrote: Parentheses capture - anything that matches a parenthesized portion of a regular expression is returned as part of the result of the match: user= (re-seq #a(.)c abc) ([abc b]) If you don't want that behavior, you can use the special non-capturing syntax, (?:...): user= (re-seq #a(?:.)c abc) (abc) You don't have to escape pipes or any other special characters inside a character class (that is, between [...]), because characters lose their special meanings there: [.*] matches either a period or an asterisk and has no relationship to the any character symbol or zero or more repetition operator. The only special things inside a character class are a leading '^', which negates the class, and a '-' in the middle, which makes a range: [^a-z] matches any single character that is not a lowercase letter (of the English alphabet). Position matters: [-^] matches a literal hyphen or caret, and [] is not an empty character class but a syntax error (an unclosed character class that so far includes a literal ']' character). On Tue, Mar 30, 2010 at 12:37 PM, Glen Rubin rubing...@gmail.com wrote: The result is a little bit strange still, since I am getting dupliates. First, it returns the string I want 49|00|12 12|a9|a4|ff but then it also returns the same string without the first and last 4 characters, e.g. 12|12|a9| Also, how come I don't need to escape the | inside the parenthesis? thanks Meikel!! On Mar 30, 10:59 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, you have to escape the |. user= (re-seq #49\|00\|([0-9a-f|]+)\|a4\|ff a5|a5|49|23|49|00|12| fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff|ae) ([49|00|12|fc|5e|a4|ff|a7|49|00|ee|d3|a4|ff 12|fc|5e|a4|ff|a7|49|00| ee|d3]) However this will be greedy... Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: intuitive stack trace
But that doesn't address the fundamental lack of useful information in the error messages, which is something I've noticed as well. The compiler could stand to be a bit friendlier in this regard.. On Mon, Mar 29, 2010 at 3:55 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: One nice thing about Clojure is that double-parenthesized ((anything)) is usually wrong. Stu Hi, On Mon, Mar 29, 2010 at 11:23:29AM -0700, strattonbrazil wrote: (import '(javax.swing JTable) '(javax.swing.table TableModel)) (def table (new JTable((proxy [TableModel] [] (getColumnCount [] 10) (getRowCount [] 10) (getValueAt [row column] (* row column)) java.lang.ClassCastException: clojure.proxy.java.lang.Object $TableModel (NO_SOURCE_FILE:2) You have an extra pair of parens around the proxy call which will treat the proxy as function which won't work. Try this: (import 'javax.swing.JTable 'javax.swing.table.TableModel) (def table (JTable. (proxy [TableModel] [] (getColumnCount [] 10) (getRowCount [] 10) (getValueAt [row column] (* row column) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Can't call public method of non-public class
That's the one. But the solution given by the bug reporter doesn't address the case that came up on this thread, since it's not the class of the invocant but the types of the parameters that prevent the match from being found. On Thu, Mar 25, 2010 at 7:06 AM, atucker agjf.tuc...@googlemail.com wrote: Is this it? http://www.assembla.com/spaces/clojure/tickets/259 On Mar 23, 8:26 pm, Mark J. Reed markjr...@gmail.com wrote: As far as I can tell, you're doing nothing wrong and just hitting a bug in Clojure. Which is still in 1.2.0-master... On Tue, Mar 23, 2010 at 11:43 AM, Konstantin Barskiy zuftw...@gmail.com wrote: I'm trying to reproduce ProcessBuilder example from java documentation http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html This is that example: ProcessBuilder pb = new ProcessBuilder(myCommand, myArg1, myArg2); MapString, String env = pb.environment(); env.put(VAR1, myValue); env.remove(OTHERVAR); env.put(VAR2, env.get(VAR1) + suffix); pb.directory(new File(myDir)); Process p = pb.start(); I'm typing folowing in clojure repl: D:\Users\Konstantinjava -jar clojure.jar Clojure 1.1.0 user= (def pb (new ProcessBuilder [myCommand myArg])) #'user/pb user= (def env (.environment pb)) #'user/env user= (.put env VAR1, myValue) java.lang.IllegalArgumentException: Can't call public method of non- public class: public java.lang.String java.lang.ProcessEnvironment.put(java.lang.String,java.lang.String) (NO_SOURCE_FILE:0) What does this error mean and what i am doing wrong? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Nubie Question
Right. Let's make this clear: outside of the Java interoperability stuff, you cannot change the value of a variable in Clojure. Ever. All the data types are immutable; you can only build new values on top of existing ones, not modify the old ones. When you conj something onto a vector, it doesn't change that vector; it returns a new vector. The new vector reuses the old one's memory for efficiency, but if you look at the old one it doesn't have the new member. It's unchanged. What can change are references. So you can make a reference to the vector, and then build a new vector with the new items, and then change the reference to point to the new vector. That's what (swap!) does. But you have to have a reference to start with. Which (atom) gives you. But a reference is not the same as a vector; you can't use it directly when you need a vector, but must dereference it with @. Example: Clojure 1.1.0 user= (def start-colors [:black :white]) #'user/start-colors user= (def saved-colors (atom start-colors)) #'user/saved-colors user= start-colors [:black :white] user= @saved-colors [:black :white] user= (swap! saved-colors conj :red) [:black :white :red] user= start-colors [:black :white] user= saved-colors #a...@1d256fa: [:black :white :red] user= @saved-colors [:black :white :red] user= -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Choosing a Clojure build tool
On Thu, Mar 25, 2010 at 6:17 PM, Brian Carper briancar...@gmail.com wrote: Ruby: gem install X Perl: perl -MCPAN -e shell, then install X If you're just installing CPAN module X, then on most installations all you need to run is this: cpan X You can still go into the interactive shell if you want, usually by just running cpan with no args. You don't have to do that to install a module, but if you need to find a module whose exact name you don't know, or if a module fails to build and you want to poke around the build tree, etc, the cpan shell is handy. And other languages have their own flavors - PHP has PEAR/PECL, while Python is trying to get there with PyPI, but it's not quite there yet. The problem with CPAN is that many modules require compiling native code (C in this case), which means that just running cpan won't work if you don't have C dev tools installed. You can often get modules with prebuilt binaries, but the mechanism is platform-dependent. For instance, each module is its own apt package for Debian/Ubuntu, while ActivePerl on Windows uses its own Perl Package Manager (ppm.exe). -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: referencing an atom inside a function used for swapping
I would just pass the atom and move the @ inside the function... On Thursday, March 25, 2010, strattonbrazil strattonbra...@gmail.com wrote: I have a function that I use for adding a JPanel to a ui atom. When I call swap! that ui atom is sent to that function I call with the swap! on and is dereferenced inside the function so I don't need to call @ui on it. However, I want to add listeners to my JPanel that can affect that atom, but I don't have the actual atom anymore since it's deferenced when I pass it to swap. I believe I could just pass it as another parameter, but that seems like a hack. (defn swap-function [ui atomWithUiInIt] ; add code that on a click or press or something, alter the atomWithUiInIt atom ...) Is there better way to handle this? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: referencing an atom inside a function used for swapping
Ah, right, this is the function called from swap!. So move the listener stuff out of your swap function and into the function that calls swap! instead? On Thu, Mar 25, 2010 at 11:02 PM, Josh Stratton strattonbra...@gmail.com wrote: I would just pass the atom and move the @ inside the function... But the non-atom is automatically dereferenced and sent to the respective function when I use swap! So unless there's another function to alter atoms, I'm going to have the dereferenced version there no matter what, right? On Thursday, March 25, 2010, strattonbrazil strattonbra...@gmail.com wrote: I have a function that I use for adding a JPanel to a ui atom. When I call swap! that ui atom is sent to that function I call with the swap! on and is dereferenced inside the function so I don't need to call @ui on it. However, I want to add listeners to my JPanel that can affect that atom, but I don't have the actual atom anymore since it's deferenced when I pass it to swap. I believe I could just pass it as another parameter, but that seems like a hack. (defn swap-function [ui atomWithUiInIt] ; add code that on a click or press or something, alter the atomWithUiInIt atom ...) Is there better way to handle this? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Can't call public method of non-public class
On Tue, Mar 23, 2010 at 7:38 PM, Stuart Campbell stuart.william.campb...@gmail.com wrote: From JDK docs (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html#environment%28%29): The behavior of the returned map is system-dependent. A system may not allow modifications to environment variables or may forbid certain variable names or values. For this reason, attempts to modify the map may fail with UnsupportedOperationException or IllegalArgumentException if the modification is not permitted by the operating system. Sure, but that's not the problem here; Clojure is not even getting as far as compiling the code because its reflection code is too strict when matching methods to candidates. I submit the attached patch as a more general solution than Armando's, although whether it's worthwhile I'll leave up to Rich and company... -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. Reflector.patch.gz Description: GNU Zip compressed data
Re: Can't call public method of non-public class
This looks like the old type erasure problem - the returned map is of a private class, so clojure looks for a public version of the put method in one of the interfaces/base classes - but does an exact comparison on parameter types, so put(String, String) doesn't match put(Object, Object) and the search fails. You might think that the Reflection API would provide a way of looking for methods that you could call with the types given, instead of just exact match, but using getMethod() or getDeclaredMethod() instead of looping and comparing manually yields the same result. However, as mentioned at http://christerblog.wordpress.com/2010/02/27/java-reflection-matching-formal-parameter-list-to-actual-parameter-list/ , the Coherence Common Incubator project has a ReflectorHelper module that provides a solution (at least in the case of constructors); I''m thinking Clojure could adapt/adopt that solution. On Tue, Mar 23, 2010 at 4:26 PM, Mark J. Reed markjr...@gmail.com wrote: As far as I can tell, you're doing nothing wrong and just hitting a bug in Clojure. Which is still in 1.2.0-master... On Tue, Mar 23, 2010 at 11:43 AM, Konstantin Barskiy zuftw...@gmail.com wrote: I'm trying to reproduce ProcessBuilder example from java documentation http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html This is that example: ProcessBuilder pb = new ProcessBuilder(myCommand, myArg1, myArg2); MapString, String env = pb.environment(); env.put(VAR1, myValue); env.remove(OTHERVAR); env.put(VAR2, env.get(VAR1) + suffix); pb.directory(new File(myDir)); Process p = pb.start(); I'm typing folowing in clojure repl: D:\Users\Konstantinjava -jar clojure.jar Clojure 1.1.0 user= (def pb (new ProcessBuilder [myCommand myArg])) #'user/pb user= (def env (.environment pb)) #'user/env user= (.put env VAR1, myValue) java.lang.IllegalArgumentException: Can't call public method of non- public class: public java.lang.String java.lang.ProcessEnvironment.put(java.lang.String,java.lang.String) (NO_SOURCE_FILE:0) What does this error mean and what i am doing wrong? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Can't call public method of non-public class
As far as I can tell, you're doing nothing wrong and just hitting a bug in Clojure. Which is still in 1.2.0-master... On Tue, Mar 23, 2010 at 11:43 AM, Konstantin Barskiy zuftw...@gmail.com wrote: I'm trying to reproduce ProcessBuilder example from java documentation http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html This is that example: ProcessBuilder pb = new ProcessBuilder(myCommand, myArg1, myArg2); MapString, String env = pb.environment(); env.put(VAR1, myValue); env.remove(OTHERVAR); env.put(VAR2, env.get(VAR1) + suffix); pb.directory(new File(myDir)); Process p = pb.start(); I'm typing folowing in clojure repl: D:\Users\Konstantinjava -jar clojure.jar Clojure 1.1.0 user= (def pb (new ProcessBuilder [myCommand myArg])) #'user/pb user= (def env (.environment pb)) #'user/env user= (.put env VAR1, myValue) java.lang.IllegalArgumentException: Can't call public method of non- public class: public java.lang.String java.lang.ProcessEnvironment.put(java.lang.String,java.lang.String) (NO_SOURCE_FILE:0) What does this error mean and what i am doing wrong? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Help optimizing array-to-integer operation?
On Tue, Mar 23, 2010 at 8:19 PM, Raph mart...@gmail.com wrote: (My opinion, anyway.I think a byte should be 8 bits and I should be able to use all of them.) Er, it is, and you can. A Java byte still gives you all 8 bits' worth of 256 different possible values; the interpretation of those values is all that differs here. Whereas C lets you pick between signed and unsigned (with the default unfortunately not always well-defined), Java gives you no choice but to use the signed interpretation. But you still get to use all 8 bits of the byte; it's just that the numbers mapped to [128, 255] in unsigned interpretations map to [-128,-1] instead. The dissonance here comes from the fact that there's no real tradition of negative hexadecimal numbers in programming. We've typically used the hexadecimal form of the unsigned integer interpretation to represent the corresponding bit patterns no matter how they're being used in a given program or context. So anyone experienced with manipulating things at the bit level comes in expecting things like (byte 0xff) to just work, and is surprised when they don't. Still, the nice thing about Clojure vs Java is it's not hard to write a fix: (defmacro unsigned-byte [bval] (byte (if ( bval 127) (- bval 256) bval))) Or call it (ubyte) for less wordiness... -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Help optimizing array-to-integer operation?
On Tue, Mar 23, 2010 at 8:40 AM, Per Vognsen per.vogn...@gmail.com wrote: Sorry, I didn't put that right. 0xFF would only be -1 as a signed byte. What I'm saying is that the interaction between the type system of integers and the reader's hexadecimal notation is pretty surprising to me. In particular, (byte 0xFF) throws an error. What version? It works here: Clojure 1.1.0 user= (byte 0xff) -1 In fact, it seems that (byte) doesn't check the range at all: user= (byte -129) 127 -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Why I have chosen not to employ clojure
On Mon, Mar 22, 2010 at 7:03 PM, cageface milese...@gmail.com wrote: On the other hand, if you go to the getting started pages of Jruby, Groovy they're actually far more daunting (IMO) than Clojure's: http://groovy.codehaus.org/Tutorial+1+-+Getting+started http://kenai.com/projects/jruby/pages/GettingStarted The relevant bits of Groovy's page don't seem more daunting to me: Setting up your Groovy environment Download the Groovy installer or binaries from the downloads page and follow the installation instructions. (There is currently an issue where you cannot have spaces in the path where Groovy is installed under windows. So, instead of accepting the default installation path of c:\Program Files\Groovy you will want to change the path to something like c:\Groovy) One sentence and one caveat. Now, it's preceded by detailed instructions for installing Java, but those same steps are just as applicable to Clojure or any other JVM-hosted language, and having them there is probably not a bad thing. (Though I would replace them with a link - If you don't have Java, click here and follow the instructions.) JRuby's installation is more manual, but includes examples. All three install on Ubuntu with apt-get, though the latest Clojure there is 1.0. It does come with a clojure shell script for starting up a REPL, though. -- Mark J. Reed markjr...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Check my idioms?
(I'd say something about my own particular idiom, but that's more of a Python thing.) Anyway, new to Clojure but not to Lisp or Java. Writing something to interoperate with some Perl code that stores a hash in a simple flat file syntax: key1tabvalue1newlinekey2tabvalue2newline... sorted on the keys. These are my load and save routines; the load has nothing to handle misformatted files yet, but I'm just looking to get a feel for idiomatic Clojure. Do these look reasonable? The save routine feels a little clunky to me. (defn load-map [filename] (apply sorted-map (re-seq #[^\n\t]+ (slurp filename (defn save-map [the-map filename] (doto (java.io.FileWriter. filename) (.write (apply str (interleave (apply concat (seq the-map) (cycle \t\n (.close))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.