Discussion:
The empty string in Oberon-07/11
(too old to reply)
August Karlstrom
2011-09-21 13:56:49 UTC
Permalink
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
August Karlstrom
2011-09-21 14:42:47 UTC
Permalink
Post by August Karlstrom
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
2011-09-28 21:30:52 UTC
Permalink
Post by August Karlstrom
"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
Chris Burrows
2011-09-23 13:50:08 UTC
Permalink
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
August Karlstrom
2011-09-23 15:33:44 UTC
Permalink
Post by Chris Burrows
There are several examples of single-character strings being compared with
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
Chris Burrows
2011-09-23 23:22:03 UTC
Permalink
Post by August Karlstrom
Post by Chris Burrows
There are several examples of single-character strings being compared with
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.
Loading...