From bug-octave-request at bevo dot che dot wisc dot edu Tue Nov 18 15:14:30 1997 Subject: Re: Interpretation of '\' in strings From: "John W. Eaton" To: Maximilian Pitschi Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 18 Nov 1997 15:11:57 -0600 On 23-Sep-1997, Maximilian Pitschi wrote: | Octave with --traditional interprets '\' as an escape character. | In matlab, in normal strings, i.e., no format strings, '\' has no | special meaning. | Octave, version 2.0.9 (hppa1.1-hp-hpux10.20). | Copyright (C) 1996, 1997 John W. Eaton. | This is free software with ABSOLUTELY NO WARRANTY. | For details, type `warranty'. | | octave:1> '\[' | warning: unrecognized escape sequence `\[' -- converting to `[' | ans = [ | | or even worse: | | octave:1> '\' | error: unterminated string constant | parse error: | | >>> '\' | | The examples should return '\[' and '\', respectively. And I replied: | Here is a patch to try. It should turn off all special interpretation | of backslash characters in strings, as well as turning off their use | as a continuation line marker if you set the new variable | `backslash_escapes' to 0. The default value is 1 unless you use the | --traditional or --brain-dead options. Unless someone points out a | major flaw with this, it should be in 2.0.10. Unfortunately, there are some major flaws. First, Maximilian Pitschi pointed out that Matlab does treat backslash sequences as special characters in printf and scanf formats, so that complicates things a bit. After thinking about it a bit more, I also decided that I don't really want to add yet another preference variable, because it makes it harder to write M-files that will work no matter what the user settings are. I considered changing things so that backslashes are only special in double quoted strings, since people who care about Matlab compatibility would probably be using single quotes anyway. But then what about strings that are constructed from numeric matrices, or things like ["foo\n"; 'bar\n']? To ensure that these things would work consistently in printf and scanf formats, Octave would have to keep track of the type of string in many more places, and that just seems like too much work. So, I'm sorry to say that I'm going to have to withdraw this patch. jwe