[Top][All Lists]

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

Re: Tidy way to test and set when using test egg?

From: John Cowan
Subject: Re: Tidy way to test and set when using test egg?
Date: Fri, 10 Jan 2020 10:21:53 -0500

Mixing definitions and expressions in a block isn't actually legal Scheme, though it does work in Chicken.  All defines are supposed to come first and all expressions afterwards.  Since the test library is shared with Chibi, and since Chibi doesn't allow this extension, I can't see adding this to the library.

On Fri, Jan 10, 2020 at 10:18 AM Matt Welland <address@hidden> wrote:
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)

So I can do:

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


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]