[rucksack-devel] indexing issue?
Cyrus Harmon
ch-rucksack at bobobeach.com
Wed Nov 29 23:54:25 UTC 2006
perhaps I'm doing something wrong here, but I can't seem to get
indexing for non symbols to work properly:
=====
(cl:defpackage :rucksack-object-test (:use :cl :rucksack))
(cl:in-package :rucksack-object-test)
(eval-when (:compile-toplevel :load-toplevel)
(defparameter *test-suite* #p"/tmp/rucksack-object-test/"))
(defparameter *names* '("David" "Jim" "Peter" "Thomas"
"Arthur" "Jans" "Klaus" "James" "Martin"))
(defparameter *moods* '("Happy" "Sad" "Mad" "Tired" "Bored"))
(defclass thingy ()
((frobosity :accessor frobosity :initarg :frobosity :initform 32)))
(eval-when (:compile-toplevel :load-toplevel)
(with-rucksack (rucksack *test-suite* :if-exists :supersede)
(with-transaction ()
(defclass person (thingy)
((id :initform (gensym "PERSON-")
:reader hacker-id
:index :symbol-index
:unique t)
(name :initform (elt *names* (random (length *names*)))
:initarg :name
:accessor name
:index :case-insensitive-string-index)
(age :initform (random 100)
:initarg :age
:accessor age
:index :number-index)
(mood :initform (elt *moods* (random (length *moods*)))
:accessor mood
:index :string-index))
(:metaclass persistent-class)
(:index t)))))
(defmethod print-object ((person person) stream)
(print-unreadable-object (person stream :type t)
(format stream "called ~S of age ~D who is ~A"
(name person)
(age person)
(mood person))))
(defun test-create (&key (nr-objects 10))
"Test creating a rucksack with many persons."
(with-rucksack (rucksack *test-suite*)
(with-transaction ()
(loop for i below nr-objects
do (let ((person (make-instance 'person :age i)))
(print (age person))
(add-rucksack-root person rucksack))))))
(defun test-get ()
(with-rucksack (rucksack *test-suite*)
(with-transaction ()
(map-rucksack-roots (lambda (root)
(print (cons root (frobosity root))))
rucksack))))
(defun test-number-index ()
(with-rucksack (rucksack *test-suite*)
(with-transaction ()
(rucksack-map-slot rucksack 'person 'age #'print :equal 1))))
(defun test-string-index ()
(with-rucksack (rucksack *test-suite*)
(with-transaction ()
(rucksack-map-slot rucksack 'person 'mood #'print :equal "Sad")))
(with-rucksack (rucksack *test-suite*)
(with-transaction ()
(dotimes (i 10) (let ((q (make-instance 'person)))
(add-rucksack-root q rucksack))))))
======
and then
(test-create)
(test-number-index)
gives the following:
Argument X is not a NUMBER:
#<PERSISTENT-CONS #97 in #<STANDARD-CACHE of size 10000, heap #P"/
tmp/rucksack-object-test/heap" and 24 objects in memory.>>
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Abort #<STANDARD-TRANSACTION #337383312100000 with 0
dirty objects>
1: [RETRY] Retry #<STANDARD-TRANSACTION #337383312100000 with 0
dirty objects>
2: [ABORT-REQUEST] Abort handling SLIME request.
3: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-
thread" {1190A6B1}>)
Backtrace:
0: (SB-KERNEL:TWO-ARG-* #<PERSISTENT-CONS #97 in #<STANDARD-CACHE
of size 10000, heap #P"/tmp/rucksack-object-test/heap" and 24 objects
in memory.>> 16)
1: (RUCKSACK::OBJECT-ID-TO-BLOCK #<PERSISTENT-CONS #97 in
#<STANDARD-CACHE of size 10000, heap #P"/tmp/rucksack-object-test/
heap" and 24 objects in memory.>> #<RUCKSACK::OBJECT-TABLE {128C6A29}>)
2: (RUCKSACK::OBJECT-HEAP-POSITION #<RUCKSACK::OBJECT-TABLE
{128C6A29}> #<PERSISTENT-CONS #97 in #<STANDARD-CACHE of size 10000,
heap #P"/tmp/rucksack-object-test/heap" and 24 objects in memory.>>)
3: (RUCKSACK::FIND-COMMITTED-OBJECT-VERSION #<PERSISTENT-CONS #97
in #<STANDARD-CACHE of size 10000, heap #P"/tmp/rucksack-object-test/
heap" and 24 objects in memory.>> 337383312100000 #<MARK-AND-SWEEP-
HEAP {128C8499}>)
4: ((SB-PCL::FAST-METHOD RUCKSACK::LOAD-OBJECT (T T STANDARD-
CACHE)) #<unavailable argument> #<unavailable argument> #<PERSISTENT-
CONS #97 in #<STANDARD-CACHE of size 10000, heap #P"/tmp/rucksack-
object-test/heap" and 24 objects in memory.>> #<STANDARD-TRANSACTION
#337383312100000 with 0 dirty objects> #<STANDARD-CACHE of size
10000, heap #P"/tmp/rucksack-object-test/heap" and 24 objects in
memory.>)
5: ((SB-PCL::FAST-METHOD CACHE-GET-OBJECT (T STANDARD-CACHE))
#<unavailable argument> #<unavailable argument> #<PERSISTENT-CONS #97
in #<STANDARD-CACHE of size 10000, heap #P"/tmp/rucksack-object-test/
heap" and 24 objects in memory.>> #<STANDARD-CACHE of size 10000,
heap #P"/tmp/rucksack-object-test/heap" and 24 objects in memory.>)
6: ((LAMBDA (SLOT-VALUE OBJECT-ID)) #<unavailable argument>
#<PERSISTENT-CONS #97 in #<STANDARD-CACHE of size 10000, heap #P"/tmp/
rucksack-object-test/heap" and 24 objects in memory.>>)
7: ((LABELS RUCKSACK::MAP-SLOT) #<PERSISTENT-CLASS PERSON>)
8: ((SB-PCL::FAST-METHOD RUCKSACK-MAP-SLOT (STANDARD-RUCKSACK
#1="#<...>" . #1#)) #<unavailable argument> #<unavailable argument>
#<RUCKSACK::SERIAL-TRANSACTION-RUCKSACK in #P"/tmp/rucksack-object-
test/" with 10 roots {128C3319}> PERSON AGE #<FUNCTION PRINT>)
9: (TEST-NUMBER-INDEX)
10: (SB-INT:SIMPLE-EVAL-IN-LEXENV (TEST-NUMBER-INDEX) #<NULL-LEXENV>)
--more--
any ideas what I might be doing wrong?
Thanks,
Cyrus
More information about the rucksack-devel
mailing list