[Oberon] Understanding ORS.Mod.txt
Srinivas Nayak
sinu.nayak2001 at gmail.com
Sun Jun 12 17:34:29 CEST 2016
Hmmm...
I feel...while invoking Ten(), if e=5 (say),
then immediately inside WHILE,
IF ODD(e) THEN x := t * x END ;
will be executed and x will hold a value 10.
After that e will never be ODD.
So t will gather the value 10000.
While returning, we should multiply x to t resulting 100000.
Please correct me.
With thanks and best regards,
Yours sincerely,
Srinivas Nayak
Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/
On 06/12/2016 08:48 PM, John R. Strohm wrote:
> "RETURN x" is correct.
>
> On exit from the loop, e = 0. (Strictly, x <= 0, but DIV preserves the sign of the dividend, so it is not possible for e to go negative.)
>
> On the pass immediately before exiting from the loop, e = 1. ODD(1) is TRUE, so x := t * x will be executed in that pass.
>
> -----Original Message----- From: Srinivas Nayak
> Sent: Sunday, June 12, 2016 8:41 AM
> To: ETH Oberon and related systems
> Subject: [Oberon] Understanding ORS.Mod.txt
>
> We see
>
> PROCEDURE Ten(e: LONGINT): REAL;
>
> VAR x, t: REAL;
>
> BEGIN x := 1.0; t := 10.0;
>
> WHILE e > 0 DO
>
> IF ODD(e) THEN x := t * x END ;
>
> t := t * t; e := e DIV 2
>
> END ;
>
> RETURN x
>
> END Ten;
>
> Should it be, RETURN x * t ?
>
>
> With thanks and best regards,
>
> Yours sincerely,
> Srinivas Nayak
>
> Home: http://www.mathmeth.com/sn/
> Blog: http://srinivas-nayak.blogspot.in/
>
> On 06/12/2016 07:01 PM, Srinivas Nayak wrote:
>> Dear Friends,
>>
>> Finally I could gather my courage to read NW's compiler implementation.
>> Hope to get your help when I get doubts.
>>
>> In ORS.Mod.txt we see
>>
>> PROCEDURE Mark*(msg: ARRAY OF CHAR);
>>
>> VAR p: LONGINT;
>>
>> BEGIN p := Pos();
>>
>> IF (p > errpos) & (errcnt < 25) THEN
>>
>> Texts.WriteLn(W); Texts.WriteString(W, " pos "); Texts.WriteInt(W, p, 1); Texts.Write(W, " ");
>>
>> Texts.WriteString(W, msg); Texts.Append(Oberon.Log, W.buf)
>>
>> END ;
>>
>> INC(errcnt); errpos := p + 4
>>
>> END Mark;
>>
>> Why we did, errpos := p + 4 ?
>> How do I understand/interpret this?
>> I was thinking, it should be errpos := p + 1 ...
>> Kindly correct me.
>>
>>
>> With thanks and best regards,
>>
>> Yours sincerely,
>> Srinivas Nayak
>>
>> Home: http://www.mathmeth.com/sn/
>> Blog: http://srinivas-nayak.blogspot.in/
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
More information about the Oberon
mailing list