Re: copying structures

2010-03-30 Thread Jarkko Oranen
> The def was for legibility (or I was going for legibility). Speaking > of redefing, is there a way to block a redef so I or someone else > doesn't monkey-patch a function? You can set a validator on the Var to prevent accidents. However, someone who really wants to redefine a function can just

Re: copying structures

2010-03-29 Thread Josh Stratton
> Please note that actually def'ing each value is not what you're > supposed to do :) def is reserved for global constants and dynamically > rebindable variables, and redefing an existing variable is considered > bad style. The def was for legibility (or I was going for legibility). Speaking of r

Re: copying structures

2010-03-29 Thread Jarkko Oranen
On Mar 29, 1:26 am, strattonbrazil wrote: > Is this the common way to do it? > > (def sister (assoc brother :name "Cindy")) > Please note that actually def'ing each value is not what you're supposed to do :) def is reserved for global constants and dynamically rebindable variables, and redefing

Re: copying structures

2010-03-28 Thread Rick Mouritzen
The Clojure data structures are immutable, so there's no need to copy. Just "modify" the existing structure and you have a new immutable instance. If you are coming from Java, it helps to think of these immutable structures like Java's String. On Sun, Mar 28, 2010 at 9:29 AM, strattonbrazil wrot

Re: copying structures

2010-03-28 Thread Richard Newman
Is this the common way to do it? (def sister (assoc brother :name "Cindy")) If you want to change the value of one key in a map, yes. (In this example it looks weird, of course.) If you want to create a new map by taking only some values from another map: user=> (def sister (assoc (sele

Re: copying structures

2010-03-28 Thread strattonbrazil
Is this the common way to do it? (def sister (assoc brother :name "Cindy")) Reading up more on structs, it seems they have base keys that can't be dissoc. Is that the main difference then between it and a hash? On Mar 28, 2:48 pm, strattonbrazil wrote: > I did a poor job explaining myself.  S

Re: copying structures

2010-03-28 Thread Richard Newman
Is there a shorter way to do this? See my earlier message. dissoc and assoc will do what you want. (def brother {:name "Gary" :address "..." :mother "Mary" :father "John"}) (def sister (assoc brother :name "Cindy")) user=> sister {:name "Cindy", :address "...", :mother "Mary", :father "John

Re: copying structures

2010-03-28 Thread strattonbrazil
I did a poor job explaining myself. Sorry. I understand that copying an immutable structure is worthless. I want a copy of a structure except one or two specific properties. For example, (defstruct person :name :address :mother :father) (def brother (struct person "Gary" ...)) (def sister (st

Re: copying structures

2010-03-28 Thread B Smith-Mannschott
On Sun, Mar 28, 2010 at 18:29, strattonbrazil wrote: > This may be really basic.  So much so that it's hard to find on the > internet, but is there something like a copy constructor in clojure, A copy-constructor is redundant in a language where values are immutable. (Just refer to it since it ca

Re: copying structures

2010-03-28 Thread Laurent PETIT
As for papers on the Interner on the subject of persistent data structures, one gentle introduction might be this blog entry: http://eclipsesource.com/blogs/2009/12/13/persistent-trees-in-git-clojure-and-couchdb-data-structure-convergence/ (with examples from several fields: git, clojure, etc.) H

Re: copying structures

2010-03-28 Thread Richard Newman
This may be really basic. So much so that it's hard to find on the internet, but is there something like a copy constructor in clojure, where I can copy everything in a structure except one or two keys? Maybe something like struct-map, but fills in the other variables not supplied by another data

copying structures

2010-03-28 Thread strattonbrazil
This may be really basic. So much so that it's hard to find on the internet, but is there something like a copy constructor in clojure, where I can copy everything in a structure except one or two keys? Maybe something like struct-map, but fills in the other variables not supplied by another data