Scheme中Structs的参数

时间:2010-10-24 19:11:02

标签: parameters struct scheme racket

我为人们提供了这个结构:

(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的姓氏,我该怎么做?

由于

1 个答案:

答案 0 :(得分:6)

(structname-fieldname struct)

所以对你的例子来说:

(person-last P-00000)