pip icon indicating copy to clipboard operation
pip copied to clipboard

Add ways of accessing locals from higher scopes?

Open dloscutoff opened this issue 10 months ago • 0 comments

My original plan, a while back, was for \a et al to refer to the value of the local variable at the next higher scope level. I implemented it as global variables referring to the program args instead, mainly because it was easier and that's usually what's wanted. However, there are some cases where the local variable reference would be useful and distinct from the program arg reference. Maybe we can have both?

  • \a refers to the value of a at one scope level up
  • $a refers to the first program argument
  • \\a refers to the value of a at two scope levels up (and so on for more backslashes; would require a change to the scanner)

The main problems here:

  • This change potentially breaks backward compatibility, although I'm not sure if any of the programs that use \a so far would actually break.
  • $a doesn't scan the same as \a; in particular, you can't have another lowercase variable, number, or underscore after it without a space in between. This problem is somewhat mitigated by the fact that in many situations, \a will refer to the same value as $a and can be used instead.

Investigate how much of a problem these problems actually are.

dloscutoff avatar Mar 26 '24 15:03 dloscutoff