[英]How to match a struct
我想匹配一个struct test
,并从中构建一个结构,但我该怎么做呢?
我甚至不能用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)
] )
此外,虽然它不在匹配的文档中,`((AK = #s(test,val))(AV))是一个有效的模式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.