On Aug 20, 9:46 am, Chouser <[EMAIL PROTECTED]> wrote:
> On Wed, Aug 20, 2008 at 7:11 AM, Parth Malwankar
>
> <[EMAIL PROTECTED]> wrote:
>
> > (sclass (struct mystruct)) => mystruct
>
> It doesn't look like it.  It appears that although the StructMap keeps
> a reference to the Def, there's no way to get it back out.  Even if
> there were, I'm not sure how you'd get back to the name given to the
> Def -- in fact, there could be many (or no) names.  Here's an
> anonymous struct:
>
> user=> (struct (create-struct :a :b) 1 2)
> {:a 1, :b 2}
>
> I suppose you could try to use an incompatible accessor -- if there's
> no exeception, you know it's the right kind of struct:
>
> user=> (defstruct foo :a :b)
> user=> (defstruct bar :c :d)
> user=> ((accessor foo :a) (struct foo))
> nil
> user=> ((accessor foo :a) (struct bar))
> java.lang.Exception: Accessor/struct mismatch
>
> But this all seems a little wrong.  I think structs are meant to be
> just a little performance (memory) improvement over a regular hashmap.
>  It seems like meta-data would be a better fit, but I'm not quite sure
> how to use it:
>
> user=> (defstruct mystruct :a :b)
> user=> (def v1 #^mystruct {})
> user=> ^v1
> {:tag mystruct}
> user=> (def v2 #^mystruct (struct mystruct 1 2))
> user=> ^v2
> nil

Yes. These are some of the many reasons:

structs can be anonymous

They are just an optimization

Metadata can be used for type and other tagging, and the same method
will work for other non-struct maps

We need to get away from putting single 'types' on information, they
are just maps

There could be many taxonomies of 'types', having a privileged one is
just a recipe for yet-another-type-system

Using metadata/attributes will work with the new a la carte hierarchy
and isa dispatch stuff.

Structs are dynamic - would the 'types' of instances created from two
revisions of the same-named defstruct be the same?

If I give you struct types, you'll next ask for struct derivation

etc :)

Rich
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to