Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add prop:constructor-style-printer #1337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AlexKnauth
Copy link
Member

@AlexKnauth AlexKnauth commented Jun 10, 2016

This struct-type property allows structs to specify how they should by printed by constructor-style printing. I'm also submitting a pull request to pconvert-lib (racket/pconvert#6) to recognize this property and use it when converting structs into s-expressions.

It also cooperates with the pretty printer just like make-constructor-style-printer does, since it uses make-constructor-style-printer to do the printing.

> (require racket/struct)
> (struct point (x y) ; this struct is opaque and wouldn't print like this otherwise
    #:property prop:constructor-style-printer
    (list
     (lambda (p) 'point)
     (lambda (p) (list (point-x p) (point-y p)))))
> (print (point 1 2))
(point 1 2)
> (parameterize ([pretty-print-columns 10])
    (pretty-print (point 3000000 4000000)))
(point
 3000000
 4000000)
> (require mzlib/pconvert)
> (print-convert (point 1 2)) ; with my other pull request to pconvert-lib
(list 'point 1 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant