2010-10-24 42 views
2

我有這樣的結構適合人羣:參數對於結構方案

(define-struct person 
    ( 
    first ; a string: first name 
    last  ; a string: last name 
    sex  ; a symbol: 'male, 'female 
    eyes  ; a symbol: 'blue, 'brown', 'green 
    hair  ; a symbol: 'blonde, 'brown, 'black, 'red 
    mother ; a person: empty if not known 
    father ; a person: empty if not known 
    born  ; a number: year of birth 
    ) 
) 

,然後我讓人們:

(define P-00000 (make-person "Alexandra" "Harper" 'female 'blue 'red empty empty 1897)) 
(define P-10000 (make-person "Joshua" "Sherman" 'male 'green 'blonde empty empty 1881)) 
; ... etc 

如何我現在可以訪問特定段的結構。舉個例子,我想顯示P-00000的姓氏,我該怎麼做?

感謝

+0

標準方案沒有結構,所以我把增加球拍標籤的自由。如果你正在使用別的東西,請糾正它。 – sepp2k 2010-10-24 19:21:07

回答

6
(structname-fieldname struct) 

因此,對於你的例子:

(person-last P-00000) 
+0

有關更多詳細信息,請參閱HtDP的第6.3節:http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-9.html#node_sec_6.3 – 2010-10-25 04:53:57