Message Boards Message Boards

0
|
2802 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

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

Posted 3 years ago

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

POSTED BY: Chess Denman
2 Replies
Posted 3 years ago

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

POSTED BY: Chess Denman

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 BY: Nikolay Shilov
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