views:

75

answers:

3

Hello Everyone,

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 information.

Thank you

+3  A: 

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.

Eli Barzilay
I need to make this program so that it works right out of the box without any dependencies. I've worked with graphviz before and knew that this would be the way to go. Unfortunately, I can't. Any ideas how I can do this straight within scheme?
inspectorG4dget
I'd try *really* hard to somehow lump it with your application... Maybe as a library, or even drop some cgi script somewhere to be used as a service for your application. I tried to do something similar, but it's all very hairy and a whole huge project in itself, and you'd still be doing much less than what they do. You might get away if you only have very simple structures -- like trees for some mostly known shape, but even that can be challenging.
Eli Barzilay
I did try hard to lump it in. I made every argument that I could, but I got this reply: "You're right, but do what I say, anyways". All I have to deal with are "simple" trees and rectangles. I'm not going for anything uber complex here. This is a pain, I know, but if you have /anything/, please let me know
inspectorG4dget
+1. You came up with the suggestion that I would have otherwise gone with, but unfortunately, KevinHwang's is the one that am allowed to go with
inspectorG4dget
I'm not here for the competition, so feel free to with anything. The answer that you're talking about is a link to a graphics drawing library -- and having that is the *least* of your problems.
Eli Barzilay
+1  A: 

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.

Kevin Hwang
A: 

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)))
inspectorG4dget