[racket] unrequire for modules, or a new, clean sub-context?

From: Danny Yoo (dyoo at hashcollision.org)
Date: Mon Apr 29 15:36:26 EDT 2013

Often, you can use the 'prefix-in' feature of require to put a
namespace prefix around the exports of a module.  See:

    http://docs.racket-lang.org/guide/module-require.html

for some details and examples.


A module such as parser-tools/lex-sre provides definitions for "*",
"+", and other mathy-looking operations, but for regular expressions
instead of numbers.  To make sure we don't get these confused with the
ones that work on numbers, we can tell the module system to prefix the
exports of parser-tools/lex-sre to avoid clashing.

As a small, nonsense example:

;;;;;;
#lang racket/base
(require parser-tools/lex
         (prefix-in sre: parser-tools/lex-sre))
(define zero-lexer (lexer ((sre:+ "0") "zeros")))
(define example-input-port (open-input-string "00000011"))
(+ (string-length (zero-lexer example-input-port))
   42)
;;;;;;


For your other two questions: I'm not quite sure what you mean by
"dump a module".  Can you say more?  Also, it looked like your second
question got cut off in mid-sentence.


Good luck!

Posted on the users mailing list.