Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created April 21, 2011 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseanpg/935161 to your computer and use it in GitHub Desktop.
Save joseanpg/935161 to your computer and use it in GitHub Desktop.
Modules ( R7RS-Draft 9 March 2011)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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)
@tiye
Copy link

tiye commented Jan 10, 2013

I thought we only have draft-8 by now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment