racket/collects/tests/eopl/chapter8/simplemodules/subtyping.rkt
David Van Horn 7491e172ea EOPL test suite re-written in Racket-based #lang eopl and rackunit
The eopl language is now racket-based rather than mzscheme-based.  This
test-suite, which was originally distributed on the book's web-site has
been re-written in the new language.  Changes include dropping all
drscheme-init.scm and top.scm files.  Remaining files were renamed to
use the .rkt extension and edited to use the #lang syntax (instead of
modulue).  Require and provide forms were changed to reflect racket's
syntax instead of mzscheme's (eg, only-in vs. only).  Several
occurrences of one-armed ifs were changed to use when and unless.  All
tests have been run successfully.
2012-02-24 14:46:18 -05:00

41 lines
1.2 KiB
Racket
Executable File

#lang eopl
(require "lang.rkt")
(provide <:-iface)
;; <:-iface : Iface * Iface * Tenv -> Bool
;; Page: 289
(define <:-iface
(lambda (iface1 iface2 tenv)
(cases interface iface1
(simple-iface (decls1)
(cases interface iface2
(simple-iface (decls2)
(<:-decls decls1 decls2 tenv)))))))
;; <:-decls : Listof(Decl) * Listof(Decl) * Tenv -> Bool
;; Page: 289
;;
;; s1 <: s2 iff s1 has at least as much stuff as s2, and in the same
;; order. We walk down s1 until we find a declaration that declares
;; the same name as the first component of s2. If we run off the
;; end of s1, then we fail. As we walk down s1, we record any type
;; bindings in the tenv
;;
(define <:-decls
(lambda (decls1 decls2 tenv)
(cond
((null? decls2) #t)
((null? decls1) #f)
(else
(let ((name1 (decl->name (car decls1)))
(name2 (decl->name (car decls2))))
(if (eqv? name1 name2)
(and
(equal?
(decl->type (car decls1))
(decl->type (car decls2)))
(<:-decls (cdr decls1) (cdr decls2) tenv))
(<:-decls (cdr decls1) decls2 tenv)))))))