Page 1 of 1

printing Struct

PostPosted: Fri Jul 27, 2012 1:17 am
by mparsa
Hi,
How can I print the struct without #s ?
For example my result is #S(U) and I just want to print U. How can I do that !?

Re: printing Struct

PostPosted: Fri Jul 27, 2012 4:00 am
by wvxvw
http://psg.com/~dlamkins/sl/chapter06.html Looks like this should help you.

Re: printing Struct

PostPosted: Sat Jul 28, 2012 12:21 am
by Kompottkin
The MOP functions illustrated by the following REPL transcript might or might not be useful:

Code: Select all
CL-USER(1): (defstruct point x y)
POINT

CL-USER(2): (defvar *a* (make-point :x 10 :y 20))
*A*

CL-USER(3): *a*
#S(POINT :X 10 :Y 20)

CL-USER(4): (sb-mop:class-slots (class-of *a*))
(#<SB-PCL::STRUCTURE-EFFECTIVE-SLOT-DEFINITION X>
 #<SB-PCL::STRUCTURE-EFFECTIVE-SLOT-DEFINITION Y>)

CL-USER(5): (mapcar #'sb-mop:slot-definition-name (sb-mop:class-slots (class-of *a*)))
(X Y)

Re: printing Struct

PostPosted: Mon Aug 13, 2012 1:49 am
by mparsa
Hi again,
I have another problem about struct now,
For example if I have a variable contains this : #S(ini__trs_0__call_0_0 :k 0
:b #(#(1 2 3) 3)
:cs #S(ini___1 :a #(#(1 2 3) 3))
:st #<Function (internal step_0 0)>
:fi #<Function (internal final 0)>)
and I want to retrive each eelment of the struct, for example I want to get the value of the b which is #(#(1 2 3) 3) in this struct. Is there any way to do that ! I checked those links that was sent here but I didn't find anything related to what I need !

Re: printing Struct

PostPosted: Mon Aug 13, 2012 6:07 am
by Kompottkin
mparsa wrote:I want to get the value of the b


Code: Select all
CL-USER(3): (defstruct point2d x y)
POINT2D
CL-USER(4): (make-point2d :x 1 :y 2)
#S(POINT2D :X 1 :Y 2)
CL-USER(5): (slot-value * 'x)
1
CL-USER(6): (slot-value ** 'y)
2

Re: printing Struct

PostPosted: Mon Aug 13, 2012 6:10 am
by Kompottkin
Also:

Code: Select all
CL-USER(1): (defvar *x* (make-point2d :x 10 :y 20))
*X*
CL-USER(2): (mapcan #'(lambda (slot-name) (list slot-name (slot-value *x* slot-name))) (mapcar #'sb-mop:slot-definition-name (sb-mop:class-slots (class-of *x*))))
(X 10 Y 20)