Message Boards Message Boards

0
|
3237 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Association key names and optional argument names

Posted 3 years ago

Is there a standard practice for choosing key names? I come from a Python background where these names are not subject to replacement (that is, they are not part of a global name space). But, in the Wolfram Language I find that they are. So, I feel that there are two choices:

1 Use Strings as key names

2 Use any name and Protect it

But, most of the examples I see in the documentation show using any name (abc->True) where, presumably, you would not want to have abc be subject to substitution due to some prior (or later) assignment expression (abc=3).

I had started the practice of using key names starting with a dollar sign ($abc->True) and Protecting those names. That way I wasn't arbitrarily Protecting names (like abc) thus preventing (or interfering with) there use.

I am new to Wolfram Language so any insights would be appreciated.

POSTED BY: Terry Stewart
3 Replies

Thanks to both Jason and Henrik for your replies. They were helpful.

POSTED BY: Terry Stewart

Here is just a remark: There are Formal Symbols (denoted by a single point below the symbol) which are protected per se, i.e. one cannot assign a value. Sometimes this can be quite useful. But yes: As key names strings can have advantages, e.g. when using lookups (see documentation about Association):

The explicit Key can be omitted when the keys are strings ...

POSTED BY: Henrik Schachner

In almost all situations I use strings as key names in an Association.

POSTED BY: Jason Biggs
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