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 moderat

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

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

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 Goog

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 l

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

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 th

Re: Update

2014-04-29 Thread Divyansh Prakash
I looked into a port of Clojure to Parrot, and it basically does the same thing . -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clo

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 f

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

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 clojure@googlegr

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 t

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 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 update-in! >  

Re: update-in! (?)

2010-01-17 Thread Chouser
On Sun, Jan 17, 2010 at 8:25 AM, Gabi 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! then calls assoc

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! (?)

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 wrote: > Right. I thought that transient performing deep 'transientivity'. > Here is a fix

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

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 Thi

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 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 column and a third for

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 wrote: > I need to add/delete much more frequently than just updating > actually. > > On Jan 20, 4:59 pm, Sean Devlin wrote: > > > Gabi, > >

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 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 wrote: > > > I need to

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 wrote: > How about a sorted set w/ a custom comparator?  Of course, this rules > out tr

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 wrote: > I concur: a map (or a sorted map if you need to emulate access to a > subtree) ca

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 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 wrote: > > > > > I concur:

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 wrote: > Any chance you could rethink your approach & use a zipper? > > On Jan 20, 9:32 am, Gabi wrote: > > > I posted a question on SO about it. Interesting > > discussion:http://stackoverflow.com/questions/2102606/algori

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) [fa

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 val

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

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

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 wrote: > > Thanks for the quick reply and I understand that

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 7:37 am, "Heinz N. Gies" 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 you expect tha

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

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 1:42 pm, "Heinz N. Gies" 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 give it, since t

Re: update-in oddness

2010-06-04 Thread Joost
On Jun 4, 2:03 pm, Joost 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 received this messa

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

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" 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 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" wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly {2 3})) >>> >

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 y

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 Stua

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 wrote: > It's strange that it hasn't made it to central yet. ... > On Tue, Nov 1, 2011 at 1:59 PM, gaz jones wrote: >> The release has been cut, but the last time I checked it still hadn't >> hit maven central, so this is

Re: update to clojure.tools.cli

2011-11-01 Thread Sean Corfield
On Tue, Nov 1, 2011 at 10:59 AM, gaz jones 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 / notification of the changes > --

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 wrote: > > Hi, I was experimenting with clojure-contrib's sql features and found > that there wasn't any update-valu

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" 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 :) > (ahem) > >

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 valu

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-14 Thread budu
Good, anyway it was only a relatively minor modification of insert- values function. I'm sending my contributor agreement today, hoping to contribute further in a near future. Thanks On Jan 14, 12:13 am, "Stephen C. Gilardi" wrote: > On Jan 11, 2009, at 10:42 AM, Stephen C. Gilardi wrote: > > >

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

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 > >     >     > > (:require (clojure [xml :as xml] [zip :as zip]) >      [clojure.contrib.zip-filter.xml :as zf]) > (let >   [src (-> "c:/my.xml" io/file xml/parse zip/xml-zip) >

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 p

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 yo

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 an

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 r

Re: update a ref struct

2008-11-24 Thread Shawn Hoover
On Mon, Nov 24, 2008 at 5:17 PM, Brian Doyle <[EMAIL PROTECTED]> wrote: > I am parsing a file and to compare the current line > with the previous line of the file. I am using line-seq > to go thru the file and I thought I would create a > ref to store the previous line. When I want to update >

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 Jeff Rose
For using references in general, here is a little example: [EMAIL PROTECTED]:~$ clj Clojure user=> (def foo (ref 0)) #'user/foo user=> foo # user=> @foo 0 user=> (ref-set foo 1) java.lang.IllegalStateException: No transaction running (NO_SOURCE_FILE:0) user=> (dosync (ref-set foo 1)) 1 user=> @fo

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 ref

Re: update a ref struct

2008-11-24 Thread Stuart Halloway
Another possible approach. Key idea here is to use partition to create a sliding window over the lines, plus a sentinel value (I picked "") before the first line. Pretty sure I like partition over reduce for this particular example. (ns examples.convert (:use [clojure.contrib.duck-stre

Re: update a ref struct

2008-11-24 Thread Brian Doyle
Yep, that's just a typo in the email. Something was wrong with my browser and I couldn't just paste the code in :( On Mon, Nov 24, 2008 at 3:33 PM, Shawn Hoover <[EMAIL PROTECTED]>wrote: > On Mon, Nov 24, 2008 at 5:17 PM, Brian Doyle <[EMAIL PROTECTED]>wrote: > >> I am parsing a file and to comp

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 Fredrickson
Time for another person named Mark to chime in. I expect to hear from all the other Marks before this thread is over. I have three responses to your suggestion: 1. Data: Is this really a problem that is slowing down Clojure programs in practice? Can you provide some data to that effect? I

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 create

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 o

Re: update in place for unique references

2009-01-09 Thread Stuart Sierra
On Jan 8, 10:45 pm, Mark P 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 has been >

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

Re: update in place for unique references

2009-01-09 Thread Mark P
Hi Stuart, > I think the big strength of Clojure is how easy it is to integrate > Java code. If you have some performance-critical code you can always > drop down to Java. Certainly, performance is important to Clojure, but > I think the assumption is that it will never compete with pure Java on

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 s

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 lo

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 hav

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 wrote: > Hello everybody, > > How can I update values in the vector given vector of id-s a

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

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 give

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 upd

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 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 for update-in, I usu

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

2009-12-30 Thread Timothy Pratley
On Dec 13, 1:24 am, Rich Hickey 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 'could' as 'patch welcom

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

2010-01-01 Thread Timothy Pratley
On Dec 13, 1:24 am, Rich Hickey 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 prefer specifying the 'd

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?

2010-01-02 Thread Timothy Pratley
2010/1/2 Sean Devlin : > 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 but here what I've been u

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

2010-01-02 Thread Timothy Pratley
2010/1/2 Timothy Pratley : > 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 should have done: user=>

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

2010-01-29 Thread Rich Hickey
On Dec 30 2009, 6:18 am, Timothy Pratley wrote: > On Dec 13, 1:24 am, Rich Hickey 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

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 wrote: > On Dec 30 2009, 6:18 am, Timothy Pratley > wrote: > > > On Dec 13, 1:24 am, Rich Hickey wrote: > > > > fnil seems to me to have greater utility than patching all f

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

2010-01-29 Thread Rich Hickey
On Jan 29, 9:04 am, Sean Devlin 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 this message because you

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

2010-01-29 Thread Timothy Pratley
2010/1/30 Rich Hickey : > 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, Tim. -- You recei

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

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 somethi

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 Brandm

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

2010-02-01 Thread Meikel Brandmeyer
Hi, On Feb 1, 1:57 pm, Timothy Pratley 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}) > #'user/m > user=> (get-i

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

2010-02-01 Thread Timothy Pratley
On 2 February 2010 00:18, Meikel Brandmeyer 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 is small.

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 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} > ;; this is existing b

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 col

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

2010-02-01 Thread Meikel Brandmeyer
Hi, On Feb 2, 7:55 am, Richard Newman 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 message because you ar

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

2010-02-02 Thread Timothy Pratley
On 2 February 2010 17:55, Richard Newman 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 was not thinking

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

2010-02-02 Thread Meikel Brandmeyer
Hi, On Feb 2, 1:48 pm, Timothy Pratley 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 of get. get-in now

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

2010-02-02 Thread Timothy Pratley
On 2 February 2010 17:41, Meikel Brandmeyer wrote: > I would get rid of the if-let. Ah yes! Ok patch updated to: + ([m ks not-found] + (if (seq ks) + (get (reduce get m (butlast ks)) (last ks) not-found) + m))) Note that (seq ks) will throw an illegal argument exception if ks is 5 fo

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

2010-02-02 Thread Meikel Brandmeyer
Hi, On Feb 2, 2:31 pm, Timothy Pratley 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. > Are you thinki

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

  1   2   >