Re: Update multiple values in vector at once

2015-04-03 Thread Leon Grapenthin
(defn upd-vec [input-vector ids new-values] (apply assoc input-vector (interleave ids new-values))) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) ;= [0 1.44 0 1.45 0] On Monday, March 30, 2015 at 8:05:44 PM UTC+2, Alexandr wrote: Hello everybody, How can I update values in the vector given

Re: Update multiple values in vector at once

2015-03-30 Thread Michał Marczyk
(defn upd-vec [input-vector ids new-values] (reduce-kv #(assoc %1 %3 (new-values %2)) input-vector ids)) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) ;= [0 1.44 0 1.45 0] On 30 March 2015 at 20:05, Alexandr updates...@gmail.com wrote: Hello everybody, How can I update values in the vector

Re: Update multiple values in vector at once

2015-03-30 Thread Alexandr
Thanks a lot! On Monday, March 30, 2015 at 8:11:25 PM UTC+2, Michał Marczyk wrote: (defn upd-vec [input-vector ids new-values] (reduce-kv #(assoc %1 %3 (new-values %2)) input-vector ids)) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) ;= [0 1.44 0 1.45 0] On 30 March 2015 at 20:05, Alexandr

Re: Update

2014-04-29 Thread Divyansh Prakash
Why are Clojure features defined in terms of Java classes, instead of as bytecode primitives? For eg: Cons is a class containing two objects: first and rest. Is this only to achieve Java interoperability, or is there more to it? -- You received this message because you are subscribed to the

Re: Update

2014-04-29 Thread Andrew Chambers
Well, why write it in primitives when there is a perfectly good compiler from java to primitives? I dont quite understand why you think there would be benefit from manually writing everything with java bytecode. The JVM works with classes, thats how its designed, Clojure itself is just a java

Re: Update

2014-04-29 Thread David Powell
The JVM is very class-oriented. It is basically designed for Java, and corresponds pretty much to the things you can do in Java. Code belongs to methods which belong to classes, and calls are made using java method calling conventions. Data has to be stored in primitives, arrays, or objects;

Re: Update

2014-04-29 Thread Divyansh Prakash
Thank you for the explanation. What if I target a non-OO-centric VM (like Parrot or LLVM)? I've noticed that most Lisp implementations define lambda calculus primitives, and then use those as the core. I wonder what would be if we had bytecode primitives, and defined everything else on top of

Re: Update

2014-04-29 Thread Divyansh Prakash
I looked into a port of Clojure to Parrot, and it basically does the same thinghttps://github.com/ayardley/ClojurePVM/blob/master/src/c/lisp/microlisp/lisp.c . -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Update

2014-04-29 Thread Divyansh Prakash
Why not emit bytecode directly from the language? Couldn't this potentially lead to tons of specialized optimizing macros? -- 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

Re: Update

2014-04-29 Thread Gary Trakhman
The hard part with other runtimes will be details around things like garbage collection for the implementation of persistent data structures. Clojurescript is a better example of how this is done since most of the impls are implemented in the language itself, different from clojure-proper.

Re: Update

2014-04-29 Thread Divyansh Prakash
Check out my previous reply. The parrot vm provides gc and everything, But still the author defines lambda primitives in c, and then builds over it. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Update

2014-04-29 Thread Andrew Chambers
For the llvm based approach you can look at vmkit. On Wednesday, April 30, 2014 3:39:21 AM UTC+12, Divyansh Prakash wrote: Check out my previous reply. The parrot vm provides gc and everything, But still the author defines lambda primitives in c, and then builds over it. -- You received

Re: Update

2014-04-28 Thread Divyansh Prakash
Jasmin would be a much better choice, btw, because it could be used as a dependency in Clojure. -- 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

Re: Update

2014-04-28 Thread Gary Trakhman
Seen: https://github.com/clojure/tools.emitter.jvm ? Here's the actual ASM emit: https://github.com/clojure/tools.emitter.jvm/blob/master/src/main/clojure/clojure/tools/emitter/jvm/transform.clj On Mon, Apr 28, 2014 at 5:43 PM, Divyansh Prakash divyanshprakas...@gmail.com wrote: ---IDEA--- I

Re: Update

2014-04-28 Thread Divyansh Prakash
Thanks! Exactly what I was looking for. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To

Re: Update to downloads page?

2012-06-21 Thread Timothy Baldridge
Or perhaps something like this: Although it is possible to download Clojure directly here link, for a more complete package management system please see Leiningen. But yes, I agree, we need a big fat notice that says don't download directly unless you know what you're doing. Timothy On Thu,

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread Andy Fingerhut
Here is one way to do it called update-in+. It returns a vector consisting of the new udpated value, like update-in does, followed by the original value (in case you might want to see that for some reason), followed by the updated value. (defn update-in+ ([m [k ks] f args] (if ks

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread Jay Fields
I would have written the fn like this, if I was following what you've been doing: (def m {:planet {:country {:state {:city {:borough 4}) (let [mm (update-in m [:planet :country :state :city :borough ] (fnil inc -1))] (get-in mm [:planet :country :state :city :borough ])) However, when I

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
Thanks Andy, Two comments: 1. Your version does not use a transient/mutable, which is great, but it does create one vector for each level. I thought that since this would be wrapped and hidden from external view, a mutable would have been more appropriate. More generally, I still don't know

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 4:30 PM, blais goo...@furius.ca wrote: (Generally I find I get too little cultural osmosis when it comes to practical application of Clojure, so questions like this one come up all the time while I'm coding. Meetups and books touch on topics I understand well but

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
On Thursday, April 26, 2012 4:36:52 PM UTC-4, David Nolen wrote: On Thu, Apr 26, 2012 at 4:30 PM, blais goo...@furius.ca wrote: (Generally I find I get too little cultural osmosis when it comes to practical application of Clojure, so questions like this one come up all the time while I'm

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 4:52 PM, blais goo...@furius.ca wrote: I suppose I could elect to move refs for modifiable things towards the leaves, but that seems to me like going against the grain and may have implications for concurrency (there are few but some threads running in parallel in this

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
On Thursday, April 26, 2012 4:59:31 PM UTC-4, David Nolen wrote: On Thu, Apr 26, 2012 at 4:52 PM, blais goo...@furius.ca wrote: I suppose I could elect to move refs for modifiable things towards the leaves, but that seems to me like going against the grain and may have implications for

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 5:08 PM, blais goo...@furius.ca wrote: I receive events from a network. My application calls for storing these events and doing different things based on the changing status of orders attached to these events. I need to store them somewhere, I need to track this state

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread kurtharriger
I think you are too concerned with micro optimizations. get-in is probably just as efficient as attempting to bubble the state change back up and certainly simpler to work with. In practice, optimizations like this do not have a significant impact on the overall performace. Measure before

Re: Update an item from a list of maps in STM transaction

2012-04-02 Thread Stephen Compall
On Sat, 2012-03-31 at 11:00 -0700, Marcelo Macedo de Melo Silva wrote: I'm running multiple threads using this same list and need to update the value of an item inside a STM transaction. If you mean by value of an item the value in the database: I suggest you create an updater agent instead,

Re: Update swank classpath on the fly?

2011-11-04 Thread Jack Moffitt
I've noticed that swank (which I run in emacs using M-x clojure-jack- in) doesn't pickup changes to the classpath on-the-fly. For example, if I update my leiningen project.clj with a new dependency and run lein deps, I need to restart swank to have it use the library. Is there a way to load

Re: Update swank classpath on the fly?

2011-11-04 Thread Chas Emerick
On Nov 4, 2011, at 11:53 AM, AndyK wrote: I've noticed that swank (which I run in emacs using M-x clojure-jack- in) doesn't pickup changes to the classpath on-the-fly. For example, if I update my leiningen project.clj with a new dependency and run lein deps, I need to restart swank to have

Re: update to clojure.tools.cli

2011-11-01 Thread Aaron Bedra
It's strange that it hasn't made it to central yet. This is normally a few hours on the high end and it's been over 12 now. I double checked that the release hit sonatype https://oss.sonatype.org/content/repositories/public/org/clojure/tools.cli/0.2.0/ We might need to summon the all mighty

Re: update to clojure.tools.cli

2011-11-01 Thread Sean Corfield
It's on Maven Central now... On Tue, Nov 1, 2011 at 11:59 AM, Aaron Bedra aaron.be...@gmail.com wrote: It's strange that it hasn't made it to central yet. ... On Tue, Nov 1, 2011 at 1:59 PM, gaz jones gareth.e.jo...@gmail.com wrote: The release has been cut, but the last time I checked it

Re: update to clojure.tools.cli

2011-11-01 Thread Sean Corfield
On Tue, Nov 1, 2011 at 10:59 AM, gaz jones gareth.e.jo...@gmail.com wrote: The update is therefore going to break the existing API which you obviously need to be aware of if you are currently using 0.1.0 and intend to upgrade to 0.2.0. ... Apologies for anyone upset by the timing /

Re: update xml attribute value

2011-06-02 Thread Allen Johnson
Does anyone know how to update xml element attribute value on the zipper data structure? I have something like root     element1 name=x1 description=d1/     element2 name=x2 description=d2/ /root (:require (clojure [xml :as xml] [zip :as zip])      [clojure.contrib.zip-filter.xml :as zf])

Re: update xml attribute value

2011-06-02 Thread siyu798
Thanks Allen, it works, I did not know the loc can be treated like a hash. siyu -- 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

Re: update xml attribute value

2011-06-02 Thread Allen Johnson
Thanks Allen, it works, I did not know the loc can be treated like a hash. 'loc itself isn't a map even though zip/edit makes it seem that way. Behind the scenes zip/edit calls (zip/node loc) which will return a map, at least in the case of this xml example. zip/edit then applies the function

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 7:37 am, Heinz N. Gies he...@licenser.net wrote: Update-in behaves oddly when getting an empty path. (update-in [] {1 2} (constantly {2 3})) returns {nil {2 3} 1 2} not {2 3} as I'd expect. get-in works well with empty pathes so I think this isn't a good behavior. I don't know why

Re: update-in oddness

2010-06-04 Thread Heinz N. Gies
On Jun 4, 2010, at 11:15 , Joost wrote: On Jun 4, 7:37 am, Heinz N. Gies he...@licenser.net wrote: Update-in behaves oddly when getting an empty path. (update-in [] {1 2} (constantly {2 3})) returns {nil {2 3} 1 2} not {2 3} as I'd expect. get-in works well with empty pathes so I think

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 1:42 pm, Heinz N. Gies he...@licenser.net wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly {2 3})) Yes, that gives {nil {2 3}, 1 2} You're not giving any key in the key list, so that is the reason there's a nil key now, and {2 3} is just the value that you

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 2:03 pm, Joost jo...@zeekat.nl wrote: Seems correct as far as the documentation of update-in is concerned. Addendum: though I think you've got a point in that inserting a nil key is unexpected. Personally, I don't really know what to expect from that expression. Joost. -- You

Re: update-in oddness

2010-06-04 Thread Heinz N. Gies
On Jun 4, 2010, at 14:03 , Joost wrote: On Jun 4, 1:42 pm, Heinz N. Gies he...@licenser.net wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly {2 3})) Yes, that gives {nil {2 3}, 1 2} You're not giving any key in the key list, so that is the reason there's a

Re: update-in oddness

2010-06-04 Thread Heinz N. Gies
On Jun 4, 2010, at 14:11 , Heinz N. Gies wrote: On Jun 4, 2010, at 14:03 , Joost wrote: On Jun 4, 1:42 pm, Heinz N. Gies he...@licenser.net wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly {2 3})) Yes, that gives {nil {2 3}, 1 2} You're not giving any

Re: update-in oddness

2010-06-04 Thread Chouser
On Fri, Jun 4, 2010 at 10:04 AM, Heinz N. Gies he...@licenser.net wrote: On Jun 4, 2010, at 14:11 , Heinz N. Gies wrote: On Jun 4, 2010, at 14:03 , Joost wrote: On Jun 4, 1:42 pm, Heinz N. Gies he...@licenser.net wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly

Re: update-in oddness

2010-06-04 Thread Heinz N. Gies
On Jun 4, 2010, at 16:23 , Chouser wrote: I agree with the spirit of your argument, but not your implementation: (update-in* {nil 2} [nil] (constantly 3)) ;= 3 As so often Chouser, you are of cause totally right :). I just realized the flaw when I was about to open a ticket but you

Re: update-in and get-in why no default?

2010-02-02 Thread Timothy Pratley
On 2 February 2010 17:55, Richard Newman holyg...@gmail.com wrote: If you view 'get-in' as an unwrapping operation, unwrapping by zero steps should return the existing collection, no? Thanks for that description I completely agree. Can you explain why you think the result should be nil? I

Re: update-in and get-in why no default?

2010-02-02 Thread Meikel Brandmeyer
Hi, On Feb 2, 1:48 pm, Timothy Pratley timothyprat...@gmail.com wrote: If you view 'get-in' as an unwrapping operation, unwrapping by zero steps should return the existing collection, no? Thanks for that description I completely agree. Hmm.. I thought of get-in as a recursive application

Re: update-in and get-in why no default?

2010-02-02 Thread Meikel Brandmeyer
Hi, On Feb 2, 2:31 pm, Timothy Pratley timothyprat...@gmail.com wrote: Hmm.. I thought of get-in as a recursive application of get. get-in now diverges from get. Maybe this version should be called unwrap instead? Zero applications of get to a map might be thought of as the map itself.

Re: update-in and get-in why no default?

2010-02-01 Thread Timothy Pratley
Am 31.01.2010 um 18:29 schrieb Daniel Werner: If I understand this arity version of get-in correctly, won't the default also be used if the value stored in the nested data structure evaluates to something false-y? Thanks for spotting that early! On 1 February 2010 05:46, Meikel Brandmeyer

Re: update-in and get-in why no default?

2010-02-01 Thread Meikel Brandmeyer
Hi, On Feb 1, 1:57 pm, Timothy Pratley timothyprat...@gmail.com wrote: Good idea, but peek and pop work differently on vectors and sequences, seeing get-in is not constrained to use vectors this could lead to an unexpected behavior: user= (def m  {:a 1, :b 2, :c {:d 3, :e 4}, :f nil})

Re: update-in and get-in why no default?

2010-02-01 Thread Timothy Pratley
On 2 February 2010 00:18, Meikel Brandmeyer m...@kotka.de wrote: Consider this (admittedly constructed) case: (get-in {:a {:b 1}} [:x :c] {:c :uhoh}) Excellent point! Or to use butlast/last instead of peek/pop. I think this is the best approach. butlast/last have linear time so the overhead

Re: update-in and get-in why no default?

2010-02-01 Thread Meikel Brandmeyer
Hi Timothy, On Feb 2, 1:19 am, Timothy Pratley timothyprat...@gmail.com wrote: There are still some sharp edges I'm not sure about: (A) user= (get-in {:a 1} []) {:a 1} ;; this is existing behavior, but I feel the result should be nil +1 for nil (B) user= (get-in {:a 1} nil) {:a 1} ;;

Re: update-in and get-in why no default?

2010-02-01 Thread Richard Newman
There are still some sharp edges I'm not sure about: (A) user= (get-in {:a 1} []) {:a 1} ;; this is existing behavior, but I feel the result should be nil +1 for nil I think I disagree. If you view 'get-in' as an unwrapping operation, unwrapping by zero steps should return the existing

Re: update-in and get-in why no default?

2010-02-01 Thread Meikel Brandmeyer
Hi, On Feb 2, 7:55 am, Richard Newman holyg...@gmail.com wrote: I think I disagree. Can you explain why you think the result should be nil? Woops. I got confused. I didn't mean nil for empty key sequences. I meant throwing an exception as does get. Sincerely Meikel -- You received this

Re: update-in and get-in why no default?

2010-01-31 Thread Daniel Werner
([m ks not-found] (if-let [v (reduce get m ks)] v not-found))) If I understand this arity version of get-in correctly, won't the default also be used if the value stored in the nested data structure evaluates to something false-y? Anyway, thanks for creating the patches! -- You

Re: update-in and get-in why no default?

2010-01-31 Thread Meikel Brandmeyer
Hi, Am 31.01.2010 um 18:29 schrieb Daniel Werner: ([m ks not-found] (if-let [v (reduce get m ks)] v not-found))) If I understand this arity version of get-in correctly, won't the default also be used if the value stored in the nested data structure evaluates to something false-y?

Re: update-in and get-in why no default?

2010-01-29 Thread Rich Hickey
On Dec 30 2009, 6:18 am, Timothy Pratley timothyprat...@gmail.com wrote: On Dec 13, 1:24 am, Rich Hickey richhic...@gmail.com wrote: fnil seems to me to have greater utility than patching all functions that apply functions with default-supplying arguments. Neat :) I like it. The

