TYPE
PrimeIterator = RECORD
(* вырожденная запись, с ней связываем методы *)
END;
PROCEDURE (VAR t: PrimeIterator) Init (high: LONGINT);
BEGIN
Pascaline.r.int := high; Pascaline.InitPrime;
END Init;
PROCEDURE (VAR t: PrimeIterator) First
(VAR elem: LONGINT): BOOLEAN;
BEGIN
Pascaline.FirstPrime; elem := 0;
IF Pascaline.sPrimeIsEmpty THEN RETURN FALSE
ELSE elem := Pascaline.r.result; RETURN TRUE
END;
END First;
PROCEDURE (VAR t: PrimeIterator) Next
(VAR elem: LONGINT): BOOLEAN;
BEGIN
Pascaline.NextPrime; elem := 0;
IF Pascaline.sPrimeIsEmpty THEN RETURN FALSE
ELSE elem := Pascaline.r.result; RETURN TRUE
END;
END Next;
PROCEDURE P (high: LONGINT);
VAR num: Number.Integer; iter: PrimeIterator;
ok: BOOLEAN;
s: ARRAY 256 OF CHAR;
BEGIN
iter.Init(high); num.picture := ?@N_12?;
ok := iter.First(num.body);
WHILE ok DO
num.Format(s); Print(s); ok := iter.Next(num.body);
END;
END P;

назад