Common Lisp Package: WEBLOCKS-UTIL

General Lisp utilities traditionally exported with Weblocks.

README:

FUNCTION

Public

ADD-GET-PARAM-TO-URL (URL NAME VALUE)

Based on Edi's code in URL-REWRITE but uses & instead of & which is more appropriate for our uses.

ALIST->PLIST (ALIST)

Converts an alist to plist.

APPEND-CUSTOM-FIELDS (CUSTOM-FIELDS ARGS)

Appends 'custom-fields' to the end of custom fields that are already defined in 'args'.

ASDF-SYSTEM-DIRECTORY (ASDF-SYSTEM-NAME)

Computes the directory in which the .asdf file for a given ASDF system resides.

DROP-LAST (LIST)

Returns a copy of the list without the last element.

FIND-SLOT-DSD (CLASS SLOT-NAME)

Returns a direct-slot-definition object of a slot with 'slot-name' in 'class'.

FIND-SLOT-ESD (CLASS SLOT-NAME)

Returns an effective-slot-definition object of a slot with 'slot-name' in 'class'.

FUNCTION-DESIGNATOR-P (OBJ)

Returns true if the object is a function designator.

GEN-ID (&OPTIONAL (PREFIX dom))

Generates an ID unique accross the session. The generated ID can be used to create IDs for html elements, widgets, etc.

HASH-KEYS (HASHTABLE)

Returns all keys in the hashtable.

INSERT-AFTER (NEWELT LIST INDEX)

Destructively inserts 'newelt' into 'list' after 'index'.

INTERSPERSE (LIST DELIMETER &KEY (LAST DELIMETER))

