base.scm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. ;;; R7RS (scheme base)
  2. ;;; Copyright (C) 2024 Igalia, S.L.
  3. ;;;
  4. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  5. ;;; you may not use this file except in compliance with the License.
  6. ;;; You may obtain a copy of the License at
  7. ;;;
  8. ;;; http://www.apache.org/licenses/LICENSE-2.0
  9. ;;;
  10. ;;; Unless required by applicable law or agreed to in writing, software
  11. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  12. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ;;; See the License for the specific language governing permissions and
  14. ;;; limitations under the License.
  15. ;;; Commentary:
  16. ;;;
  17. ;;; A definition of R7RS (scheme base).
  18. ;;;
  19. ;;; Code:
  20. (library (scheme base)
  21. (export *
  22. +
  23. -
  24. ...
  25. _
  26. /
  27. <
  28. <=
  29. =
  30. =>
  31. >
  32. >=
  33. abs
  34. and
  35. append
  36. apply
  37. assoc
  38. assq
  39. assv
  40. begin
  41. binary-port?
  42. boolean=?
  43. boolean?
  44. bytevector
  45. bytevector-append
  46. bytevector-copy
  47. bytevector-copy!
  48. bytevector-length
  49. bytevector-u8-ref
  50. bytevector-u8-set!
  51. bytevector?
  52. caar
  53. cadr
  54. call-with-current-continuation
  55. call-with-port
  56. call-with-values
  57. call/cc
  58. car
  59. case
  60. cdar
  61. cddr
  62. cdr
  63. ceiling
  64. char->integer
  65. char-ready?
  66. char<=?
  67. char<?
  68. char=?
  69. char>=?
  70. char>?
  71. char?
  72. close-input-port
  73. close-output-port
  74. close-port
  75. complex?
  76. cond
  77. cond-expand
  78. cons
  79. current-error-port
  80. current-input-port
  81. current-output-port
  82. define
  83. define-record-type
  84. define-syntax
  85. define-values
  86. denominator
  87. do
  88. dynamic-wind
  89. else
  90. eof-object?
  91. equal?
  92. error
  93. error-object-message
  94. even?
  95. exact-integer-sqrt
  96. exact?
  97. features
  98. floor
  99. floor-remainder
  100. flush-output-port
  101. gcd
  102. get-output-string
  103. if
  104. include-ci
  105. inexact?
  106. input-port?
  107. integer?
  108. lcm
  109. let
  110. let*-values
  111. let-values
  112. letrec*
  113. list
  114. list->vector
  115. list-ref
  116. list-tail
  117. make-bytevector
  118. make-parameter
  119. make-vector
  120. max
  121. memq
  122. min
  123. negative?
  124. not
  125. number->string
  126. numerator
  127. open-input-bytevector
  128. open-output-bytevector
  129. or
  130. output-port?
  131. parameterize
  132. peek-u8
  133. positive?
  134. quasiquote
  135. quotient
  136. raise-continuable
  137. rationalize
  138. read-bytevector!
  139. read-error?
  140. read-string
  141. real?
  142. reverse
  143. set!
  144. set-cdr!
  145. string
  146. string->number
  147. string->utf8
  148. string-append
  149. eof-object
  150. eq?
  151. eqv?
  152. error-object-irritants
  153. error-object?
  154. exact
  155. exact-integer?
  156. expt
  157. file-error?
  158. floor-quotient
  159. floor/
  160. for-each
  161. get-output-bytevector
  162. guard
  163. include
  164. inexact
  165. input-port-open?
  166. integer->char
  167. lambda
  168. length
  169. let*
  170. let-syntax
  171. letrec
  172. letrec-syntax
  173. list->string
  174. list-copy
  175. list-set!
  176. list?
  177. make-list
  178. make-string
  179. map
  180. member
  181. memv
  182. modulo
  183. newline
  184. null?
  185. number?
  186. odd?
  187. open-input-string
  188. open-output-string
  189. output-port-open?
  190. pair?
  191. peek-char
  192. port?
  193. procedure?
  194. quote
  195. raise
  196. rational?
  197. read-bytevector
  198. read-char
  199. read-line
  200. read-u8
  201. remainder
  202. round
  203. set-car!
  204. square
  205. string->list
  206. string->symbol
  207. string->vector
  208. string-copy
  209. string-copy!
  210. string-for-each
  211. string-map
  212. string-set!
  213. string<?
  214. string>=?
  215. string?
  216. symbol->string
  217. symbol?
  218. syntax-rules
  219. truncate
  220. truncate-remainder
  221. u8-ready?
  222. unquote
  223. utf8->string
  224. vector
  225. vector->string
  226. vector-copy
  227. vector-fill!
  228. vector-length
  229. vector-ref
  230. vector?
  231. with-exception-handler
  232. write-char
  233. write-u8
  234. string-fill!
  235. string-length
  236. string-ref
  237. string<=?
  238. string=?
  239. string>?
  240. substring
  241. symbol=?
  242. syntax-error
  243. textual-port?
  244. truncate-quotient
  245. truncate/
  246. unless
  247. unquote-splicing
  248. values
  249. vector->list
  250. vector-append
  251. vector-copy!
  252. vector-for-each
  253. vector-map
  254. vector-set!
  255. when
  256. write-bytevector
  257. write-string
  258. zero?)
  259. (import (hoot syntax)
  260. (hoot features)
  261. (hoot cond-expand)
  262. (hoot bytevectors)
  263. (hoot char)
  264. (hoot control)
  265. (hoot dynamic-wind)
  266. (hoot eq)
  267. (hoot error-handling)
  268. (hoot not)
  269. (hoot parameters)
  270. (hoot pairs)
  271. (hoot procedures)
  272. (hoot ports)
  273. (hoot errors)
  274. (only (hoot read) string->number)
  275. (only (hoot primitives) apply)
  276. (hoot exceptions)
  277. (hoot equal)
  278. (hoot lists)
  279. (hoot assoc)
  280. (hoot numbers)
  281. (hoot match)
  282. (hoot strings)
  283. (hoot symbols)
  284. (hoot write)
  285. (hoot values)
  286. (hoot vectors)
  287. (srfi srfi-9))
  288. ;; Here we should have definitions of procedures that aren't generally
  289. ;; useful: they only exist for conformity with R7RS.
  290. (define (boolean? x) (match x ((or #f #t) #t) (_ #f)))
  291. (define boolean=?
  292. (case-lambda
  293. ((x y)
  294. (check-type x boolean? 'boolean=?)
  295. (check-type y boolean? 'boolean=?)
  296. (eq? x y))
  297. ((x y . z)
  298. (let lp ((z z) (res (boolean=? x y)))
  299. (match z
  300. (() res)
  301. ((y . z)
  302. (lp z (boolean=? x y))))))))
  303. (define (symbol=? x y . z)
  304. (check-type x symbol? 'symbol=?)
  305. (check-type y symbol? 'symbol=?)
  306. (for-each (lambda (z) (check-type z symbol? 'symbol=?)) z)
  307. (apply eq? x y z))
  308. (define* (string->vector str #:optional (start 0)
  309. (end (string-length string)))
  310. (list->vector (string->list str start end)))
  311. (define* (vector->string v #:optional (start 0) (end (vector-length v)))
  312. (list->string (vector->list v start end)))
  313. (define (error-object? x)
  314. (and (exception-with-message? x)
  315. (exception-with-irritants? x)))
  316. (define error-object-message exception-message)
  317. (define error-object-irritants exception-irritants)
  318. (define read-error? lexical-violation?)
  319. (define file-error? i/o-error?))