Re: update-in and get-in why no default?

2010-01-29 Thread Sean Devlin
Rich, Your example didn't support a variadic signature. Is that the long term plan? Sean On Jan 29, 8:48 am, Rich Hickey richhic...@gmail.com wrote: On Dec 30 2009, 6:18 am, Timothy Pratley timothyprat...@gmail.com wrote: On Dec 13, 1:24 am, Rich Hickey richhic...@gmail.com wrote: fnil

Re: update-in and get-in why no default?

2010-01-29 Thread Rich Hickey
On Jan 29, 9:04 am, Sean Devlin francoisdev...@gmail.com wrote: Rich, Your example didn't support a variadic signature.  Is that the long term plan? It's the short term plan. Let's see if there's any real need for more than three. I've never needed more than one. Rich -- You received

Re: update-in and get-in why no default?

2010-01-29 Thread Timothy Pratley
2010/1/30 Rich Hickey richhic...@gmail.com: Patches welcome for get-in, and my fnil. Groovy! uploaded to: https://www.assembla.com/spaces/clojure/tickets/256-get-in-optional-default-value https://www.assembla.com/spaces/clojure/tickets/257-add-fnil-for-wrapping-functions-to-handle-nil Regards,

Re: update-in! (?)

2010-01-21 Thread Gabi
I don't think zipper would help in this case On Jan 21, 12:40 am, brianh brian.h.w...@gmail.com wrote: Any chance you could rethink your approach use a zipper? On Jan 20, 9:32 am, Gabi bugspy...@gmail.com wrote: I posted a question on SO about it. Interesting

Re: update-in! (?)

2010-01-20 Thread Gabi
Guys, I really need your expertise here. I have lots of deeply nested vectors, which i need to manipulate frequently (thousands of times) What is the most effective way to do this ? On Jan 17, 4:27 pm, Gabi bugspy...@gmail.com wrote: Right. I thought that transient performing deep

Re: update-in! (?)

2010-01-20 Thread Christophe Grand
Hi Gabi! Can you tell us more about your problem, what do those deeply nested vectors represent and how are you going to update them? (are all updates batched in one part of your program?) With transients current implementation you can't write an efficient update-in! Christophe On Wed, Jan 20,

Re: update-in! (?)

2010-01-20 Thread Gabi
These vectors represent trees which need to updated very frequently. So If there was an efficient way to use transients to represent transient trees the whole process would be much more efficient (so each update to a tree would be done in place instead of creating new one.) As discussed above,

Re: update-in! (?)

2010-01-20 Thread Sean Devlin
Gabi, A similar technique is used with sparse matrices. You usually have severals arrays, one for the non-zero elements, and another one for indexing the column and a third for indexing the rows. http://pasadena.wr.usgs.gov/office/baagaard/research/papers/thesis/figs/methods/sparseMatrix.gif

Re: update-in! (?)

2010-01-20 Thread Gabi
I need to add/delete much more frequently than just updating actually. On Jan 20, 4:59 pm, Sean Devlin francoisdev...@gmail.com wrote: Gabi, A similar technique is used with sparse matrices.  You usually have severals arrays, one for the non-zero elements, and another one for indexing the

