chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tidy way to test and set when using test egg?


From: Matt Welland
Subject: Tidy way to test and set when using test egg?
Date: Fri, 10 Jan 2020 08:14:09 -0700

I find myself doing stuff like this very often when writing tests using the test egg:

;; A trivial example where  the function under test is "-"
(define data #f)
(test #f 1 (let ((res (- 2 1)))(set! data res) res))

I'd really prefer to do something like:

(test-and-define data #f 1 (- 2 1))

But the closest I could get was:

(define-syntax test-and-set
  (syntax-rules ()
    ((_ name arg1 arg2 body ...)
     (test arg1 arg2
  (let ((res (begin body ...)))
    (set! name res)
    res
    )))))

So I can do:

(define data #f)
(test-and-set data #f 1 (- 2 1))

Questions:

1. Is there a generally better way to test and gather the result for use in downstream tests?

2. Is there a way to write a macro that can create the toplevel binding?


--
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]