我有一个供人们使用的结构:
(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)
关于方案中结构体的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4009920/