Re: update-in! (?)

2010-01-20 Thread Sean Devlin
How about a sorted set w/ a custom comparator? Of course, this rules out transients, but maybe the flatness will make up for it? On Jan 20, 10:15 am, Gabi bugspy...@gmail.com wrote: I need to add/delete much more frequently than just updating actually. On Jan 20, 4:59 pm, Sean Devlin

Re: update-in! (?)

2010-01-20 Thread Gabi
Can you elaborate more ? How can trees be represented in sorted sets? On Jan 20, 5:24 pm, Sean Devlin francoisdev...@gmail.com wrote: How about a sorted set w/ a custom comparator?  Of course, this rules out transients, but maybe the flatness will make up for it? On Jan 20, 10:15 am, Gabi

Re: update-in! (?)

2010-01-20 Thread Christophe Grand
I concur: a map (or a sorted map if you need to emulate access to a subtree) can be an option. [[1 2] [3 4]] is represented by {[0 0] 1, [0 1] 2, [1 0] 3, [1 1] 4} On Wed, Jan 20, 2010 at 4:24 PM, Sean Devlin francoisdev...@gmail.com wrote: How about a sorted set w/ a custom comparator?  Of

Re: update-in! (?)

2010-01-20 Thread Gabi
I posted a question on SO about it. Interesting discussion: http://stackoverflow.com/questions/2102606/algorithm-to-implement-non-binary-trees-using-1-dimensional-vector On Jan 20, 5:39 pm, Christophe Grand christo...@cgrand.net wrote: I concur: a map (or a sorted map if you need to emulate

