2.我不能使用ac-map来代替hash-table,因为,这个class的对象很多,而文档(acache.pdf)说:Therefore
use maps sparingly (create no more than a few hundred of them).
3.acache支持的类型中不包括hash-table,但是包括non-persistent的object.就是通过encode-object和decode-object来支持存储hash.我还在学习common
lisp,所以对概念不是很清楚。我无法直接(defmethod encode-object ((object
hash-table)))来支持存储hash-table,只能先定义另外一个non-persistent的class,然后写关于这个class的encode-object来间接支持。比如:
(defpackage :foo
(:use :cl :db.ac :alexandria))
(in-package :foo)
(defclass hash ()
((h :initarg :h :accessor h)))
(defclass bar ()
((i :initarg :i :accessor i))
(:metaclass persistent-class))
(defmethod encode-object ((object hash))
(hash-table-plist (h object)))
(defmethod decode-object ((object hash) vals)
(make-instance (class-of object) :h (plist-hash-table vals :test #'equalp)))
大家有什么想法嘛?我感觉我这样做,实在不够酷.谢谢。
--
Lisp-cn(Lisp中文用户组)
CLUG http://lisp.org.cn
嗯,对,我尝试直接写hash-table的,但是失败了。或许我哪里写错了,今天有机会的话,我再把hash-table的代码贴下。
要不你试试看?
(defpackage :foo
(:use :cl :db.ac :alexandria))
(in-package :foo)
(defclass bar ()
((i :initarg :i :accessor i))
(:metaclass persistent-class))
(defmethod encode-object ((object hash-table))
(hash-table-plist object))
(defmethod decode-object ((object hash-table) vals)
(plist-hash-table vals :test #'equalp))
况且你的 decode-object 定义得也不对,objects 的 type 应该是 list
如果 object 的 type 是 list,那问题是是否所有的 plist 都要转化为 hash-table?
你想办法定义一个 generic 的 map 吧,或者用现成的。
2012/2/22 Jeova Sanctus Unus <jeova.san...@gmail.com>:
--
黄 澗石 (Jianshi Huang)
http://huangjs.net/
(defclass bar ()
((i :initarg :i :accessor i))
(:metaclass persistent-class))
(defmethod encode-object ((object hash))
(format t "encode:~a~%" object)
(hash-table-plist (h object)))
(defmethod decode-object ((object hash) vals)
(format t "decode:~a ~a~%" object vals)
(make-instance (class-of object) :h (plist-hash-table vals :test #'equalp)))
(defmethod encode-object ((object hash))
(cons 'h (hash-table-plist (h object))))
(defmethod decode-object ((object hash) slot-vals)
(let ((plist (cdr (assoc 'h slot-vals))))
(make-instance 'hash :h (plist-hash-table plist :test #'equalp))))
2012/2/22 Jeova Sanctus Unus <jeova.san...@gmail.com>:
>
> (defmethod encode-object ((object hash))
> (format t "encode:~a~%" object)
> (hash-table-plist (h object)))
>
> (defmethod decode-object ((object hash) vals)
> (format t "decode:~a ~a~%" object vals)
> (make-instance (class-of object) :h (plist-hash-table vals :test #'equalp)))
--