Slide 13 of 80
Notes:
- Bang folding: echo !!!!varname writes !!varname to $stdlist echo !!!varname writes ! followed by varname’s value to $stdlist
- Number conversion example: :setvar x “123” :if !x > 0 then …
:input x, “enter a value” # user enters 123 :if x = 123 then # ERROR, x is a string! :if !x = 123 then # OK
- Here is an example when using explicit variable referencing is incorrect:
(assume an “array” of variables: name1, name2, name3, etc.)
1) setvar j 0 2) while setvar(j,j+1) <= limit and name!j <> “EXIT” do …
Line 2 will always be reference the N-1th element in the “array”, and, worse, will try to reference ‘name0’ the first time.Solution: 2) while setvar(j,j+1) <= limit and name![j - 1] <> “EXIT” do … -- or -- while setvar(j,j+1) <= limit do if name!j <> “EXIT” then ...
- The biggest issue with regards to using !varname is that varname’s type is lost. Sometimes, this is exactly what is desired, as shown in the number conversion examples. Other times, the type was never intended to be lost, and therefore the user needs to surround a string !varname with quotes to preserve its type. It is this second usage that I am trying to reduce because, in my opinion, readability and maintainability suffer.