Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Common Lisp

Name: Anonymous 2011-05-26 16:37

has no structure-p or structure-slots

Name: Anonymous 2011-05-26 16:39

but you can implement them in 1 line of Common Perlisp

Name: Anonymous 2011-05-26 17:05

>>2
You are a truly awful person.

Name: Anonymous 2011-05-26 19:02

In Common Perlisp, if you use a list in a scalar context you get the number of cons cells divided by the implementation's closest approximation to pi.

Name: Anonymous 2011-05-27 7:04

>>1
Of course it does, but it's not perfect(won't work if you changed the type to list or vector):
(typep your-structure 'structure-object)
And you can use slot-value and to find the slots, you can just use the MOP:

CL-USER> (defstruct lol a b c)
LOL
CL-USER> (mop:class-slots (class-of (make-lol)))
(#<SB-PCL::STRUCTURE-EFFECTIVE-SLOT-DEFINITION A>
 #<SB-PCL::STRUCTURE-EFFECTIVE-SLOT-DEFINITION B>
 #<SB-PCL::STRUCTURE-EFFECTIVE-SLOT-DEFINITION C>)
CL-USER> (mapcar #'mop:slot-definition-name *)
(A B C)
CL-USER> (slot-value (make-lol :c 3) 'c)
3


Do you know why CL doesn't have a structure-p or structure-slots?
Because structures can be implemented without CLOS in some implementations and because you can specify their type to be a list of a vector. Structures are the precursor of objects. If it's a list or a vector, you won't be able to tell them apart.
However, structures do let you define a struct-name-p function for each structure you define, which would work regardless of the type you use (which checks the car or first item in the vector, if the type is that). However, since MOP isn't in all the CL implementations, you should just use CLOS instead of structures if you are not satisfied with the struct-name-p defined by defstruct.

Name: Anonymous 2011-05-28 16:24

>>5
Structures are the precursor of objects. If it's a list or a vector, you won't be able to tell them apart.
You still have structure's metaobject, that describes layout of slots in your vector.

Name: Anonymous 2011-05-28 16:25

>>6
And for macros one mostly needs just slot names.

Name: Anonymous 2011-05-28 18:10

The Jews are after me

Name: Anonymous 2011-05-28 18:12

The Jews are after me

Don't change these.
Name: Email:
Entire Thread Thread List