A question of metadata

A recent post about a Lisp variant got me thinking about the usefulness of metadata and its desired properties.

  1. - should metadata be preserved by copy?
  2. - should metadata be preserved by reuse (my language is prototype-based)?
  3. - should metadata be preserved when assigned a new value to the variable?

Points 1 and 2 raise the question whether the metadata should be part of the variable or outside of it.
Point 3 questions if the metadata should be associated with a name or with a memory location.

Is there a good list of desirable properties for metadata?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Clojure's Example?

Denis,

I presume you're aware of Clojure's language-level support for metadata? if not, see Clojure Metadata

Clojure

Thanks. The Lisp variant in question was Clojure then.

That says only that two objects with different metadata can be equal, it does not answer my questions as far as I can tell. If it is used for typing purposes I can guess how it behaves though.

What happens in Clojure when you do a copy of a variable with metadata?
(I expect metadata is preserved)
What happens in Clojure when you assign a new value to a variable with metadata?
(I expect metadata is lost)
Does Clojure support any extension of a variable with additional properties? If it does, is the metadata of that variable preserved?
(Not sure what to expect)

Misunderstanding

In Clojure, the metadata is bound to values, not variables. Thus, if you assign a new value to a variable, the metadata stays on the old value, and the assigned value retains whatever metadata it had. This is complicated by the fact that assignable variables in Clojure (refs) are themselves values, and thus could have metadata bound directly on them as well. The closest Clojure comes to a variable with "properties" is a structmap, which can't be extended. If you take a regular old map and add a new value, you get a new map, which (IIRC) doesn't carry along any metadata from the old one.

Clojure metadata examples

That is as I expected, thanks. I will look for examples of use.