aboutsummaryrefslogtreecommitdiff
path: root/src/algebra
diff options
context:
space:
mode:
Diffstat (limited to 'src/algebra')
-rw-r--r--src/algebra/aggcat2.spad.pamphlet15
-rw-r--r--src/algebra/data.spad.pamphlet16
2 files changed, 20 insertions, 11 deletions
diff --git a/src/algebra/aggcat2.spad.pamphlet b/src/algebra/aggcat2.spad.pamphlet
index a49e955d..7fea65b4 100644
--- a/src/algebra/aggcat2.spad.pamphlet
+++ b/src/algebra/aggcat2.spad.pamphlet
@@ -56,6 +56,11 @@ FiniteLinearAggregateFunctions2(S, A, R, B):
++ \spad{[reduce(f,[a1],r),reduce(f,[a1,a2],r),...]}.
Implementation ==> add
+ getRSample(): R ==
+ R has sample: R => sample()$R
+ R has random: () -> R => random()$R
+ NIL$Lisp -- R got to be non-trivial.
+
if A has ListAggregate(S) then -- A is a list-oid
reduce(fn, l, ident) ==
empty? l => ident
@@ -72,12 +77,12 @@ FiniteLinearAggregateFunctions2(S, A, R, B):
else -- A is a list-oid, B a mutable array-oid
map(f, l) ==
- i := minIndex(w := new(#l,NIL$Lisp)$B)
+ i := minIndex(w := new(#l,getRSample())$B)
for a in entries l repeat (qsetelt_!(w, i, f a); i := inc i)
w
scan(fn, l, ident) ==
- i := minIndex(w := new(#l,NIL$Lisp)$B)
+ i := minIndex(w := new(#l,getRSample())$B)
vl := ident
for a in entries l repeat
vl := qsetelt_!(w, i, fn(a, vl))
@@ -105,13 +110,13 @@ FiniteLinearAggregateFunctions2(S, A, R, B):
else -- A and B are array-oid's
if B has shallowlyMutable then -- B is also mutable
map(f, v) ==
- w := new(#v,NIL$Lisp)$B
+ w := new(#v,getRSample())$B
for i in minIndex w .. maxIndex w repeat
qsetelt_!(w, i, f qelt(v, i))
w
scan(fn, v, ident) ==
- w := new(#v,NIL$Lisp)$B
+ w := new(#v,getRSample())$B
vl := ident
for i in minIndex v .. maxIndex v repeat
vl := qsetelt_!(w, i, fn(qelt(v, i), vl))
@@ -188,6 +193,8 @@ FiniteSetAggregateFunctions2(S, A, R, B): Exports == Implementation where
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
+--Copyright (C) 2007-2009, Gabriel Dos Reis.
+--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
diff --git a/src/algebra/data.spad.pamphlet b/src/algebra/data.spad.pamphlet
index 43a3b07d..eb69372a 100644
--- a/src/algebra/data.spad.pamphlet
+++ b/src/algebra/data.spad.pamphlet
@@ -33,11 +33,11 @@ Byte(): Public == Private where
++ bitand(x,y) returns the bitwise `and' of `x' and `y'.
bitior: (%,%) -> %
++ bitor(x,y) returns the bitwise `inclusive or' of `x' and `y'.
- sample: () -> %
- ++ sample() returns a sample datum of type Byte.
+ sample: %
+ ++ \spad{sample} gives a sample datum of type Byte.
Private == SubDomain(NonNegativeInteger, #1 < 256) add
byte(x: NonNegativeInteger): % == per x
- sample() = 0$Lisp
+ sample = 0$Lisp
coerce(c: Character) == per ord c
coerce(x: %): Character == char rep x
x = y == byteEqual(x,y)$Lisp
@@ -91,8 +91,10 @@ ByteOrder(): Public == Private where
++ for system programming tasks, i.e. interfacting with the hosting
++ operating system, reading/writing external binary format files.
SystemInteger(N: PositiveInteger): Public == Private where
- Public == OrderedFinite
+ Public == OrderedFinite with
+ sample: % ++ \spad{sample} gives a sample datum of this type.
Private == SubDomain(Integer, length #1 <= N) add
+ sample == per(0@Integer)
min == per(-shift(1,N-1))
max == per(shift(1,N-1)-1)
size() == (rep max - rep min + 1)::NonNegativeInteger
@@ -159,12 +161,12 @@ SystemNonNegativeInteger(N: PositiveInteger): Public == Private where
++ bitand(x,y) returns the bitwise `and' of `x' and `y'.
bitior: (%,%) -> %
++ bitor(x,y) returns the bitwise `inclusive or' of `x' and `y'.
- sample: () -> %
- ++ sample() returns a sample datum of type Byte.
+ sample: %
+ ++ \spad{sample} gives a sample datum of type Byte.
Private == SubDomain(NonNegativeInteger, length #1 <= N) add
min == per 0
max == per((shift(1,N)-1)::NonNegativeInteger)
- sample() == min
+ sample == min
bitand(x,y) == BOOLE(BOOLE_-AND$Lisp,x,y)$Lisp
bitior(x,y) == BOOLE(BOOLE_-IOR$Lisp,x,y)$Lisp