Question

In a class I am taking we are using the old R5RS standard of Scheme to solve SICP assignments. I like to do test first development, so I figured a unit testing framework would be nice, and I chose SchemeUnit for writing the small tests.

This has worked fine so far, just testing primitives in the output (strings, numbers, ...), but I hit a road block when trying to test lists. It has probably something to do with differences in the Scheme dialect used to run the tests:

foo.scm: (define a-list (list 2))

foo-tests.scm: (check-equal? a-list (list 2))

Result when running the tests:

Unnamed test 
FAILURE
name:       check-equal?
location:   tester.scm:22:3
actual:     {2}

expected:   (2)

To make the test suite run, I have to add "#lang scheme/base to the top of foo-tests.scm and require the schemeunit package. In foo.scm I need to have #lang r5rs and (#%provide (all-defined)) at the top.

I guess lists are somehow differently implemented in R5RS and "scheme/base". Any way to get them to work together? And why does it fail ({} vs ())?

Was it helpful?

Solution

Yes, as you've noticed, lists are implemented differently in #lang r5rs vs #lang scheme/base. If it's possible to write the tests in your foo-tests.scm in r5rs, that would help to eliminate the possible confusion.

You should be able to do this by having this at the top of your foo-tests.scm file.

#lang r5rs

(#%require schemeunit)
(#%require "foo.scm")

;; Now you can add your tests here:
(check-equal? a-list (list 1 2 3))

If the test suite is written in the same language, then the constructs --- and in particular, the representation for lists --- should match up. The test above should hopefully pass.

To elaborate on the difference between the r5rs lists and the one in #lang scheme (and #lang racket): Racket uses immutable cons pairs to represent lists. Immutable cons pairs do not support the set-car! and set-cdr! functions of r5rs, so it wouldn't be faithful to the standard for the #lang r5rs language to use the built-in immutable pairs. To support the r5rs standard, Racket includes a separate mutable pairs data type, and uses it consistently within r5rs. But it means that the standard pairs in Racket and the mutable pairs do not compare equally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top