Hi, that have been some really embarrassing typos in my post (typing too fast in too stupid an interface, I think).
On Nov 27, 12:52 pm, "Alex Osborne" <a...@meshy.org> wrote: > Stefan Kamphausen <ska2...@googlemail.com> writes: > > On Nov 8, 3:46 am, Alex Osborne <a...@meshy.org> wrote: > > As far as the documentation says, Vars can't have metadata: > > > "Symbols and collections support metadata," --http://clojure.org/metadata > > > "Symbols, Lists, Vector, Sets and Maps can have metadata" -- > >http://clojure.org/reader > > I don't think the documentation is *wrong* per se, it just only seems to > cover the immutable types. Which is kind of wrong, isn't it? I strongly believe that this should be changed. > Vars, refs, atoms, agents and namespaces can > all have metadata as well, but it works a little differently for them as they > are mutable. You change their metadata using the alter-meta! > function. The with-meta function will not work on them. While I understand that the mutating functions will not apply to immutable types, I don't get why I can't create the metadata using the same interface. > > Really? Then why the metadata of the symbol empty? > > user=> (meta 'greet) > > nil > > > Or am I not accessing the symbol's metadata that way? > > You are creating a new symbol 'greet, A *new* symbol? I would have thought I'm getting the original symbol again. OK, but I see: user=> (resolve 'greet) #'user/greet user=> (meta (resolve 'greet)) {:ns #<Namespace user>, :name greet, :file "NO_SOURCE_PATH", :line 66, :arglists ([]), :xxx 1} Sometimes the 'E' in 'REPL' stands for Enlightenment, and the 'P' must be Pleasure then. Don't ask me about 'R' and 'L', though. ;-) > It might make more sense if we consider the case of metadata on > collections. I think I already understood them. At least I can align things I read in documentation and implementation with what I find in experiments on the REPL. > Note that (perhaps suprisingly) this doesn't work: > > (meta #^{:a 1} 'greet) ; => {:a 1} > > Why? Well because #^ attaches the metadata to the next read form. > What's the next read form? It's 'greet. But in fact 'greet is just > sugar for (quote greet). So we're actually affixing the metadata to a > list containing two symbols (quote and greet). When the compiler > evaluates (quote greet) it turns it into just the symbol greet and then > throws the list (and thus our metadata) away. This is subtle! It really feels like one of those things that will still feel creepy another 50 years from now. I'll have to meditate on this a bit. > > * What part of the (Java)-code should I read to understand the > > implementation of metadata (if I assume that my understanding of how > > the classes extent/implement is not correct). > > I think you are just being confused by the differences in how metadata > works with mutable and immutable types. Definitely, and I don't like the distinction too much either. > There are three interfaces to do with metadata: > > IMeta.java meta -- reading metadata > IObj.java with-meta -- "changing" metadata on immutables > IReference.java alter-meta! reset-meta! -- changing metadata on mutables OK, I see. I missed the last one. > I hope that helps clarify things a bit. It does. I get a growing feeling of understanding how things work under the hood here. Your help is highly appreciated, thank you very much. Regards, Stefan -- 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en