It looks like when you initialise a parameter having a string value ending in $ you not only need to escape it, but also surround it with parenthesis but that is not needed for local variables.
Why is that?
If you forget the parenthesis, then you see it fail.
It doesn’t give me a comfortable feel about the scripting language.
Just try running the below code on the console (examples from https://gist.github.com/jpluimers/9b239814e3b0aa5a3d0853efc02d9861 )
{
:local showValue do={
:local logLine "value='$value'"
:put $logLine
}
## fails each line that ends after \$" with a `syntax error (line 12 column 4)` (the line numbers vary)
:put "-----------------------------start"
$showValue value="^scripts.Function..*"
$showValue value="^scripts.Function..*\$"
$showValue value=("^scripts.Function..*\$")
$showValue value="\$"
$showValue value=("\$")
:put "-----------------------------finish"
}
This one works though:
# showValuesFromParameters
{
:local showValue do={
:local logLine "value='$value'"
:put $logLine
}
:put "-----------------------------start"
$showValue value="^scripts.Function..*"
$showValue value=("^scripts.Function..*\$")
$showValue value=("\$")
:put "-----------------------------finish"
}
And it will give you this output:
-----------------------------start
value='^scripts.Function..*'
value='^scripts.Function..*$'
value='$'
-----------------------------finish
The odd thing is that it works fine for :local variables, whether they are directly initialised at declaration time or later using a :set statement:
{
:local showValuesFromDirectInitilisation do={
:local value1 "^scripts.Function..*"
:local logLine1 "value='$value1'"
:put $logLine1
:local value2 "^scripts.Function..*\$"
:local logLine2 "value='$value2'"
:put $logLine2
:local value3 ("^scripts.Function..*\$")
:local logLine3 "value='$value3'"
:put $logLine3
:local value4 "\$"
:local logLine4 "value='$value4'"
:put $logLine4
:local value5 ("\$")
:local logLine5 "value='$value5'"
:put $logLine5
}
:put "-----------------------------start"
$showValuesFromDirectInitilisation
:put "-----------------------------finish"
}
and
{
:local showValuesFromSetInitilisation do={
:local value
:local logLine
:set $value "^scripts.Function..*"
:set logLine "value='$value'"
:put $logLine
:set $value "^scripts.Function..*\$"
:set logLine "value='$value'"
:put $logLine
:set $value ("^scripts.Function..*\$")
:set logLine "value='$value'"
:put $logLine
:set $value "\$"
:set logLine "value='$value'"
:put $logLine
:set $value ("\$")
:set logLine "value='$value'"
:put $logLine
}
:put "-----------------------------start"
$showValuesFromSetInitilisation
:put "-----------------------------finish"
}
both give this result:
-----------------------------start
value='^scripts.Function..*'
value='^scripts.Function..*$'
value='^scripts.Function..*$'
value='$'
value='$'
-----------------------------finish
So again: why the difference for parameters?
And what about assignment patterns: should you always initialise parameters and variables using parenthesis around them?
–jeroen