rhoScript - command reference

UNSURE :: ->

(UNSURE NIL NIL NIL :MESSY "Do nothing." 42)

Do nothing.

DUP :: :A TYPE => :A -> :A, :A

(DUP ((:A TYPE)) ((:A OTHER)) (:A :A) "Duplicate the top element of the stack." (LIST OTHER OTHER))

Duplicate the top element of the stack.

DUP-TOP-TWO :: :A TYPE, :B TYPE => :A, :B -> :A, :B, :A, :B

(DUP-TOP-TWO ((:A TYPE) (:B TYPE)) ((:A OTHER1) (:B OTHER2)) (:A :B :A :B) "Duplicate the top two elements of the stack." (LIST OTHER1 OTHER2 OTHER1 OTHER2))

Duplicate the top two elements of the stack.

SWAP :: :A TYPE, :B TYPE => :A, :B -> :B, :A

(SWAP ((:A TYPE) (:B TYPE)) ((:A A) (:B B)) (:B :A) "Swap the order of the top two elements on the stack." (LIST B A))

Swap the order of the top two elements on the stack.

EQ :: TYPE, TYPE -> BOOL

(EQ NIL ((TYPE A) (TYPE B)) (BOOL) "Compare the top two elements of the stack for equality." (EQUALP A B))

Compare the top two elements of the stack for equality.

NEQ :: TYPE, TYPE -> BOOL

(NEQ NIL ((TYPE A) (TYPE B)) (BOOL) "Compare the top two elements of the stack for inequality." (NOT (EQUALP A B)))

Compare the top two elements of the stack for inequality.

DROP :: TYPE ->

(DROP NIL ((TYPE Q)) NIL "Remove the top element of the stack." Q)

Remove the top element of the stack.

PRINT :: ->

(PRINT NIL NIL NIL "Pretty-print the entire stack; useful only for debugging." (PROGN (FORMAT T "Stack dump:~%") (LOOP FOR EL IN STACK FOR I FROM 0 DO (FORMAT T " ~a. ~a~%" I EL)) (FORMAT T "~%")))

Pretty-print the entire stack; useful only for debugging.

ROT :: :A TYPE, :B TYPE, :C TYPE => :A, :B, :C -> :B, :C, :A

(ROT ((:A TYPE) (:B TYPE) (:C TYPE)) ((:A A) (:B B) (:C C)) (:B :C :A) "Rotate the top three elements: A B C -> B C A" (LIST B C A))

Rotate the top three elements: A B C -> B C A

UNROT :: :A TYPE, :B TYPE, :C TYPE => :A, :B, :C -> :C, :A, :B

(UNROT ((:A TYPE) (:B TYPE) (:C TYPE)) ((:A A) (:B B) (:C C)) (:C :A :B) "Rotate the top three elements in the reverse direction: A B C -> C A B" (LIST C A B))

Rotate the top three elements in the reverse direction: A B C -> C A B

ARG-A :: -> TYPE

(ARG-A NIL NIL (TYPE) "Push the top element of the stack, at the time of the last context establishment, to the stack." (CAR (CAR ARGUMENT-RESTORE-STACK)))

Push the top element of the stack, at the time of the last
context establishment, to the stack.

ARG-B :: -> TYPE

(ARG-B NIL NIL (TYPE) "Push the second to top element of the stack, at the time of the last context establishment, to the stack." (CADR (CAR ARGUMENT-RESTORE-STACK)))

Push the second to top element of the stack, at the time of the last
context establishment, to the stack.

ARG-C :: -> TYPE

(ARG-C NIL NIL (TYPE) "Push the third to top element of the stack, at the time of the last context establishment, to the stack." (CADDR (CAR ARGUMENT-RESTORE-STACK)))

Push the third to top element of the stack, at the time of the last
context establishment, to the stack.

ARG-D :: -> TYPE

(ARG-D NIL NIL (TYPE) "Push the fourth to top element of the stack, at the time of the last context establishment, to the stack." (CADDDR (CAR ARGUMENT-RESTORE-STACK)))

Push the fourth to top element of the stack, at the time of the last
context establishment, to the stack.

FOREVER :: TYPE -> LIST

(FOREVER NIL ((TYPE ARG)) (LIST) "Create an infinite list containing a single element." (CREATING-NEW-LIST (NEXT (VECTOR-PUSH-EXTEND ARG RESULT))))

Create an infinite list containing a single element.

NATURALS :: -> LIST

(NATURALS NIL NIL (LIST) "Return a sequence of all the natural numbers (0, 1, 2, 3...)." (LET ((I 0)) (CREATING-NEW-LIST (NEXT (VECTOR-PUSH-EXTEND I RESULT) (INCF I)))))

Return a sequence of all the natural numbers (0, 1, 2, 3...).

BOX :: TYPE -> LIST

(BOX NIL ((TYPE ARG)) (LIST) "Place an element in a list containing only itself." (CREATING-NEW-LIST (INITIALLY (VECTOR-PUSH-EXTEND ARG RESULT))))

Place an element in a list containing only itself.

CONS :: :A ANYLIST => TYPE, :A -> :A

(CONS ((:A ANYLIST)) ((TYPE ARG) (:A L)) (:A) "Add an item to the front of a list." (LIST-TO-LIST-ITER L (INITIALLY (VECTOR-PUSH-EXTEND ARG RESULT)) (NEXT (VECTOR-PUSH-EXTEND EACH RESULT))))

Add an item to the front of a list.

RCONS :: :A ANYLIST => TYPE, :A -> :A

(RCONS ((:A ANYLIST)) ((TYPE ARG) (:A L)) (:A) "Add an item to the end of a list." (LIST-TO-LIST-ITER L (NEXT (VECTOR-PUSH-EXTEND EACH RESULT)) (FINALLY (VECTOR-PUSH-EXTEND ARG RESULT))))

Add an item to the end of a list.

MEMBER :: TYPE, LIST -> BOOL

(MEMBER NIL ((TYPE ARG) (LIST L)) (BOOL) "Test if an item is a member of a list." (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST DO (IF (EQUALP EL ARG) (RETURN T)))))

