Fixed my terrible, broken, no-good readme. Now with API!

This commit is contained in:
Elf M. Sternberg 2015-06-23 13:10:05 -07:00
parent c34a0f391b
commit 02f8b8e4dd
2 changed files with 53 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# A simple implementation of Lisp-like cons() lists, using vectors
# This library contains a javascript implementation of Lisp-like cons(), using vectors
## Purpose
@ -7,6 +7,57 @@ with in each and every variant of Lisp I wrote while working my way
through List In Small Pieces, so I decided to break it out into its own
managed repo.
## API
A cons is a singly-link list consisting of *cells*, two-position
objects. In a true cons *list*, the leftmost cell (the "car") contains
a data object of interest, and the rightmost cell (the "cdr") contains a
pointer to the next cell. (A cell in which the second object is not a
pointer to the next cell is called a *pair*.) Cons lists traditionally
end with a cdr object pointing to an empty list. The following
functions are provided to create, identify, traverse, and modify cons
lists.
nil: An empty list, used as a static sentinel
cons(): Construct an empty list
cons(obj): Create a new list of one object
cons(obj, lst): Append an object to the head of an existing list
car(lst): Return the contents of the current cell, or nil.
cdr(lst): Return a reference to the next item in the list, or nil.
nilp(lst): (Boolean) is list an empty list?
pairp(lst): (Boolean) is this a cell object?
listp(lst): (Boolean) si this a list object?
list:(a, b, ...): Construct a list out of the arguments
vectorToList(v): Return a cons list from a vector. Recursive: if a
vector is encountered inside v, it will be converted to a cons list.
listToVector(l): Return a vector given a cons list. Recursive: if
car(l) is a vector, the return list will contain a list at that
position.
setcar(obj, l): Replace the contents of car(l) with obj
setcdr(obj, l): Replace the contents of cdr(l) with obj
cadr, cddr, cdar, caar, caddr, cdddr, cadar, cddar, caadr, cdadr: Common
lisp functions that extend standard list addressing.
metacadr(string): For more complex addressing, metacadr() can be
provided with a string that describes the address desired, and returns
the qualifying function. For example, this library does not provide
caddddr(), but it can easily be generated: metacadr("caddddr") will
return a function to get the data content of the fifth cell.
## LICENSE AND COPYRIGHT NOTICE: NO WARRANTY GRANTED OR IMPLIED
Copyright (c) 2015 Elf M. Sternberg

View File

@ -58,8 +58,7 @@ module.exports =
list: list
nilp: nilp
pairp: pairp
vectorp: vectorp
recordp: recordp
listp: listp
vectorToList: vectorToList
listToVector: listToVector
setcar: (a, l) -> l[0] = a; a