racket - What is the difference between a transparent and a prefab struct? -


as title implies, don't understand difference between using #:transparent , using #:prefab when defining struct. reference mentions prefab involves sort of global sharing.

what difference between them? in situation should use 1 on other?

to make structure type transparent, use #:transparent keyword after field-name sequence:

(struct posn (x y)         #:transparent)  > (posn 1 2) (posn 1 2) 

an instance of transparent structure type prints call constructor, shows structures field values. transparent structure type allows reflective operations, such struct? , struct-info, used on instances.

although transparent structure type prints in way shows content, printed form of structure cannot used in expression structure back, unlike printed form of number, string, symbol, or list.

a prefab (“previously fabricated”) structure type built-in type known racket printer , expression reader. infinitely many such types exist, , indexed name, field count, supertype, , other such details. printed form of prefab structure similar vector, starts #s instead of #, , first element in printed form prefab structure type’s name.

lastly, think may need using #:transparent of time on #:prefab ,based on experience use #:transparent.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -