Can I get the R5RS code to work with SchemeUnit?

In the class I am taking, we are using the old R5RS Schema standard to resolve SICP assignments. I love testing the first development, so I thought a unit testing system would be nice and I chose SchemeUnit for writing small tests.

This has worked fine so far, just testing the primitives in the output (strings, numbers, ...), but when trying to check lists I ended up in a roadblock. This is likely due to differences in the Scheme dialect used to run tests:

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

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

Result when running tests:

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

expected:   (2)

      

To run the test suite, I must add "#lang scheme/base

foo-tests.scm and require

the schema package to the top . In foo.scm I need to have #lang r5rs

, and (#%provide (all-defined))

at the top.

I think lists are somehow implemented differently in R5RS and schema / base. Any way to make them work together? And why does this fail ({} vs ())?

+3


source to share


1 answer


Yes, as you see, lists are implemented differently in #lang r5rs

vs #lang scheme/base

. If it is possible to write tests in foo-tests.scm

r5rs, this will help eliminate possible confusion.

You should be able to do this by listing it 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 case is written in the same language, then the constructs - and, in particular, the representation for lists - must match. The above test will hopefully pass.

Figure out the difference between lists r5rs

and what's in #lang scheme

(and #lang racket

): Racket uses immutable pair-pairs to represent lists. Consistent pairs do not support functions from set-car!

and set-cdr!

from r5rs, so the language #lang r5rs

will not conform to standard language using immutable inline pairs. To support the r5rs standard, Racket includes a separate mutable pair data type and uses it consistently within r5rs. But this means that standard pairs in Racket and mutable pairs do not compare in the same way.

+4


source







All Articles