There's a number of issues here to consider beyond the ones Dar has mentioned.
First of all, the writing is on the wall for the way the input string to 'format()' works. There is a huge problem with format() and matchText() - for the argument list, the way script is tokenized is changed. This means that what a token means is different depending on whether it is within the parantheses for format()/matchText() or whether it is within the parantheses of anywhere else in the language. This is because the way strings are tokenized is changed (see 'allowescapes') during parsing. This is a really really bad idea because it means that the syntactic structure of the script has a direct affect on the lexical structure of the script. (I don't think I can over-stress just how bad an idea this is in terms of language design - it means the parsing and lexical phases cannot be entirely separated, and it heavily restricts the type of parsing you can use).
So, in the new scheme of things (with the new parser), the format of the input strings to both format() and matchText() will change to remove the offending problem - that is of allowing \" (escaped quotes) - instead something like \q will map to a quote. [ Note that this is a transformation that can be done by the script translater that will be built-in, so there's no problem with 'breaking' things here ].
With that out of the way, back to Monte's original suggestion. There are two issues I see here.
The first is backwards compatibility right now - we cannot (right now) change significantly how string constants are interpreted as this will break any one's scripts that contain '\' in string constants.
The second is the simple question - do we want C-style formatted strings as the default in the language? My issue here is that it does slightly go against the 'easy-to-use' language aspect as it means you have to understand much more about the format of string constants to be able to use them.
In terms of the first problem, then we could consider changing things at the new syntax point as there will be a translater for old-style scripts so all string constants could be transformed to adopt any new scheme. However, there is a compromise option which could be done now without any issue with backwards-compatibility and that is to adopt the Pascal approach:
Would result in the string
Here two quotes next to each other would be elided to a single quote. Since there is no place (at the moment) you can have two string constants next to each other (in all cases it is a syntax error) there's no issue with backwards compatibility. The only slight issue I have with this is readability (although no less readable perhaps than having \" all over the place) and that would be mitigated heavily by script highlighting.
Of course, this compromise option does mean you don't get \t and \n, but then I think it is quotes in string literals that cause the most problem at the moment:
Code: Select all
put "I \"think\" it would be cool if we could \n do this" into whereDoIStart
Would be written something like this:
Code: Select all
put "I ""think"" it would be cool if we could" & return & \
"do this" into whereDoIStart
So that is essentially the only option we have right now.
Talking to the second concern I had above about usability - I am slightly uncomfortable forcing the notion of C-style formatted strings upon the language since I don't think they quite fit. Yes, I can see how such things would be convenient - but there is a balance to be struck between convenience for the (experienced) developer, and ease-of-use for all. Now, that being said, it doesn't seem too onerous to suggest that if you want C-style formatting you use 'format()' - especially as that allows you to do a lot more things than just parse out escape characters. Also, constant-folding (as Dar suggested) will be a relatively easy optimisation to add in the new scheme of things (with the new parser / evaluator) and at that point such uses of 'format' would become free.
P.S. I had no problem using the 'code' block formatting option here - I used it above...