Intersperses a list with a delimeter. If 'last' is specified, it will be used for the last delimeter, instead of 'delimeter'. (intersperse '(1 2 3 4 5) 0) => (1 0 2 0 3 0 4 0 5)

LIST-STARTS-WITH (LIST ELEMENTS &KEY (TEST 'EQ))

Determines if a list starts with the given elements.

MAKE-CLASS (SLOTS &OPTIONAL (CLASS-NAME (GENSYM)))

Makes an anonymous class with a number of slots. 'slots' - a list of symbols to be used as slot names.

PUBLIC-FILE-RELATIVE-PATH (TYPE FILENAME)

Infer FILENAME's relative path and extension from TYPE. Example: (public-file-relative-path :stylesheet "navigation") => "stylesheets/navigation.css"

PUBLIC-FILES-RELATIVE-PATHS (&REST ARGS)

A helper function that returns a list of paths for files provided in 'args'. Each argument must be a cons cell where car is either :stylesheet or :script and cdr is a name of the file. Useful when generating a list of dependencies for widgets and/or the application (see the 'dependencies' generic function and *application-dependencies*.) Ex: (get-public-files-paths '(:stylesheet . "navigation") '(:script . "effects")) => (#P"stylesheets/navigation.css" #P"scripts/effects.js")

REMOVE-KEYWORD-PARAMETER (PARAMETER-LIST KEYWORD)

Removes a keyword parameter from a parameter-list. (remove-keyword-parameter '(1 2 3 :a 1 :b 2 :c 3) :b) => (1 2 3 :a 1 :c 3)

REMOVE-KEYWORD-PARAMETERS (PARAMETER-LIST &REST KEYWORDS)

Removes all parameters with keys in 'keywords' from 'parameter-list'.

REMOVE-PARAMETER-FROM-URI (URI PARAMETER)

Removes the given parameter from a URI.

REMOVE-SPURIOUS-SLASHES (STR)

Condense multiple consecutively occuring slashes in STR into a single slash. ex: (remove-spurious-slashes "/ab/////c///") => "/ab/c/"

REQUEST-PARAMETER (NAME)

Get parameter 'name' from the request. If the request was submitted via GET method, the parameter is obtained from the query string. If the request was submitted via POST, the parameter is obtained from the body of the request. Otherwise, an error is signalled.

REQUEST-PARAMETERS

Get parameters alist from the request. If the request was submitted via GET method, the parameters are obtained from the query string. If the request was submitted via POST, the parameters are obtained from the body of the request. Otherwise, an error is signalled.

REQUEST-URI-PATH

Returns the path component of the request URI. The path component does not include the domain name, and any query string parameters. Ex (when URI is http://blah.com/foo/bar?x=1&y=2): (request-uri-path) => "/foo/bar"

SAFE-APPLY (FN &REST ARGS)

Apply 'fn' if it isn't nil. Otherwise return nil.

SAFE-FUNCALL (FN &REST ARGS)

Funcall 'fn' if it isn't nil. Otherwise return nil.

SAFE-GETF (LIST NAME)

Like GETF but copes with odd argument lists. Extracts the first value whose predecessor matches NAME. Returns NIL as second value if the key wasn't found at all.

SAFE-SUBSEQ (SEQUENCE START &OPTIONAL END)

A safe alternative to subseq that automatically adjust indices.

SLOT-EQUAL (O1 O2 &KEY EXCLUDE (TEST #'EQUAL))

Whether O1 and O2 have identical slot contents, excluding slot names in EXCLUDE. Two slots are considered equal if they are either both unbound or if they are both bound and pass TEST. Signals an error when the slot names of O1 and O2 don't match.

SLOT-VALUE-BY-PATH (OBJ PATH)

Retrieves a value of a slot from a hierarchy of objects. A nil on the path is ignored. ex: (slot-value-by-path employee '(address street)) => "17 Sunvalley St." (slot-value-by-path employee '(address)) => #<ADDRESS {XXX}> (slot-value-by-path employee 'address) => #<ADDRESS {XXX}> (slot-value-by-path address '(street)) => "17 Sunvalley St." (slot-value-by-path address '(nil street)) => "17 Sunvalley St." obj - a CLOS object path - a list of slot names

STABLE-SET-DIFFERENCE (LIST-1 LIST-2 &KEY (TEST #'EQL) (KEY #'IDENTITY))

Returns a list of element of 'list-1' that do not appear in 'list-2'.

STRING-REMOVE-LEFT (STR PREFIX &KEY IGNORE-CASE-P)

If string 'str' starts with 'prefix', remove 'prefix' from the start of 'str'.

STRING-REMOVE-RIGHT (STR SUFFIX &KEY IGNORE-CASE-P)

If string 'str' ends with 'suffix', remove 'suffix' from the end of 'str'.

STRING-WHITESPACE-P (STR)

Returns true if every character in a string is a whitespace character, nil otherwise.

SYMBOL-STATUS (SYMBOL)

Returns a status of 'symbol' in its package (internal, external, etc.)

Undocumented

NINSERT (LIST THING POS)

PARSE-LOCATION-HASH

STRING-INVERT-CASE (STR)

MACRO

Public

INSERT-AT (NEWELT LIST INDEX)

Destructively inserts 'newelt' into 'list' before 'index'.

Undocumented

DEFRENDER (WIDGET-TYPE &BODY BODY)

TIMING (NAME &BODY BODY)

GENERIC-FUNCTION

Public

ATTRIBUTIZE-NAME (NAME)

Convert objects to a format suitable for serialization (in particular for markup languages like HTML). Ex: (attributize-name 'hello-world) => "hello-world"

HUMANIZE-NAME (NAME)

Convert objects to a human-readable string suitable for presentation. Default implementations beautify strings and symbols. Ex: (humanize-name 'hello-world) => "Hello World" (humanize-name "HELLO-WORLD") => "Hello World"

OBJECT-CLASS-NAME (OBJ)

Returns an object's class name (i.e. "Employee"). This method is be used to present the name of an entity to the user. Override this method to change the name for particular objects.

VARIABLE

Public

Undocumented

*ENABLE-TIMINGS*

*TIMING-REPORT-FN*