;(QUOTE (((DIRF F) - print the functions on a library file) (ARGUMENT: F - the name of an iLISP library file) (DESCRIPTION: DIRF prints the names of the entries on the) (library file in a semi-regular fashion with tabs separating) (each entry%'s name.)))
(DEFINE DIRF (X) (PRL (DIRFILE X)))
(QUOTE ())
;(QUOTE (((RANDINT N) - generate a random integer) (ARGUMENT: N - an integer) (DESCRIPTION: generates a random integer which is greater than or) (equal to zero, but less than N.) (VALUE: the newly generated integer.)))
(DEFINE RANDINT (N) (FIX (* N (RANDOM))))
(QUOTE ())
;(QUOTE (((CONCATENATE X Y) - concatenate two literal atoms) (ARGUMENTS: X, Y - literal atoms) (DESCRIPTION: Produces a new literal atom whose print name is the) (concatenation of X and Y.)))
;(QUOTE (((SUBSTRING STRING START COUNT) - extract a substring of a literal atom) (ARGUMENTS:) (% STRING - a literal atom) (% START, COUNT - integers) (DESCRIPTION: Constructs a new literal atom whose print name is the) (substring of the print name of STRING, beginning with the START character) (and extending for COUNT characters. E.g.) (% (SUBSTRING (QUOTE interesting) 1 4) = inter) (% (SUBSTRING (QUOTE interesting) 5 7) = resting)))
;(QUOTE (((REPEAT N expression) - a simple control macro) (ARGUMENTS:) (% N - an integer) (% expression - any lisp expression to be evaluated) (DESCRIPTION: REPEAT is a MACRO. Its meaning is:) (% EVALUATE the expression N times.) (VALUE: Always NIL.)))
;(QUOTE (((UNSETF F) - UNSET all functions in a file) (ARGUMENT: F - an iLISP library file name) (DESCRIPTION: Applies UNSET to all of the entry names in file F.) (It effectively reverses an INFILE to the file F.) (This releases the free space and full space occupied by those) (functions for use by new ones.) (VALUE: F)))
;(QUOTE (((ADDEL NEW LIST POS) - add an element to a list) (ARGUMENTS:) (% NEW - the new element) (% LIST - the list to receive the new element) (% POS - the position after which the element is to be inserted) (DESCRIPTION: This function is one of three (ADDEL DELETEL and REPLACEL)) (which allow you to treat lists as arrays. It actually modifies the list) (you give it, using RPLACAD, and inserts the new element into the list) (after the POSth element of the list.) (EXAMPLES:) (% (SETQ X (QUOTE (A B C D E)))) (% (ADDEL (QUOTE Z) X 1) = (A Z B C D E)) (% (ADDEL (QUOTE Q) X 0) = (Q A Z B C D E)) (% (ADDEL (QUOTE V) X 7) = (Q A Z B C D E V))))
(DEFINE ADDEL (N L P) (COND ((= (LENGTH L) P) (NCONC L (LIST N))) (T (LET ((L (CDRS L P))) (RPLACAD L (CONS N (CONS (CAR L) (CDR L))))) L)))
(QUOTE ())
;(QUOTE (((DELETEL L POS) - delete the POSth element of list L) (ARGUMENTS:) (% L - the list to be modified) (% POS - the position of the element to be removed) (DESCRIPTION: This function is one of three (ADDEL, DELETEL and REPLACEL)) (which allow you to treat lists as arrays. DELETEL actually modifies) (the list L (using RPLACAD) and removes the POSth element from it.) (% If L only has one element in it, the value of DELETEL will be NIL,) (but, it is impossible for DELETEL to change L into () so the actual list) (structure will be unchanged.) (EXAMPLES:) (% (SETQ X (QUOTE (A B C)))) (% (DELETEL X 1) = (B C)) (% (DELETEL X 2) = (B)) (% X = (B)) (% (DELETEL X 1) = ()) (% X = (B) %;you can (QUOTE t) change a list into ())))
(DEFINE DELETEL (L P) (COND ((= 1 (LENGTH L)) ()) ((= (LENGTH L) P) (RPLACD (CDRS L (- P 2)) ()) L) (T (LET ((L (CDRS L (SUB1 P)))) (RPLACAD L (CDR L))) L)))
(QUOTE ())
;(QUOTE (((REPLACEL N L POS) - replace an element of a list) (ARGUMENTS:) (% N - the new element) (% L - the list to be changed) (% POS - the position of the element to be replaced) (DESCRIPTION: REPLACEL is one of the functions (ADDEL, DELETEL and REPLACEL)) (which allow you to treat lists as arrays. REPLACEL will actually replace the) (POSth element of the list L with the new element N (using RPLACA) .) (EXAMPLES:) (% (SETQ X (QUOTE (A B C D E)))) (% (REPLACEL (QUOTE Z) X 1) = (Z B C D E)) (% (REPLACEL (QUOTE Q) X 3) = (Z B Q D E)) (% (REPLACEL (QUOTE R) X 4) = (Z B Q R E))))
(DEFINE REPLACEL (N L P) (PROGN (RPLACA (CDRS L (SUB1 P)) N) L))
(QUOTE ())
;(QUOTE (((PRL L) - print the elements of a list) (ARGUMENT: L - any list) (DESCRIPTION: PRL prints the individual elements of the list L, each) (followed by a TAB character for separation. It is used primarily by) (functions such as DIR and DIRF for presenting literal atoms.)))
;(QUOTE (((DIR group) - the standard file directory command) (ARGUMENT: group, OPTIONAL, a file group description) (DESCRIPTION: DIR duplicates the CP/M CCP DIR command. It will) (print out the directory of the current or specified disk. If) (called with no arguments it will print out all of the .LSP files) (on the current disk, but it can be called with any standard) (file group description and it will produce the correct response, e.g.) (% (DIR %'*.*)) (% (DIR %'*.TXT)) (% (DIR %'LISP.*) etc.)))
(DEFINE DIR FORM (PRL (FILDIR (IF FORM (CAR FORM) (QUOTE *)))))
(QUOTE ())
;(QUOTE (((LOAD F) - load a binary file) (ARGUMENT: F, a file name) (DESCRIPTION: loads the contents of the binary file and packs it into) (the print name of a literal atom.) (VALUE: The literal atom.)))
;(QUOTE (((DO I J F A R) - MAP over a list of numbers) (ARGUMENTS:) (% I - the starting integer) (% J - the final integer) (% F - the function) (% A - the accumulating function) (% R - the accumulating register) (DESCRIPTION: This function is similar to MAP. In effect it applies) (the function F to each element of a list of integers from I to J) (and accumulates the results to R using A.) (EXAMPLE:) (% (DO 1 10 PRINT EQ ()) - prints the numbers from 1 to 10) (% (DO 10 20 ID + 0) - adds the numbers from 10 to 20)))
(DEFINE DO (I J F A R) (IF (> I J) R (DO (ADD1 I) J F A (A (F I) R))))
(QUOTE ())
;(QUOTE (((TYPE file) - type the contents of a file) (ARGUMENT: a file name) (DESCRIPTION: TYPE duplicates the CP/M CCP command TYPE. It takes) (one argument, a file name, and types out the contents of the file on) (the current output device (presumably the console) .) (% ) (TYPE is interesting because it illustrates the use of a local function,) (TYPELOOP. This is defined as the value of a local variable, one defined) (inside the LET statement. The function is used by TYPE, but its definition) (disappears once TYPE is exited.)))
;(QUOTE (((PRINTD N) - print a number in a monetary format) (ARGUMENT: N - an integer taken to be a number of cents) (DESCRIPTION: N is printed out with a leading dollar sign) (and a decimal point inserted before the penultimate digit.) (VALUE: ())))
;(QUOTE (((NodeCount L) - count the nodes in a list) (ARGUMENT: L - a list) (DESCRIPTION: Counts the total number of list nodes in a list) (including all sublists. NodeCount contains a built in DESCRIBE) (call so that it can be called directly on user defined functions.) (EXAMPLES:) (% (NodeCount NodeCount) = 25) (% (NodeCount (QUOTE (a b c (d e)))) = 6)))