Re: update-in! (?)

2010-01-20 Thread brianh
Any chance you could rethink your approach use a zipper? On Jan 20, 9:32 am, Gabi bugspy...@gmail.com wrote: I posted a question on SO about it. Interesting discussion:http://stackoverflow.com/questions/2102606/algorithm-to-implement-non... On Jan 20, 5:39 pm, Christophe Grand

Re: update-in! (?)

2010-01-17 Thread Gabi
Forgot to mention that v in the example is defined to [[1 2] [3 4]] On Jan 17, 3:19 pm, Gabi bugspy...@gmail.com wrote: I really needed an update-in! version that works on transients. I couldn't find one so I just modified the original update-in core (just replaced assoc assoc!): (defn

Re: update-in! (?)

2010-01-17 Thread Chouser
On Sun, Jan 17, 2010 at 8:25 AM, Gabi bugspy...@gmail.com wrote: user= (persistent!(update-in!(transient v) [0] reverse)) Forgot to mention that v in the example is defined to  [[1 2] [3 4]] So you've got a transient vector of persistent vectors of numbers. The problem is your update-in!

Re: update-in! (?)

2010-01-17 Thread Gabi
Right. I thought that transient performing deep 'transientivity'. Here is a fixed version. It takes a regular coll converts whatever it can to transient and update the stuff. The problem is that doing persistent!(assoc!(transient m)) on each level probably misses the whole point of performance. So

