Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.4K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Same unit and symbol variable name

Posted 3 years ago

Hi there

I have created some variables to represent units that I use a lot.

Example:

s = Quantity[1, “Second”];
A = Quantity[1, “Ampere”];

The issue I’m having occurs when symbol names interferes with the unit variables. As an example we use “s” as a symbol for distance, here where I study. I have a +50 units defined, so I often run into this problem. I could of course use a different symbol name each time the problem occurs, but I was wondering if I could do something smarter here. I’m new at Mathematica, and the basic knowledge I have, gives me no obvious answer. I’m thinking some sort of namespace, but has no clue if that’s the way to go.

Any inputs are much appreciated.

POSTED BY: Jak SD
2 Replies
Posted 3 years ago
POSTED BY: Jak SD
Posted 3 years ago

If you're wanting to save keystrokes (e.g. you want to type something like 5 s and have it transform to Quantity[5, "Seconds"]), then using a namespace (i.e. a Context) will be counterproductive.

How are you avoiding name collisions among your 50 units? I would think that that's more of a problem than colliding with single-letter System symbols.

You could just use more letters. If you used a three-letter convention, you could define sec = Quantity[1, "Seconds"] and probably avoid collisions.

You could also use InputAliases, cf http://reference.wolfram.com/language/ref/InputAliases.html . You can also access this with the option inspector (via menu, Format -> Option Inspector). This would avoid name collisions entirely, but you'd have to use the escape key.

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