我喜欢如何在透明结构中保留表示:
(struct posn (x y)
#:transparent)
> (posn 1 2)
(posn 1 2)
但是有没有办法自定义它?就像在Python中一样?
我喜欢如何在透明结构中保留表示:
(struct posn (x y)
#:transparent)
> (posn 1 2)
(posn 1 2)
但是有没有办法自定义它?就像在Python中一样?
在这里查看prop:custom-write
房产。这是一个简单的实现:
(struct pr (x y)
#:transparent
#:property prop:custom-write (λ (v p w?)
(fprintf p "<~a,~a>" (pr-x v) (pr-y v))))
> (pr 1 2)
<1,2>
请注意,这也适用于非#:transparent
结构。