[racket] on contract violation after adding 1471 strings to a BST
On Tue, Aug 5, 2014 at 5:06 PM, Jens Axel Søgaard <jensaxel at soegaard.net>
wrote:
> What happens in create-bst-word, when the word to inserted is the same
> as (node-word bst) ?
Aha! I see. It returns void because there is no case for when the string is
equal.
> (void? (create-bst-word (create-bst-word false "dan") "dan"))
#t
I patched it with an else-case now.
(define (create-bst-word bst str)
(cond
((false? bst)
(make-node str false false))
((string<? str (node-word bst)) ;; insert at the left
(make-node (node-word bst)
(create-bst-word (node-left bst) str)
(node-right bst)))
((string>? str (node-word bst)) ;; insert at the right
(make-node (node-word bst)
(node-left bst)
(create-bst-word (node-right bst) str)))
(else (make-node (node-word bst)
(node-left bst)
(node-right bst)))))
> (void? (create-bst-word (create-bst-word false "dan") "dan"))
#f
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140805/e83999ac/attachment.html>