Now, the bug itself is just that the compiler is not verifying that 'the result' can be assigned to - that would be easy to fix, but looking at @trevordevore's code, what he is trying to do doesn't actually make sense, even though at first glance it seems so. The code is this:
Code: Select all
variable tScript as String
put "get URLEncode(\q" & pString & "\q);return it" into tScript
execute script tScript
replace "+" with "%20" in the result
replace "*" with "%2A" in the result
return the result
Given that we have a general 'into' postfix syntax, I therefore wonder whether 'the result' is needed at all. Either you are interested in the result of a command, or you aren't - if you are interested in it then you can almost as easily use a postfix into syntax. Indeed, in the above, due to the action of 'replace' it is a 'mutation in place' command meaning that it never communicates anything by a return value.
One of the reasons for adding 'the result' was to ease the writing of short runs of code which transform a value - so it was more to do with code brevity than anything else. i.e. It avoids you having to declare a variable to do the same thing. However, I wonder if adding something like this for the purposes of code brevity is only going to cause annoying and subtle errors; as well as frustration when you realize you can't use 'the result' in a particular context because you need to use a command like 'replace'.
So - proposal - get rid of 'the result' and 'get' and instead allow you to *not* have to declare variables... It should be possible to imagine a set of rules where the compiler implicit declares variables for you when they are used as the target of a pure 'out' context. This would model what I was trying to achieve with 'the result' (an implicitly defined variable which is typed by use) without the drawback it has as outlined above.
In this model, @trevordevore's code could become:
Code: Select all
variable tScript as String
put "get URLEncode(\q" & pString & "\q);return it" into tScript
execute script tScript into tURL
replace "+" with "%20" in tURL
replace "*" with "%2A" in tURL
return tURL