我有这个结构供人们使用:
(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的姓氏怎么办?
谢谢
最佳答案
(structname-fieldname struct)
因此,对于您的示例:
(person-last P-00000)
关于parameters - 方案中结构的参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4009920/