|
|||
|
In the new 2011 revision of Oberon-07, character literals where removed
and instead single-character strings are now compatible with character variables. Still, I find it hard to reason about expressions involving the empty string like ch = 0X (*has to be valid*) ch = "" (*valid?*) using the stated rules of the language (rather than intuition). How can I conclude that the empty string is compatible with a character variable? Where does it say that a character variable can be compared with a single-character string or the empty string? Can somebody help me? August -- The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague. --Edsger Dijkstra |
|
|
||||
|
||||
|
|
|
|||
|
On 2011-09-21 15:56, August Karlstrom wrote:
> In the new 2011 revision of Oberon-07, character literals where removed > and instead single-character strings are now compatible with character > variables. Still, I find it hard to reason about expressions involving > the empty string like > > ch = 0X (*has to be valid*) > ch = "" (*valid?*) > > using the stated rules of the language (rather than intuition). How can > I conclude that the empty string is compatible with a character > variable? Where does it say that a character variable can be compared > with a single-character string or the empty string? Can somebody help me? I think I got the first part now. The literal 0X is a single-character string but its length is zero. The expression ch = "" must be invalid. My mistake was to think of 0X as the empty string. These examples may clarify the concepts: "hello" (*five-character string of length five*) "A" (*single-character string of length one*) 0X (*single-character string of length zero*) "" (*zero-character string of length zero*) August -- The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague. --Edsger Dijkstra |
|
|||
|
"August Karlstrom" <fusionfile@gmail.com> wrote in message
news:j5cqf2$qm1$1@dont-email.me... > >Where does it say that a character variable can be compared with a >single-character string or the empty string? There are several examples of single-character strings being compared with character variables included in the report: e.g. Section 9.4: IF (ch >= "A") & (ch <= "Z") THEN ReadIdentifier You have already answered the empty string part of the question yourself. Regards, Chris Burrows CFB Software Astrobe v3.4: ARM Oberon Development System http://www.astrobe.com |
|
|||
|
On 2011-09-23 15:50, Chris Burrows wrote:
> There are several examples of single-character strings being compared with > character variables included in the report: > > e.g. Section 9.4: > IF (ch>= "A")& (ch<= "Z") THEN ReadIdentifier Yes, but it is not stated in section 8.2.4 about relations (strings are not mentioned at all). Maybe Prof Wirth reasons that the validity of string comparisons is implied by the assignment compatibility between single-character strings and character variables and between strings and character arrays. August -- The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague. --Edsger Dijkstra |
|
|||
|
"August Karlstrom" <fusionfile@gmail.com> wrote in message
news:j5i8so$4p6$1@dont-email.me... > On 2011-09-23 15:50, Chris Burrows wrote: >> There are several examples of single-character strings being compared >> with >> character variables included in the report: >> >> e.g. Section 9.4: >> IF (ch>= "A")& (ch<= "Z") THEN ReadIdentifier > > Yes, but it is not stated in section 8.2.4 about relations (strings are > not mentioned at all). Maybe Prof Wirth reasons that the validity of > string comparisons is implied by the assignment compatibility between > single-character strings and character variables and between strings and > character arrays. > Yes - IMO it fits into the category mentioned at the beginning of the report "...because it is derivable from stated rules of the language...". I would have much more difficulty in believing the alternative possibility that you might be able to store a value in a variable but not be able to inspect its value. |
|
|||
|
On 2011-09-21 16:42, August Karlstrom wrote:
> These examples may clarify the concepts: > > "hello" (*five-character string of length five*) > "A" (*single-character string of length one*) > 0X (*single-character string of length zero*) > "" (*zero-character string of length zero*) After having gained a little more insight I can conclude that the null string (0X) is of length one but in all array contexts it will turn into the empty string so to speak. Though being of pure theoretical interest, this means that it is impossible to correctly compute the length of the null string; for instance, the function procedure call Strings.Length(0X) will evaluate to zero. August -- The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague. --Edsger Dijkstra |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|