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
is
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
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 may
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't
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
andi.xeno...@googlemail.com wrote:
I think your use of
Hi,
I would like to know why defstruct without providing any keys (like
(defstruct s)) is not allowed (exception: Must supply keys).
Let me shortly describe why I think that this would be useful: Imagine
you have a defstruct like in Rich's Ants demo:
(defstruct cell :food :pher) ;may also have
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
andi.xeno...@googlemail.com wrote:
Hi,
I would like to know why defstruct
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:
On 20 Jan., 00:56, Kevin Downey redc...@gmail.com 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
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 reason why
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,
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 group,
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.
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 better readable
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
andi.xeno...@googlemail.com wrote:
I fail to see how it requires changing a lot of
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?)
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
andi.xeno...@googlemail.com wrote:
how is that not an argument? I'm pretty sure I just used it
2010/1/20 Andreas Wenger andi.xeno...@googlemail.com:
(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
18 matches
Mail list logo