Re: update-in and get-in why no default?

2010-01-02 Thread Timothy Pratley
2010/1/2 Sean Devlin francoisdev...@gmail.com: I don't think your version of the signature supports variadic defaults well. Hi Sean, Thanks for commenting. Just by way of clarification, taking the function as the last argument seems to work fine in my experiments. I'm sure it could be better

Re: update-in and get-in why no default?

2010-01-02 Thread Timothy Pratley
2010/1/2 Timothy Pratley timothyprat...@gmail.com: user= ((fnil-2 1 +) nil 2 3 4 5) java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0) Correction, I just realized of course it doesn't work if I specify the arguments around the wrong way! I

Re: update-in and get-in why no default?

2010-01-01 Thread Timothy Pratley
On Dec 13, 1:24 am, Rich Hickey richhic...@gmail.com wrote: fnil seems to me to have greater utility than patching all functions that apply functions with default-supplying arguments. Hi Rich, To further comment on fnil, after having experimented with it a bit now, I've come to slightly

Re: update-in and get-in why no default?

2010-01-01 Thread Sean Devlin
Tim, I don't think your version of the signature supports variadic defaults well. Also, I'd (initially) implement fnil differently that Rich. Here's my fnil-2 that I *suspect* has the intended behavior (defn fnil-2 [f defaults] (fn[ args] (let [used-args (map (fn [default-value value]

Re: update-in and get-in why no default?

