我想匹配一个 struct test
,并从中构建一个 struct ,但我该怎么做呢?
我什至不能eval
用来做这个?
请参考代码,
#lang racket
(struct test (num) #:prefab)
(define s `((AK= #(struct:test 100))
(AV)
))
(define ns (make-base-namespace))
(define (set-state-space-vals!)
(namespace-set-variable-value! 'test test #f ns)
)
(match s
[`((AK= #(struct:test ,val) (AV))) ;; can't match
(displayln val)
]
[`((AK= ,val) (AV)) ;; can match, but how to build the struct?
(struct? (eval val ns))
(match-define (struct test (num)) (eval val ns)) ;this will fail
(displayln num)
] )