home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / gensym.scm < prev    next >
Text File  |  2001-03-21  |  2KB  |  55 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: gensym.scm,v 14.6 2001/03/21 19:15:07 cph Exp $
  4.  
  5. Copyright (c) 1988-2001 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program 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 this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. 02111-1307, USA.
  21. |#
  22.  
  23. ;;;; Symbol Generation
  24. ;;; package: (runtime gensym)
  25.  
  26. (declare (usual-integrations))
  27.  
  28. (define (generate-uninterned-symbol #!optional argument)
  29.   (let ((prefix
  30.      (cond ((or (default-object? argument) (not argument))
  31.         name-prefix)
  32.            ((string? argument)
  33.         argument)
  34.            ((symbol? argument)
  35.         (symbol-name argument))
  36.            ((exact-nonnegative-integer? argument)
  37.         (set! name-counter argument)
  38.         name-prefix)
  39.            (else
  40.         (error:wrong-type-argument argument "symbol or integer"
  41.                        'GENERATE-UNINTERNED-SYMBOL)))))
  42.     (string->uninterned-symbol
  43.      (string-append prefix
  44.             (number->string
  45.              (let ((result name-counter))
  46.                (set! name-counter (1+ name-counter))
  47.                result))))))
  48.  
  49. (define name-counter)
  50. (define name-prefix)
  51.  
  52. (define (initialize-package!)
  53.   (set! name-counter 0)
  54.   (set! name-prefix "G")
  55.   unspecific)