gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: LENGTH() on Solaris 10/sparc


From: Fischlin Andreas
Subject: [Gm2] Re: LENGTH() on Solaris 10/sparc
Date: Wed, 28 Jul 2010 11:30:03 +0000

Oh, and I forgot to comment on the comment 

(*
   Length - returns the length of a string, a. This is called whenever
           the user calls LENGTH and the parameter cannot be calculated
           at compile time.
*)

does not make much sense. The only case where you could calculate at compile 
time the length of a string variable is immediately after you have assigned it 
some value. Say

        VAR s: ARRAY [0..31] OF CHAR; c: CARDINAL;
...

        s := "Hello"; c := LENGTH(s);

but that is asking IMHO too much of a compiler, since the following code would 
already defy the compiler:

        s := "Hello"; MyProc(s); c := LENGTH(s);

or even

        s := "Hello"; MyProc; c := LENGTH(s);

would suffice if the procedure MyProc is having a side effect on s. Thus it is 
quite normal that LENGTH does nothing else than calculate a value only at run 
time. BTW, I know of no Modula-2 compiler that would calculate at compile time 
the length of a string in the manner implied above.

I suggest again to remove the entire export of Length including this confusing 
comment from module RTMS. 

Regards,
Andreas
 


ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND

address@hidden
www.sysecol.ethz.ch

+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 221-4657 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________



On 25/Jul/2010, at 03:00 , john o goyo wrote:

> Andreas:
> 
> On 24-Jul-10, at 2:20 PM, Fischlin Andreas wrote:
>> Hi John,
>> 
>> Sorry, I don't quite get your issue.
>> 
>> On 24/Jul/2010, at 04:27 , john o goyo wrote:
>>> Examination of the failed test cases shows a real oddity.
>>> 
>>> In a call to LENGTH(s), where s is a string, HIGH(s) is passed as zero and 
>>> LENGTH(s) is always 1.
>>> 
>> 
>> HIGH(s) is passed as zero has nothing to do with LENGTH(s).
> [..]
>> 
>> Perhaps you are actually talking about something else, but then you should 
>> explain better what kind of oddity you actually mean.
> 
> I wrote the above in the context of gm2, specifically, in the context of the 
> failed test cases of Length().  I shall elucidate.
> 
> In gm2, LENGTH() is defined in terms of Length() under certain circumstances. 
>  If you read the comment before the function Length() in M2RTS.mod, you will 
> find the following.
> 
> (*
>    Length - returns the length of a string, a. This is called whenever
>            the user calls LENGTH and the parameter cannot be calculated
>            at compile time.
> *)
> 
> In the failed test case iso/run/pass/tstLength.mod, the value of LENGTH(s) is 
> compared to the value of Length(s), where "s" is an array of characters.  The 
> former is converted into a call to the latter and the latter uses HIGH(s) in 
> its count.  Unfortunately, as I wrote above, HIGH(s) is zero and consequently 
> Length(s) returns 1, hence LENGTH(s) returns 1.
> 
> john




reply via email to

[Prev in Thread] Current Thread [Next in Thread]