printing Struct

Discussion of Common Lisp

printing Struct

Postby mparsa » Fri Jul 27, 2012 1:17 am

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 !?
mparsa
 
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

Re: printing Struct

Postby wvxvw » Fri Jul 27, 2012 4:00 am

http://psg.com/~dlamkins/sl/chapter06.html Looks like this should help you.
wvxvw
 
Posts: 127
Joined: Sat Mar 26, 2011 6:23 am

Re: printing Struct

Postby Kompottkin » Sat Jul 28, 2012 12:21 am

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)
User avatar
Kompottkin
 
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany

Re: printing Struct

Postby mparsa » Mon Aug 13, 2012 1:49 am

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 !
mparsa
 
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

Re: printing Struct

Postby Kompottkin » Mon Aug 13, 2012 6:07 am

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
Last edited by Kompottkin on Mon Aug 13, 2012 6:11 am, edited 1 time in total.
User avatar
Kompottkin
 
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany

Re: printing Struct

Postby Kompottkin » Mon Aug 13, 2012 6:10 am

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)
User avatar
Kompottkin
 
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany


Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron