greghendershott / rackjure

Provide a few Clojure-inspired ideas in Racket. Where Racket and Clojure conflict, prefer Racket.
BSD 2-Clause "Simplified" License
236 stars 17 forks source link

Use check-expand-* instead of check-equal? for threading tests #34

Closed qerub closed 10 years ago

qerub commented 10 years ago

I opted out of using one module+ block per macro because it got too crowded IMHO.

Let me know if you think I overdid it with test-threader. (I wanted to test arity 1 only once and figured it would be right to do it on something else than the real threading macros. OTOH, threading-syntax-parser is an implementation detail which begs the question of white vs. black box testing.)

sigh Testing is hard.

greghendershott commented 10 years ago

I think it's great. IMO sometimes tests can also have value as "documentation or comments by other means".[^1] Although threading-syntax-parser may be an implementation detail, it's an important detail -- it's the core form. Your tests are concrete usage examples that could help someone else understand it.

[1]: I've been mulling a define variant that lets you state x => y things that expand both into (a) check-equal?s in a test submodule and (b) Scribble "Examples" similar to scribble/srcdoc. Because the examples are good test cases, and because nothing is more embarrassing than examples don't work. So a sort of define/provide/contract/document/test form, but with a shorter name like oh say defn.

qerub commented 10 years ago

Thanks for the feedback.

About your define variant: Sounds like a great idea, but I have hard time imagining what such a definition form would look like. Do you have any concrete syntax in mind already?

greghendershott commented 10 years ago

An earlier cut at it is here: https://github.com/greghendershott/def-jambda

But more recently on a project I've been trying something where the args are traditional and the contract is a #:: keyword, e.g.

(defn (foo x y)
  #:: (integer? integer? -> integer?)
  ... usual function body ...

Without the other features like docs, this is very similar to define/contract except the #:: makes explicit the contract, and it applies the contract only on the provide/module boundary, which is generally faster than on the function itself. If it were typed Racket than it would be the type spec instead.

qerub commented 10 years ago

Oh! Yeah, that works out nicely. Thanks for sharing.

+1 on separating the parameter names and "types"/contracts.

(By the way: I always get a funny feeling when I see infix operators like your -> in S-expressions. My all-or-nothing brain wants to see all operators have the same position.)

greghendershott commented 10 years ago

Yeah I typed that too fast here and omitted the dots. Should be either

I wasn't proposing making -> be a syntax literal or anything like that.