Andy Ball wrote:
>
> Hello Scott,
>
> SAM> A Basic mode string is a relatively expensive data
> > structure, and often the same character handling can
> > be done with a simple array of characters. You can
> > use an array of characters to build up essentially
> > the same complexity as Basic strings, so you are
> > effectively losing little.
>
> One reason that I'm thinking of using a BASIC-style string
> is that it would save me having to guess ahead of time how
> long its content is going to be, and perhaps make it easier
> to convert a numeric string into an integer. I would like to
> stick with standard Pascal if that's practical though.
>
> - Andy Ball
When you use basic strings, you are "guessing" the standard length of the
string. That is, when you declare a string variable, it allocates space
for
an entire string, whether you use it or not.
The process is simply hidden from you, so it "looks" painless. Most
implementations with Basic strings also allow you to set the maximum
length of the string, like "string[100]", but that is no different
than declaring an array of characters with length 100.
The usual mode in original Pascal for string is to use "right padded"
strings, which works for the majority of purposes. However, it is also
possible to use lengthed strings. A lot of this is covered in the
ANSI-ISO Pascal FAQ listed in my sig below.
Typically, you can wrap functions/procedures around any choosen string
method. Where it becomes difficult is assigning fixed constants to
strings, because original Pascal requires the entire string be assigned:
var s: packed array [1..20] of char;
....
s := 'hi there ';
which is inconvenient. However, virtually all implementations of Pascal
have a method where this can be performed by a procedure:
copy(s, 'hi there');
Including the Level 1 of the ISO 7185 standard, so called "conformant
arrays".
Wirth took a lot of heat for not including what are called "dynamic
arrays"
in the original language. Algol, which Pascal was based on had them, and
so did all of Wirth's languages after Pascal. Wirth correctly stated that
it complicated the compiler for the language. However, it was clearly one
restriction too far, and severly limited Pascal's application to
professional programming use.
Virtually all Pascal compilers have a way to work with dynamic arrays,
although it was (unfortunately, in my opinion) common to restrict them
to strings only. The extended Pascal standard has full dynamic arrays
as well (but oddly, felt the need to also include the redundant string
capability).
I mention this all to make a point. String processing would be one area
where it would be wise to choose an extention to the original Pascal.
I wish they could all be compatible, but the reality is that they are
not. If you are only interested in strings, and not dynamic arrays
in general, then the UCSD implementation probally qualifies as the
most widely implemented such extention. It appears nowdays in both the
Borland series, and both GPC and FPC, differing in only minor details.
I really don't see the standards for Pascal as black an white. Use of
an extention here and there is not going to kill you. Wirth's own
original implementation of Pascal (the CDC 6600 compiler) had extentions.
The only time use of extentions hurts you is if you throw away the
original language and start using non-standard features of your local
implementation with abandon. This will determine simply if you
will ever have the capability to one day move your program to another
implementation of Pascal.
Luck !
--
Samiam is Scott A. Moore
Personal web site: http:/www.moorecad.com/scott
My electronics engineering consulting site: http://www.moorecad.com
ISO 7185 Standard Pascal web site: http://www.moorecad.com/standardpascal
Classic Basic Games web site: http://www.moorecad.com/classicbasic
The IP Pascal web site, a high performance, highly ****table ISO 7185
Pascal
compiler system: http://www.moorecad.com/ippas
Good does not always win. But good is more patient.


|