base.scm 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ;;; base.scm --- The R6RS base library
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 3 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (library (rnrs base (6))
  18. (export boolean? symbol? char? vector? null? pair? number? string? procedure?
  19. define define-syntax syntax-rules lambda let let* let-values
  20. let*-values letrec letrec* begin
  21. quote lambda if set! cond case
  22. or and not
  23. eqv? equal? eq?
  24. + - * / max min abs numerator denominator gcd lcm floor ceiling
  25. truncate round rationalize real-part imag-part make-rectangular angle
  26. div mod div-and-mod div0 mod0 div0-and-mod0
  27. expt exact-integer-sqrt sqrt exp log sin cos tan asin acos atan
  28. make-polar magnitude angle
  29. complex? real? rational? integer? exact? inexact? real-valued?
  30. rational-valued? integer-values? zero? positive? negative? odd? even?
  31. nan? finite? infinite?
  32. exact inexact = < > <= >=
  33. number->string string->number
  34. cons car cdr caar cadr cdar cddr caaar caadr cadar cdaar caddr cdadr
  35. cddar cdddr caaaar caaadr caadar cadaar cdaaar cddaar cdadar cdaadr
  36. cadadr caaddr caddar cadddr cdaddr cddadr cdddar cddddr
  37. list? list length append reverse list-tail list-ref map for-each
  38. symbol->string string->symbol symbol=?
  39. char->integer integer->char char=? char<? char>? char<=? char>=?
  40. make-string string string-length string-ref string=? string<? string>?
  41. string<=? string>=? substring string-append string->list list->string
  42. string-for-each string-copy
  43. vector? make-vector vector vector-length vector-ref vector-set!
  44. vector->list list->vector vector-fill! vector-map vector-for-each
  45. error assertion-violation assert
  46. call-with-current-continuation call/cc call-with-values dynamic-wind
  47. values apply
  48. quasiquote unquote unquote-splicing
  49. let-syntax letrec-syntax
  50. syntax-rules identifier-syntax)
  51. (import (rename (guile) (quotient div) (modulo mod))
  52. (srfi srfi-11))
  53. (define (vector-for-each proc . vecs)
  54. (apply for-each (cons proc (map vector->list vecs))))
  55. (define (vector-map proc . vecs)
  56. (list->vector (apply map (cons proc (map vector->list vecs)))))
  57. (define (div-and-mod x y) (let ((q (div x y)) (r (mod x y))) (values q r)))
  58. (define (div0 x y)
  59. (call-with-values (lambda () (div0-and-mod0 x y)) (lambda (q r) q)))
  60. (define (mod0 x y)
  61. (call-with-values (lambda () (div0-and-mod0 x y)) (lambda (q r) r)))
  62. (define (div0-and-mod0 x y)
  63. (call-with-values (lambda () (div-and-mod x y))
  64. (lambda (q r)
  65. (cond ((< r (abs (/ y 2))) (values q r))
  66. ((negative? y) (values (- q 1) (+ r y)))
  67. (else (values (+ q 1) (+ r y)))))))
  68. )