home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / scheme / 2606 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  5.1 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!olivea!charnel!psgrain!percy!data!kend
  2. From: kend@data.rain.com (Ken Dickey)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: Modules for Scheme
  5. Message-ID: <735@data.rain.com>
  6. Date: 16 Nov 92 19:17:35 GMT
  7. References: <RPG.92Nov10203748@clones.cs.tulane.edu>
  8. Distribution: comp
  9. Organization: Microtek DSD, Hillsboro, OR
  10. Lines: 164
  11.  
  12. rpg@cs.tulane.edu (Robert Goldman) writes:
  13.  
  14.  
  15. >I was considering composing a package of definitions to give a
  16. >module facility to Scheme (Scheme does what we want with just
  17. >lexical scoping, o' course, but I would like to augment the syntax
  18. >to enhance readability).  I would like to take a look at any such
  19. >packages which exist now to avoid reinventing the wheel.  Any
  20. >pointers to such would be appreciated.
  21.  
  22. Pavel Curtis & James Rauen: "A Module System for Scheme",  Proceedings
  23. of the 1990 ACM Conference on Lisp and Functional Programming, June
  24. 27-29, 1992, [ACM # 552900]
  25.  
  26. Sho-Huan Simun Tung: "Interactive Modular Programming in Scheme,
  27. Proceedings of the 1992 ACM Conference on Lisp and Functional
  28. Programming, June 22-24, 1992, [ACM # 552920].
  29.  
  30. The traditional trivial module system follows.
  31.  
  32. Enjoy!
  33. -Ken
  34. ==============================================================
  35. ;; FILE        "country.scm"
  36. ;; IMPLEMENTS    NameSpace management via IMPORT/EXPORT
  37. ;; AUTHOR    Kenneth A Dickey
  38. ;; DATE        1991 October 26
  39. ;; LAST UPDATED    1991 November 1 -- updated EXPORT syntax
  40.  
  41. ;(##declare (standard-bindings))  ;; Gambit 1.71
  42.  
  43. ;; INTERFACE:
  44. ;;
  45. ;;   (IMPORT <country> <name>) -> value of <name> exported by <country>.
  46. ;;
  47. ;;   (EXPORT-LIST <country>)   -> list of exported names (symbols).
  48. ;;
  49. ;;   (EXPORT <name1> <name2> ...)  ;; returned as definition of exporting
  50. ;;                                 ;; `country'.
  51.  
  52. ;; NOTES:
  53. ;;
  54. ;;   The EXPORT special form needs to be defined in your local syntax
  55. ;; system.  Note that the scheme initial environment definitions are
  56. ;; available from SCHEME::COUNTRY if this file is loaded in the
  57. ;; initial environment.  This allows files to be loaded multiple times
  58. ;; without damaging definitions (e.g. redefining LOAD each time).
  59.  
  60.  
  61. ;; SAMPLE USAGE: DEFINITION OF EXPORTING `COUNTRY'
  62. ;;
  63. ;@ (define BIT-MANIPULATION::COUNTRY
  64. ;@   (let ()
  65. ;@    (define (BIT-AND some-bits other-bits) ...)
  66. ;@    (define (BIT-XOR some-bits other-bits) ...)
  67. ;@    ...
  68. ;@
  69. ;@    (EXPORT bit-and bit-or ...)  ;; the return value
  70. ;@ ) )
  71. ;@ ;; EOF
  72.  
  73.  
  74. ;; SAMPLE USAGE: IMPORT LOADFILE
  75. ;;
  76. ;@ ;;Recognize country--add to the United Nations 8^)
  77. ;@ (require 'bit-manipulation) ;; a.k.a. (load "bits.scm")
  78. ;@ (define BIT-AND (IMPORT bit-manipulation::country 'bit-and))
  79. ;@ (define BIT-XOR (IMPORT bit-manipulation::country 'bit-xor))
  80. ;@ ...
  81. ;@ ;; EOF
  82.  
  83.  
  84. ;;
  85. ;; IMPLEMENTATION
  86. ;;
  87.  
  88.   (define (IMPORT country name) 
  89.      (let ( (probe (assq name country)) )
  90.     (and probe (cdr probe))
  91.   )  )
  92.  
  93.  
  94.   (define (EXPORT-LIST country) (map car country))
  95.  
  96.  
  97.   ;; Redefine EXPORT in your local syntax system
  98.   ;; R^4RS
  99.  
  100.   (define-syntax EXPORT
  101.     (syntax-rules ()
  102.       ((export <name> ...)
  103.       ;=>
  104.       (list (cons '<name> <name>) ...))  ;; just an a-list
  105.   ) )
  106.  
  107. ;; OLD STYLE
  108. ;;  (##define-macro (EXPORT . name-list)
  109. ;;    `(list ,@(map (lambda (name) `(cons (quote ,name) ,name)) name-list)) )
  110.  
  111.  
  112.  
  113. ;;
  114. ;; CAPTURE (presumed) INITIAL SCHEME ENVIRONMENT
  115. ;;
  116.  
  117.   (define SCHEME::COUNTRY
  118.  
  119.     (EXPORT
  120.  
  121.     ; IEEE Scheme
  122.  
  123.     not    boolean?    eqv?    eq?    equal?    
  124.     pair?    cons    car    cdr    set-car!    set-cdr!    
  125.     caar    cadr    cdar    cddr    caaar    caadr    cadar    
  126.     caddr    cdaar    cdadr    cddar    cdddr    caaaar    caaadr    
  127.     caadar    caaddr    cadaar    cadadr    caddar    cadddr    cdaaar    
  128.     cdaadr    cdadar    cdaddr    cddaar    cddadr    cdddar    cddddr    
  129.     null?    list?    list    length    append    reverse    list-ref
  130.     memq    memv    member    assq    assv    assoc    
  131.     symbol?    symbol->string    string->symbol    number?    complex?
  132.     real?    rational?    integer?    exact?    inexact?
  133.     =    <    >    <=    >=    zero?    positive?
  134.     negative?    odd?    even?    max    min
  135.     +    *    -    /    abs    quotient
  136.     remainder    modulo    gcd    lcm    numerator
  137.     denominator    floor    ceiling    truncate    round
  138.     rationalize    exp    log    sin    cos    tan
  139.     asin    acos    atan    sqrt    expt    make-rectangular
  140.     make-polar    real-part    imag-part    magnitude
  141.     angle    exact->inexact    inexact->exact
  142.     number->string    string->number
  143.     char?    char=?    char<?    char>?    char<=?    char>=?    char-ci=?
  144.     char-ci<?    char-ci>?    char-ci<=?    char-ci>=?
  145.     char-alphabetic?    char-numeric?    char-whitespace?
  146.     char-upper-case?    char-lower-case?    char->integer
  147.     integer->char    char-upcase    char-downcase    
  148.     string?    make-string    string    string-length    string-ref
  149.     string-set!    string=?    string<?    string>?
  150.     string<=?    string>=?    string-ci=?    string-ci<?
  151.     string-ci>?    string-ci<=?    string-ci>=?    substring
  152.     string-append    vector?    make-vector    vector    vector-length
  153.     vector-ref    vector-set!    procedure?    apply    map
  154.     for-each    call-with-current-continuation    call-with-input-file
  155.     call-with-output-file    input-port?    output-port?
  156.     current-input-port    current-output-port    open-input-file
  157.     open-output-file    close-input-port    close-output-port
  158.     eof-object?    read    read-char    peek-char    write
  159.     display    newline    write-char
  160.  
  161.     ; R4RS Scheme
  162.  
  163.     list-tail    string->list    list->string    string-copy
  164.     string-fill!    vector->list    list->vector    vector-fill!
  165.     force    with-input-from-file    with-output-to-file
  166.     char-ready?    load    transcript-on    transcript-off
  167.  
  168.     ; Your favorate extensions here...
  169.  
  170. ;@;    touch
  171.     )
  172.   )
  173.  
  174.  
  175. ;;            --- E O F ---            ;;
  176.