Seokmin Hong
Seokmin Hong

Reputation: 622

Enforce strurct-constructor evaluation in Racket

By following code:

(struct int (num) #transparent)

(list (int 3) (int 5)) ;; case-1
'((int 3) (int 5))     ;; case-2

the case-1 prints (#(struct:int 3) #(struct:int 5)), but the case-2 prints ((int 3) (int 5)).

How can I deal with the second one as a struct:int list?

Upvotes: 0

Views: 30

Answers (1)

soegaard
soegaard

Reputation: 31147

The expression:

'((int 3) (int 5))

is more or less equivalent to:

(list (list 'int 3)  (list 'int 5))

So if you want to create a list with a structure as an element, either use list directly or ... you can use quasiquote:

`(,(int 3) ,(int 5))

Upvotes: 1

Related Questions