2009-12-30 Thread Timothy Pratley
On Dec 13, 1:24 am, Rich Hickey richhic...@gmail.com wrote: fnil seems to me to have greater utility than patching all functions that apply functions with default-supplying arguments. Neat :) I like it. The get-in function could be enhanced, and would mirror get. Should I interpret

Re: update-in and get-in why no default?

2009-12-12 Thread Rich Hickey
On Thu, Dec 10, 2009 at 7:20 AM, Timothy Pratley timothyprat...@gmail.com wrote: Hi, update-in is an especially useful function but I find the update function inevitably requires a check for nil. If I could supply a not- found value then my code would get better golf scores. When I reach

Re: update-in and get-in why no default?

2009-12-10 Thread Sean Devlin
Tim, I like both of these ideas. I agree, get-in2 seems to make sense as a drop in replacement. With update-in2 I prefer a new name, because I do occasionally write code that constructs lists of functions. I'd hate to get a weird bug while doing this. Sean On Dec 10, 7:20 am, Timothy Pratley

Re: update-in and get-in why no default?

2009-12-10 Thread ataggart
Seconded; I like the intention of both changes, and do something similar in a lot of my code (e.g., parsing functions that take an extra arg if the parse is unsuccessful). Also, testing the type of update-in2's second arg is a bad idea, imo. As for the breaking change of adding another arg to

Re: update-proxy doc - what is this ?

2009-11-01 Thread Alex Osborne
msappler wrote: user= (doc update-proxy) It says:the first arg corresponding to this What is meant with this? this means the proxy object itself (like the this keyword in Java). --~--~-~--~~~---~--~~ You received this message because you are subscribed to

Re: update/update-in

2009-04-29 Thread David Nolen
Because update-in can use any function to do the update. On Wed, Apr 29, 2009 at 6:54 PM, mifrai fraim...@gmail.com wrote: Hi, I was wondering why there was no update to update-in? But there is an assoc to assoc-in and a get to a get-in. - Mike

Re: update/update-in

2009-04-29 Thread mifrai
Thanks for the quick reply and I understand that's the functionality of it. But just like get-in is the recursive form of get - I'm just wondering why there's no singular form of update-in. I know it's not much more work to go (update-in map [:single-key] conj 3) - but from experience there

Re: update/update-in

2009-04-29 Thread David Nolen
I see what you mean, does seem like a useful addition: (defn update [m k f args] (assoc m k (apply f (k m) args))) (update {:foo 0} :foo inc) vs. (assoc {:foo 0} :foo (inc (:foo {:foo 0}))) On Wed, Apr 29, 2009 at 7:13 PM, mifrai fraim...@gmail.com wrote: Thanks for the quick reply and I

Re: update-in wildcards?

2009-04-13 Thread Ozzi Lee
Well, I expected someone to tell my that was a horrible idea, not to implement it for me. Thanks! One thing that concerns me is that :* could conceivable be used as a key in a hash-map. Perhaps a separate distinct value should be used as a wildcard? Does clojure have a facility for creating a

Re: update-in wildcards?

2009-04-13 Thread Ozzi Lee
Does clojure have a facility for creating a value that will never be considered equal to any other value? Duh, brainfart. Gensym will work nicely, of course. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure

Re: update-in wildcards?

