From: kend@data.rain.com (Ken Dickey)
Newsgroups: comp.lang.scheme
Subject: Re: Modules for Scheme
Date: 16 Nov 92 19:17:35 GMT
Distribution: comp
Organization: Microtek DSD, Hillsboro, OR

rpg@cs.tulane.edu (Robert Goldman) writes:


>I was considering composing a package of definitions to give a
>module facility to Scheme (Scheme does what we want with just
>lexical scoping, o' course, but I would like to augment the syntax
>to enhance readability).  I would like to take a look at any such
>packages which exist now to avoid reinventing the wheel.  Any
>pointers to such would be appreciated.

Pavel Curtis & James Rauen: "A Module System for Scheme",  Proceedings
of the 1990 ACM Conference on Lisp and Functional Programming, June
27-29, 1992, [ACM # 552900]

Sho-Huan Simun Tung: "Interactive Modular Programming in Scheme,
Proceedings of the 1992 ACM Conference on Lisp and Functional
Programming, June 22-24, 1992, [ACM # 552920].

The traditional trivial module system follows.

Enjoy!
-Ken
==============================================================
;; FILE		"country.scm"
;; IMPLEMENTS	NameSpace management via IMPORT/EXPORT
;; AUTHOR	Kenneth A Dickey
;; DATE		1991 October 26
;; LAST UPDATED	1991 November 1 -- updated EXPORT syntax

;(##declare (standard-bindings))  ;; Gambit 1.71

;; INTERFACE:
;;
;;   (IMPORT <country> <name>) -> value of <name> exported by <country>.
;;
;;   (EXPORT-LIST <country>)   -> list of exported names (symbols).
;;
;;   (EXPORT <name1> <name2> ...)  ;; returned as definition of exporting
;;                                 ;; `country'.

;; NOTES:
;;
;;   The EXPORT special form needs to be defined in your local syntax
;; system.  Note that the scheme initial environment definitions are
;; available from SCHEME::COUNTRY if this file is loaded in the
;; initial environment.  This allows files to be loaded multiple times
;; without damaging definitions (e.g. redefining LOAD each time).


;; SAMPLE USAGE: DEFINITION OF EXPORTING `COUNTRY'
;;
;@ (define BIT-MANIPULATION::COUNTRY
;@   (let ()
;@	(define (BIT-AND some-bits other-bits) ...)
;@	(define (BIT-XOR some-bits other-bits) ...)
;@	...
;@
;@	(EXPORT bit-and bit-or ...)  ;; the return value
;@ ) )
;@ ;; EOF


;; SAMPLE USAGE: IMPORT LOADFILE
;;
;@ ;;Recognize country--add to the United Nations 8^)
;@ (require 'bit-manipulation) ;; a.k.a. (load "bits.scm")
;@ (define BIT-AND (IMPORT bit-manipulation::country 'bit-and))
;@ (define BIT-XOR (IMPORT bit-manipulation::country 'bit-xor))
;@ ...
;@ ;; EOF


;;
;; IMPLEMENTATION
;;

  (define (IMPORT country name) 
     (let ( (probe (assq name country)) )
	(and probe (cdr probe))
  )  )


  (define (EXPORT-LIST country) (map car country))


  ;; Redefine EXPORT in your local syntax system
  ;; R^4RS

  (define-syntax EXPORT
    (syntax-rules ()
      ((export <name> ...)
      ;=>
      (list (cons '<name> <name>) ...))  ;; just an a-list
  ) )

;; OLD STYLE
;;  (##define-macro (EXPORT . name-list)
;;    `(list ,@(map (lambda (name) `(cons (quote ,name) ,name)) name-list)) )



;;
;; CAPTURE (presumed) INITIAL SCHEME ENVIRONMENT
;;

  (define SCHEME::COUNTRY

    (EXPORT

	; IEEE Scheme

	not	boolean?	eqv?	eq?	equal?	
	pair?	cons	car	cdr	set-car!	set-cdr!	
	caar	cadr	cdar	cddr	caaar	caadr	cadar	
	caddr	cdaar	cdadr	cddar	cdddr	caaaar	caaadr	
	caadar	caaddr	cadaar	cadadr	caddar	cadddr	cdaaar	
	cdaadr	cdadar	cdaddr	cddaar	cddadr	cdddar	cddddr	
	null?	list?	list	length	append	reverse	list-ref
	memq	memv	member	assq	assv	assoc	
	symbol?	symbol->string	string->symbol	number?	complex?
	real?	rational?	integer?	exact?	inexact?
	=	<	>	<=	>=	zero?	positive?
	negative?	odd?	even?	max	min
	+	*	-	/	abs	quotient
	remainder	modulo	gcd	lcm	numerator
	denominator	floor	ceiling	truncate	round
	rationalize	exp	log	sin	cos	tan
	asin	acos	atan	sqrt	expt	make-rectangular
	make-polar	real-part	imag-part	magnitude
	angle	exact->inexact	inexact->exact
	number->string	string->number
	char?	char=?	char<?	char>?	char<=?	char>=?	char-ci=?
	char-ci<?	char-ci>?	char-ci<=?	char-ci>=?
	char-alphabetic?	char-numeric?	char-whitespace?
	char-upper-case?	char-lower-case?	char->integer
	integer->char	char-upcase	char-downcase	
	string?	make-string	string	string-length	string-ref
	string-set!	string=?	string<?	string>?
	string<=?	string>=?	string-ci=?	string-ci<?
	string-ci>?	string-ci<=?	string-ci>=?	substring
	string-append	vector?	make-vector	vector	vector-length
	vector-ref	vector-set!	procedure?	apply	map
	for-each	call-with-current-continuation	call-with-input-file
	call-with-output-file	input-port?	output-port?
	current-input-port	current-output-port	open-input-file
	open-output-file	close-input-port	close-output-port
	eof-object?	read	read-char	peek-char	write
	display	newline	write-char

	; R4RS Scheme

	list-tail	string->list	list->string	string-copy
	string-fill!	vector->list	list->vector	vector-fill!
	force	with-input-from-file	with-output-to-file
	char-ready?	load	transcript-on	transcript-off

	; Your favorate extensions here...

;@;	touch
    )
  )


;;			--- E O F ---			;;
Newsgroups: comp.lang.scheme