[racket] on contract violation after adding 1471 strings to a BST
Warning: you switched from a teaching language to full Racket.
The former would have caught this mistake, which is why we
designed them for HtDP. Racket is for grown-up parenthesis
eaters -- who want the behavior of cond that you just experienced,
or so I am told. -- Matthias
On Aug 5, 2014, at 4:25 PM, Daniel Bastos <dbastos at toledo.com> wrote:
> 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.
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users