Mhoram
Mhoram

Reputation: 431

"Translating" from ALGOL

I have just found a book that describes a procedure very similar to what I need to do. However, the book, being from 1972, shows the solution in ALGOL, whereas I need to write my code in a more recent language. I am trying to find out if I understand correctly what the ALGOL code in front of me is doing:

  1. Am I right that the following code,

    sl:=ff;

,simply assigns a value, as , for example, the sl = ff; statement would do in SAS?

  1. Does the ↑ character mean "raised to the power of"?

  2. What is a "realprocedure"? Is it the ALGOL equivalent of a subroutine in FORTRAN or a module in SAS?

  3. Earlier in the code, I read that a is an array. Am I right, then, that the following code,

    for i: 1 step 1 until m do 
    
    begin a[i]:=0;
    
        for j:=1 step 1 until m do
    
        a[i] :=a[i] + ww[j] x slope;
    
        a[i]:=1/a[j];
    

populates the matrix a, where i is the row number, j is the column number, and m is (apparently) i * j?

Upvotes: 1

Views: 223

Answers (2)

Wojja62
Wojja62

Reputation: 96

I concur with the adjacent comments 1 to 3.

The code given above is anomalous in several ways. I suspect there have been transcription errors.

Firstly, the 'begin' 'end' pairing is incomplete.

In Algol, a 'begin . . . end' pair is EITHER a compound statement, OR, if there are declarations inside too, then it is a block.

In this code, what follows 'for i:= 1 step 1 until m do' starts like a compound statement with 'begin', but no matching 'end' is visible. If we assume that an 'end' appears as the next following token then this would complete the compound statement controlled by this 'for i:= ...' clause. All of this compound statement would be repeated m times with i containing successive values from 1 to m.

The second anomaly is that the second loop, controlled by 'for j:= ...' only attaches to the next single statement (up to the ';') and sums up the same collection of values into each a[i] and this is then overwritten with 1/a[j]! (I am assuming that 'slope' is a scalar variable and not a parameterless function so that it supplies the same value at each execution.)

Thirdly, in Algol, it is not a good idea to make any assumptions about the value of the control variable in a 'for' loop after the loop terminates. In many Algol implementations j, here, would be left containing m + 1. So all the elements from a[1] to a[m] will contain 1/a[m + 1]. This might fail 'divide by zero' if a[m + 1] contains zero or if a was declared 'real array a[1:m];' then it might fail with 'invalid index'.

If there is a transcription error here and we assume the final statement should have read a[i]:= 1/a[i], all the values calculated and stored in a[1] ... a[m] will still be the same and there are faster ways of coding this!

I hope this tirade (longer than I'd hoped) has been helpful.

Upvotes: 2

Adolfo Diaz
Adolfo Diaz

Reputation: 21

  1. Yes, ":=" assigns a value to a variable

  2. Yes, the character "^" mean "raised to the power of"

  3. "realprocedure", I suppose is "real procedure". Thats mean a procedure that return a real value.

  4. In Algol there are blocks of code. Each block begin with "begin" and end with "end". If you omit begin-end words, then the block is only one instruction. Your code here is unclear.

Upvotes: 2

Related Questions