home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / 1.6.0 / ice-9 / slib.scm < prev    next >
Encoding:
Text File  |  2004-01-06  |  8.7 KB  |  292 lines

  1. ;;;; slib.scm --- definitions needed to get SLIB to work with Guile
  2. ;;;;
  3. ;;;;    Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This file is part of GUILE.
  6. ;;;; 
  7. ;;;; GUILE is free software; you can redistribute it and/or modify it
  8. ;;;; under the terms of the GNU General Public License as published by
  9. ;;;; the Free Software Foundation; either version 2, or (at your
  10. ;;;; option) any later version.
  11. ;;;; 
  12. ;;;; GUILE is distributed in the hope that it will be useful, but
  13. ;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. ;;;; General Public License for more details.
  16. ;;;; 
  17. ;;;; You should have received a copy of the GNU General Public License
  18. ;;;; along with GUILE; see the file COPYING.  If not, write to the
  19. ;;;; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. ;;;; Boston, MA 02111-1307 USA
  21. ;;;;
  22. ;;;; As a special exception, the Free Software Foundation gives permission
  23. ;;;; for additional uses of the text contained in its release of GUILE.
  24. ;;;;
  25. ;;;; The exception is that, if you link the GUILE library with other files
  26. ;;;; to produce an executable, this does not by itself cause the
  27. ;;;; resulting executable to be covered by the GNU General Public License.
  28. ;;;; Your use of that executable is in no way restricted on account of
  29. ;;;; linking the GUILE library code into it.
  30. ;;;;
  31. ;;;; This exception does not however invalidate any other reasons why
  32. ;;;; the executable file might be covered by the GNU General Public License.
  33. ;;;;
  34. ;;;; This exception applies only to the code released by the
  35. ;;;; Free Software Foundation under the name GUILE.  If you copy
  36. ;;;; code from other Free Software Foundation releases into a copy of
  37. ;;;; GUILE, as the General Public License permits, the exception does
  38. ;;;; not apply to the code that you add in this way.  To avoid misleading
  39. ;;;; anyone as to the status of such modified files, you must delete
  40. ;;;; this exception notice from them.
  41. ;;;;
  42. ;;;; If you write modifications of your own for GUILE, it is your choice
  43. ;;;; whether to permit this exception to apply to your modifications.
  44. ;;;; If you do not wish that, delete this exception notice.
  45. ;;;;
  46. (define-module (ice-9 slib)
  47.   :export (slib:load
  48.        implementation-vicinity
  49.        library-vicinity
  50.        home-vicinity
  51.        scheme-implementation-type
  52.        scheme-implementation-version
  53.        make-random-state
  54.        require)
  55.   :no-backtrace)
  56.  
  57.  
  58.  
  59. (define (eval-load <filename> evl)
  60.   (if (not (file-exists? <filename>))
  61.       (set! <filename> (string-append <filename> (scheme-file-suffix))))
  62.   (call-with-input-file <filename>
  63.     (lambda (port)
  64.       (let ((old-load-pathname *load-pathname*))
  65.     (set! *load-pathname* <filename>)
  66.     (do ((o (read port) (read port)))
  67.         ((eof-object? o))
  68.       (evl o))
  69.     (set! *load-pathname* old-load-pathname)))))
  70.  
  71.  
  72.  
  73. (define slib:exit quit)
  74. (define slib:error error)
  75. (define slib:warn warn)
  76. (define slib:eval (lambda (x) (eval x slib-module)))
  77. (define defmacro:eval (lambda (x) (eval x (interaction-environment))))
  78. (define logical:logand logand)
  79. (define logical:logior logior)
  80. (define logical:logxor logxor)
  81. (define logical:lognot lognot)
  82. (define logical:ash ash)
  83. (define logical:logcount logcount)
  84. (define logical:integer-length integer-length)
  85. (define logical:bit-extract bit-extract)
  86. (define logical:integer-expt integer-expt)
  87. (define logical:ipow-by-squaring ipow-by-squaring)
  88. (define slib:eval-load eval-load)
  89. (define slib:tab #\tab)
  90. (define slib:form-feed #\page)
  91.  
  92. (define slib-module (current-module))
  93.  
  94. (define (defined? symbol)
  95.   (module-defined? slib-module symbol))
  96.  
  97. (define slib:features
  98.   (append '(source
  99.         eval
  100.         abort
  101.         alist
  102.         defmacro
  103.         delay
  104.         dynamic-wind
  105.         full-continuation
  106.         hash
  107.         hash-table
  108.         line-i/o
  109.         logical
  110.         multiarg/and-
  111.         multiarg-apply
  112.         promise
  113.         rev2-procedures
  114.         rev4-optional-procedures
  115.         string-port
  116.         with-file)
  117.  
  118.       (if (defined? 'getenv)
  119.           '(getenv)
  120.           '())
  121.  
  122.       (if (defined? 'current-time)
  123.           '(current-time)
  124.           '())
  125.  
  126.       (if (defined? 'system)
  127.           '(system)
  128.           '())
  129.  
  130.       (if (defined? 'array?)
  131.           '(array)
  132.           '())
  133.  
  134.       (if (defined? 'char-ready?)
  135.           '(char-ready?)
  136.           '())
  137.  
  138.       (if (defined? 'array-for-each)
  139.           '(array-for-each)
  140.           '())
  141.  
  142.       (if (and (string->number "0.0") (inexact? (string->number "0.0")))
  143.           '(inexact)
  144.           '())
  145.  
  146.       (if (rational? (string->number "1/19"))
  147.           '(rational)
  148.           '())
  149.  
  150.       (if (real? (string->number "0.0"))
  151.           '(real)
  152.           ())
  153.  
  154.       (if (complex? (string->number "1+i"))
  155.           '(complex)
  156.           '())
  157.  
  158.       (let ((n (string->number "9999999999999999999999999999999")))
  159.         (if (and n (exact? n))
  160.         '(bignum)
  161.         '()))))
  162.  
  163.  
  164. ;;; FIXME: Because uers want require to search the path, this uses
  165. ;;; load-from-path, which probably isn't a hot idea.  slib
  166. ;;; doesn't expect this function to search a path, so I expect to get
  167. ;;; bug reports at some point complaining that the wrong file gets
  168. ;;; loaded when something accidentally appears in the path before
  169. ;;; slib, etc. ad nauseum.  However, the right fix seems to involve
  170. ;;; changing catalog:get in slib/require.scm, and I don't expect
  171. ;;; Aubrey will integrate such a change.  So I'm just going to punt
  172. ;;; for the time being.
  173. (define (slib:load name)
  174.   (save-module-excursion
  175.    (lambda ()
  176.      (set-current-module slib-module)
  177.      (let ((errinfo (catch 'system-error
  178.                (lambda ()
  179.                  (load-from-path name)
  180.                  #f)
  181.                (lambda args args))))
  182.        (if (and errinfo
  183.         (catch 'system-error
  184.                (lambda ()
  185.              (load-from-path
  186.               (string-append name ".scm"))
  187.              #f)
  188.                (lambda args args)))
  189.        (apply throw errinfo))))))
  190.  
  191. (define slib:load-source slib:load)
  192. (define defmacro:load slib:load)
  193.  
  194. (define slib-parent-dir
  195.   (let* ((path (%search-load-path "slib/require.scm")))
  196.     (if path
  197.     (substring path 0 (- (string-length path) 17))
  198.     (error "Could not find slib/require.scm in " %load-path))))
  199.  
  200. (define (implementation-vicinity)
  201.   (string-append slib-parent-dir "/"))
  202. (define (library-vicinity)
  203.   (string-append (implementation-vicinity) "slib/"))
  204. (define home-vicinity
  205.   (let ((home-path (getenv "HOME")))
  206.     (lambda () home-path)))
  207. (define (scheme-implementation-type) 'guile)
  208. (define (scheme-implementation-version) "")
  209.  
  210. (define (output-port-width . arg) 80)
  211. (define (output-port-height . arg) 24)
  212. (define (identity x) x)
  213.  
  214. ;;; {Random numbers}
  215. ;;;
  216. (define (make-random-state . args)
  217.   (let ((seed (if (null? args) *random-state* (car args))))
  218.     (cond ((string? seed))
  219.       ((number? seed) (set! seed (number->string seed)))
  220.       (else (let ()
  221.           (require 'object->string)
  222.           (set! seed (object->limited-string seed 50)))))
  223.     (seed->random-state seed)))
  224.  
  225. ;;; {Time}
  226. ;;;
  227.  
  228. (define difftime -)
  229. (define offset-time +)
  230.  
  231.  
  232. (define %system-define define)
  233.  
  234. (define define
  235.   (procedure->memoizing-macro
  236.    (lambda (exp env)
  237.      (if (= (length env) 1)
  238.      `(define-public ,@(cdr exp))
  239.      `(%system-define ,@(cdr exp))))))
  240.  
  241. ;;; Hack to make syncase macros work in the slib module
  242. (if (nested-ref the-root-module '(app modules ice-9 syncase))
  243.     (set-object-property! (module-local-variable (current-module) 'define)
  244.               '*sc-expander*
  245.               '(define)))
  246.  
  247. (define (software-type)
  248.   "Return a symbol describing the current platform's operating system.
  249. This may be one of AIX, VMS, UNIX, COHERENT, WINDOWS, MS-DOS, OS/2,
  250. THINKC, AMIGA, ATARIST, MACH, or ACORN.
  251.  
  252. Note that most varieties of Unix are considered to be simply \"UNIX\".
  253. That is because when a program depends on features that are not present
  254. on every operating system, it is usually better to test for the presence
  255. or absence of that specific feature.  The return value of
  256. @code{software-type} should only be used for this purpose when there is
  257. no other easy or unambiguous way of detecting such features."
  258.  'UNIX)
  259.  
  260. (slib:load (in-vicinity (library-vicinity) "require.scm"))
  261.  
  262. (define require require:require)
  263.  
  264. ;; {Extensions to the require system so that the user can add new
  265. ;;  require modules easily.}
  266.  
  267. (define *vicinity-table*
  268.   (list
  269.    (cons 'implementation (implementation-vicinity))
  270.    (cons 'library (library-vicinity))))
  271.  
  272. (define (install-require-vicinity name vicinity)
  273.   (let ((entry (assq name *vicinity-table*)))
  274.     (if entry
  275.     (set-cdr! entry vicinity)
  276.     (set! *vicinity-table*
  277.           (acons name vicinity *vicinity-table*)))))
  278.  
  279. (define (install-require-module name vicinity-name file-name)
  280.   (if (not *catalog*)         ;Fix which loads catalog in slib
  281.       (catalog:get 'random)) ;(doesn't load the feature 'random)
  282.   (let ((entry (assq name *catalog*))
  283.     (vicinity (cdr (assq vicinity-name *vicinity-table*))))
  284.     (let ((path-name (in-vicinity vicinity file-name)))
  285.       (if entry
  286.       (set-cdr! entry path-name)
  287.       (set! *catalog*
  288.         (acons name path-name *catalog*))))))
  289.  
  290. (define (make-exchanger obj)
  291.   (lambda (rep) (let ((old obj)) (set! obj rep) old)))
  292.