Last active
June 22, 2018 14:34
-
-
Save euhmeuh/2f771a5702464741e21388bfcff8b68c to your computer and use it in GitHub Desktop.
Modules in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; How modules work in Racket | |
(require fruits) => "fruits/main.rkt" | |
(require fruits/banana) => "fruits/banana.rkt" | |
#lang fruits => "fruits/lang/reader.rkt" OR (submod "fruits/main.rkt" reader) | |
#lang fruits/apple => "fruits/apple/lang/reader.rkt" OR (submod "fruits/apple.rkt" reader) | |
fruits | |
| | |
+- main.rkt (require fruits) | |
| | |
+- apple.rkt (require fruits/apple) | |
| | |
+- banana.rkt (require fruits/banana) | |
| | |
+- pineapple | |
| | |
+- main.rkt (require fruits/pineapple/main) | |
================================================================================ | |
;;; Publicly provide a private lang with a default reader: | |
;; collection/private/lingua.rkt | |
#lang racket/base | |
(provide #%module-begin) | |
;; collection/lingua.rkt | |
#lang racket/base | |
(module reader syntax/module-reader collection/private/lingua) | |
================================================================================ | |
;;; Publicly provide a private lang with its own reader: | |
;; collection/private/lingua/reader.rkt | |
#lang racket/base | |
(provide read read-syntax) | |
(define (read-syntax src in) | |
#'(module whatever collection/private/lingua/expander | |
parse-tree-from-in)) | |
;; collection/private/lingua/expander.rkt | |
#lang racket/base | |
(provide #%module-begin) | |
;; collection/lingua.rkt | |
#lang racket/base | |
(module reader racket/base | |
(provide (all-from-out collection/private/lingua/reader)) | |
(require collection/private/lingua/reader)) | |
;; OR | |
(module reader reprovide collection/private/lingua/reader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment