aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/array1.spad.pamphlet
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2009-04-27 01:41:53 +0000
committerdos-reis <gdr@axiomatics.org>2009-04-27 01:41:53 +0000
commita6b14a62e4c347c6459d7aee6590581aff17f001 (patch)
tree4e16d7e30d9d1d24ce5fefe55f8785f67d6be62c /src/algebra/array1.spad.pamphlet
parent859f04d06f9961fe66abcace3ba37985f641d30c (diff)
downloadopen-axiom-a6b14a62e4c347c6459d7aee6590581aff17f001.tar.gz
* interp/sys-macros.lisp (makeSimpleArrayFromList): New.
* algebra/array1.spad.pamphlet (construct$PrimitiveArray): Implement. (copy$PrimitiveArray): Likewise. (IndexedOneDimensionalArray): Rework. Explicitly use PrimitiveArray(S) as representation domain.
Diffstat (limited to 'src/algebra/array1.spad.pamphlet')
-rw-r--r--src/algebra/array1.spad.pamphlet58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/algebra/array1.spad.pamphlet b/src/algebra/array1.spad.pamphlet
index 7fe6df24..00117332 100644
--- a/src/algebra/array1.spad.pamphlet
+++ b/src/algebra/array1.spad.pamphlet
@@ -20,10 +20,13 @@ PrimitiveArray(S:Type): OneDimensionalArrayAggregate S == add
minIndex x ==
0
-
+
empty() ==
makeSimpleArray(getVMType(S)$Lisp,0$Lisp)$Lisp
+ construct l ==
+ makeSimpleArrayFromList(getVMType(S)$Foreign(Builtin),l)$Foreign(Builtin)
+
new(n, x) ==
makeFilledSimpleArray(getVMType(S)$Lisp,n,x)$Lisp
@@ -42,6 +45,9 @@ PrimitiveArray(S:Type): OneDimensionalArrayAggregate S == add
fill!(x, s) ==
FILL(x,s)$Foreign(Builtin)
+ copy x ==
+ COPY_-SEQ(x)$Foreign(Builtin)
+
@
@@ -362,24 +368,27 @@ FlexibleArray(S: Type) == Implementation where
IndexedOneDimensionalArray(S:Type, mn:Integer):
OneDimensionalArrayAggregate S == add
- Qmax ==> QVMAXINDEX$Lisp
- Qsize ==> QVSIZE$Lisp
- Qelt ==> QVELT$Lisp
- Qsetelt ==> QSETVELT$Lisp
--- Qelt1 ==> QVELT_-1$Lisp
--- Qsetelt1 ==> QSETVELT_-1$Lisp
- Qnew ==> GETREFV$Lisp
- I ==> Integer
-
- #x == Qsize x
- fill_!(x, s) == (for i in 0..Qmax x repeat Qsetelt(x, i, s); x)
- minIndex x == mn
-
- empty() == Qnew(0$Lisp)
- new(n, s) == fill_!(Qnew n,s)
-
- map_!(f, s1) ==
- n:Integer := Qmax(s1)
+ macro Qmax == maxIndexOfSimpleArray$Foreign(Builtin)
+ macro Qsize == sizeOfSimpleArray$Foreign(Builtin)
+ macro Qelt == getSimpleArrayEntry$Foreign(Builtin)
+ macro Qsetelt == setSimpleArrayEntry$Foreign(Builtin)
+ macro I == Integer
+ Rep == PrimitiveArray S
+
+ newArray(n: Integer): % ==
+ makeSimpleArray(getVMType(S)$Foreign(Builtin),n)$Foreign(Builtin)
+
+ #x == # rep x
+ copy x == per copy rep x
+ fill!(x, s) == per fill!(rep x, s)
+ minIndex x == mn
+
+ empty() == per empty()$Rep
+ new(n, s) == per new(n,s)$Rep
+ construct l == per construct(l)$Rep
+
+ map!(f, s1) ==
+ n: Integer := Qmax(s1)
n < 0 => s1
for i in 0..n repeat Qsetelt(s1, i, f(Qelt(s1,i)))
s1
@@ -387,14 +396,14 @@ IndexedOneDimensionalArray(S:Type, mn:Integer):
map(f, s1) ==
n:Integer := Qmax(s1)
n < 0 => s1
- ss2:% := Qnew(n+1)
+ ss2:% := newArray(n+1)
for i in 0..n repeat Qsetelt(ss2, i, f(Qelt(s1,i)))
ss2
map(f, a, b) ==
maxind:Integer := min(Qmax a, Qmax b)
maxind < 0 => empty()
- c:% := Qnew(maxind+1)
+ c:% := newArray(maxind+1)
for i in 0..maxind repeat
Qsetelt(c, i, f(Qelt(a,i),Qelt(b,i)))
c
@@ -452,12 +461,7 @@ OneDimensionalArray(S:Type): Exports == Implementation where
oneDimensionalArray: (NonNegativeInteger, S) -> %
++ oneDimensionalArray(n,s) creates an array from n copies of element s
Implementation == IndexedOneDimensionalArray(S, ARRAYMININDEX) add
- oneDimensionalArray(u) ==
- n := #u
- n = 0 => empty()
- a := new(n, first u)
- for i in 2..n for x in rest u repeat a.i := x
- a
+ oneDimensionalArray(u) == construct u
oneDimensionalArray(n,s) == new(n,s)
@