Guest User

Untitled

a guest
Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. ;; How modules work in Racket
  2.  
  3. (require fruits) => "fruits/main.rkt"
  4. (require fruits/banana) => "fruits/banana.rkt"
  5. #lang fruits => "fruits/lang/reader.rkt" OR (submod "fruits/main.rkt" reader)
  6. #lang fruits/apple => "fruits/apple/lang/reader.rkt" OR (submod "fruits/apple.rkt" reader)
  7.  
  8. fruits
  9. |
  10. +- main.rkt (require fruits)
  11. |
  12. +- apple.rkt (require fruits/apple)
  13. |
  14. +- banana.rkt (require fruits/banana)
  15. |
  16. +- pineapple
  17. |
  18. +- main.rkt (require fruits/pineapple/main)
  19.  
  20.  
  21. ================================================================================
  22.  
  23. ;;; Publicly provide a private lang with a default reader:
  24.  
  25. ;; collection/private/lingua.rkt
  26. #lang racket/base
  27. (provide #%module-begin)
  28.  
  29. ;; collection/lingua.rkt
  30. #lang racket/base
  31. (module reader syntax/module-reader collection/private/lingua)
  32.  
  33.  
  34. ================================================================================
  35.  
  36. ;;; Publicly provide a private lang with its own reader:
  37.  
  38. ;; collection/private/lingua/reader.rkt
  39. #lang racket/base
  40. (provide read read-syntax)
  41. (define (read-syntax src in)
  42. #'(module whatever collection/private/lingua/expander
  43. parse-tree-from-in))
  44.  
  45. ;; collection/private/lingua/expander.rkt
  46. #lang racket/base
  47. (provide #%module-begin)
  48.  
  49. ;; collection/lingua.rkt
  50. #lang racket/base
  51. (module reader racket/base
  52. (provide (all-from-out collection/private/lingua/reader))
  53. (require collection/private/lingua/reader))
  54. ;; OR
  55. (module reader reprovide collection/private/lingua/reader)
Add Comment
Please, Sign In to add comment