14 comments

[ 4.0 ms ] story [ 22.5 ms ] thread
Author here.

The book is about augmenting the Gambit Scheme compiler with the code which it is compiling, thus treating the compiler as an interpreter. Testing dominates the compile-time computation, as each procedure in the book is collocated with tests for that procedure. Should any test fail, the library fails to compile, like a type error in a statically-typed language.

Thanks for this interesting topic.

ps: is `[|y| (cons x y)]` standard notation in gambit ?

It is not. I made a preprocessor which expands "lambda literals" into lambdas.

[|y| (cons x y)] turns into (lambda (y) (cons x y))

this looks awesome, thanks for sharing it with the community for free. I've had it book marked from another site elsewhere for a couple weeks now, can't wait to get into it.
Looks very nice. I've recently written a bunch of Racket, which also encourages tests to be written alongside definitions, although they're not run as part of compilation. However, I've actually ended up with similar functionality, by packaging these scripts using Nix and having a dependency which runs the test suite and aborts on failure.

It's nice to see more investigations going on into the nuances of programming "stages", rather than the usual compile vs interpret dogma.

Another approach which seems similar in spirit is Zig's use of compile-time execution http://ziglang.org

Coming from things like Babel I was really amazed what the OCaml compiler could do at compile time.
With Gambit and libbug (my book), any computation can be done at compile time, including state and I/O :-)
Impossible O:
Not impossible, I do it in the book. I write both macro definitions and namespace declarations to file during compile time! :-)
Sounds like an interesting idea. Reminds me a little of doctests in Python. This can also be applied to languages and compilers that do not allow the tests to run at compile time by wrapping the tests in #If DEBUG ... #End If or whatever the construct is in the language to compile the tests in debug mode only. Or define a special symbol WITHTESTS.

Then at least your tests will be close by the code that they are testing and they won't affect the size of the delivered binary.

Thanks for the reference on doctests.

I encourage the collocation of tests with procedures in every language, but I personally doubt the efficacy of pound defines.

Assert macros are great, but how can a programmer guarantee that they are ever even invoked?

"mo' tests mo' problems" -Sean 'puff daddy" Combs.