Test if an item is a member of a list.

INDEX-OF :: TYPE, LIST -> INT

(INDEX-OF NIL ((TYPE ARG) (LIST L)) (INT) "Find the index of an item in a list, or -1 if not present." (WITH-FORCED L LIST (BLOCK OUT (LOOP FOR EL ACROSS LIST FOR COUNT FROM 0 DO (IF (EQUALP EL ARG) (RETURN-FROM OUT COUNT))) -1)))

Find the index of an item in a list, or -1 if not present.

PICK :: INT -> TYPE

(PICK NIL ((INT N)) (TYPE) "Take the nth element of the stack and duplicate it on the top of the stack." (NTH N STACK))

Take the nth element of the stack and duplicate it on the top of the stack.

OR :: BOOL, BOOL -> BOOL

(OR NIL ((BOOL A) (BOOL B)) (BOOL) "Logical or of the top two elements of the stack." (OR A B))

Logical or of the top two elements of the stack.

NOT :: BOOL -> BOOL

(NOT NIL ((BOOL A)) (BOOL) "Logical not of the top element of the stack." (NOT A))

Logical not of the top element of the stack.

AND :: BOOL, BOOL -> BOOL

(AND NIL ((BOOL A) (BOOL B)) (BOOL) "Logical and of the top two elements of the stack." (AND A B))

Logical and of the top two elements of the stack.

GTE :: INT, INT -> BOOL

(GTE NIL ((INT A) (INT B)) (BOOL) "Check if the first argument is larger than the second." (NOT (> A B)))

Check if the first argument is larger than the second.

GT :: INT, INT -> BOOL

(GT NIL ((INT A) (INT B)) (BOOL) "Check if the first argument is larger than or equal to the second." (NOT (>= A B)))

Check if the first argument is larger than or equal to the second.

LT :: INT, INT -> BOOL

(LT NIL ((INT A) (INT B)) (BOOL) "Check if the first argument is less than the second." (>= A B))

Check if the first argument is less than the second.

LTE :: INT, INT -> BOOL

(LTE NIL ((INT A) (INT B)) (BOOL) "Check if the first argument is less than or equal to the second." (> A B))

Check if the first argument is less than or equal to the second.

ADD :: INT, INT -> INT

(ADD NIL ((INT A) (INT B)) (INT) "Add the top two elements of the stack." (+ A B))

Add the top two elements of the stack.

NEGATE :: INT -> INT

(NEGATE NIL ((INT A)) (INT) "Negate the top element of the stack." (- 0 A))

Negate the top element of the stack.

INC :: INT -> INT

(INC NIL ((INT A)) (INT) "Increment the top element of the stack." (+ A 1))

Increment the top element of the stack.

DEC :: INT -> INT

(DEC NIL ((INT A)) (INT) "Decrement the top element of the stack." (- A 1))

Decrement the top element of the stack.

MULTIPLY :: INT, INT -> INT

(MULTIPLY NIL ((INT A) (INT B)) (INT) "Multiply the top two elements of the stack." (* A B))

Multiply the top two elements of the stack.

SUBTRACT :: INT, INT -> INT

(SUBTRACT NIL ((INT A) (INT B)) (INT) "Subtract from the second-to-top by the top of the stack." (- B A))

Subtract from the second-to-top by the top of the stack.

SWAPSUBTRACT :: INT, INT -> INT

(SWAPSUBTRACT NIL ((INT A) (INT B)) (INT) "Subtract from the top by the second-to-top of the stack." (- A B))

Subtract from the top by the second-to-top of the stack.

DIVIDE :: INT, INT -> INT

(DIVIDE NIL ((INT A) (INT B)) (INT) "Divide from the second-to-top by the top of the stack." (FLOOR (/ B A)))

Divide from the second-to-top by the top of the stack.

SWAPDIVIDE :: INT, INT -> INT

(SWAPDIVIDE NIL ((INT A) (INT B)) (INT) "Divide from the top by the second-to-top of the stack." (FLOOR (/ A B)))

Divide from the top by the second-to-top of the stack.

POW :: INT, INT -> INT

(POW NIL ((INT A) (INT B)) (INT) "Return the second-to-top element to the power of the top element." (EXPT B A))

Return the second-to-top element to the power of the top element.

SQUARE :: INT -> INT

(SQUARE NIL ((INT A)) (INT) "Square the top element of the stack." (* A A))

Square the top element of the stack.

MOD :: INT, INT -> INT

(MOD NIL ((INT A) (INT B)) (INT) "Compute the remainder of the second-to-top when divided by the top of the stack." (MOD B A))

Compute the remainder of the second-to-top when divided by the top of the stack.

DIVIDES :: INT, INT -> BOOL

(DIVIDES NIL ((INT A) (INT B)) (BOOL) "Test if the top element divides the second-to-top element" (= (MOD B A) 0))

Test if the top element divides the second-to-top element

ABS :: INT -> INT

(ABS NIL ((INT A)) (INT) "Compute the absolute value of the top of the stack." (ABS A))

Compute the absolute value of the top of the stack.

ZERO :: INT -> BOOL

(ZERO NIL ((INT A)) (BOOL) "Test if a number is zero." (= A 0))

Test if a number is zero.

EVEN :: INT -> BOOL

(EVEN NIL ((INT A)) (BOOL) "Test if the top of the stack is an even number." (EVENP A))

Test if the top of the stack is an even number.

ODD :: INT -> BOOL

(ODD NIL ((INT A)) (BOOL) "Test if the top of the stack is an odd number." (ODDP A))

Test if the top of the stack is an odd number.

GCD :: INT, INT -> INT

(GCD NIL ((INT A) (INT B)) (INT) "Compute the greatest common divisor of two integers." (LET ((TMP 0)) (LOOP WHILE (AND (> A 0) (> B 0)) DO (SETF TMP A) (SETF A (MOD B A)) (SETF B TMP)) B))

Compute the greatest common divisor of two integers.

TAKE :: :A ANYLIST => INT, :A -> :A

