Disallowing Specific Functions

It would be handy to be able to set! a function such as reverse to an expression which raises an error in a module. PLT Scheme does not allow this. However, it provides a different way through a module provide to export a binding as a different name than the one inside of the module itself: rename-out.

The following code illustrates how to bar a particular tested file from using reverse or append; note, however, that this will not autodetect if the students themselves implement such a function, and so hand-checking will still likely be necessary.

#lang scheme

(provide (rename-out (d-reverse reverse))
         (rename-out (d-append append)))

(define-syntax disallow
  (syntax-rules ()
    ((~ func)
     (lambda args
       (error (format "Disallowed function ~a called" (quote func)))))))

(define d-reverse (disallow reverse))
(define d-append  (disallow append))

-- TerryVaskor - 12 Mar 2009

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2010-02-17 - BobCui
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback