I want to match a struct test, and build a struct from that, but how can I do that?
I can’t even use eval to do this?
Please reference to the code,
#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)
] )
I think you were looking for something like this:
Also, in general using
evalin a situation like this is highly inadvisable. When in doubt, do not useeval. See this blog post for a longer explanation. You might also want to see the Guide entries on prefabs and pattern matching.