gelisam / klister

an implementation of stuck macros
BSD 3-Clause "New" or "Revised" License
132 stars 11 forks source link

explain lambda-case and mega-const #139

Closed gelisam closed 2 years ago

gelisam commented 3 years ago

I added two comments, each explaining what a macros does using a commented-out example of what code the macro expands to.

Doing so made me realize that the (example <expr>) form has two flaws. First, since the output is in the golden file, it is cumbersome for the reader to jump between the example and its output. I think I would prefer (example <expr> <expected-output>), similarly to check-equal?.

Second, if (<macro> <args>) outputs (f 1 2 3), then (example (<macro> <args>)) outputs the result of the call (f 1 2 3), not the code '(f 1 2 3). When giving an example of what a macro does, like I did in those two comments, showing the code is often more helpful. I think we should thus have a variant of example which does that.

david-christiansen commented 2 years ago

As far as example goes, I agree that it's not great for a test suite, but I like it's current behavior for interactive programming (e.g. instead of a REPL).

Can we write check-equal? as a macro? Something like:

(check-equal NAME PRED ACTUAL EXPECTED)
====>
(example (if (PRED ACTUAL EXPECTED) (success 'NAME) (failure 'NAME ACTUAL EXPECTED)))

with a suitable sum type for the success and failure constructors? I think this would yield readable output with a minimum of work, and it could later be made into something with an effect on failure.