diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/algebra/aggcat.spad.pamphlet | 27 | ||||
-rw-r--r-- | src/algebra/string.spad.pamphlet | 44 |
3 files changed, 51 insertions, 28 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d525a5a9..374eb67c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2010-06-12 Gabriel Dos Reis <gdr@cs.tamu.edu> + * algebra/aggcat.spad.pamphlet (UnaryRecursiveAggregate) + [#, cycleEntry, cycleLength]: Tidy. + (ListAggregate) [position]: Likewise. + * algebra/string.spad.pamphlet (IndexedString) [replace,split, + leftTrim, rightTrim]: Likewise. + +2010-06-12 Gabriel Dos Reis <gdr@cs.tamu.edu> + * algebra/aggcat.spad.pamphlet (OneDimensionalArrayAggregate) [merge,insert,delete]: Tidy. diff --git a/src/algebra/aggcat.spad.pamphlet b/src/algebra/aggcat.spad.pamphlet index 3f4b4783..a23c9e4e 100644 --- a/src/algebra/aggcat.spad.pamphlet +++ b/src/algebra/aggcat.spad.pamphlet @@ -1573,10 +1573,11 @@ UnaryRecursiveAggregate(S:Type): Category == RecursiveAggregate S with empty? l and zero? i #x == - k : NonNegativeInteger - for k in 0.. while not empty? x repeat + k: NonNegativeInteger := 0 + while not empty? x repeat k = cycleMax and cyclic? x => error "cyclic list" x := rest x + k := k + 1 k tail x == @@ -1608,8 +1609,10 @@ UnaryRecursiveAggregate(S:Type): Category == RecursiveAggregate S with empty? x => x empty?(y := findCycle x) => y z := rest y - l : NonNegativeInteger - for l in 1.. while not eq?(y,z) repeat z := rest z + l: NonNegativeInteger := 1 + while not eq?(y,z) repeat + z := rest z + l := l + 1 y := x for k in 1..l repeat y := rest y while not eq?(x,y) repeat (x := rest x; y := rest y) @@ -1619,8 +1622,10 @@ UnaryRecursiveAggregate(S:Type): Category == RecursiveAggregate S with empty? x => 0 empty?(x := findCycle x) => 0 y := rest x - k : NonNegativeInteger - for k in 1.. while not eq?(x,y) repeat y := rest y + k: NonNegativeInteger := 1 + while not eq?(x,y) repeat + y := rest y + k := k + 1 k rest(x, n) == @@ -2417,9 +2422,10 @@ ListAggregate(S:Type): Category == Join(StreamAggregate S, first x position(f:S -> Boolean, x:%) == - k : Integer - for k in minIndex(x).. while not empty? x and not f first x repeat + k := minIndex(x) + while not empty? x and not f first x repeat x := rest x + k := k + 1 empty? x => minIndex(x) - 1 k @@ -2511,9 +2517,10 @@ ListAggregate(S:Type): Category == Join(StreamAggregate S, position(w, x, s) == s < (m := minIndex x) => error "index out of range" x := rest(x, (s - m)::NonNegativeInteger) - k : Integer - for k in s.. while not empty? x and w ~= first x repeat + k := s + while not empty? x and w ~= first x repeat x := rest x + k := k + 1 empty? x => minIndex x - 1 k diff --git a/src/algebra/string.spad.pamphlet b/src/algebra/string.spad.pamphlet index ebec0fa2..e97d0501 100644 --- a/src/algebra/string.spad.pamphlet +++ b/src/algebra/string.spad.pamphlet @@ -294,10 +294,16 @@ IndexedString(mn:Integer): Export == Implementation where h:I := if hasHi sg then hi(sg) - mn else maxIndex s - mn l < 0 or h >= m or h < l-1 => error "index out of range" r := new((m-(h-l+1)+n)::N, space$C) - k : NonNegativeInteger - for k in 0.. for i in 0..l-1 repeat Qsetelt(r, k, Qelt(s, i)) - for k in k.. for i in 0..n-1 repeat Qsetelt(r, k, Qelt(t, i)) - for k in k.. for i in h+1..m-1 repeat Qsetelt(r, k, Qelt(s, i)) + k: NonNegativeInteger := 0 + for i in 0..l-1 repeat + Qsetelt(r, k, Qelt(s, i)) + k := k + 1 + for i in 0..n-1 repeat + Qsetelt(r, k, Qelt(t, i)) + k := k + 1 + for i in h+1..m-1 repeat + Qsetelt(r, k, Qelt(s, i)) + k := k + 1 r setelt(s:%, i:I, c:C) == @@ -339,48 +345,50 @@ IndexedString(mn:Integer): Export == Implementation where split(s, c) == n := maxIndex s - i : NonNegativeInteger - for i in mn..n while s.i = c repeat 0 + i := mn + while i <= n and s.i = c repeat i := i + 1 l := empty()$List(%) j:Integer -- j is conditionally intialized while i <= n and (j := position(c, s, i)) >= mn repeat l := concat(s(i..j-1), l) - for i in j..n while s.i = c repeat 0 + i := j + while i <= n and s.i = c repeat i := i + 1 if i <= n then l := concat(s(i..n), l) reverse! l split(s, cc) == n := maxIndex s - i : NonNegativeInteger - for i in mn..n while member?(s.i,cc) repeat 0 + i := mn + while i <= n and member?(s.i,cc) repeat i := i + 1 l := empty()$List(%) j:Integer -- j is conditionally intialized while i <= n and (j := position(cc, s, i)) >= mn repeat l := concat(s(i..j-1), l) - for i in j..n while member?(s.i,cc) repeat 0 + i := j + while i <= n and member?(s.i,cc) repeat i := i + 1 if i <= n then l := concat(s(i..n), l) reverse! l leftTrim(s, c) == n := maxIndex s - i : NonNegativeInteger - for i in mn .. n while s.i = c repeat 0 + i := mn + while i <= n and s.i = c repeat i := i + 1 s(i..n) leftTrim(s, cc) == n := maxIndex s - i : NonNegativeInteger - for i in mn .. n while member?(s.i,cc) repeat 0 + i := mn + while i <= n and member?(s.i,cc) repeat i := i + 1 s(i..n) rightTrim(s, c) == - j : NonNegativeInteger - for j in maxIndex s .. mn by -1 while s.j = c repeat 0 + j := maxIndex s + while j >= mn and s.j = c repeat j := j - 1 s(minIndex(s)..j) rightTrim(s, cc) == - j : NonNegativeInteger - for j in maxIndex s .. mn by -1 while member?(s.j, cc) repeat 0 + j := maxIndex s + while j >= mn and member?(s.j, cc) repeat j := j - 1 s(minIndex(s)..j) concat l == |