(TAKE ((:A ANYLIST)) ((INT A) (:A L)) (:A) "Take the first n elements of a list." (LET ((INDEX 0)) (CREATING-NEW-LIST (NEXT (IF (<= (INCF INDEX) A) (VECTOR-PUSH-EXTEND (LIST-GET L (1- INDEX)) RESULT))))))

Take the first n elements of a list.

UNTAKE :: :A ANYLIST => INT, :A -> :A

(UNTAKE ((:A ANYLIST)) ((INT A) (:A L)) (:A) "Take all but the first n elements of a list." (LET ((INDEX 0)) (CREATING-NEW-LIST (NEXT (IF (> (INCF INDEX) A) (VECTOR-PUSH-EXTEND (LIST-GET L (1- INDEX)) RESULT))))))

Take all but the first n elements of a list.

IMPLODE :: INT -> LIST

(IMPLODE NIL ((INT COUNT)) (LIST) :MESSY "Pop the top count elements off the stack and make a list out of them." (LET ((A (NEW-ARRAY))) (LOOP FOR J FROM 1 TO COUNT DO (VECTOR-PUSH-EXTEND (POP STACK) A)) (MAKE-TYPE-LIST :ARRAY A)))

Pop the top count elements off the stack and make a list out of them.

RANGE :: INT -> LIST

(RANGE NIL ((INT N)) (LIST) "Generate a list of numbers from 0 (inclusive) to n (exclusive)." (LET ((ARR (MAKE-ARRAY N :ADJUSTABLE T))) (LOOP FOR N FROM 0 TO (- N 1) DO (SETF (AREF ARR N) N)) (MAKE-TYPE-LIST :ARRAY ARR)))

Generate a list of numbers from 0 (inclusive) to n (exclusive).

RANGE-FROM-1 :: INT -> LIST

(RANGE-FROM-1 NIL ((INT N)) (LIST) "Generate a list of numbers from 1 (inclusive) to n (exclusive)." (LET ((ARR (MAKE-ARRAY N :ADJUSTABLE T))) (LOOP FOR N FROM 1 TO N DO (SETF (AREF ARR (1- N)) N)) (MAKE-TYPE-LIST :ARRAY ARR)))

Generate a list of numbers from 1 (inclusive) to n (exclusive).

RANGE-FROM-TO :: INT, INT -> LIST

(RANGE-FROM-TO NIL ((INT A) (INT B)) (LIST) "Generate a list of numbers from the first number (inclusive) to the second number (exclusive)." (LET ((ARR (MAKE-ARRAY (- A B) :ADJUSTABLE T))) (LOOP FOR N FROM B TO (1- A) DO (SETF (AREF ARR (- N B)) N)) (MAKE-TYPE-LIST :ARRAY ARR)))

Generate a list of numbers from the first number (inclusive) to the second number (exclusive).

GET :: INT, LIST -> TYPE

(GET NIL ((INT I) (LIST L)) (TYPE) "Get the nth element of a list." (LIST-GET L I))

Get the nth element of a list.

SUBSTR :: INT, INT, LIST -> LIST

(SUBSTR NIL ((INT START) (INT END) (LIST L)) (LIST) "Return a subsequence of the elements of a list." (LET ((ARR (NEW-ARRAY))) (LOOP FOR I FROM START TO (1- END) DO (VECTOR-PUSH-EXTEND (LIST-GET L I) ARR)) (MAKE-TYPE-LIST :ARRAY ARR)))

Return a subsequence of the elements of a list.

COMBINATIONS :: :A ANYLIST => INT, :A -> :A

