Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: String Theo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 16 Topic 151 of 215
Post > Topic >>

Re: String Theory

by Scott Moore <scott.moore6@[EMAIL PROTECTED] > Apr 8, 2005 at 01:02 PM

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.
 




 16 Posts in Topic:
String Theory
Andy Ball <null@[EMAIL  2005-04-08 15:50:46 
Re: String Theory
CBFalconer <cbfalconer  2005-04-08 16:51:02 
Re: String Theory
John Reagan <john.reag  2005-04-08 18:40:36 
Re: String Theory
Scott Moore <scott.moo  2005-04-08 11:16:03 
Re: String Theory
Andy Ball <null@[EMAIL  2005-04-08 19:30:09 
Re: String Theory
Scott Moore <scott.moo  2005-04-08 13:02:50 
Re: String Theory
Frank Heckenbach <fran  2005-04-12 12:59:17 
Re: String Theory
Marco van de Voort <ma  2005-04-12 13:20:10 
Re: String Theory
Frank Heckenbach <fran  2005-04-19 11:12:47 
Re: String Theory
Marco van de Voort <ma  2005-04-19 11:39:25 
Re: String Theory
Marco van de Voort <ma  2005-04-08 20:08:40 
Re: String Theory
CBFalconer <cbfalconer  2005-04-08 21:49:56 
Re: String Theory
Marco van de Voort <ma  2005-04-09 09:10:49 
Re: String Theory
CBFalconer <cbfalconer  2005-04-09 12:12:06 
Re: String Theory
Dave Thompson <david.t  2005-04-18 05:08:13 
Re: String Theory
Marco van de Voort <ma  2005-04-18 07:36:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 5:46:57 CDT 2008.