Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.CESARUM.UTILITY

This package exports some utility & syntactic sugar functions and macros. License: AGPL3 Copyright Pascal J. Bourguignon 2003 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

COMPUTE-CLOSURE (FUN SET)

FUN: set --> P(set) x |--> { y } RETURN: The closure of fun on the set. NOTE: Not a lisp closure! EXAMPLE: (compute-closure (lambda (x) (list (mod (* x 2) 5))) '(1)) --> (2 4 3 1) NOTE: This version avoids calling FUN twice with the same argument.

CONC-SYMBOL (&REST ARGS)

DO: Concatenate the arguments and INTERN the resulting string. NOTE: The last two arguments maybe :PACKAGE <a-package> in which case the symbol is interned into the given package instead of *PACKAGE*.

CONCAT (&REST ARGS)

Concatenate anything into a string.

COPY-HASH-TABLE (TABLE)

TABLE: (OR NULL HASH-TABLE) RETURN: If TABLE is NIL, then NIL, else a new HASH-TABLE with the same TEST, SIZE, REHASH-THRESHOLD REHASH-SIZE and KEY->VALUE associations than TABLE. (Neither the keys nor the values are copied).

DICHOTOMY (MATCHP MIN MAX)

MATCHP: A function taking an integer between START and END, and returning an order (signed integer). MIN: The minimum integer. MAX: The maximum integer. RETURN: (values found index order) POST: (<= min index max) +-------------------+----------+-------+----------+----------------+ | Case | found | index | order | Error | +-------------------+----------+-------+----------+----------------+ | x < a[i] | FALSE | min | less | 0 | | a[i] < x < a[i+1] | FALSE | i | greater | 0 | | x = a[i] | TRUE | i | equal | 0 | | a[max] < x | FALSE | max | greater | 0 | +-------------------+----------+-------+----------+----------------+

EIGHTH-ARG (G178 G179 G180 G181 G182 G183 G184 G185 &REST G177)

RETURN: The eighth argument.

EQUIV (A B)

Return A ⇔ B

FIFTH-ARG (G115 G116 G117 G118 G119 &REST G114)

RETURN: The fifth argument.

FIRST-ARG (G59 &REST G58)

RETURN: The first argument.

FOURTH-ARG (G98 G99 G100 G101 &REST G97)

RETURN: The fourth argument.

HASH-TABLE-ENTRIES (HASH)

Returns an a-list of the entries (key . val) in the hash-table.

HASH-TABLE-KEYS (HASH)

Returns a list of the keys in the hash-table.

HASH-TABLE-PATH (HTABLE &REST KEYS)

Given a hash-table that may contain other hash-table, walks down the path of KEYS, returning the ultimate value

HASH-TABLE-VALUES (TABLE)

Returns a list of the values in the hash-table.

HASHTABLE (&KEY (TEST #'EQL) (SIZE NIL SIZEP) (REHASH-SIZE NIL REHASH-SIZE-P) (REHASH-THRESHOLD NIL REHASH-THRESHOLD-P) ELEMENTS)

Creates a new hash-table, filled with the given ELEMENTS. ELEMENTS must be a list of lists of two items, the key and the value. Note: we use the name HASHTABLE to avoid name collision.

IMPLY (P Q)

Return P ⇒ Q

INCLUDE (PATH)

NOTE: Untasty, but sometimes useful. DO: Read from the file at PATH all the sexps and returns a list of them prefixed with 'progn. USAGE: #.(include "source.lisp")

MAKE-KEYWORD (SYM)

RETURN: A new keyword with SYM as name.

MAXIMIZE (PREDICATE LIST)

RETURN: The maximum value and the item in list for which predicate is the maximum.

NINTH-ARG (G203 G204 G205 G206 G207 G208 G209 G210 G211 &REST G202)

RETURN: The ninth argument.

NSUBSEQ (SEQUENCE START &OPTIONAL (END NIL))

RETURN: When the SEQUENCE is a vector, the SEQUENCE itself, or a dispaced array to the SEQUENCE. When the SEQUENCE is a list, it may destroy the list and reuse the cons cells to make the subsequence.

OP-TYPE-OF (SYMBOL &OPTIONAL ENV)

From: nikodemus@random-state.net Newsgroups: comp.lang.lisp Date: 29 Jul 2004 03:59:50 GMT Message-ID: <ce9snm$4bp8o$1@midnight.cs.hut.fi>

SAFE-APPLY (FUN &REST ARGS)

DO: Call APPLY or REDUCE depending on the length of ARGS. NOTE: No prefix argument are allowed for REDUCE! (safe-apply 'concatenate 'string list-of-sequence) doesn't work! Use instead: (safe-apply (lambda (a b) (concatenate 'string a b)) list-of-sequence)

