listschemeracketr6rs

Racket lists incompatible with r6rs?


I'm writing a program in which i have to reuse code from one of my professors. My program is written in Racket and the code i want to reuse is written in r6rs.

When I want to test my program it always fails. This is because I call a procedure with as argument a list (racket list), but that procedure is in the R6RS file. In the R6RS file there is (assert (list? argument)) , this is always false...

Here a simple example : Racket code :

#lang racket
(require "test2.ss")

(define a (list 1 2 3))
(b a)

R6RS code :

#!r6rs

(library 
 (test)
 (export b)
 (import (rnrs base (6))
         (rnrs control (6))
         (rnrs lists (6))
         (rnrs io simple (6)))

 (define (b a)
   (display "a is : ") (display a) (newline)
   (display "list? : ") (display (list? a)) (newline)))

The list? test in the R6RS file is always false... even if I pass as argument a newly created list like in the above example.

How can I do the same as in the example above, so that the list? tests results true.

Thanks for your help!

EDIT : I could not find a r6rs test that results in true on a immutable list, but I found another way to resolve my problem (by passing a mutable list to the procedure).


Solution

  • Racket pairs are different from Scheme pairs since Racket pairs are immutable while Scheme pairs are not.

    As far as I know, there is no way to check for Racket's immutable lists in pure RnRS Scheme. However, it is possible to use Scheme's mutable lists in Racket (though of course that isn't really recommended).

    #lang racket
    
    (require compatibility/mlist
             "test2.ss")
    
    (define a (mlist 1 2 3))
    (b a)
    

    Here's an excerpt from the documentation for compatibility/mlist:

    This compatibility/mlist library provides support for mutable lists. Support is provided primarily to help porting Lisp/Scheme code to Racket.

    Use of mutable lists for modern Racket code is strongly discouraged. Instead, consider using lists.

    Still, if you need to interact with Scheme code, that's probably your only reasonable option.