chicken-users
[Top][All Lists]
Advanced

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

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


From: Kristian Lein-Mathisen
Subject: Re: Tidy way to test and set when using test egg?
Date: Fri, 10 Jan 2020 16:41:45 +0100


Hi Matt,

So you want to keep the result for more upcoming test? Why? Just curious.

I've for the most part been content with:

(test-group
 "-"
  (define res (- 2 1))
  (test 1 res)
 (print "res: " res) )
;; res out of scope here (good thing, no?)

K.



On Fri, Jan 10, 2020, 16:22 John Cowan <address@hidden> wrote:
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)
    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]