From e688a0421303fb51afe31bb4b36774011bfac76d Mon Sep 17 00:00:00 2001 From: dos-reis Date: Thu, 9 May 2013 01:34:59 +0000 Subject: Simplify copy --- src/algebra/list.spad.pamphlet | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src/algebra') diff --git a/src/algebra/list.spad.pamphlet b/src/algebra/list.spad.pamphlet index ea7960fb..9f0cc282 100644 --- a/src/algebra/list.spad.pamphlet +++ b/src/algebra/list.spad.pamphlet @@ -72,19 +72,18 @@ List(S:Type): Exports == Implementation where import %tail: % -> % from Foreign Builtin import %lreverse: % -> % from Foreign Builtin import %lreverse!: % -> % from Foreign Builtin + import %lcopy: % -> % from Foreign Builtin import %llength: % -> NonNegativeInteger from Foreign Builtin import %icst0: NonNegativeInteger from Foreign Builtin import %icst1: NonNegativeInteger from Foreign Builtin import %idec: Integer -> Integer from Foreign Builtin Qpush ==> PUSH$Lisp - cycleMax ==> 1000 -- value used in checking for cycles nil == %nil null l == %peq(l,%nil) cons(s, l) == %pair(s,l) append(l:%, t:%) == %lconcat(l,t) - #x == %llength x concat(s:S,x:%) == %pair(s,x) eq?(x,y) == %peq(x,y) @@ -110,11 +109,11 @@ List(S:Type): Exports == Implementation where empty? x => error "Cannot update an empty list" %store(%tail x,y)$Foreign(Builtin) %tail x - construct l == l pretend % - parts s == s pretend List S + construct l == l + parts s == s reverse! x == %lreverse! x reverse x == %lreverse x - minIndex x == 1 + minIndex x == %icst1 rest(x, n) == for i in %icst1..n repeat @@ -122,13 +121,7 @@ List(S:Type): Exports == Implementation where x := %tail x x - copy x == - y := empty() - for i in %icst0.. while not empty? x repeat - if i = cycleMax and cyclic? x then error "cyclic list" - y := %pair(%head x,y) - x := %tail x - %lreverse! y + copy x == %lcopy x if S has CoercibleTo(OutputForm) then coerce(x):OutputForm == -- cgit v1.2.3