From ed0626e869fa09984c1f5856cb6b207b887221ea Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 1 Oct 2008 21:50:51 +0000 Subject: * algebra/array2.spad.pamphlet (TwoDimensionalArrayCategory): Tidy. --- src/algebra/array2.spad.pamphlet | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/algebra') diff --git a/src/algebra/array2.spad.pamphlet b/src/algebra/array2.spad.pamphlet index f6a89047..5cbff9ce 100644 --- a/src/algebra/array2.spad.pamphlet +++ b/src/algebra/array2.spad.pamphlet @@ -164,9 +164,15 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where entryList --% Creation + -- array creation requires an initial element used to + -- populate the array. This is a best effort attempt + -- to supply such element, when semantics permits. + sampleElement(): R == + R has sample: () -> R => sample()$R + NIL$Lisp -- better obfuscation welcome. copy m == - ans := new(nrows m,ncols m,NIL$Lisp) + ans := new(nrows m,ncols m,sampleElement()) for i in minRowIndex(m)..maxRowIndex(m) repeat for j in minColIndex(m)..maxColIndex(m) repeat qsetelt_!(ans,i,j,qelt(m,i,j)) @@ -179,7 +185,7 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where m map(f,m) == - ans := new(nrows m,ncols m,NIL$Lisp) + ans := new(nrows m,ncols m,sampleElement()) for i in minRowIndex(m)..maxRowIndex(m) repeat for j in minColIndex(m)..maxColIndex(m) repeat qsetelt_!(ans,i,j,f(qelt(m,i,j))) @@ -194,7 +200,7 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where map(f,m,n) == (nrows(m) ~= nrows(n)) or (ncols(m) ~= ncols(n)) => error "map: arguments must have same dimensions" - ans := new(nrows m,ncols m,NIL$Lisp) + ans := new(nrows m,ncols m,sampleElement()) for i in minRowIndex(m)..maxRowIndex(m) repeat for j in minColIndex(m)..maxColIndex(m) repeat qsetelt_!(ans,i,j,f(qelt(m,i,j),qelt(n,i,j))) @@ -203,7 +209,7 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where map(f,m,n,r) == maxRow := max(maxRowIndex m,maxRowIndex n) maxCol := max(maxColIndex m,maxColIndex n) - ans := new(max(nrows m,nrows n),max(ncols m,ncols n),NIL$Lisp) + ans := new(max(nrows m,nrows n),max(ncols m,ncols n),sampleElement()) for i in minRowIndex(m)..maxRow repeat for j in minColIndex(m)..maxCol repeat qsetelt_!(ans,i,j,f(elt(m,i,j,r),elt(n,i,j,r))) @@ -248,7 +254,7 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where row(m,i) == i < minRowIndex(m) or i > maxRowIndex(m) => error "row: index out of range" - v : Row := new(ncols m,NIL$Lisp) + v : Row := new(ncols m,sampleElement()) for j in minColIndex(m)..maxColIndex(m) _ for k in minIndex(v)..maxIndex(v) repeat qsetelt_!(v,k,qelt(m,i,j)) @@ -259,7 +265,7 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where column(m,j) == j < minColIndex(m) or j > maxColIndex(m) => error "column: index out of range" - v : Col := new(nrows m,NIL$Lisp) + v : Col := new(nrows m,sampleElement()) for i in minRowIndex(m)..maxRowIndex(m) _ for k in minIndex(v)..maxIndex(v) repeat qsetelt_!(v,k,qelt(m,i,j)) -- cgit v1.2.3