Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLOS: How to make a slot have an enforced type of vector of symbols?

I'm trying to create a class that can store a vector of symbols in a slot in SBCL. I cannot figure out how to set it up.

My best guess thus far has been

(defclass Individual ()
  ((discrete-decisions :type (vector symbol))))

This returns the following error:

keyword argument not a symbol:
(DISCRETE-DECISIONS :TYPE (VECTOR SYMBOL)).
   [Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]

Some experimenting has shown that changing the type to just symbol returns the same error. I thought that symbol was a valid type in Common Lisp... am I mistaken?

How can I get this to work?

[EDIT]

The above problem I had was running SBCL 1.0.58 in the 09-22-2012 Slime build under Emacs 24.2. When I run SBCL 1.0.58 from the command line, there is no problem. This doesn't seem like an SBCL issue...

like image 313
sadakatsu Avatar asked Sep 23 '12 21:09

sadakatsu


2 Answers

You might consider defining an :after method on slot accessor/writer. Also, the ultimate degree of control can be exercised by defining your own metaclass and customization of slot-value-using-class

like image 162
Dan Lentz Avatar answered Nov 09 '22 16:11

Dan Lentz


I know I'm probably too late, but you should wrap around your classe declaration with a optimization for safety. For example:

(locally (declare (optimize safety))
    (defclass test-class ()
      ((some-slot :type real :initarg :some-slot :accessor :test-some-slot))))
like image 22
YuriAlbuquerque Avatar answered Nov 09 '22 16:11

YuriAlbuquerque