2009-04-12 Thread Mitch
(use '[clojure.contrib.generic.functor :only (fmap)]) (defn update-in-wildcard Like update-in, but with :* as a wildcard matcher ([m [k ks] f args] (condp = [(= k :*) (boolean ks)] [true true] (fmap #(apply update-in-wildcard % ks f args) m) [true false] (fmap f m) [false

Re: update-values for clojure.contrib.sql

2009-01-13 Thread Stephen C. Gilardi
On Jan 11, 2009, at 10:42 AM, Stephen C. Gilardi wrote: I'd like to include something like this in clojure.contrib.sql. That will go smoothest if I can base it directly on what you've written and that's only possible if you send in a contributor agreement. Would you please send one in?

Re: update-values for clojure.contrib.sql

2009-01-11 Thread Stephen C. Gilardi
On Jan 2, 2009, at 2:21 AM, budu wrote: Hi, I was experimenting with clojure-contrib's sql features and found that there wasn't any update-values function. I've written my own and I'm sharing it here: (defn update-values [table where column-names values] Update columns of a table with

Re: update in place for unique references

2009-01-09 Thread Timothy Pratley
Most structures of this type would start life as a uniquely-referenced structure (either empty or a copy of an immutable), and have lots of mutations effectively applied to them in a safe environment, until they are ready to be frozen and released to the world as an immutable version of the

Re: update in place for unique references

2009-01-09 Thread Stuart Sierra
On Jan 8, 10:45 pm, Mark P pierh...@gmail.com wrote: I should also clarify one point.  I am not asking for this language feature so much as asking whether people have thought about it.  There may (or may not) be good reasons for not offering such a language feature.  I'm just wondering if it

Re: update in place for unique references

2009-01-09 Thread Mark P
Hi Tim, I appreciate your comments. It is possible to achieve this behavior explicitly if you really wanted to: (defn create-add-2 []   (with-local-vars [x 1]     (do       (var-set x 1)       (var-set x (inc @x))       (let [z @x]         (fn [y] (+ y z)) That's true. Only the

Re: update in place for unique references

2009-01-08 Thread Mark Engelberg
Clean doesn't allow mutation, so it has to do tricks like this or else you'd never be able to write a useful program. Clojure gives you a set of data structures that do very fast non-destructive update. Clojure also gives you tools like atoms, refs, and full access to Java's mutable behavior to

Re: update in place for unique references

2009-01-08 Thread Mark P
Clojure gives you a set of data structures that do very fast non-destructive update.  Clojure also gives you tools like atoms, refs, and full access to Java's mutable behavior to specify update in place if that's what you want. Yes, I can see that one could implement this oneself via Java.

Re: update in place for unique references

2009-01-08 Thread Mark P
Hi Mark F, Thanks for your responses. 1. Data: Is this really a problem that is slowing down Clojure programs in practice? Can you provide some data to that effect? I would suggest writing a couple of Java benchmarks - one that updates a simple structure in place and one that only creates

Re: update-values for clojure.contrib.sql

2009-01-02 Thread Christian Vest Hansen
Well, one thing that sticks out (particularly to me) is the fact that you forgot to put your doc-string *before* your [params*] list :) (ahem) On Fri, Jan 2, 2009 at 8:21 AM, budu nbudu...@gmail.com wrote: Hi, I was experimenting with clojure-contrib's sql features and found that there wasn't

Re: update-values for clojure.contrib.sql

2009-01-02 Thread budu
D'oh! I have a hard time kicking out that old habit. And changing code after testing it too! On Jan 2, 4:21 am, Christian Vest Hansen karmazi...@gmail.com wrote: Well, one thing that sticks out (particularly to me) is the fact that you forgot to put your doc-string *before* your [params*] list

Re: update a ref struct

2008-11-24 Thread Kevin Downey
I know you are asking about refs, but you might want to think about using reduce to walk the line-seq. the nature of reduce lets you have access to the line-seq, two lines at a time no need for a ref. On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle [EMAIL PROTECTED] wrote: I am parsing a file and

Re: update a ref struct

2008-11-24 Thread Brian Doyle
Thanks Kevin, I will try using reduce instead. I would like to know what I'm doing wrong with updating the ref for future reference. Thanks. On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey [EMAIL PROTECTED] wrote: I know you are asking about refs, but you might want to think about using

Re: update a ref struct

2008-11-24 Thread Kevin Downey
ref-set needs its one set of parens, and the last thing in the ref-set call needs to be a function either (fn [x] ...) or a symbol for a var that holds a function On Mon, Nov 24, 2008 at 2:30 PM, Brian Doyle [EMAIL PROTECTED] wrote: Thanks Kevin, I will try using reduce instead. I would like

Re: update a ref struct

2008-11-24 Thread Kevin Downey
On Mon, Nov 24, 2008 at 2:34 PM, Kevin Downey [EMAIL PROTECTED] wrote: ref-set needs its one set of parens, and the last thing in the ref-set call needs to be a function either (fn [x] ...) or a symbol for a var that holds a function I made a mistake here. I was thinking of alter, not

  1   2   >