Permalink
Browse files

first draft of access library (pulled out of adwutils)

  • Loading branch information...
bobbysmith007 committed Nov 9, 2011
1 parent 838cc59 commit 6e9726fb0b3c4d456e7790134663fc808be48902
Showing with 723 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +133 −0 README.md
  3. +31 −0 access.asd
  4. +390 −0 access.lisp
  5. +149 −0 test/access.lisp
View
20 LICENSE
@@ -0,0 +1,20 @@
+;; Copyright (c) 2011 Russ Tyndall , Acceleration.net http://www.acceleration.net
+
+;; Permission is hereby granted, free of charge, to any person obtaining
+;; a copy of this software and associated documentation files (the
+;; "Software"), to deal in the Software without restriction, including
+;; without limitation the rights to use, copy, modify, merge, publish,
+;; distribute, sublicense, and/or sell copies of the Software, and to
+;; permit persons to whom the Software is furnished to do so, subject to
+;; the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
133 README.md
@@ -0,0 +1,133 @@
+# Access
+
+A Common Lisp library to unify access to the most common data
+structures and to allow you to operate on them as they are (ie as a
+bunch of dictionaries with slightly different apis)
+
+## access, accesses , (setf access), (setf accesses)
+
+These functions allow unified access to these data structures:
+ * accessor access to CLOS objects
+ * slot access to CLOS objects if the key matches a slot name but not
+ an accessor
+ * plists
+ * alists
+ * hash-tables
+
+They also opts to produce nil as opposed to signaling errors when they
+fail to access (eg (access nil 'anything) produces nil rather than
+signaling a missing method on nil (though if 'anything is specialized
+on nil it will call that method))
+
+This library will probably appeal most to new comers to the language
+as everyone else will probably be happy just calling each type of
+access according to its own api.
+
+### A word on performance
+
+This libary is meant to make writing the program easier. It does many
+runtime lookups and checks to make sure that funcations called can
+support the types they are called with. As such it should not be used
+in code where performance is important. It should however allow you to
+prototype more rapidly and change the backing data stores without
+having to change their access (ie I can switch from a plist to an
+alist and everything will continue to work)
+
+## Utilities
+
+### has-slot?, has-reader?, has-writer?
+
+Given a function or symbol, see if the object has a slot named that or
+a reader/writer function associated with that name
+
+### class-slot-names, class-slot-readers, class-slot-writers
+
+Returns the names associated with the classes slots. Readers and
+writers returns the functions used to access and set these slots,
+however these currently only support readers/writers with the same
+name as the slot.
+
+### call-if-applicable, call-applicable-fns
+Given an object and a function / funcation-name, this will call the
+function passing in the object if it seems like that will work
+
+
+
+### class-of-object
+A helper to find you the class of a given thing
+
+```
+ (typecase o
+ (symbol (find-class o))
+ (standard-class o)
+ (standard-object (class-of o)))
+```
+
+### equalper
+
+A predicate to make comparing symbols in different packages easier, by
+comparing them case-insensitively based on symbol-name. In other
+respects it is equalp.
+
+### plist-val, rem-plist-val, :set-plist-val
+
+Functions to ease access to plist values (used by access when
+detecting a plist)
+
+
+## DOT syntax
+
+DOT syntax is invoked with #D reader macro on a form or by wrapping
+that form in a with-dot call
+
+Many new comers to the language long for their dot operator from other
+lanugages they know. This functionality is provided (when desired) by
+enable-dot-syntax and in a block by using the with-dot macro. I wrote
+these for fun and much prefer just using the access functions directly
+(ie. I never actually use these syntax transformers). That said, when
+the dot syntax is enabled symbols with a dot in them will be
+transformed to the appropriate accesses calls.
+
+
+ EX: foo.bar.bast => (accesses foo 'bar 'bast)
+ EX: (setf ht.key.subkey new-val) => (setf (accesses foo 'bar 'bast) new-val)
+
+## Authors
+
+ * [Acceleration.net](http://www.acceleration.net/) - [Donate](http://www.acceleration.net/programming/donate-to-acceleration-net/)
+ * [Russ Tyndall](http://russ.unwashedmeme.com/blog)
+ * [Nathan Bird](http://the.unwashedmeme.com/blog)
+ * [Ryan Davis](http://ryepup.unwashedmeme.com/blog)
+
+```
+;; Copyright (c) 2011 Russ Tyndall , Acceleration.net http://www.acceleration.net
+;; All rights reserved.
+;;
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are
+;; met:
+;;
+;; - Redistributions of source code must retain the above copyright
+;; notice, this list of conditions and the following disclaimer.
+;;
+;; - Redistributions in binary form must reproduce the above copyright
+;; notice, this list of conditions and the following disclaimer in the
+;; documentation and/or other materials provided with the distribution.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+```
+
+
+
+
+
View
@@ -0,0 +1,31 @@
+;; -*- lisp -*-
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (unless (find-package :access.system)
+ (defpackage :access.system (:use :common-lisp :asdf))))
+
+(in-package :access.system)
+
+(defsystem :access
+ :description "A library providing functions that unify data-structure access for Common Lisp:
+ access and (setf access)"
+ :licence "BSD"
+ :version "0.1"
+ :serial t
+ :components ((:file "access"))
+ :depends-on (:iterate :closer-mop :alexandria :anaphora :cl-interpol))
+
+(defsystem :access-test
+ :description "Tests for the access library"
+ :licence "BSD"
+ :version "0.1"
+ :serial t
+ :components ((:module :tests
+ :serial t
+ :components ((:file "access"))))
+ :depends-on (:access :lisp-unit))
+
+(defmethod asdf:perform ((o asdf:test-op) (c (eql (find-system :data-table))))
+ (asdf:oos 'asdf:load-op :access-test)
+ (let ((*package* (find-package :access-test)))
+ (eval (read-from-string "(run-tests)"))))
Oops, something went wrong.

0 comments on commit 6e9726f

Please sign in to comment.