🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #1

Re: Pointers in ALGOL

#1
From: Wilhelm B. Kloke
Date: Tue, 27 Oct 1992 08:06
78 lines
3370 bytes
In article <BwqwKt.AGI@nic.umass.edu> rmuller@neural.hampshire.edu (Rich Muller) writes:
>in a lunch table discussion none of us could remember what facilities
>ALGOL has for using pointers: declaring pointer variables,
what ALGOL do you mean algol-60 or algol-68?
as I remember, Algol60 has no pointers, but there is a dirty trick,
Jensens's device, to do some applications needing pointers
>dereferencing them, doing pointer arithmetic.  Could someone with a
>better memory ( or current knowledge ) send me some fragments of code
>which use pointers?
I append an algol68 example which I got from C.H.Lindsey:
(look for the REF keyword,REF [] BOOL is a pointer to a row of BOOL)

COMMENT this program places 8 queens on a chessboard
such that no two queens attack one another. the method used
is of recursive descent : all valid possibilities
on a given row are tried - each produces another branch of
possibilities on further rows. if a queen may be placed on the
last row then this is a solution and is output.
note: to save machine time simple reflections are produced
mechanically if exhaustive solutions are only found for
the queen on the first row positions 1,2,3,4. the
symmetry of the chessboard means that solutions with
the queen in row 1 in positions 5,6,7,8 correspond 1-1
with these.
COMMENT
##
BEGIN
LOC INT row := 0, countsoln := 0;
LOC[1:8]INT result;
LOC[1:8, -6:15]BOOL allows;
##
PROC solutionhead = VOID:
  BEGIN print((newline, "solution", whole(countsoln, -5), ":- ")); countsoln +:=1 END;
##
PROC place = (INT position)VOID:
  COMMENT this is a recursive procedure.
  it allocates all possible values in the current row as defined
  by each row. after considering which squares are not permissible
  (because already attacked), it outputs any solutions it finds
  (iE. when we reach the last row).
  COMMENT
  BEGIN
    row +:= 1; result[row] := position;
    REF [] BOOL allow = allows[row, ];
    IF row=8
    THEN #we have found solution number countsoln
          so output it#
      solutionhead;
      FOR k TO 8 DO print(REPR(result[k]+ABS"0")) OD;
      solutionhead;
      FOR k TO 8 DO print(REPR(9-result[k]+ABS"0")) OD
    ELSE
      FOR i TO 8 DO allow[i] := TRUE OD;
        #disallow attacked squares#
      FOR i TO row
      DO INT res = result[i];
        allow[res] := FALSE;
        allow[res+row+1-i] := FALSE;
        allow[res-row-1+i] := FALSE
      OD;
        #construct another level where possible#
      FOR i TO 8 DO IF allow[i] THEN place(i) FI OD
    FI;
    #now up a level#
    row -:= 1
  END; #of place#
##
#initialise output#
print(("placement of queens such that no two"
       " attack each other", newline));
FOR j TO 4 DO place(j) OD;
#tidy up output#
print(("list complete", newline))
END
-- 
Dipl.-Math. Wilhelm Bernhard Kloke,
Institut fuer Arbeitsphysiologie an der Universitaet Dortmund
Ardeystrasse 67, D-4600 Dortmund 1, Tel. 0231-1084-257
Technical Details
Message-ID: <1992Oct27.080658.28422@arb-phys.uni-dortmund.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ifado!wb
References: <BwqwKt.AGI@nic.umass.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!ifado!wb
From: wb@arb-phys.uni-dortmund.de (Wilhelm B. Kloke)
Subject: Re: Pointers in ALGOL
Message-ID: <1992Oct27.080658.28422@arb-phys.uni-dortmund.de>
Organization: Institut f. Arbeitsphysiologie a.d. Uni Dortmund
References: <BwqwKt.AGI@nic.umass.edu>
Date: Tue, 27 Oct 92 08:06:58 GMT
Lines: 78