SECOND-ARG (G70 G71 &REST G69)

RETURN: The second argument.

SET-EQUAL (A B)

Return A ⊂ B ∧ A ⊃ B

SEVENTH-ARG (G155 G156 G157 G158 G159 G160 G161 &REST G154)

RETURN: The seventh argument.

SIGN (N)

RETURN: -1 if N is negative, +1 if N is positive, 0 if N is 0.

SIXTH-ARG (G134 G135 G136 G137 G138 G139 &REST G133)

RETURN: The sixth argument.

TENTH-ARG (G230 G231 G232 G233 G234 G235 G236 G237 G238 G239 &REST G229)

RETURN: The tenth argument.

THIRD-ARG (G83 G84 G85 &REST G82)

RETURN: The third argument.

TOPOLOGICAL-SORT (NODES LESSP)

RETURN: A list of NODES sorted topologically according to the partial order function LESSP. If there are cycles (discounting reflexivity), then the list returned won't contain all the NODES.

UNDISPLACE-ARRAY (ARRAY)

RETURN: The fundamental array and the start and end positions into it of a displaced array. AUTHOR: Erik Naggum <erik@naggum.no>

VECTOR-INIT (VECTOR CONSTRUCTOR)

DO: Sets all the slots in vector to the successive results of the function CONSTRUCTOR called with integers from 0 up to the dimension of the VECTOR. RETURN: VECTOR

XOR (A B)

Return A ⊻ B

Private

+EPSILON (FLOAT)

Returns the float incremented by the smallest increment possible.

-EPSILON (FLOAT)

Returns the float incremented by the smallest increment possible.

Undocumented

COMPOSE-SEXP (FUNCTIONS VAR)

GET-NAME (OPTION)

GET-OPTION (KEY OPTIONS &OPTIONAL LIST)

INFIX-TO-TREE (SEQUENCE)

MAKE-NAME (OPTION PREFIX NAME SUFFIX)

MAP-TREE-POSTFIX (FUN TREE)

MACRO

Public

COMPOSE (&REST FUNCTIONS)

RETURN: The functional composition of the FUNCTIONS. EXAMPLE: (compose abs sin cos) = (lambda (x) (abs (sin (cos x))))

COMPOSE-AND-CALL (&REST FUNCTIONS-AND-ARG)

DO: Call the functional composition of the functions, on the argument. EXAMPLE: (compose-and-call abs sin cos 0.234) --> 0.8264353

DEFENUM (NAME-AND-OPTIONS &REST CONSTANTS)

Define an named enumeration type, a set of constants with integer values, and a lable function to produce the name of the constants from the numerical value.

DEFINE-IF-UNDEFINED (&REST DEFINITIONS)

Use this to conditionally define functions, variables, or macros that may or may not be pre-defined in this Lisp. This can be used to provide CLtL2 compatibility for older Lisps. WHO'S THE AUTHOR?

DEFINE-STRUCTURE-CLASS (NAME-AND-OPTIONS &REST DOC-AND-SLOTS)