(COMBINATIONS ((:A ANYLIST)) ((INT SIZE) (:A L)) (:A) "Compute all of the combinations of a list." (WITH-FORCED L LIST (LABELS ((COMBINE (LST SZ) (IF (EQ SZ 0) (LIST NIL) (REDUCE #'APPEND (MAPLIST (LAMBDA (X) (MAPCAR (LAMBDA (Y) (CONS (CAR X) Y)) (COMBINE (CDR X) (1- SZ)))) LST))))) (TO-ARRAY (MAPCAR (LAMBDA (X) (TO-ARRAY X)) (COMBINE (COERCE LIST 'LIST) SIZE))))))

Compute all of the combinations of a list.

INT-TO-STR-BASE-10 :: INT -> STRING

(INT-TO-STR-BASE-10 NIL ((INT X)) (STRING) "Convert an integer to a string, in base 10." (TO-ARRAY (WRITE-TO-STRING X :BASE 10)))

Convert an integer to a string, in base 10.

INT-TO-STR-BASE-16 :: INT -> STRING

(INT-TO-STR-BASE-16 NIL ((INT X)) (STRING) "Convert an integer to a string, in base 16." (TO-ARRAY (WRITE-TO-STRING X :BASE 16)))

Convert an integer to a string, in base 16.

INT-TO-STR-BASE-2 :: INT -> STRING

(INT-TO-STR-BASE-2 NIL ((INT X)) (STRING) "Convert an integer to a string, in base 12." (TO-ARRAY (WRITE-TO-STRING X :BASE 2)))

Convert an integer to a string, in base 12.

INT-TO-STR-BASE-2 :: INT, INT -> STRING

Convert an integer to a string, in base 12.

LIST-TO-STRING :: LIST -> STRING

(LIST-TO-STRING NIL ((LIST L)) (STRING) "Convert a list of bytes to a string." (LABELS ((L2S (INP) (WITH-FORCED INP R (MAKE-TYPE-LIST :KIND 'STRING :ARRAY (IF (AND (> (LENGTH R) 0) (NOT (NUMBERP (AREF R 0)))) (MAP 'VECTOR #'L2S R) R))))) (L2S L)))

Convert a list of bytes to a string.

STRING-TO-LIST :: STRING -> LIST

(STRING-TO-LIST NIL ((STRING S)) (LIST) "Convert a string to a list of bytes." (WITH-FORCED S _ (MAKE-TYPE-LIST :ARRAY (TYPE-LIST-ARRAY S) :KIND 'LIST)))

Convert a string to a list of bytes.

EXPLODE :: ANYLIST ->

(EXPLODE NIL ((ANYLIST L)) NIL :MESSY "Push each element of a list onto the stack; the head of the list will become the top of the stack." (WITH-FORCED L LIST (LOOP FOR X ACROSS (REVERSE LIST) DO (PUSH X STACK))))

Push each element of a list onto the stack; the head of the list
will become the top of the stack.

OUTER :: LIST, LIST -> LIST

(OUTER NIL ((LIST A) (LIST B)) (LIST) "Create a new list which contains all pairs of elements in the two input lists." (LIST-TO-LIST-ITER A (NEXT (LET ((TMP EACH)) (VECTOR-PUSH-EXTEND (LIST-TO-LIST-ITER B (NEXT (VECTOR-PUSH-EXTEND (TO-ARRAY (LIST TMP EACH)) RESULT))) RESULT)))))

Create a new list which contains all pairs of elements in the two input lists.

SUM :: LIST -> INT

(SUM NIL ((LIST L)) (INT) "Compute the sum of a list." (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST SUM EL)))

Compute the sum of a list.

MIN :: LIST -> INT

(MIN NIL ((LIST L)) (INT) "Find the smallest element of a list." (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST MINIMIZE EL)))

Find the smallest element of a list.

MAX :: LIST -> INT

(MAX NIL ((LIST L)) (INT) "Find the largest element of a list." (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST MAXIMIZE EL)))

Find the largest element of a list.

ARG-MIN :: LIST -> INT

(ARG-MIN NIL ((LIST L)) (INT) "Find the smallest element of a list." (LET ((BEST (LIST-GET L 0))) (WITH-FORCED L LIST (LOOP FOR EL IN (LOOP FOR EL ACROSS LIST FOR II FROM 0 COLLECT (IF (<= EL BEST) (PROGN (SETF BEST EL) II) -1)) MAXIMIZE EL))))

Find the smallest element of a list.

ARG-MAX :: LIST -> INT

(ARG-MAX NIL ((LIST L)) (INT) "Find the smallest element of a list." (LET ((BEST (LIST-GET L 0))) (WITH-FORCED L LIST (LOOP FOR EL IN (LOOP FOR EL ACROSS LIST FOR II FROM 0 COLLECT (IF (>= EL BEST) (PROGN (SETF BEST EL) II) -1)) MAXIMIZE EL))))

Find the smallest element of a list.

WITH-INDEX :: LIST -> LIST

(WITH-INDEX NIL ((LIST L)) (LIST) "Return a new list, where each element is a list of the index and the corresponding element." (LIST-TO-LIST-ITER L (NEXT (VECTOR-PUSH-EXTEND (TO-ARRAY (LIST INDEX EACH)) RESULT))))

Return a new list, where each element is a list of the index and the corresponding element.

SORT :: LIST -> LIST

(SORT NIL ((LIST L)) (LIST) "Sort the elements of a list." (WITH-FORCED L LIST (SORT LIST #'<)))

Sort the elements of a list.

REVERSE :: :A ANYLIST => :A -> :A

(REVERSE ((:A ANYLIST)) ((:A L)) (:A) "Reverse a list." (WITH-FORCED L LIST (TO-ARRAY (REVERSE LIST))))

Reverse a list.

FIRST-AND-REST :: :A ANYLIST => :A -> TYPE, :A

(FIRST-AND-REST ((:A ANYLIST)) ((:A L)) (TYPE :A) "Push both the first element of a list and the remaining list to the stack." (LIST (LIST-GET L 0) (LIST-TO-LIST-ITER L (NEXT (IF (NOT (EQ INDEX 0)) (VECTOR-PUSH-EXTEND EACH RESULT))))))

Push both the first element of a list and the remaining list to the stack.

FIRST :: ANYLIST -> TYPE

(FIRST NIL ((ANYLIST L)) (TYPE) "Get the first element of a list." (LIST-GET L 0))

Get the first element of a list.

REST :: :A ANYLIST => :A -> :A

(REST ((:A ANYLIST)) ((:A L)) (:A) "Get every element other than the first element of a list." (LIST-TO-LIST-ITER L (NEXT (IF (NOT (EQ INDEX 0)) (VECTOR-PUSH-EXTEND EACH RESULT)))))

Get every element other than the first element of a list.

LAST :: ANYLIST -> TYPE

(LAST NIL ((ANYLIST L)) (TYPE) "Get the first element of a list." (WITH-FORCED L LST (LIST-GET L (1- (LENGTH LST)))))

Get the first element of a list.

BUTLAST :: :A ANYLIST => :A -> :A

(BUTLAST ((:A ANYLIST)) ((:A L)) (:A) "Get every element other than the first element of a list." (LIST-TO-LIST-ITER L (NEXT (IF (NOT (EQ (LIST-GET L (1+ INDEX)) NULL-SYMBOL)) (VECTOR-PUSH-EXTEND EACH RESULT)))))

Get every element other than the first element of a list.

SET-MINUS :: LIST, LIST -> LIST

(SET-MINUS NIL ((LIST TAKEAWAY) (LIST GIVEN)) (LIST) "The set difference of two lists: all of the elements in the second list, except for those which occur in the first list." (WITH-FORCED TAKEAWAY FORCED-TAKEAWAY-ARR (LET ((FORCED-TAKEAWAY (COERCE FORCED-TAKEAWAY-ARR 'LIST))) (LIST-TO-LIST-ITER GIVEN (NEXT (IF (NOT (MEMBER EACH FORCED-TAKEAWAY)) (VECTOR-PUSH-EXTEND EACH RESULT)))))))

The set difference of two lists: all of the elements in the second list, except
for those which occur in the first list.

ANY :: LIST -> BOOL

(ANY NIL ((LIST L)) (BOOL) "Test if any of the elements in a list are true." (NOT (LOOP FOR I FROM 0 UNTIL (EQ (LIST-GET L I) NULL-SYMBOL) NEVER (LIST-GET L I))))

Test if any of the elements in a list are true.

ALL :: ANYLIST -> BOOL

(ALL NIL ((ANYLIST L)) (BOOL) "Test if all of the elements in a list are true." (LOOP FOR I FROM 0 UNTIL (EQ (LIST-GET L I) NULL-SYMBOL) ALWAYS (LIST-GET L I)))

Test if all of the elements in a list are true.

ZIP :: :A ANYLIST => :A, :A -> :A

(ZIP ((:A ANYLIST)) ((:A A) (:A B)) (:A) "Take two lists and form a new list, pairing up elements together." (LET ((I 0)) (CREATING-NEW-LIST (NEXT (LET ((E1 (LIST-GET A I)) (E2 (LIST-GET B I))) (IF (OR (EQ E1 NULL-SYMBOL) (EQ E2 NULL-SYMBOL)) NIL (PROGN (VECTOR-PUSH-EXTEND (TO-ARRAY (LIST E1 E2)) RESULT) (INCF I))))))))

Take two lists and form a new list, pairing up elements together.

TRANSPOSE :: :A ANYLIST => :A -> :A

(TRANSPOSE ((:A ANYLIST)) ((:A L)) (:A) "Take a multi-dimensional list and reverse the order of the first and second axes. That is, if 'some_list i get j get' is the same as 'some_list transpose j get i get'." (LET ((INDEX 0)) (CREATING-NEW-LIST (NEXT (WHEN (NOT (EQ (LIST-GET (LIST-GET L 0) INDEX) NULL-SYMBOL)) (LET ((JINDEX 0) (IINDEX INDEX)) (VECTOR-PUSH-EXTEND (FUNCALL (IF (EQ (TYPE-LIST-KIND L) 'STRINGQ) #'AS-STRING (LAMBDA (X) X)) (CREATING-NEW-LIST (NEXT (LET ((TMP (LIST-GET L JINDEX))) (INCF JINDEX) (WHEN (NOT (EQ TMP NULL-SYMBOL)) (VECTOR-PUSH-EXTEND (LIST-GET TMP IINDEX) RESULT)))))) RESULT)) (INCF INDEX))))))

Take a multi-dimensional list and reverse the order of the first and second axes.
That is, if 'some_list i get j get' is the same as 'some_list transpose j get i get'.

LENGTH :: ANYLIST -> INT

(LENGTH NIL ((ANYLIST L)) (INT) "Compute the length of a list." (WITH-FORCED L LIST (LENGTH LIST)))

Compute the length of a list.

CONCATENATE :: :A ANYLIST => :A, :A -> :A

(CONCATENATE ((:A ANYLIST)) ((:A A) (:A B)) (:A) "Concatenate two lists." (LET ((RES (NEW-ARRAY))) (WITH-FORCED B LIST (LOOP FOR J FROM 0 TO (1- (LENGTH LIST)) DO (VECTOR-PUSH-EXTEND (AREF LIST J) RES))) (WITH-FORCED A LIST (LOOP FOR J FROM 0 TO (1- (LENGTH LIST)) DO (VECTOR-PUSH-EXTEND (AREF LIST J) RES))) (MAKE-TYPE-LIST :ARRAY RES)))

Concatenate two lists.

PREFIXES :: :A ANYLIST => :A -> :A

(PREFIXES ((:A ANYLIST)) ((:A L)) (:A) "Compute all of the prefixes of a list." (LIST-TO-LIST-ITER L (INITIALLY (VECTOR-PUSH-EXTEND (MAKE-TYPE-LIST :ARRAY (NEW-ARRAY)) RESULT)) (NEXT (VECTOR-PUSH-EXTEND (MAKE-TYPE-LIST :ARRAY (SUBSEQ (TYPE-LIST-ARRAY L) 0 (1+ INDEX))) RESULT))))

Compute all of the prefixes of a list.

FLATTEN :: LIST -> LIST

(FLATTEN NIL ((LIST L)) (LIST) "Flatten a n-dimensional list to an (n-1)-dimensional list." (LIST-TO-LIST-ITER L (NEXT (WITH-FORCED EACH EACH-LIST (LOOP FOR EL ACROSS EACH-LIST DO (VECTOR-PUSH-EXTEND EL RESULT))))))

Flatten a n-dimensional list to an (n-1)-dimensional list.

UNIQ :: LIST -> LIST

(UNIQ NIL ((LIST L)) (LIST) "Return only the unique elements of a list, order-preserved." (LET ((SEEN (MAKE-HASH-TABLE :TEST 'EQUALP))) (LIST-TO-LIST-ITER L (NEXT (IF (NOT (GETHASH EACH SEEN)) (PROGN (SETF (GETHASH EACH SEEN) T) (VECTOR-PUSH-EXTEND EACH RESULT)))))))

Return only the unique elements of a list, order-preserved.

SUFFIXES :: :A ANYLIST => :A -> :A

(SUFFIXES ((:A ANYLIST)) ((:A L)) (:A) "Compute all of the suffixes of a list." (WITH-FORCED L LIST (LET ((LENGTH (LENGTH LIST))) (LIST-TO-LIST-ITER L (NEXT (VECTOR-PUSH-EXTEND (MAKE-TYPE-LIST :ARRAY (SUBSEQ (TYPE-LIST-ARRAY L) INDEX LENGTH)) RESULT)) (FINALLY (VECTOR-PUSH-EXTEND (MAKE-TYPE-LIST :ARRAY (NEW-ARRAY)) RESULT))))))

Compute all of the suffixes of a list.

PERMUTATIONS :: :A ANYLIST => :A -> :A

(PERMUTATIONS ((:A ANYLIST)) ((:A L)) (:A) "Compute all of the permutations of a list." (WITH-FORCED L LIST (LABELS ((PERMUTE (LIST) (IF (<= (LENGTH LIST) 1) (LIST LIST) (LOOP FOR I FROM 0 TO (1- (LENGTH LIST)) APPEND (MAPCAR (LAMBDA (X) (CONS (NTH I LIST) X)) (PERMUTE (WITHOUT I LIST)))))) (WITHOUT (I LIST) (IF (= I 0) (CDR LIST) (CONS (CAR LIST) (WITHOUT (1- I) (CDR LIST)))))) (TO-ARRAY (MAPCAR (LAMBDA (X) (TO-ARRAY X)) (PERMUTE (COERCE LIST 'LIST)))))))

Compute all of the permutations of a list.

ROTATIONS :: :A ANYLIST => :A -> :A

(ROTATIONS ((:A ANYLIST)) ((:A L)) (:A) "Compute all of the rotations of a list." (WITH-FORCED L LIST (LABELS ((ROTATE (LIST I) (APPEND (SUBSEQ LIST I (LENGTH LIST)) (SUBSEQ LIST 0 I))) (ROTATIONS (LIST) (TO-ARRAY (LOOP FOR I FROM 0 TO (1- (LENGTH LIST)) COLLECT (TO-ARRAY (ROTATE LIST I)))))) (ROTATIONS (COERCE LIST 'LIST)))))

Compute all of the rotations of a list.

JOIN :: :A ANYLIST => :A, :A -> :A

(JOIN ((:A ANYLIST)) ((:A JOINON) (:A L)) (:A) "Flatten out a list, placing a second list in between each sublist." (LIST-TO-LIST-ITER L (NEXT (LOOP FOR E ACROSS (WITH-FORCED EACH EA EA) DO (VECTOR-PUSH-EXTEND E RESULT)) (IF (NOT (EQ (LIST-GET L (1+ INDEX)) NULL-SYMBOL)) (LOOP FOR E ACROSS (WITH-FORCED JOINON J J) DO (VECTOR-PUSH-EXTEND E RESULT))))))

Flatten out a list, placing a second list in between each sublist.

INTERSPERSE :: :A ANYLIST => TYPE, :A -> :A

(INTERSPERSE ((:A ANYLIST)) ((TYPE ITEM) (:A L)) (:A) "Intersperse an item in a list." (LIST-TO-LIST-ITER L (NEXT (VECTOR-PUSH-EXTEND EACH RESULT) (IF (NOT (EQ (LIST-GET L (1+ INDEX)) NULL-SYMBOL)) (VECTOR-PUSH-EXTEND ITEM RESULT)))))

Intersperse an item in a list.

FORCE :: LIST -> LIST

(FORCE NIL ((LIST L)) (LIST) "Force a list to be evaluated completely." (WITH-FORCED L LIST LIST L))

Force a list to be evaluated completely.

PUTS :: STRING ->

(PUTS NIL ((STRING S)) NIL "Print out the contents of a string." (WITH-FORCED S STR (FORMAT T "~a" (MAP 'STRING #'CODE-CHAR STR))))

Print out the contents of a string.

STR-TO-INT-BASE-10 :: STRING -> INT

(STR-TO-INT-BASE-10 NIL ((STRING S)) (INT) "Convert a string to an integer, treating the string as base 10." (PARSE-INTEGER (TO-STRING S)))

Convert a string to an integer, treating the string as base 10.

MAGIC-READ :: STRING -> TYPE

(MAGIC-READ NIL ((STRING S)) (TYPE) "Attempt to read the string in to the appropriate data structures. Try hard to do \"the right thing\" whenever possible. Types are entirely data-dependent, and this function might behave incorrectly on some inputs." (MAGIC-READ (TO-STRING S)))

Attempt to read the string in to the appropriate data structures. Try hard to do
"the right thing" whenever possible. Types are entirely data-dependent, and this function
might behave incorrectly on some inputs.

MAGIC-READ-KIND :: INT, STRING -> TYPE

(MAGIC-READ-KIND NIL ((INT HOW) (STRING S)) (TYPE) "Read the string into the appropriate data structures, as directed by the flags. A 1 in the low bit indicates that if there is only one line, flatten the array once. A 1 in the second bit indicates that if there is a line with only one word, flatten that array. A 1 in the third bit indicates words should not attempt to be parsed to their kind if possible. A 1 in the fourth bit indicates that lines should not attempt to be read at all." (LABELS ((ZERO (X) (= X 0))) (MAGIC-READ (TO-STRING S) (NOT (ZERO (LOGAND HOW 1))) (NOT (ZERO (LOGAND HOW 2))) (ZERO (LOGAND HOW 4)) (ZERO (LOGAND HOW 8)))))

Read the string into the appropriate data structures, as directed by the flags.
A 1 in the low bit indicates that if there is only one line, flatten the array once.
A 1 in the second bit indicates that if there is a line with only one word, flatten that array.
A 1 in the third bit indicates words should not attempt to be parsed to their kind if possible.
A 1 in the fourth bit indicates that lines should not attempt to be read at all.

SPLIT-BY-WHITESPACE :: STRING -> LIST

(SPLIT-BY-WHITESPACE NIL ((STRING S)) (LIST) "Split a string to a list of strings, splitting on any whitespace." (WITH-FORCED S _ (TO-ARRAY (MAPCAR #'TO-ARRAY (CL-PPCRE:SPLIT "\\W+" (TO-STRING S))))))

Split a string to a list of strings, splitting on any whitespace.

SPLIT-BY-NEWLINES :: STRING -> LIST

(SPLIT-BY-NEWLINES NIL ((STRING S)) (LIST) "Split a string to a list of strings, splitting on newlines." (WITH-FORCED S _ (TO-ARRAY (MAPCAR #'TO-ARRAY (CL-PPCRE:SPLIT "[\\r\\n]" (TO-STRING S))))))

Split a string to a list of strings, splitting on newlines.

SPLIT-BY-NEWLINES-TO-STR :: STRING -> STRING

(SPLIT-BY-NEWLINES-TO-STR NIL ((STRING S)) (STRING) "Split a string to a multi-level string, splitting on newlines." (WITH-FORCED S _ (AS-STRING (TO-ARRAY (MAPCAR #'TO-ARRAY (CL-PPCRE:SPLIT "[\\r\\n]" (TO-STRING S)))))))

Split a string to a multi-level string, splitting on newlines.

SPLIT-BY-SPACES :: STRING -> LIST

(SPLIT-BY-SPACES NIL ((STRING S)) (LIST) "Split a string to a list of strings, splitting on spaces." (WITH-FORCED S _ (TO-ARRAY (MAPCAR #'TO-ARRAY (CL-PPCRE:SPLIT "[ \\t]+" (TO-STRING S))))))

Split a string to a list of strings, splitting on spaces.

UPPERCASE-STRING :: STRING -> STRING

(UPPERCASE-STRING NIL ((STRING S)) (STRING) "Force every character in a string to upper case." (WITH-FORCED S _ (TO-ARRAY (STRING-UPCASE (TO-STRING S)))))

Force every character in a string to upper case.

LOWERCASE-STRING :: STRING -> STRING

(LOWERCASE-STRING NIL ((STRING S)) (STRING) "Force every character in a string to lower case." (WITH-FORCED S _ (TO-ARRAY (STRING-DOWNCASE (TO-STRING S)))))

Force every character in a string to lower case.

CAPITALIZE-STRING :: STRING -> STRING

(CAPITALIZE-STRING NIL ((STRING S)) (STRING) "Make a string capitalized: every word starts with a capital letter, all other letters are lower case." (WITH-FORCED S _ (TO-ARRAY (STRING-CAPITALIZE (TO-STRING S)))))

Make a string capitalized: every word starts with a capital letter, all other letters
are lower case.

SPLIT :: STRING, STRING -> LIST

(SPLIT NIL ((STRING SPLIT-AT) (STRING LONGSTR)) (LIST) "Split a string by occurrences of a specific string." (WITH-FORCED LONGSTR _ (WITH-FORCED SPLIT-AT _ (TO-ARRAY (MAPCAR #'TO-ARRAY (CL-PPCRE:SPLIT (LIST :SEQUENCE (TO-STRING SPLIT-AT)) (TO-STRING LONGSTR)))))))

Split a string by occurrences of a specific string.

SIMPLE-REPLACE :: STRING, STRING, STRING -> STRING

(SIMPLE-REPLACE NIL ((STRING REPLACE-WITH) (STRING REPLACE-THIS) (STRING REPLACE-IN)) (STRING) "Replace one string with another string for all occurrences of a third string." (WITH-FORCED REPLACE-IN _ (WITH-FORCED REPLACE-WITH _ (WITH-FORCED REPLACE-THIS _ (AS-STRING (TO-ARRAY (CL-PPCRE:REGEX-REPLACE-ALL (LIST :SEQUENCE (TO-STRING REPLACE-THIS)) (TO-STRING REPLACE-IN) (TO-STRING REPLACE-WITH))))))))

Replace one string with another string for all occurrences of a third string.

STRIP :: STRING -> LIST

(STRIP NIL ((STRING S)) (LIST) "Strip a string, removing whitespace around the outside." (WITH-FORCED S _ (TO-ARRAY (CL-PPCRE:REGEX-REPLACE "^\\W*(\\w|\\w.*\\w)\\W*$" (TO-STRING S) "\\1"))))

Strip a string, removing whitespace around the outside.

CALL :: FUN ->

(CALL NIL ((FUN F)) NIL "Take a function off the stack and run it." (SAVE-ARGUMENTS (FUNCALL F STATE 0 NIL)))

Take a function off the stack and run it.

CALL-WITH-RETURN :: FUN -> TYPE

(CALL-WITH-RETURN NIL ((FUN F)) (TYPE) "Take a function off the stack and run it, returning the top element of the stack." (SAVE-ARGUMENTS (FUNCALL F STATE 1 NIL)))

Take a function off the stack and run it, returning the top element of the stack.

CALL-WITH-ARG-AND-RETURN :: FUN, TYPE -> TYPE

(CALL-WITH-ARG-AND-RETURN NIL ((FUN F) (TYPE ARG)) (TYPE) "Take a function off the stack and run it with the second-to-top element of the stack, returning the top element of the stack." (SAVE-ARGUMENTS (FUNCALL F STATE 1 (LIST ARG))))

Take a function off the stack and run it with the second-to-top element of the
stack, returning the top element of the stack.

MAP :: :A ANYLIST => FUN, :A -> :A

(MAP ((:A ANYLIST)) ((FUN FN) (:A L)) (:A) "Map a function over a list. Each element of the new list is the function applied to the old element." (SAVE-ARGUMENTS (LIST-TO-LIST-ITER L (NEXT (VECTOR-PUSH-EXTEND (FUNCALL FN STATE 1 (LIST EACH)) RESULT)))))

Map a function over a list. Each element of the new list is the function applied
to the old element.

KEEP-MAXES-BY :: FUN, LIST -> LIST

(KEEP-MAXES-BY NIL ((FUN FN) (LIST L)) (LIST) "Keep only the largest elements of a list as decided by a function." (SAVE-ARGUMENTS (LET ((BEST (FUNCALL FN STATE 1 (LIST (LIST-GET L 0)))) (RESULT NIL)) (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST DO (LET ((VALUE (FUNCALL FN STATE 1 (LIST EL)))) (WHEN (> VALUE BEST) (SETF BEST VALUE) (SETF RESULT NIL)) (IF (>= VALUE BEST) (PUSH EL RESULT))))) (TO-ARRAY (REVERSE RESULT)))))

Keep only the largest elements of a list as decided by a function.

FILTER :: :A ANYLIST => FUN, :A -> :A

(FILTER ((:A ANYLIST)) ((FUN FN) (:A L)) (:A) "Return a new list where only elements for which the function returns true are retained." (SAVE-ARGUMENTS (LIST-TO-LIST-ITER L (NEXT (IF (FUNCALL FN STATE 1 (LIST EACH)) (VECTOR-PUSH-EXTEND EACH RESULT))))))

Return a new list where only elements for which the function returns true are retained.

REDUCE :: FUN, LIST -> TYPE

(REDUCE NIL ((FUN FN) (LIST L)) (TYPE) "Return a single element which is the result of calling a function on successive elements of a list." (SAVE-ARGUMENTS (LET ((INIT (LIST-GET L 0))) (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST FOR I FROM 0 IF (NOT (EQ I 0)) DO (SETF INIT (FUNCALL FN STATE 1 (LIST EL INIT)))) INIT))))

Return a single element which is the result of calling a function on successive
elements of a list.

FOLD :: FUN, TYPE, LIST -> TYPE

(FOLD NIL ((FUN FN) (TYPE INIT) (LIST L)) (TYPE) "Identical to reduce, but specifying a different initial value. This is a left-fold." (SAVE-ARGUMENTS (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST DO (SETF INIT (FUNCALL FN STATE 1 (LIST EL INIT)))) INIT)))

Identical to reduce, but specifying a different initial value. This is a left-fold.

UNIQ-BY :: FUN, LIST -> LIST

(UNIQ-BY NIL ((FUN FN) (LIST L)) (LIST) "Return a new list of only the unique elements, using some other predicate than equality." (SAVE-ARGUMENTS (LET ((SEEN NIL)) (LIST-TO-LIST-ITER L (NEXT (WHEN (NOT (SOME (LAMBDA (X) X) (MAPCAR (LAMBDA (X) (FUNCALL FN STATE 1 (LIST X EACH))) SEEN))) (VECTOR-PUSH-EXTEND EACH RESULT) (PUSH EACH SEEN)))))))

Return a new list of only the unique elements, using some other predicate than equality.

TABULATE-FOREVER :: FUN -> LIST

(TABULATE-FOREVER NIL ((FUN FN)) (LIST) "Create a sequence obtained by calling a function on the integers from 0" (LET ((NUMBER 0)) (SAVE-ARGUMENTS (CREATING-NEW-LIST (NEXT (VECTOR-PUSH-EXTEND (FUNCALL FN STATE 1 (LIST NUMBER)) RESULT) (INCF NUMBER))))))

Create a sequence obtained by calling a function on the integers from 0

TABULATE :: FUN, INT -> LIST

(TABULATE NIL ((FUN FN) (INT UPTO)) (LIST) "Create a sequence obtained by calling a function on the integers from 0 up to a number" (LET ((NUMBER 0)) (SAVE-ARGUMENTS (CREATING-NEW-LIST (NEXT (WHEN (< NUMBER UPTO) (VECTOR-PUSH-EXTEND (FUNCALL FN STATE 1 (LIST NUMBER)) RESULT) (INCF NUMBER)))))))

Create a sequence obtained by calling a function on the integers from 0 up to a number

PARTITION :: FUN, LIST -> LIST

(PARTITION NIL ((FUN FN) (LIST L)) (LIST) "Partition a list to a list of lists, where each element of each list has the same value when the function is applied to it." (LET ((SEEN (MAKE-HASH-TABLE :TEST 'EQUALP)) (RES (NEW-ARRAY))) (SAVE-ARGUMENTS (WITH-FORCED L LIST (LOOP FOR EL ACROSS LIST DO (LET ((VAL (FUNCALL FN STATE 1 (LIST EL)))) (IF (NOT (GETHASH VAL SEEN)) (SETF (GETHASH VAL SEEN) (NEW-ARRAY))) (VECTOR-PUSH-EXTEND EL (GETHASH VAL SEEN)))))) (MAPHASH (LAMBDA (KEY VALUE) (DECLARE (IGNORE KEY)) (VECTOR-PUSH-EXTEND (LIST VALUE) RES)) SEEN) (MAKE-TYPE-LIST :ARRAY RES)))

Partition a list to a list of lists, where each element of each list has the same value
when the function is applied to it.

FIXPOINT :: :A TYPE => FUN, :A -> :A

(FIXPOINT ((:A TYPE)) ((FUN A) (:A START)) (:A) "Compute the fixedpoint of applying a function to an item, terminating when the function returns the same a value for the second time, not necessarily consecutively." (LET ((SEEN (MAKE-HASH-TABLE :TEST 'EQUALP))) (SAVE-ARGUMENTS (LOOP WHILE (NOT (GETHASH START SEEN)) DO (SETF (GETHASH START SEEN) T) (SETF START (FUNCALL A STATE 1 (LIST START))))) START))

Compute the fixedpoint of applying a function to an item, terminating when the function
returns the same a value for the second time, not necessarily consecutively.

FIXPOINT-WITH-HISTORY :: :A TYPE => FUN, :A -> :A

(FIXPOINT-WITH-HISTORY ((:A TYPE)) ((FUN A) (:A START)) (:A) "Compute the fixedpoint of applying a function to an item, terminating when the function returns the same a value for the second time, not necessarily consecutively. Return the full sequence generated." (LET ((SEEN (MAKE-HASH-TABLE :TEST 'EQUALP)) (RES (NEW-ARRAY))) (SAVE-ARGUMENTS (LOOP WHILE (NOT (GETHASH START SEEN)) DO (VECTOR-PUSH-EXTEND START RES) (SETF (GETHASH START SEEN) T) (SETF START (FUNCALL A STATE 1 (LIST START))))) (MAKE-TYPE-LIST :ARRAY RES)))

Compute the fixedpoint of applying a function to an item, terminating when the function
returns the same a value for the second time, not necessarily consecutively. Return the
full sequence generated.

ITE :: FUN, FUN, BOOL ->

(ITE NIL ((FUN A) (FUN B) (BOOL CASE)) NIL "Run one of two functions based on whether the next element on the stack is true or not." (SAVE-ARGUMENTS (IF CASE (FUNCALL A STATE 0 NIL) (FUNCALL B STATE 0 NIL))))

Run one of two functions based on whether the next element on the stack is true or not.

IF :: FUN, BOOL ->

(IF NIL ((FUN A) (BOOL CASE)) NIL "Run a function if the top of the stack is true." (SAVE-ARGUMENTS (IF CASE (FUNCALL A STATE 0 NIL))))

Run a function if the top of the stack is true.

DO-WHILE :: FUN ->

(DO-WHILE NIL ((FUN FN)) NIL "Run a function as long as it returns true from the top of the stack." (SAVE-ARGUMENTS (LET ((CONT T)) (LOOP WHILE CONT DO (SETF CONT (FUNCALL FN STATE 1 NIL))))))

Run a function as long as it returns true from the top of the stack.

CALL-N-TIMES :: FUN, INT ->

(CALL-N-TIMES NIL ((FUN FN) (INT N)) NIL "Run the top function n times." (SAVE-ARGUMENTS (LOOP FOR I FROM 0 TO (1- N) DO (FUNCALL FN STATE 0 NIL))))

Run the top function n times.