[Global Variables] Request for Vote: handling multichar variable names in formulas
See original GitHub issueAfter recent discussion let’s try to reach a decision on how to handle multichar variable names in formulas.
IMHO this is a two-fold decision:
- whether to use prefix or surround notation (see explanation below), and
- which character/symbol to use as a marker
Prefix notation means to use a certain symbol/character to mark the start of a variable name, but not have such a marker for the end of the variable name. In this case the end of the variable name is denoted by the first character not allowed in var names (non-digit and non-alpha), eg. a parenthesis or the end of the formula.
Surround notation means to use a certain symbol/character to mark the start of a variable name and another symbol/char to mark its end (start marker and end marker may or may not be the same symbol).
Current implementation uses prefix notation with $
as the start marker symbol. The following example expression shows how this can be used in a more complex formula with variables A
, B
and hello
:
AB + $hello + A$hello(AB)(B+1)
With A=1
, B=5
and hello=2
this expression would be evaluated to 15 + 2 + 12156 = 12173
.
Here are some examples on how this expression would look like with different notations and symbols:
- Prefix notation with
#
as marker:AB + #hello + A#hello(AB)(B+1)
- Prefix notation with
@
as marker:AB + @hello + A@hello(AB)(B+1)
- Surround notation with
#
as marker:AB + #hello# + A#hello#AB(B+1)
- Surround notation with
[]
as markers:AB + [hello] + A[hello]AB(B+1)
- Surround notation with
{}
as markers:AB + {hello} + A{hello}AB(B+1)
- Surround notation with
()
as markers:AB + (hello) + A(hello)AB(B+1)
Note that Surround notation with ()
is a very special case because this means that ()
is in the future interpreted in two different ways: if the inside of the ()
is purely filled with alphas and digits (a valid var name), it is interpreted as “marker” for a multichar var name, in all other cases it is interpreted as expression grouper and to influence operator precedence (as today). Something like (AB)
is then always interpreted as one var with name AB
, never as two concatenated vars A
and B
any more.
Note that <>
cannot be used as markers since this would conflict with relational operator interpretation.
Finally, here is a screenshot of the “first class” symbols (easy to reach on Android virtual keyboard) - at least on my device. Hope this is a typical example:
Please use the emojis to vote on the notation to use:
- “Thumbs up” for “prefix notation”
- “Thumbs down” for “suround notation”
Also please use the emojis to vote for the symbol(s) to use as markers:
- “Smiley” for
$
- “Party hat” for
#
- “Frowning smiley” for
@
- “Heart” for
()
- “Rocket” for
[]
- “Eyes to left” for
{}
If there are any other ideas, please comment. But this is all I got…
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:8 (8 by maintainers)
Top GitHub Comments
() [] are often used in formulas, even if it technically works using those would make reading formulas very hard.
I’d like to add another suggestion that linux users should be familar with: Both
$test
and${test}
- this gives the advantage of “easy” to use with $ or “advanced” with ${…} for more complex situations, e.g. for the${test}A
situationNo need imho. It is simply far easier for the user if formula syntax is the same for simple variables and for coordinates calculation than introducing two different syntaxes. Also, as so often, I am directing towards GCBuddy which is doing it the same way. Third point: why would I invest effort in explicitly removing functionality if there’s no need to do it?
There’s already a help button on variable page. I tried to explain the syntax as easy as I could, everyone is free to work on this page.