AccelerationNet / access

A common lisp library to unify access to common dictionary-like data-structures
Other
84 stars 12 forks source link

"The value NIL is not of type HASH-TABLE." #1

Closed phmarek closed 10 years ago

phmarek commented 10 years ago

I guess I'm doing something wrong... but trying this I get the error message above.

(ql:quickload :access)
(defparameter *test* (make-hash-table))
(setf (access:accesses *test* 
                       '(:da :type :hash-table :test #'equalp)
                       '(5 :type :array)
                       '(:key :type :hash-table)
                       '("aa" :type :alist)) 
      T)
bobbysmith007 commented 10 years ago

Thanks for the bug report.

The error is caused because access is not creating the array or hashtable for you. Creating the correct list mappings is easy (and accomplished), creating a hashtable is a touch harder (but I will added it). Creating an array however is one of those things I'm not sure how to get right? I guess create an expandable array of whatever size the key specified, and calling adjust array if its not big enough?

I will patch this shortly

bobbysmith007 commented 10 years ago

Also:

phmarek commented 10 years ago

Hello Russ,

thanks for the quick answer.

If you're planning to support arrays, what should the "short" form (#D) be for them? Simply #D1.2?

Thank you very much for your help! (BTW: I've suggested that CL21 should use ACCESS by default, too ;)

bobbysmith007 commented 10 years ago

The keys for arrays would match the make-array aref syntax of being either an index or a list of indexes. Your usage above looks like what I would expect.

bobbysmith007 commented 10 years ago

I screwed up my commit reference but, I have pushed a patch resolving your issues and your example should work now. I also added a test case similar to your example to prevent regressions and document how access currently works

(let (test)
               (setf (access:accesses test
                       '("aa" :type :alist)
                       '(5 :type :array)
                       '(:da :type :hash-table :test #'equalp)
                       '(:key :type :hash-table)
                       ) 
      T) 
   test)

=>(("aa"  . #(NIL NIL NIL NIL NIL #<HASH-TABLE :COUNT 1>)))

Thanks for the support re CL21 and access. I tried to take some steps in this patch to make access a bit more extensible so that perhaps it could make sense there. The real problem with access is that it is a bit too much "magic" in it that leaves rough edge cases. While it works great in normal conditions I have a feeling that the quirks might out weigh the benefits for a language level feature. Perhaps it could provide a useful jumping off point, or be changed in such a way as to be more stable for broad use.

The biggest issue I am talking about is the part of access that finds and dispatches accessor functions. Its easy to contrive situations where access will balk because fn / slot / key names overlap. While I use access regularly, and really appreciate what it provides, its still necessary to sometimes fall back to more direct access to avoid these naming issues.

Either way thanks for the input and bug report.

bobbysmith007 commented 10 years ago

Just a note there was a bug in this, that I just fixed. It was creating hash-tables by default instead of plists. This has been restored to the previous behaviour