So here is your test:
(maxi
(Nd
1
(Nd 2
(Nd 4
(Nd 8 'E 'E)
(Nd 9 'E 'E))
(Nd 5 'E 'E))
(Nd 3
(Nd 6 'E 'E)
(Nd 7 'E 'E)))
0)
And here is what happens:
acc root what to do?
---------------------------------
0 1 go left with acc = root
1 2 idem
2 4 idem
4 8 idem
8 E return 8
If you expect your input trees to satisfy the binary search tree property, stating that values on the left subtree are always greater than root and values of the right subtree are all smaller or equal, then your test tree is a malformed BST, since 9 is greater than 4.
By the way, if you had a BST, where would the maximal value be located?
If however the tree is just a random tree, then you have to compute the maximum of both subtrees and the root value before being able to determine the overall maximal value.
Basically, you want to do:
(tree-max (Nd root left right)) = (max root
(tree-max left)
(tree-max right))
If you want to do it recursively, you will encounter a problem in the base case because you will have to provide a maximal value for an empty leaf node: any value you will pick will make your code incorrect for a tree which contains values strictly below that value. Say you choose zero and compute the max of a tree with only strictly negative numbers, then zero is the wrong answer because it does not appear in the tree (what could you do?).
You can choose to use an accumulator instead of recursion, but in that case you will need two accumuators: the maximum so far and the list of subtrees to visit next. Basically you replace the call stack with a heap-allocated stack.
I can't currently test the following code, but here is a possible implementation:
(define tree-max (tree greatest todo)
(match tree
('E greatest (if (null? todo)
greatest
(tree-max (first rest)
greatest
(rest todo))
((Nd root left right) (tree-max left
(max greatest root)
(cons right todo))))