[Openmcl-devel] Applying sequence functions to a new type
Denis Bueno
dbueno at stygian.net
Tue Mar 1 04:06:11 PST 2005
Define it like so, as a struct:
(defstruct (vec2 (:type vector))
a
b)
Then you can do:
> (make-vec2 :a 'a-val :b 'b-val)
#(A-VAL B-VAL)
> (vec2-a *)
A-VAL
> (vec2-b **)
B-VAL
On 01 Mar 2005, at 02.14, Andrew P. Lentvorski, Jr. wrote:
> This is probably a really stupid question, but how do I define the
> sequence functions so that they apply to a new class?
>
> For example, let's say I want a stupid class that always has two
> elements a and b. I would like to be able to access a and b as
> thought they were elements 0 and 1 of a sequence.
>
> Welcome to OpenMCL Version (Beta: Darwin) 0.14.2-040925!
> ? (defclass Vec2 ()
> ((a :accessor a
> :initarg :a)
> (b :accessor b
> :initarg :b)))
> #<STANDARD-CLASS VEC2>
> ? (setq v2 (make-instance 'Vec2 :a 7 :b 11))
> #<VEC2 #x644EAB6>
> ? (elt v2 0)
> > Error in process listener(1): value #<VEC2 #x644EAB6> is not of the
> expected type SEQUENCE.
> > While executing: CCL::SEQUENCE-TYPE
> > Type :POP to abort.
> Type :? for other options.
> 1 > ^D
> ? ;; Okay, let's try a different tack
> (defclass Vec2 (sequence)
> ((a :accessor a
> :initarg :a)
> (b :accessor b
> :initarg :b)))
> > Error in process listener(1): The class #<BUILT-IN-CLASS SEQUENCE>
> was specified as a
> > super-class of the class
> #<STANDARD-CLASS VEC2>;
> > but the meta-classes #<STANDARD-CLASS
> BUILT-IN-CLASS> and
> > #<STANDARD-CLASS STANDARD-CLASS> are
> incompatible.
> > While executing: #<CCL::STANDARD-KERNEL-METHOD SHARED-INITIALIZE
> :AFTER (CCL::SLOTS-CLASS T)>
> > Type :POP to abort.
> Type :? for other options.
> 1 >
> ? ;; Okay, that sure didn't work
>
> So how do I define a function elt or redefine Vec2 such that elt can
> be written to work with it?
>
> Thanks,
> -a
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>
--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index
"To be positive: To be mistaken at the top of one's voice." - Ambrose
Bierce
More information about the Openmcl-devel
mailing list