Author Message

I found your E-mail on the newsgroup Scheme. I'm a french
student in computer science (including the Scheme language) and
I'm wondering if you could help me on this problem:

It's about the binary trees of algebric expressions.

Suppose we have this Data Abstract Type:

  (define (make-tree R Lt Rt)
    (list R Lt Rt))

  (define (leaf? t)    
    (or (number? t) (symbol? t)))

  (define (root T)
    (if (leaf? T)
        (car T)))

  (define (left-son T)
   (if (leaf? T)
        (error T "no left son")
        (cadr T)))

  (define (right-son T)
   (if (leaf? T)
        (error T "no right son")
        (caddr T)))

  (define (leaf T)
    (if (leaf? T)
        (list T)
        (append (leaf (left-son T))
                (leaf (right-son T)))))

Well now say we have this programm (I hope it is correct):

(define (tree->postfix tree)
  (if (leaf? tree)
       (list tree)
       (append (tree->postfix (left-son tree))
               (tree->postfix (right-son tree))
               (list (root tree))))))

This function takes a binary tree of algebric expressions like that:
   *          Y
 X   2

it could be define like that
->(define tree
   (make-tree '+ (make-tree '* 'X 2) 'Y))
(+ (* X 2) Y)

The result of the function tree->postfix if we take the example would be:
-> (tree->postfix tree)
(2 X * Y +)

In fact this function returns the flat list containing all objects encountered
during the postfix journey of TREE.
At last my question: I wish I would have the reciprocal function such that
(postfix->tree tree) => (compose postfix->tree tree->postfix)=id
In fact this function "set back" the brackets in a plane list.
In our example we should have:

(postfix->tree '(2 X * Y +)) -> (+ (* X 2) Y)

Thank you so much for an answer!

P.S: I'm looking for information about the statement of a program whose
could draw geometric figures whith only a ruler and a pair of compasses.
The interface uses windows and I think we have to define a new syntax
to enable the user to do that for example:

Windows open a small window

->(draw (straight-line A B))

randomly a line is drawn between A and B.
Any information would be wonderful :)

Thank you

Tue, 15 Sep 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. None not None in Excel COM?

2. PythonCOM: com_error: (-2147418113, 'Catastrophic failure', None, None)

3. Proposal: min(None, x) and max(None, x) return x

4. Shouldn't __init__ return self instead of None? (Was: Re: [Tutor] Why error if method __init__ does not return none)

5. (none)

6. (none)

7. (none)

8. (none)

9. <none>

10. None (mail relay)

11. None

12. (none)


Powered by phpBB® Forum Software