buf: array 4 of Byte;
i: Int;
begin
- for i := 0 to LEN(buf) - 1 do buf[i] := i + 1 end;
+ for i := 0 to Length(buf) - 1 do buf[i] := i + 1 end;
f := Files.New("ReadWriteBytesTest");
Assert(f # nil);
Files.SetPos(r, f, 0);
- Files.WriteBytes(r, buf, LEN(buf));
- Files.WriteBytes(r, buf, LEN(buf));
+ Files.WriteBytes(r, buf, Length(buf));
+ Files.WriteBytes(r, buf, Length(buf));
Files.Close(f);
- for i := 0 to LEN(buf) - 1 do buf[i] := 0 end;
+ for i := 0 to Length(buf) - 1 do buf[i] := 0 end;
Files.SetPos(r, f, 0);
- Files.ReadBytes(r, buf, LEN(buf));
+ Files.ReadBytes(r, buf, Length(buf));
Assert(~r.eof);
- for i := 0 to LEN(buf) - 1 do
+ for i := 0 to Length(buf) - 1 do
Assert(buf[i] = i + 1)
end;
- Files.ReadBytes(r, buf, LEN(buf));
+ Files.ReadBytes(r, buf, Length(buf));
Assert(~r.eof);
- for i := 0 to LEN(buf) - 1 do
+ for i := 0 to Length(buf) - 1 do
Assert(buf[i] = i + 1)
end;
- Files.ReadBytes(r, buf, LEN(buf));
+ Files.ReadBytes(r, buf, Length(buf));
Assert(r.eof)
end TestReadWriteBytes;
Implements the basic library module from "The Oakwood Guidelines for Oberon-2 Compiler Developers". All character arrays are assumed to contain 0X as a terminator and positions start at 0.*)
- procedure Length*(s: array of Char): Int;
-(**Length(s) returns the number of characters in s up to and excluding the first 0X.*)
+ procedure Len*(s: array of Char): Int;
+(**Len(s) returns the number of characters in s up to and excluding the first 0X.*)
var i: Int;
begin
i := 0;
INC(i)
end
return i
- end Length;
+ end Len;
procedure Min(a, b: Int): Int;
procedure Insert*(source: array of Char; pos: Int; var dest: array of Char);
-(**Insert(src, pos, dst) inserts the string src into the string dst at position pos (0 <= pos <= Length(dst)). If pos = Length(dst), src is appended to dst. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.*)
+(**Insert(src, pos, dst) inserts the string src into the string dst at position pos (0 <= pos <= Len(dst)). If pos = Len(dst), src is appended to dst. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.*)
var sourceLength, destLength, newLength: Int;
i, lim: Int;
begin
- destLength := Length(dest);
+ destLength := Len(dest);
Assert(pos >= 0);
Assert(pos <= destLength);
- sourceLength := Length(source);
- newLength := Min(destLength + sourceLength, LEN(dest) - 1);
+ sourceLength := Len(source);
+ newLength := Min(destLength + sourceLength, Length(dest) - 1);
(*make room for source in dest*)
dest[newLength] := 0X;
procedure Append*(extra: array of Char; var dest: array of Char);
-(**Append(s, dst) has the same effect as Insert(s, Length(dst), dst).*)
+(**Append(s, dst) has the same effect as Insert(s, Len(dst), dst).*)
var destLength, newLength: Int;
i: Int;
begin
- destLength := Length(dest);
- newLength := Min(destLength + Length(extra), LEN(dest) - 1);
+ destLength := Len(dest);
+ newLength := Min(destLength + Len(extra), Length(dest) - 1);
for i := destLength to newLength - 1 do
dest[i] := extra[i - destLength]
procedure Delete*(var s: array of Char; pos, n: Int);
-(**Delete(s, pos, n) deletes n characters from s starting at position pos (0 <= pos <= Length(s)). If n > Length(s) - pos, the new length of s is pos.*)
+(**Delete(s, pos, n) deletes n characters from s starting at position pos (0 <= pos <= Len(s)). If n > Len(s) - pos, the new length of s is pos.*)
var length, n1, i: Int;
begin
- length := Length(s);
+ length := Len(s);
Assert(pos >= 0);
Assert(pos <= length);
Assert(n >= 0);
procedure Replace*(source: array of Char; pos: Int; var dest: array of Char);
-(**Replace(src, pos, dst) has the same effect as Delete(dst, pos, Length(src)) followed by an Insert(src, pos, dst).*)
+(**Replace(src, pos, dst) has the same effect as Delete(dst, pos, Len(src)) followed by an Insert(src, pos, dst).*)
var destLength, n, i: Int;
begin
- destLength := Length(dest);
+ destLength := Len(dest);
Assert(pos >= 0);
Assert(pos <= destLength);
- n := Min(Length(source), LEN(dest) - 1 - pos); (*actual number of characters to replace*)
+ n := Min(Len(source), Length(dest) - 1 - pos); (*actual number of characters to replace*)
(*replace characters*)
for i := 0 to n - 1 do
procedure Extract*(source: array of Char; pos, n: Int; var dest: array of Char);
-(**Extract(src, pos, n, dst) extracts a substring dst with n characters from position pos (0 <= pos <= Length(src)) in src. If n > Length(src) - pos, dst is only the part of src from pos to the end of src, i.e. Length(src) - 1. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.*)
+(**Extract(src, pos, n, dst) extracts a substring dst with n characters from position pos (0 <= pos <= Len(src)) in src. If n > Len(src) - pos, dst is only the part of src from pos to the end of src, i.e. Len(src) - 1. If the size of dst is not large enough to hold the result of the operation, the result is truncated so that dst is always terminated with a 0X.*)
var sourceLength, n1, i: Int;
begin
- sourceLength := Length(source);
+ sourceLength := Len(source);
Assert(pos >= 0);
Assert(pos <= sourceLength);
- n1 := Min(n, Min(sourceLength - pos, LEN(dest) - 1)); (*actual number of characters to extract*)
+ n1 := Min(n, Min(sourceLength - pos, Length(dest) - 1)); (*actual number of characters to extract*)
for i := 0 to n1 - 1 do
dest[i] := source[pos + i]
end;
procedure Pos*(pattern, s: array of Char; pos: Int): Int;
-(**Pos(pat, s, pos) returns the position of the first occurrence of pat in s. Searching starts at position pos (0 <= pos <= Length(s)). If pat is not found, -1 is returned.*)
+(**Pos(pat, s, pos) returns the position of the first occurrence of pat in s. Searching starts at position pos (0 <= pos <= Len(s)). If pat is not found, -1 is returned.*)
var idxs, idxp, result: Int;
begin
Assert(pos >= 0);
- Assert(pos < LEN(s));
+ Assert(pos < Length(s));
idxs := pos - 1;
repeat
result := -1
end;
- Assert((result = -1) or (result >= 0) & (result + idxp < LEN(s)))
+ Assert((result = -1) or (result >= 0) & (result + idxp < Length(s)))
return result
end Pos;
begin
(*test Length*)
- Assert(Strings.Length("") = 0);
+ Assert(Strings.Len("") = 0);
shortStr := "";
- Assert(Strings.Length(shortStr) = 0);
+ Assert(Strings.Len(shortStr) = 0);
shortStr := 22X;
- Assert(Strings.Length(shortStr) = 1);
+ Assert(Strings.Len(shortStr) = 1);
shortStr := "123";
- Assert(Strings.Length(shortStr) = 3);
+ Assert(Strings.Len(shortStr) = 3);
(*test Insert*)
s := "cde";
Strings.Insert("bcd", 1, shortStr);
Assert(shortStr = "abc");
s := "foo bar";
- Strings.Insert(" baz", Strings.Length(s), s);
+ Strings.Insert(" baz", Strings.Len(s), s);
Assert(s = "foo bar baz");
- Strings.Insert(" qux qux qux qux qux", Strings.Length(s), s);
+ Strings.Insert(" qux qux qux qux qux", Strings.Len(s), s);
Assert(s = "foo bar baz q");
(*test Append*)
{"FLT", TREES_FLT_PROC},
{"INC", TREES_INC_PROC},
{"INCL", TREES_INCL_PROC},
- {"LEN", TREES_LEN_PROC},
{"LSL", TREES_LSL_PROC},
+ {"Length", TREES_LEN_PROC},
{"New", TREES_NEW_PROC},
{"ORD", TREES_ORD_PROC},
{"PACK", TREES_PACK_PROC},
{"INC", TREES_PROCEDURE_KIND, TREES_INC_PROC},
{"INCL", TREES_PROCEDURE_KIND, TREES_INCL_PROC},
{"Int", TREES_TYPE_KIND, TREES_INTEGER_TYPE},
- {"LEN", TREES_PROCEDURE_KIND, TREES_LEN_PROC},
{"LSL", TREES_PROCEDURE_KIND, TREES_LSL_PROC},
+ {"Length", TREES_PROCEDURE_KIND, TREES_LEN_PROC},
{"New", TREES_PROCEDURE_KIND, TREES_NEW_PROC},
{"ORD", TREES_PROCEDURE_KIND, TREES_ORD_PROC},
{"PACK", TREES_PROCEDURE_KIND, TREES_PACK_PROC},
{"FLT", TREES_FLT_PROC},
{"INC", TREES_INC_PROC},
{"INCL", TREES_INCL_PROC},
- {"LEN", TREES_LEN_PROC},
{"LSL", TREES_LSL_PROC},
+ {"Length", TREES_LEN_PROC},
{"New", TREES_NEW_PROC},
{"ORD", TREES_ORD_PROC},
{"PACK", TREES_PACK_PROC},
Assert(i = 1);
a := "";
- Assert(LEN(a) = 10);
+ Assert(Length(a) = 10);
Assert(LSL(0, 0) = 0);
Assert(LSL(0, 1) = 0);
procedure P3(A: Matrix);
begin
- Assert(LEN(A) = 10);
- Assert(LEN(A[0]) = 20)
+ Assert(Length(A) = 10);
+ Assert(Length(A[0]) = 20)
end P3;
procedure P4(A: array of Row);
procedure P(var A: Matrix);
begin
- Assert(LEN(A) = 10);
- Assert(LEN(A[0]) = 20)
+ Assert(Length(A) = 10);
+ Assert(Length(A[0]) = 20)
end P;
procedure Q(var x: T0);
procedure P(a: array of Int);
var i: Int;
begin
- for i := 0 to LEN(a) - 1 do
+ for i := 0 to Length(a) - 1 do
Assert(a[i] = i + 1)
end
end P;
var c, i, j: Int;
begin
c := 0;
- for i := 0 to LEN(M) - 1 do
- for j := 0 to LEN(M[0]) - 1 do
+ for i := 0 to Length(M) - 1 do
+ for j := 0 to Length(M[0]) - 1 do
Assert(M[i, j] = c);
INC(c)
end
procedure Inner1(row: array of Int);
var c, j: Int;
begin
- c := LEN(row);
- for j := 0 to LEN(row) - 1 do
+ c := Length(row);
+ for j := 0 to Length(row) - 1 do
Assert(row[j] = c);
INC(c)
end
var c, i, j, k: Int;
begin
c := 0;
- for i := 0 to LEN(T) - 1 do
- for j := 0 to LEN(T[0]) - 1 do
- for k := 0 to LEN(T[0, 0]) - 1 do
+ for i := 0 to Length(T) - 1 do
+ for j := 0 to Length(T[0]) - 1 do
+ for k := 0 to Length(T[0, 0]) - 1 do
Assert(T[i, j, k] = c);
INC(c)
end
end R;
begin
- for i := 0 to LEN(a) - 1 do
+ for i := 0 to Length(a) - 1 do
a[i] := i + 1
end;
P(a);
c := 0;
- for i := 0 to LEN(M) - 1 do
- for j := 0 to LEN(M[0]) - 1 do
+ for i := 0 to Length(M) - 1 do
+ for j := 0 to Length(M[0]) - 1 do
M[i, j] := c;
INC(c)
end
Q(M);
c := 0;
- for i := 0 to LEN(T) - 1 do
- for j := 0 to LEN(T[0]) - 1 do
- for k := 0 to LEN(T[0, 0]) - 1 do
+ for i := 0 to Length(T) - 1 do
+ for j := 0 to Length(T[0]) - 1 do
+ for k := 0 to Length(T[0, 0]) - 1 do
T[i, j, k] := c;
INC(c)
end