DO: Define a class implementing the structure API. This macro presents the same API as DEFSTRUCT, but instead of defining a structure, it defines a class, and the same functions as would be defined by DEFSTRUCT. The DEFSTRUCT options: :TYPE and :INITIAL-OFFSET are not supported.

DEFINE-WITH-OBJECT (CLASS-NAME SLOTS)

DO: Define a macro: (WITH-{CLASS-NAME} object &body body) expanding to: (with-slots ({slots}) object @body)

DEFINE-WITH-STRUCTURE (NAME-AND-OPTIONS &REST SLOTS)

NAME-AND-OPTIONS: Either a structure name or a list (name . options). Valid options are: (:conc-name prefix). DO: Define a macro: (WITH-{NAME} object &body body) expanding to a symbol-macrolet embedding body where symbol macros are defined to access the slots.

FOR ((VAR FIRST LAST . REST) &BODY BODY)

For loop. DO: Repeat BODY with VAR bound to successive integer values from FIRST to LAST inclusive. If the optional STEP argument is abstent, then it is taken as 1 or -1 depending on the order of FIRST and LAST. VAR is incremented by STEP and it stops when VAR goes above or below LAST depending on the sign of STEP.

FUNCTIONAL-PIPE (&BODY FORMS)

Execute forms in sequence each in a lexical scope where *, ** and *** are bound to the results of the last three previous forms. Return the results of the last form.

HANDLING-ERRORS (&BODY BODY)

DO: Execute the BODY with a handler for CONDITION and SIMPLE-CONDITION reporting the conditions.

PJB-DEFCLASS (NAME SUPER &REST ARGS)

This macro encapsulate DEFCLASS and allow the declaration of the attributes in a shorter syntax. ARGS is a list of s-expr, whose car is either :ATT (to declare an attribute) or :DOC to give the documentation string of the class. (:OPT ...) is not implemented yet. (:ATT name type [ init-value [doc-string] | doc-string ]) defines an attribute named NAME, of type TYPE, with the given initial value and documentation strings. An accessor and an initarg keyword of same NAME are also defined.

SCASE (KEYFORM &REST CLAUSES)

DO: A CASE, but for string keys. That is, it uses STRING= as test instead of the ''being the same'' test.

SCONC (&REST ARGS)

Concatenate strings.

TRACING (&BODY BODY)

TRACE works only on non-CL functions. This macro will work somewhat on any form in body.

TRACING-LABELS (DEFS &BODY BODY)

This macro is a replacement for LABELS that traces the calls of the local functions.

TRACING-LET (CLAUSES &BODY BODY)

Like LET, but prints on the *trace-output* the value of the bindings.

TRACING-LET* (CLAUSES &BODY BODY)

Like LET*, but prints on the *trace-output* the value of the bindings.

UNTIL (CONDITION &BODY BODY)

Until loop.

WHILE (CONDITION &BODY BODY)

While loop.

WITH-GENSYMS (SYMS &BODY BODY)

DO: Replaces given symbols with gensyms. Useful for creating macros. NOTE: This version by Paul Graham in On Lisp.

WSIOSBP (&BODY BODY)

Like with-standard-io-syntax but with the current package. The *PACKAGE* is kept bound to the current package.

Private

DECF-MOD (&ENVIRONMENT ENV PLACE MODULO &OPTIONAL (DECREMENT 1))

DECF modulo MODULO

DECISION-TREE (EXPRESSION &REST CLAUSES)

CLAUSES: Each clause is of the forms: (less|:less . <body>) (<real> . <body>) DO: Evaluate the expression, which must be a real, and generate a binary decision tree to select the <body> of the clause whose limit is <= the expression and the next clause limit is > the expression.

INCF-MOD (&ENVIRONMENT ENV PLACE MODULO &OPTIONAL (INCREMENT 1))

INCF modulo MODULO

Undocumented

DEFINE-ARGUMENT-SELECTOR (NAME ARGUMENT-NUMBER)