Message Boards Message Boards

GROUPS:

[Solved] Obtaining attributes weird behavior can anyone explain this?

Posted 1 month ago
221 Views
|
2 Replies
|
1 Total Likes
|

Hi still trying to understand Mathematica and working my way through "essentials of programming..."

I am trying to explain the following behaviour.

names= Names["system`*"];

gives me a list of all the names in the system. for example currently names[[3220]] is KochCurve.

If you type either Attributes[KochCurve] or Attributes["KochCurve"] Mathematica spits back

{Protected,ReadProteced}

however if you type

Attributes[names[[3220]]]

Mathematica doesn't play ball and spits out an error message Symbol, string or HoldPattern[symbol] expected at position 1 in ......

but Head[names[[3220]]] is String.

I expect it's something stupid and simple I've not noticed but any clues would be very gladly received.

Chess

2 Replies

Well, as I understand, the clue you seek is actually inside the Attributes function. Or, more precisely, in the Attributes of the Attributes function. A line like

Attributes[Attributes]

returns a list

{HoldAll, Listable, Protected}

HoldAll attribute means that a function with this attribute does not perform any trasformations of the input arguments and "looks" at them just like you do. So, when you write Attributes[names[[3220]]] WL does not evaluate names[[3220]] and the Attributes function "sees" only the internal representation of names[[3220]] that is Part[names, 3220]. And the Head of this expression is Part, not something from Symbol, String or HoldPattern.

However, you can force Wolfram Language to evaluate the input of any function by calling the Evaluate function. Try running the following:

Attributes[Evaluate[names[[3220]]]]
Posted 1 month ago

Wow, Thank you so much. That works Furthermore your answer was incredibly helpful. Chess

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract