Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is it possible to assign custom attributes to symbols and check them later?

SetAttributes[a, b]

says

Attributes::attnf: b is not a known attribute.
share|improve this question

1 Answer 1

up vote 9 down vote accepted

No, I do not believe it is. As the documentation for your error message says:

The attributes available in each version of Mathematica are fixed and cannot be changed.

The system attributes are low level properties that fundamentally change the evaluation of symbols. I think it makes sense that these are not mixed with high-level user constructs, even though at times that would be quite convenient.

For an alternative remember that you can attach Options to a symbol, e.g.:

Options[a] = {"Attributes" -> {"b"}};

OptionValue[a, "Attributes"]
{"b"}

You could also use a single DownValues rule such as:

a["Attributes"] = {"b"};

a["Attributes"]
{"b"}
share|improve this answer
    
Thanks. But how to change individual option of a symbol? –  Suzan Cioc Jan 19 '13 at 10:14
    
Ah, I found SetOptions function. –  Suzan Cioc Jan 19 '13 at 10:15
    
@Suzan What do you mean? It is simple to replace the list of options with either method shown, e.g. SetOptions[a, "Attributes" -> {"c", "d"}]; or a["Attributes"] = {"c", "d"}; Are you asking for a way to individually append or remove these values as SetAttributes and ClearAttributes do? I could add that to my answer if you have trouble crafting it yourself. –  Mr.Wizard Jan 19 '13 at 10:17
    
@Suzan Thanks for the Accept, but please consider waiting a while first as someone else may have an answer you like better if you do not discourage them from reading the question. –  Mr.Wizard Jan 19 '13 at 10:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.