Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9c7adb53a0
Fetching contributors…

Cannot retrieve contributors at this time

71 lines (46 sloc) 2.539 kb
CL-ALREF Utility by Adlai
Many thanks to stassats on #lisp, Pascal J. Bourguignon, and also a
bit of inspiration from Arc's ALREF. Updated on Fri, Jul 10th, 2009.
Documentation:
Just (:use-package :alref).
Please use the latest version, available through git. The public
clone link is <git://github.com/adlai/ALREF.git>.
#'ALREF returns the CDR of what you would get if you called #'ASSOC
on the same arguments. If a :default argument is supplied, this
will be returned instead of NIL if no matching key is found.
(setf (alref item alist) foo) will:
- Add a key-value pair to the alist, if there is none for ITEM yet.
- Change the value under the key ITEM, if it already exists.
- Delete the key-value pair of ITEM, if FOO is NIL.
It is possible to change the default values for :test, :key,
:default with three variables exported from the :ALREF package.
The variables, and their initial default values, are:
- ALREF:*default-alref-test* defaults to #'eql
- ALREF:*default-alref-key* defaults to #'identity
- ALREF:*default-alref-default* defaults to NIL
Changelog:
This is version 2.5.
Version 1.0 used (defun (setf alref) ...), which led to a bug when
ALIST was NIL.
Version 2.0 uses a setf expansion to modify the setf macro itself,
thus generating code which can access and modify local variables
(ie, ALIST when it is bound by a LAMBDA). It also used the
with-gensyms macro in a way which was not portable, specifically
with regards to the CLISP implementation.
Version 2.1 sat in its own package, and exported 'ALREF.
Version 2.2 allowed the user to customize the default key and test
arguments. It also added some error-checking code to warn of
potentially buggy behavior.
Version 2.3 improved the customization options. It also renamed the
default variables, and introduced a bug.
Version 2.3.1 fixed that bug.
Version 2.3.2 had half of a bugfix for a more serious problem that
came from blurring the line between macro-expansion time and
evaluation time.
Version 2.4 completed that bugfix.
Version 2.5 fixes a bug which would occur when the place 'alist
had to be setf-expanded itself. ALREF now plays nicely here too.
Feel free to copy this code and use it in your projects, but please
give credit where it's due. Also, please leave this README in place.
If you have improvements to the code or find any bugs, please let me
know; I'm "Adlai" on irc.freenode.net.
Jump to Line
Something went wrong with that request. Please try again.