Scheme: Convert Code to picture
I have a weird Scheme question. This is a part of something bigger that I'm helping a friend with.
I need to convert a Tree:Data
into an image that accurately represents the tree (I'm sorry I don't have a sample image to show just yet).
Please let me know if you have any ideas for this (and/or if you have questions) so I can update with more i开发者_如何转开发nformation.
Thank you
One of the most common ways to draw such diagrams is using graphviz. You just need to scan the tree and print out the connections in a very simple syntax.
If you really, really, really have to do it directly within Scheme, then let me direct you here:
http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Drawing-Graphics.html
Scheme does indeed have a built-in graphics library, although this may be peculiar only to MIT Scheme. At Berkeley, our intro class used SICP, and we did have graphics somehow, although whether or not these graphics were built-in or whether the instructors added them for us, I'm not too clear on.
This is the answer I was looking for. I guess I should have articulated my question a little better. Thank you very much for the help anyways, @EliBarzilay and @KevinHwang
(define (Tree:Data->Pict dt)
(if (DataTree? dt)
(frame
(vl-append 10
(Tree:Data->Pict (DataTree-data dt))
(apply ht-append 10
(map Tree:Data->Pict (DataTree-children dt)))))
(code #,dt)))
精彩评论