Re: Empty defstruct

2010-01-22 Thread kyle smith
user> (defn inc-vals [m] (into (empty m) (zipmap (keys m) (map inc (vals m) #'user/inc-vals user> (inc-vals {:a 1 :b 2}) {:b 3, :a 2} user> (inc-vals (struct (create-struct :a :b) 1 2)) {:a 2, :b 3} user> (= *1 *2) true So what's the problem (other than printing differently)? -- You

Re: Empty defstruct

2010-01-22 Thread Andreas Wenger
> as I said, structs are an optimization on maps, that optimization > doesn't work for empty structs, so empty structs "of course" don't > make sense For me structs are more than just optimizations. They add documentary information to the map, which is a great feature for readability. Optimization

Re: Empty defstruct

2010-01-20 Thread Kevin Downey
"empty classes in Java" what does that mean? as I said, structs are an optimization on maps, that optimization doesn't work for empty structs, so empty structs "of course" don't make sense On Wed, Jan 20, 2010 at 12:39 AM, Andreas Wenger wrote: >> I think your use of "workaround" is pejorative.

Re: Empty defstruct

2010-01-20 Thread Andreas Wenger
> I think your use of "workaround" is pejorative. And can it even be > called a work around if it is a best practice even when there is > nothing to work around? I just can't understand why throwing an exception should be more useful than returning some object you can actually work with. I wouldn'

Re: Empty defstruct

2010-01-20 Thread Andreas Wenger
> Just another option to consider: > {:type :person, :name "Bill", :age 20} Why then use defstruct at all? I think defstruct is useful, but it would be even more useful if I had nothing to fear if it "runs empty" sometime because of little design changes. It might be only experimental and later I

Re: Empty defstruct

2010-01-19 Thread Timothy Pratley
2010/1/20 Andreas Wenger : > (struct-map person :name "Bill") Hi Andreas, Just another option to consider: {:type :person, :name "Bill", :age 20} I'll steer clear of discussing the original question :) Regards, Tim. -- You received this message because you are subscribed to the Google Groups

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
I think your use of "workaround" is pejorative. And can it even be called a work around if it is a best practice even when there is nothing to work around? On Tue, Jan 19, 2010 at 4:28 PM, Andreas Wenger wrote: >> how is that not an argument? I'm pretty sure I just used it as one. > > What I want

Re: Empty defstruct

2010-01-19 Thread Andreas Wenger
> how is that not an argument? I'm pretty sure I just used it as one. What I wanted to say is that you are completely right, if you say that it is easy to create a workaround. But although doing this is easy, this does not mean that we should not fix this inconsistency (or do you see none?) anyway

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
how is that not an argument? I'm pretty sure I just used it as one. keep in mind defstruct is largely to be superseded by deftype. http://clojure.org/contributing On Tue, Jan 19, 2010 at 4:10 PM, Andreas Wenger wrote: >> I fail to see how it requires changing a lot of code. it just means >> you

Re: Empty defstruct

2010-01-19 Thread Andreas Wenger
> > And documentary style is lost. Would be ok though, but not optimal. > > On the contrary, I think > >    {:name "Bill" :age 23 :friends 20} > > is better than > >    (struct-map person "Bill" 23 20) Please review the definition of struct-map... Actually we seem to have the same opinion! Even be

Re: Empty defstruct

2010-01-19 Thread Andreas Wenger
> I fail to see how it requires changing a lot of code. it just means > you need to change the place where you create your maps. which if you > are also type tagging them is a lot of repetitive code, so it should > already be factored out into a function, so then you just switch out > one function.

Re: Empty defstruct

2010-01-19 Thread Richard Newman
And documentary style is lost. Would be ok though, but not optimal. On the contrary, I think {:name "Bill" :age 23 :friends 20} is better than (struct-map person "Bill" 23 20) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this gr

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
I fail to see how it requires changing a lot of code. it just means you need to change the place where you create your maps. which if you are also type tagging them is a lot of repetitive code, so it should already be factored out into a function, so then you just switch out one function. On Tue,

Re: Empty defstruct

2010-01-19 Thread Andreas Wenger
> I think Andreas's point is that there's a discontinuity: > > 0 required keys: map > 1 required key:  struct-map > 2 required keys: struct-map > ... That's exactly the point! If I change only a little detail in my program, this can have impact on a huge part of my program. I can not see any reaso

Re: Empty defstruct

2010-01-19 Thread Andreas Wenger
On 20 Jan., 00:56, Kevin Downey wrote: > clojure structs are an optimized version of maps for a set of shared > keys. if you don't have a defined set of shared keys you just have a > map. so by all means, use a map You're talking about the implementation in the background, but I am talking about

Re: Empty defstruct

2010-01-19 Thread Richard Newman
clojure structs are an optimized version of maps for a set of shared keys. if you don't have a defined set of shared keys you just have a map. so by all means, use a map I think Andreas's point is that there's a discontinuity: 0 required keys: map 1 required key: struct-map 2 required keys: st

Re: Empty defstruct

2010-01-19 Thread Kevin Downey
clojure structs are an optimized version of maps for a set of shared keys. if you don't have a defined set of shared keys you just have a map. so by all means, use a map On Tue, Jan 19, 2010 at 3:52 PM, Andreas Wenger wrote: > Hi, > > I would like to know why defstruct without providing any keys