If it wasn't abundantly clear yet, I'm a Racket noob, so when I had this
kind of thing in my code:

(define x 'a)
(case x
  (('a) return-something)
  (('b) return-something-else)
  (('c) return-yet-another-thing))

  I was baffled to find out that the case form always returned void (thanks
Alex).
I made this mistake a few times in the past: quoting symbols in case forms.
I'm human, humans make errors, and I make a LOT of errors.
  I wrote the case form out of habit. I quoted symbols out of habit. I
didn't test the proc in the REPL, because well, I was quite sure how case
worked. The same habit pushed me to write a test. But I thought... bah this
is just too simple, why bother? Yet I should have, because it would have
instantly showed me that my expectations were off.

(module+ test
  (require rackunit))
...
(define (bad-case x)
  (case x
    (('a) return-something)
    (('b) return-something-else)
    (('c) return-yet-another-thing)))
; unit test
(module+ test
  (check-equal? (bad-case 'b) 'b))
; test fails, bad-case returns void.

Obviously the correct syntax is:

(case x
    ((a) return-something)
    ((b) return-something-else)
    ((c) return-yet-another-thing))

  That very basic mistake made me spend quite a few hours tracking where
that void was coming from. And when that void pipes through a few functions
before landing in a find-files predicate, and that the error doesn't quite
mentions which parameter it came from...

  I read somewhere, that we should use plenty of asserts in our code. I
usually have unit tests for most of my functions, except on the ones I find
trivial. Silly mistake.
  So uh.. if you're a noob like me, write lots of tests. Test your
functions in the REPL. We say 'there's no such thing as a stupid question'.
I say, there's no such thing as a stupid test. Best of all, tests are free
with Racket!

Dex

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CACUENr%2BmNO9WhDUB1EBs-0F-UnU9KWmMBWr-0j%2BAK-1T5sDV9Q%40mail.gmail.com.

Reply via email to