question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Global Variables] Request for Vote: handling multichar variable names in formulas

See original GitHub issue

After 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:

Screenshot_20211227-140243

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:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
ztNFnycommented, Dec 27, 2021

() [] 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 situation

0reactions
eddiemuccommented, Dec 27, 2021

this is no longer an issue because concatenation and variable referencing does not conflict any more.

Still, no real answer about the potential use case… 😉

No 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?

And BTW, we should think about introducing a small “cheat-sheet” directly into cgeo with a link to the full manual. Otherwise, nobody will be able to remember the full potential… (we already have a similar thing for “search by filter”)

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Variables - Salesforce Help
This global variable is only available for formula fields, s-controls, custom buttons and links, Visualforce pages, flows, and process formulas.
Read more >
Using global variables in a function - Stack Overflow
You can use a global variable within other functions by declaring it as global within each function that assigns a value to it:...
Read more >
Variables in C - GeeksforGeeks
A variable in C is a memory location associated with some name in order to store some form of data and retrieve it...
Read more >
How do I make a variable accessibl… | Apple Developer Forums
I need a variable that will be accessible from my main target, and an imported Framework. A Global Variable doesn't work as it's...
Read more >
define global and local scope? - Codecademy
Variables defined within a function are local variables. “Scope” is just a technical term for the parts of your code that have access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found