Created
April 21, 2011 18:18
-
-
Save joseanpg/935161 to your computer and use it in GitHub Desktop.
Modules ( R7RS-Draft 9 March 2011)
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Defining a module | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(module (sillymul) | |
;;The body | |
(begin | |
;;Private | |
(define (mul x y) (if (= x 1) y (+ y (mul (- x 1) y)))) | |
(define (by x)(lambda (y) (mul x y))) | |
;;Public | |
(define by2 (by 2)) | |
(define by3 (by 3)) | |
(define by4 (by 4))) | |
;;Exporting public | |
(export by2 by3 by4)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Importing a module | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(import sillymul) | |
(display by2 5) | |
(display by3 7) | |
(display by3 9) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Importing and prefixing a module | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(import (prefix sillymul mul:)) | |
(display mul:by2 5) | |
(display mul:by3 7) | |
(display mul:by3 9) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Defining several modules | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(module (functional) | |
(begin | |
(define (curry proc . args) | |
(lambda moreargs (apply proc (append args moreargs))))) | |
(export curry)) | |
(module (sillymul) | |
(import functional) | |
(begin | |
(define (mul x y) (if (= x 1) y (+ y (mul (- x 1) y)))) | |
(define by2 (curry mul 2)) | |
(define by3 (curry mul 3)) | |
(define by4 (curry mul 4))) | |
(export by2 by3 by4)) | |
(module (mul) | |
(import functional) | |
(begin | |
(define by2 (curry * 2)) | |
(define by3 (curry * 3)) | |
(define by4 (curry * 4))) | |
(export by2 by3 by4)) | |
(import (prefix sillymul fool:)) | |
(import (prefix mul smart:)) | |
(display fool:by2 5) | |
(display smart:by3 7) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought we only have draft-8 by now...