Unfortunately you can only attach metadata to types that implement the
IObj interface. That excludes native Java types like Integer and
Float:

user=> (with-meta 42 {:foo 42})
java.lang.ClassCastException: java.lang.Integer (NO_SOURCE_FILE:0)
user=> (with-meta 42.0 {:foo 42})
java.lang.ClassCastException: java.lang.Double (NO_SOURCE_FILE:0)
user=> (with-meta (float 42.0) {:foo 42})
java.lang.ClassCastException: java.lang.Float (NO_SOURCE_FILE:0)

I haven't thought through all the implications, but it seems like
Clojure could support externalized metadata for these sort of types
with an identity-based weak-key hash table.

Anyway, the way things stand, your best kept is probably to wrap your
data in some data structure. It could be as simple as [:frequency x]
or {:tag :frequency, :value x}.

-Per

On Sat, Apr 3, 2010 at 5:47 AM, strattonbrazil <[email protected]> wrote:
> What's the best way to keep track of what kind of value something is?
> For example, if I have a hash of floats and I want to go through each
> one and see if a given key-value, which happens to be a float, if it's
> a distance or a frequency?  Or if something is a struct or a specific
> struct?  I'm somewhat familiar with the pattern matching done in Scala
> and couldn't find similar documentation in Clojure.
>
> I would think there's some way to filter out values that are a certain
> struct, but I'd also like to attach information to primitives like
> floats.  Should I wrap my primitives in structs or do I need
> metadata?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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
>
> To unsubscribe, reply using "remove me" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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