diff options
Diffstat (limited to 'src/boot/strap/utility.clisp')
-rw-r--r-- | src/boot/strap/utility.clisp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/boot/strap/utility.clisp b/src/boot/strap/utility.clisp index 73e14218..83ee8844 100644 --- a/src/boot/strap/utility.clisp +++ b/src/boot/strap/utility.clisp @@ -21,7 +21,7 @@ |substitute!| |setDifference| |setUnion| |setIntersection| |symbolAssoc| |applySubst| |applySubst!| |applySubstNQ| |objectAssoc| |remove| |removeSymbol| |atomic?| |every?| - |any?| |takeWhile| |copyTree| |finishLine|))) + |any?| |take| |takeWhile| |drop| |copyTree| |finishLine|))) (DECLAIM (FTYPE (FUNCTION (|%Thing| |%Thing| |%Thing|) |%Thing|) |substitute|)) @@ -83,11 +83,17 @@ |any?|)) (DECLAIM + (FTYPE (FUNCTION (|%Short| (|%List| |%Thing|)) (|%List| |%Thing|)) |take|)) + +(DECLAIM (FTYPE (FUNCTION ((FUNCTION (|%Thing|) |%Thing|) (|%List| |%Thing|)) (|%List| |%Thing|)) |takeWhile|)) +(DECLAIM + (FTYPE (FUNCTION (|%Short| (|%List| |%Thing|)) (|%List| |%Thing|)) |drop|)) + (DECLAIM (FTYPE (FUNCTION (|%Thing|) |%Thing|) |copyTree|)) (DECLAIM (FTYPE (FUNCTION (|%Thing|) |%Void|) |finishLine|)) @@ -120,6 +126,26 @@ (COND (|bfVar#2| (RETURN |bfVar#2|))))) (SETQ |bfVar#1| (CDR |bfVar#1|))))) +(DEFUN |take| (|n| |l|) + (COND + ((NOT (MINUSP |n|)) + (LET ((|bfVar#3| NIL) + (|bfVar#4| NIL) + (|bfVar#1| |l|) + (|x| NIL) + (|bfVar#2| 1)) + (LOOP + (COND + ((OR (NOT (CONSP |bfVar#1|)) (PROGN (SETQ |x| (CAR |bfVar#1|)) NIL) + (> |bfVar#2| |n|)) + (RETURN |bfVar#3|)) + ((NULL |bfVar#3|) (SETQ |bfVar#3| #1=(CONS |x| NIL)) + (SETQ |bfVar#4| |bfVar#3|)) + (T (RPLACD |bfVar#4| #1#) (SETQ |bfVar#4| (CDR |bfVar#4|)))) + (SETQ |bfVar#1| (CDR |bfVar#1|)) + (SETQ |bfVar#2| (+ |bfVar#2| 1))))) + (T (|drop| (+ (LENGTH |l|) |n|) |l|)))) + (DEFUN |takeWhile| (|f| |l|) (LET ((|bfVar#2| NIL) (|bfVar#3| NIL) (|bfVar#1| |l|) (|x| NIL)) (LOOP @@ -132,6 +158,17 @@ (T (RPLACD |bfVar#3| #1#) (SETQ |bfVar#3| (CDR |bfVar#3|)))) (SETQ |bfVar#1| (CDR |bfVar#1|))))) +(DEFUN |drop| (|n| |l|) + (COND + ((NOT (MINUSP |n|)) + (LOOP + (COND + ((NOT (AND (PLUSP |n|) (CONSP |l|) (PROGN (SETQ |l| (CDR |l|)) T))) + (RETURN NIL)) + (T (SETQ |n| (- |n| 1))))) + |l|) + (T (|take| (+ (LENGTH |l|) |n|) |l|)))) + (DEFUN |copyTree| (|t|) (COND ((CONSP |t|) (CONS (|copyTree| (CAR |t|)) (|copyTree| (CDR |t|)))) (T |t|))) |