r6rs.texi 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Guile Reference Manual.
  3. @c Copyright (C) 2010, 2011, 2012
  4. @c Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node R6RS Support
  7. @section R6RS Support
  8. @cindex R6RS
  9. @xref{R6RS Libraries}, for more information on how to define R6RS libraries, and
  10. their integration with Guile modules.
  11. @menu
  12. * R6RS Incompatibilities:: Guile mostly implements R6RS.
  13. * R6RS Standard Libraries:: Modules defined by the R6RS.
  14. @end menu
  15. @node R6RS Incompatibilities
  16. @subsection Incompatibilities with the R6RS
  17. There are some incompatibilities between Guile and the R6RS. Some of
  18. them are intentional, some of them are bugs, and some are simply
  19. unimplemented features. Please let the Guile developers know if you
  20. find one that is not on this list.
  21. @itemize
  22. @item
  23. The R6RS specifies many situations in which a conforming implementation
  24. must signal a specific error. Guile doesn't really care about that too
  25. much---if a correct R6RS program would not hit that error, we don't
  26. bother checking for it.
  27. @item
  28. Multiple @code{library} forms in one file are not yet supported. This
  29. is because the expansion of @code{library} sets the current module, but
  30. does not restore it. This is a bug.
  31. @item
  32. R6RS unicode escapes within strings are disabled by default, because
  33. they conflict with Guile's already-existing escapes. The same is the
  34. case for R6RS treatment of escaped newlines in strings.
  35. R6RS behavior can be turned on via a reader option. @xref{String
  36. Syntax}, for more information.
  37. @item
  38. A @code{set!} to a variable transformer may only expand to an
  39. expression, not a definition---even if the original @code{set!}
  40. expression was in definition context.
  41. @item
  42. Instead of using the algorithm detailed in chapter 10 of the R6RS,
  43. expansion of toplevel forms happens sequentially.
  44. For example, while the expansion of the following set of toplevel
  45. definitions does the correct thing:
  46. @example
  47. (begin
  48. (define even?
  49. (lambda (x)
  50. (or (= x 0) (odd? (- x 1)))))
  51. (define-syntax odd?
  52. (syntax-rules ()
  53. ((odd? x) (not (even? x)))))
  54. (even? 10))
  55. @result{} #t
  56. @end example
  57. @noindent
  58. The same definitions outside of the @code{begin} wrapper do not:
  59. @example
  60. (define even?
  61. (lambda (x)
  62. (or (= x 0) (odd? (- x 1)))))
  63. (define-syntax odd?
  64. (syntax-rules ()
  65. ((odd? x) (not (even? x)))))
  66. (even? 10)
  67. <unnamed port>:4:18: In procedure even?:
  68. <unnamed port>:4:18: Wrong type to apply: #<syntax-transformer odd?>
  69. @end example
  70. This is because when expanding the right-hand-side of @code{even?}, the
  71. reference to @code{odd?} is not yet marked as a syntax transformer, so
  72. it is assumed to be a function.
  73. This bug will only affect top-level programs, not code in @code{library}
  74. forms. Fixing it for toplevel forms seems doable, but tricky to
  75. implement in a backward-compatible way. Suggestions and/or patches would
  76. be appreciated.
  77. @item
  78. The @code{(rnrs io ports)} module is incomplete. Work is
  79. ongoing to fix this.
  80. @item
  81. Guile does not prevent use of textual I/O procedures on binary ports.
  82. More generally, it does not make a sharp distinction between binary and
  83. textual ports (@pxref{R6RS Port Manipulation, binary-port?}).
  84. @end itemize
  85. @node R6RS Standard Libraries
  86. @subsection R6RS Standard Libraries
  87. In contrast with earlier versions of the Revised Report, the R6RS
  88. organizes the procedures and syntactic forms required of conforming
  89. implementations into a set of ``standard libraries'' which can be
  90. imported as necessary by user programs and libraries. Here we briefly
  91. list the libraries that have been implemented for Guile.
  92. We do not attempt to document these libraries fully here, as most of
  93. their functionality is already available in Guile itself. The
  94. expectation is that most Guile users will use the well-known and
  95. well-documented Guile modules. These R6RS libraries are mostly useful
  96. to users who want to port their code to other R6RS systems.
  97. The documentation in the following sections reproduces some of the
  98. content of the library section of the Report, but is mostly intended to
  99. provide supplementary information about Guile's implementation of the
  100. R6RS standard libraries. For complete documentation, design rationales
  101. and further examples, we advise you to consult the ``Standard
  102. Libraries'' section of the Report (@pxref{Standard Libraries,
  103. R6RS Standard Libraries,, r6rs, The Revised^6 Report on the Algorithmic
  104. Language Scheme}).
  105. @menu
  106. * Library Usage:: What to know about Guile's library support.
  107. * rnrs base:: The base library.
  108. * rnrs unicode:: Access to Unicode operations.
  109. * rnrs bytevectors:: Functions for working with binary data.
  110. * rnrs lists:: List utilities.
  111. * rnrs sorting:: Sorting for lists and vectors.
  112. * rnrs control:: Additional control structures.
  113. * R6RS Records:: A note about R6RS records.
  114. * rnrs records syntactic:: Syntactic API for R6RS records.
  115. * rnrs records procedural:: Procedural API for R6RS records.
  116. * rnrs records inspection:: Reflection on R6RS records.
  117. * rnrs exceptions:: Handling exceptional situations.
  118. * rnrs conditions:: Data structures for exceptions.
  119. * I/O Conditions:: Predefined I/O error types.
  120. * rnrs io ports:: Support for port-based I/O.
  121. * rnrs io simple:: High-level I/O API.
  122. * rnrs files:: Functions for working with files.
  123. * rnrs programs:: Functions for working with processes.
  124. * rnrs arithmetic fixnums:: Fixed-precision arithmetic operations.
  125. * rnrs arithmetic flonums:: Floating-point arithmetic operations.
  126. * rnrs arithmetic bitwise:: Exact bitwise arithmetic operations.
  127. * rnrs syntax-case:: Support for `syntax-case' macros.
  128. * rnrs hashtables:: Hashtables.
  129. * rnrs enums:: Enumerations.
  130. * rnrs:: The composite library.
  131. * rnrs eval:: Support for on-the-fly evaluation.
  132. * rnrs mutable-pairs:: Support for mutable pairs.
  133. * rnrs mutable-strings:: Support for mutable strings.
  134. * rnrs r5rs:: Compatibility layer for R5RS Scheme.
  135. @end menu
  136. @node Library Usage
  137. @subsubsection Library Usage
  138. Guile implements the R6RS `library' form as a transformation to a native
  139. Guile module definition. As a consequence of this, all of the libraries
  140. described in the following subsections, in addition to being available
  141. for use by R6RS libraries and top-level programs, can also be imported
  142. as if they were normal Guile modules---via a @code{use-modules} form,
  143. say. For example, the R6RS ``composite'' library can be imported by:
  144. @lisp
  145. (import (rnrs (6)))
  146. @end lisp
  147. @lisp
  148. (use-modules ((rnrs) :version (6)))
  149. @end lisp
  150. For more information on Guile's library implementation, see
  151. (@pxref{R6RS Libraries}).
  152. @node rnrs base
  153. @subsubsection rnrs base
  154. The @code{(rnrs base (6))} library exports the procedures and syntactic
  155. forms described in the main section of the Report
  156. (@pxref{Base library, R6RS Base library,, r6rs,
  157. The Revised^6 Report on the Algorithmic Language Scheme}). They are
  158. grouped below by the existing manual sections to which they correspond.
  159. @deffn {Scheme Procedure} boolean? obj
  160. @deffnx {Scheme Procedure} not x
  161. @xref{Booleans}, for documentation.
  162. @end deffn
  163. @deffn {Scheme Procedure} symbol? obj
  164. @deffnx {Scheme Procedure} symbol->string sym
  165. @deffnx {Scheme Procedure} string->symbol str
  166. @xref{Symbol Primitives}, for documentation.
  167. @end deffn
  168. @deffn {Scheme Procedure} char? obj
  169. @deffnx {Scheme Procedure} char=?
  170. @deffnx {Scheme Procedure} char<?
  171. @deffnx {Scheme Procedure} char>?
  172. @deffnx {Scheme Procedure} char<=?
  173. @deffnx {Scheme Procedure} char>=?
  174. @deffnx {Scheme Procedure} integer->char n
  175. @deffnx {Scheme Procedure} char->integer chr
  176. @xref{Characters}, for documentation.
  177. @end deffn
  178. @deffn {Scheme Procedure} list? x
  179. @deffnx {Scheme Procedure} null? x
  180. @xref{List Predicates}, for documentation.
  181. @end deffn
  182. @deffn {Scheme Procedure} pair? x
  183. @deffnx {Scheme Procedure} cons x y
  184. @deffnx {Scheme Procedure} car pair
  185. @deffnx {Scheme Procedure} cdr pair
  186. @deffnx {Scheme Procedure} caar pair
  187. @deffnx {Scheme Procedure} cadr pair
  188. @deffnx {Scheme Procedure} cdar pair
  189. @deffnx {Scheme Procedure} cddr pair
  190. @deffnx {Scheme Procedure} caaar pair
  191. @deffnx {Scheme Procedure} caadr pair
  192. @deffnx {Scheme Procedure} cadar pair
  193. @deffnx {Scheme Procedure} cdaar pair
  194. @deffnx {Scheme Procedure} caddr pair
  195. @deffnx {Scheme Procedure} cdadr pair
  196. @deffnx {Scheme Procedure} cddar pair
  197. @deffnx {Scheme Procedure} cdddr pair
  198. @deffnx {Scheme Procedure} caaaar pair
  199. @deffnx {Scheme Procedure} caaadr pair
  200. @deffnx {Scheme Procedure} caadar pair
  201. @deffnx {Scheme Procedure} cadaar pair
  202. @deffnx {Scheme Procedure} cdaaar pair
  203. @deffnx {Scheme Procedure} cddaar pair
  204. @deffnx {Scheme Procedure} cdadar pair
  205. @deffnx {Scheme Procedure} cdaadr pair
  206. @deffnx {Scheme Procedure} cadadr pair
  207. @deffnx {Scheme Procedure} caaddr pair
  208. @deffnx {Scheme Procedure} caddar pair
  209. @deffnx {Scheme Procedure} cadddr pair
  210. @deffnx {Scheme Procedure} cdaddr pair
  211. @deffnx {Scheme Procedure} cddadr pair
  212. @deffnx {Scheme Procedure} cdddar pair
  213. @deffnx {Scheme Procedure} cddddr pair
  214. @xref{Pairs}, for documentation.
  215. @end deffn
  216. @deffn {Scheme Procedure} number? obj
  217. @xref{Numerical Tower}, for documentation.
  218. @end deffn
  219. @deffn {Scheme Procedure} string? obj
  220. @xref{String Predicates}, for documentation.
  221. @end deffn
  222. @deffn {Scheme Procedure} procedure? obj
  223. @xref{Procedure Properties}, for documentation.
  224. @end deffn
  225. @deffn {Scheme Syntax} define name value
  226. @deffnx {Scheme Syntax} set! variable-name value
  227. @xref{Definition}, for documentation.
  228. @end deffn
  229. @deffn {Scheme Syntax} define-syntax keyword expression
  230. @deffnx {Scheme Syntax} let-syntax ((keyword transformer) @dots{})
  231. exp1 exp2 @dots{}
  232. @deffnx {Scheme Syntax} letrec-syntax ((keyword transformer) @dots{})
  233. exp1 exp2 @dots{}
  234. @xref{Defining Macros}, for documentation.
  235. @end deffn
  236. @deffn {Scheme Syntax} identifier-syntax exp
  237. @xref{Identifier Macros}, for documentation.
  238. @end deffn
  239. @deffn {Scheme Syntax} syntax-rules literals (pattern template) ...
  240. @xref{Syntax Rules}, for documentation.
  241. @end deffn
  242. @deffn {Scheme Syntax} lambda formals body
  243. @xref{Lambda}, for documentation.
  244. @end deffn
  245. @deffn {Scheme Syntax} let bindings body
  246. @deffnx {Scheme Syntax} let* bindings body
  247. @deffnx {Scheme Syntax} letrec bindings body
  248. @deffnx {Scheme Syntax} letrec* bindings body
  249. @xref{Local Bindings}, for documentation.
  250. @end deffn
  251. @deffn {Scheme Syntax} let-values bindings body
  252. @deffnx {Scheme Syntax} let*-values bindings body
  253. @xref{SRFI-11}, for documentation.
  254. @end deffn
  255. @deffn {Scheme Syntax} begin expr1 expr2 ...
  256. @xref{begin}, for documentation.
  257. @end deffn
  258. @deffn {Scheme Syntax} quote expr
  259. @deffnx {Scheme Syntax} quasiquote expr
  260. @deffnx {Scheme Syntax} unquote expr
  261. @deffnx {Scheme Syntax} unquote-splicing expr
  262. @xref{Expression Syntax}, for documentation.
  263. @end deffn
  264. @deffn {Scheme Syntax} if test consequence [alternate]
  265. @deffnx {Scheme Syntax} cond clause1 clause2 ...
  266. @deffnx {Scheme Syntax} case key clause1 clause2 ...
  267. @xref{Conditionals}, for documentation.
  268. @end deffn
  269. @deffn {Scheme Syntax} and expr ...
  270. @deffnx {Scheme Syntax} or expr ...
  271. @xref{and or}, for documentation.
  272. @end deffn
  273. @deffn {Scheme Procedure} eq? x y
  274. @deffnx {Scheme Procedure} eqv? x y
  275. @deffnx {Scheme Procedure} equal? x y
  276. @deffnx {Scheme Procedure} symbol=? symbol1 symbol2 ...
  277. @xref{Equality}, for documentation.
  278. @code{symbol=?} is identical to @code{eq?}.
  279. @end deffn
  280. @deffn {Scheme Procedure} complex? z
  281. @xref{Complex Numbers}, for documentation.
  282. @end deffn
  283. @deffn {Scheme Procedure} real-part z
  284. @deffnx {Scheme Procedure} imag-part z
  285. @deffnx {Scheme Procedure} make-rectangular real_part imaginary_part
  286. @deffnx {Scheme Procedure} make-polar x y
  287. @deffnx {Scheme Procedure} magnitude z
  288. @deffnx {Scheme Procedure} angle z
  289. @xref{Complex}, for documentation.
  290. @end deffn
  291. @deffn {Scheme Procedure} sqrt z
  292. @deffnx {Scheme Procedure} exp z
  293. @deffnx {Scheme Procedure} expt z1 z2
  294. @deffnx {Scheme Procedure} log z
  295. @deffnx {Scheme Procedure} sin z
  296. @deffnx {Scheme Procedure} cos z
  297. @deffnx {Scheme Procedure} tan z
  298. @deffnx {Scheme Procedure} asin z
  299. @deffnx {Scheme Procedure} acos z
  300. @deffnx {Scheme Procedure} atan z
  301. @xref{Scientific}, for documentation.
  302. @end deffn
  303. @deffn {Scheme Procedure} real? x
  304. @deffnx {Scheme Procedure} rational? x
  305. @deffnx {Scheme Procedure} numerator x
  306. @deffnx {Scheme Procedure} denominator x
  307. @deffnx {Scheme Procedure} rationalize x eps
  308. @xref{Reals and Rationals}, for documentation.
  309. @end deffn
  310. @deffn {Scheme Procedure} exact? x
  311. @deffnx {Scheme Procedure} inexact? x
  312. @deffnx {Scheme Procedure} exact z
  313. @deffnx {Scheme Procedure} inexact z
  314. @xref{Exactness}, for documentation. The @code{exact} and
  315. @code{inexact} procedures are identical to the @code{inexact->exact} and
  316. @code{exact->inexact} procedures provided by Guile's code library.
  317. @end deffn
  318. @deffn {Scheme Procedure} integer? x
  319. @xref{Integers}, for documentation.
  320. @end deffn
  321. @deffn {Scheme Procedure} odd? n
  322. @deffnx {Scheme Procedure} even? n
  323. @deffnx {Scheme Procedure} gcd x ...
  324. @deffnx {Scheme Procedure} lcm x ...
  325. @deffnx {Scheme Procedure} exact-integer-sqrt k
  326. @xref{Integer Operations}, for documentation.
  327. @end deffn
  328. @deffn {Scheme Procedure} =
  329. @deffnx {Scheme Procedure} <
  330. @deffnx {Scheme Procedure} >
  331. @deffnx {Scheme Procedure} <=
  332. @deffnx {Scheme Procedure} >=
  333. @deffnx {Scheme Procedure} zero? x
  334. @deffnx {Scheme Procedure} positive? x
  335. @deffnx {Scheme Procedure} negative? x
  336. @xref{Comparison}, for documentation.
  337. @end deffn
  338. @deffn {Scheme Procedure} for-each f lst1 lst2 ...
  339. @xref{SRFI-1 Fold and Map}, for documentation.
  340. @end deffn
  341. @deffn {Scheme Procedure} list elem @dots{}
  342. @xref{List Constructors}, for documentation.
  343. @end deffn
  344. @deffn {Scheme Procedure} length lst
  345. @deffnx {Scheme Procedure} list-ref lst k
  346. @deffnx {Scheme Procedure} list-tail lst k
  347. @xref{List Selection}, for documentation.
  348. @end deffn
  349. @deffn {Scheme Procedure} append lst @dots{} obj
  350. @deffnx {Scheme Procedure} append
  351. @deffnx {Scheme Procedure} reverse lst
  352. @xref{Append/Reverse}, for documentation.
  353. @end deffn
  354. @deffn {Scheme Procedure} number->string n [radix]
  355. @deffnx {Scheme Procedure} string->number str [radix]
  356. @xref{Conversion}, for documentation.
  357. @end deffn
  358. @deffn {Scheme Procedure} string char ...
  359. @deffnx {Scheme Procedure} make-string k [chr]
  360. @deffnx {Scheme Procedure} list->string lst
  361. @xref{String Constructors}, for documentation.
  362. @end deffn
  363. @deffn {Scheme Procedure} string->list str [start [end]]
  364. @xref{List/String Conversion}, for documentation.
  365. @end deffn
  366. @deffn {Scheme Procedure} string-length str
  367. @deffnx {Scheme Procedure} string-ref str k
  368. @deffnx {Scheme Procedure} string-copy str [start [end]]
  369. @deffnx {Scheme Procedure} substring str start [end]
  370. @xref{String Selection}, for documentation.
  371. @end deffn
  372. @deffn {Scheme Procedure} string=? s1 s2 s3 @dots{}
  373. @deffnx {Scheme Procedure} string<? s1 s2 s3 @dots{}
  374. @deffnx {Scheme Procedure} string>? s1 s2 s3 @dots{}
  375. @deffnx {Scheme Procedure} string<=? s1 s2 s3 @dots{}
  376. @deffnx {Scheme Procedure} string>=? s1 s2 s3 @dots{}
  377. @xref{String Comparison}, for documentation.
  378. @end deffn
  379. @deffn {Scheme Procedure} string-append arg @dots{}
  380. @xref{Reversing and Appending Strings}, for documentation.
  381. @end deffn
  382. @deffn {Scheme Procedure} string-for-each proc s [start [end]]
  383. @xref{Mapping Folding and Unfolding}, for documentation.
  384. @end deffn
  385. @deffn {Scheme Procedure} + z1 ...
  386. @deffnx {Scheme Procedure} - z1 z2 ...
  387. @deffnx {Scheme Procedure} * z1 ...
  388. @deffnx {Scheme Procedure} / z1 z2 ...
  389. @deffnx {Scheme Procedure} max x1 x2 ...
  390. @deffnx {Scheme Procedure} min x1 x2 ...
  391. @deffnx {Scheme Procedure} abs x
  392. @deffnx {Scheme Procedure} truncate x
  393. @deffnx {Scheme Procedure} floor x
  394. @deffnx {Scheme Procedure} ceiling x
  395. @deffnx {Scheme Procedure} round x
  396. @xref{Arithmetic}, for documentation.
  397. @end deffn
  398. @rnindex div
  399. @rnindex mod
  400. @rnindex div-and-mod
  401. @deffn {Scheme Procedure} div x y
  402. @deffnx {Scheme Procedure} mod x y
  403. @deffnx {Scheme Procedure} div-and-mod x y
  404. These procedures accept two real numbers @var{x} and @var{y}, where the
  405. divisor @var{y} must be non-zero. @code{div} returns the integer @var{q}
  406. and @code{mod} returns the real number @var{r} such that
  407. @math{@var{x} = @var{q}*@var{y} + @var{r}} and @math{0 <= @var{r} < abs(@var{y})}.
  408. @code{div-and-mod} returns both @var{q} and @var{r}, and is more
  409. efficient than computing each separately. Note that when @math{@var{y} > 0},
  410. @code{div} returns @math{floor(@var{x}/@var{y})}, otherwise
  411. it returns @math{ceiling(@var{x}/@var{y})}.
  412. @lisp
  413. (div 123 10) @result{} 12
  414. (mod 123 10) @result{} 3
  415. (div-and-mod 123 10) @result{} 12 and 3
  416. (div-and-mod 123 -10) @result{} -12 and 3
  417. (div-and-mod -123 10) @result{} -13 and 7
  418. (div-and-mod -123 -10) @result{} 13 and 7
  419. (div-and-mod -123.2 -63.5) @result{} 2.0 and 3.8
  420. (div-and-mod 16/3 -10/7) @result{} -3 and 22/21
  421. @end lisp
  422. @end deffn
  423. @rnindex div0
  424. @rnindex mod0
  425. @rnindex div0-and-mod0
  426. @deffn {Scheme Procedure} div0 x y
  427. @deffnx {Scheme Procedure} mod0 x y
  428. @deffnx {Scheme Procedure} div0-and-mod0 x y
  429. These procedures accept two real numbers @var{x} and @var{y}, where the
  430. divisor @var{y} must be non-zero. @code{div0} returns the
  431. integer @var{q} and @code{mod0} returns the real number
  432. @var{r} such that @math{@var{x} = @var{q}*@var{y} + @var{r}} and
  433. @math{-abs(@var{y}/2) <= @var{r} < abs(@var{y}/2)}. @code{div0-and-mod0}
  434. returns both @var{q} and @var{r}, and is more efficient than computing
  435. each separately.
  436. Note that @code{div0} returns @math{@var{x}/@var{y}} rounded to the
  437. nearest integer. When @math{@var{x}/@var{y}} lies exactly half-way
  438. between two integers, the tie is broken according to the sign of
  439. @var{y}. If @math{@var{y} > 0}, ties are rounded toward positive
  440. infinity, otherwise they are rounded toward negative infinity.
  441. This is a consequence of the requirement that
  442. @math{-abs(@var{y}/2) <= @var{r} < abs(@var{y}/2)}.
  443. @lisp
  444. (div0 123 10) @result{} 12
  445. (mod0 123 10) @result{} 3
  446. (div0-and-mod0 123 10) @result{} 12 and 3
  447. (div0-and-mod0 123 -10) @result{} -12 and 3
  448. (div0-and-mod0 -123 10) @result{} -12 and -3
  449. (div0-and-mod0 -123 -10) @result{} 12 and -3
  450. (div0-and-mod0 -123.2 -63.5) @result{} 2.0 and 3.8
  451. (div0-and-mod0 16/3 -10/7) @result{} -4 and -8/21
  452. @end lisp
  453. @end deffn
  454. @deffn {Scheme Procedure} real-valued? obj
  455. @deffnx {Scheme Procedure} rational-valued? obj
  456. @deffnx {Scheme Procedure} integer-valued? obj
  457. These procedures return @code{#t} if and only if their arguments can,
  458. respectively, be coerced to a real, rational, or integer value without a
  459. loss of numerical precision.
  460. @code{real-valued?} will return @code{#t} for complex numbers whose
  461. imaginary parts are zero.
  462. @end deffn
  463. @deffn {Scheme Procedure} nan? x
  464. @deffnx {Scheme Procedure} infinite? x
  465. @deffnx {Scheme Procedure} finite? x
  466. @code{nan?} returns @code{#t} if @var{x} is a NaN value, @code{#f}
  467. otherwise. @code{infinite?} returns @code{#t} if @var{x} is an infinite
  468. value, @code{#f} otherwise. @code{finite?} returns @code{#t} if @var{x}
  469. is neither infinite nor a NaN value, otherwise it returns @code{#f}.
  470. Every real number satisfies exactly one of these predicates. An
  471. exception is raised if @var{x} is not real.
  472. @end deffn
  473. @deffn {Scheme Syntax} assert expr
  474. Raises an @code{&assertion} condition if @var{expr} evaluates to
  475. @code{#f}; otherwise evaluates to the value of @var{expr}.
  476. @end deffn
  477. @deffn {Scheme Procedure} error who message irritant1 ...
  478. @deffnx {Scheme Procedure} assertion-violation who message irritant1 ...
  479. These procedures raise compound conditions based on their arguments:
  480. If @var{who} is not @code{#f}, the condition will include a @code{&who}
  481. condition whose @code{who} field is set to @var{who}; a @code{&message}
  482. condition will be included with a @code{message} field equal to
  483. @var{message}; an @code{&irritants} condition will be included with its
  484. @code{irritants} list given by @code{irritant1 ...}.
  485. @code{error} produces a compound condition with the simple conditions
  486. described above, as well as an @code{&error} condition;
  487. @code{assertion-violation} produces one that includes an
  488. @code{&assertion} condition.
  489. @end deffn
  490. @deffn {Scheme Procedure} vector-map proc v
  491. @deffnx {Scheme Procedure} vector-for-each proc v
  492. These procedures implement the @code{map} and @code{for-each} contracts
  493. over vectors.
  494. @end deffn
  495. @deffn {Scheme Procedure} vector arg @dots{}
  496. @deffnx {Scheme Procedure} vector? obj
  497. @deffnx {Scheme Procedure} make-vector len
  498. @deffnx {Scheme Procedure} make-vector len fill
  499. @deffnx {Scheme Procedure} list->vector l
  500. @deffnx {Scheme Procedure} vector->list v
  501. @xref{Vector Creation}, for documentation.
  502. @end deffn
  503. @deffn {Scheme Procedure} vector-length vector
  504. @deffnx {Scheme Procedure} vector-ref vector k
  505. @deffnx {Scheme Procedure} vector-set! vector k obj
  506. @deffnx {Scheme Procedure} vector-fill! v fill
  507. @xref{Vector Accessors}, for documentation.
  508. @end deffn
  509. @deffn {Scheme Procedure} call-with-current-continuation proc
  510. @deffnx {Scheme Procedure} call/cc proc
  511. @xref{Continuations}, for documentation.
  512. @end deffn
  513. @deffn {Scheme Procedure} values arg @dots{}
  514. @deffnx {Scheme Procedure} call-with-values producer consumer
  515. @xref{Multiple Values}, for documentation.
  516. @end deffn
  517. @deffn {Scheme Procedure} dynamic-wind in_guard thunk out_guard
  518. @xref{Dynamic Wind}, for documentation.
  519. @end deffn
  520. @deffn {Scheme Procedure} apply proc arg @dots{} arglst
  521. @xref{Fly Evaluation}, for documentation.
  522. @end deffn
  523. @node rnrs unicode
  524. @subsubsection rnrs unicode
  525. The @code{(rnrs unicode (6))} library provides procedures for
  526. manipulating Unicode characters and strings.
  527. @deffn {Scheme Procedure} char-upcase char
  528. @deffnx {Scheme Procedure} char-downcase char
  529. @deffnx {Scheme Procedure} char-titlecase char
  530. @deffnx {Scheme Procedure} char-foldcase char
  531. These procedures translate their arguments from one Unicode character
  532. set to another. @code{char-upcase}, @code{char-downcase}, and
  533. @code{char-titlecase} are identical to their counterparts in the
  534. Guile core library; @xref{Characters}, for documentation.
  535. @code{char-foldcase} returns the result of applying @code{char-upcase}
  536. to its argument, followed by @code{char-downcase}---except in the case
  537. of the Turkic characters @code{U+0130} and @code{U+0131}, for which the
  538. procedure acts as the identity function.
  539. @end deffn
  540. @deffn {Scheme Procedure} char-ci=? char1 char2 char3 ...
  541. @deffnx {Scheme Procedure} char-ci<? char1 char2 char3 ...
  542. @deffnx {Scheme Procedure} char-ci>? char1 char2 char3 ...
  543. @deffnx {Scheme Procedure} char-ci<=? char1 char2 char3 ...
  544. @deffnx {Scheme Procedure} char-ci>=? char1 char2 char3 ...
  545. These procedures facilitate case-insensitive comparison of Unicode
  546. characters. They are identical to the procedures provided by Guile's
  547. core library. @xref{Characters}, for documentation.
  548. @end deffn
  549. @deffn {Scheme Procedure} char-alphabetic? char
  550. @deffnx {Scheme Procedure} char-numeric? char
  551. @deffnx {Scheme Procedure} char-whitespace? char
  552. @deffnx {Scheme Procedure} char-upper-case? char
  553. @deffnx {Scheme Procedure} char-lower-case? char
  554. @deffnx {Scheme Procedure} char-title-case? char
  555. These procedures implement various Unicode character set predicates.
  556. They are identical to the procedures provided by Guile's core library.
  557. @xref{Characters}, for documentation.
  558. @end deffn
  559. @deffn {Scheme Procedure} char-general-category char
  560. @xref{Characters}, for documentation.
  561. @end deffn
  562. @deffn {Scheme Procedure} string-upcase string
  563. @deffnx {Scheme Procedure} string-downcase string
  564. @deffnx {Scheme Procedure} string-titlecase string
  565. @deffnx {Scheme Procedure} string-foldcase string
  566. These procedures perform Unicode case folding operations on their input.
  567. @xref{Alphabetic Case Mapping}, for documentation.
  568. @end deffn
  569. @deffn {Scheme Procedure} string-ci=? string1 string2 string3 ...
  570. @deffnx {Scheme Procedure} string-ci<? string1 string2 string3 ...
  571. @deffnx {Scheme Procedure} string-ci>? string1 string2 string3 ...
  572. @deffnx {Scheme Procedure} string-ci<=? string1 string2 string3 ...
  573. @deffnx {Scheme Procedure} string-ci>=? string1 string2 string3 ...
  574. These procedures perform case-insensitive comparison on their input.
  575. @xref{String Comparison}, for documentation.
  576. @end deffn
  577. @deffn {Scheme Procedure} string-normalize-nfd string
  578. @deffnx {Scheme Procedure} string-normalize-nfkd string
  579. @deffnx {Scheme Procedure} string-normalize-nfc string
  580. @deffnx {Scheme Procedure} string-normalize-nfkc string
  581. These procedures perform Unicode string normalization operations on
  582. their input. @xref{String Comparison}, for documentation.
  583. @end deffn
  584. @node rnrs bytevectors
  585. @subsubsection rnrs bytevectors
  586. The @code{(rnrs bytevectors (6))} library provides procedures for
  587. working with blocks of binary data. This functionality is documented
  588. in its own section of the manual; @xref{Bytevectors}.
  589. @node rnrs lists
  590. @subsubsection rnrs lists
  591. The @code{(rnrs lists (6))} library provides procedures additional
  592. procedures for working with lists.
  593. @deffn {Scheme Procedure} find proc list
  594. This procedure is identical to the one defined in Guile's SRFI-1
  595. implementation. @xref{SRFI-1 Searching}, for documentation.
  596. @end deffn
  597. @deffn {Scheme Procedure} for-all proc list1 list2 ...
  598. @deffnx {Scheme Procedure} exists proc list1 list2 ...
  599. The @code{for-all} procedure is identical to the @code{every} procedure
  600. defined by SRFI-1; the @code{exists} procedure is identical to SRFI-1's
  601. @code{any}. @xref{SRFI-1 Searching}, for documentation.
  602. @end deffn
  603. @deffn {Scheme Procedure} filter proc list
  604. @deffnx {Scheme Procedure} partition proc list
  605. These procedures are identical to the ones provided by SRFI-1.
  606. @xref{List Modification}, for a description of @code{filter};
  607. @xref{SRFI-1 Filtering and Partitioning}, for @code{partition}.
  608. @end deffn
  609. @deffn {Scheme Procedure} fold-left combine nil list1 list2 @dots{}
  610. @deffnx {Scheme Procedure} fold-right combine nil list1 list2 @dots{}
  611. These procedures are identical to the @code{fold} and @code{fold-right}
  612. procedures provided by SRFI-1. @xref{SRFI-1 Fold and Map}, for
  613. documentation.
  614. @end deffn
  615. @deffn {Scheme Procedure} remp proc list
  616. @deffnx {Scheme Procedure} remove obj list
  617. @deffnx {Scheme Procedure} remv obj list
  618. @deffnx {Scheme Procedure} remq obj list
  619. @code{remove}, @code{remv}, and @code{remq} are identical to the
  620. @code{delete}, @code{delv}, and @code{delq} procedures provided by
  621. Guile's core library, (@pxref{List Modification}). @code{remp} is
  622. identical to the alternate @code{remove} procedure provided by SRFI-1;
  623. @xref{SRFI-1 Deleting}.
  624. @end deffn
  625. @deffn {Scheme Procedure} memp proc list
  626. @deffnx {Scheme Procedure} member obj list
  627. @deffnx {Scheme Procedure} memv obj list
  628. @deffnx {Scheme Procedure} memq obj list
  629. @code{member}, @code{memv}, and @code{memq} are identical to the
  630. procedures provided by Guile's core library; @xref{List Searching},
  631. for their documentation. @code{memp} uses the specified predicate
  632. function @code{proc} to test elements of the list @var{list}---it
  633. behaves similarly to @code{find}, except that it returns the first
  634. sublist of @var{list} whose @code{car} satisfies @var{proc}.
  635. @end deffn
  636. @deffn {Scheme Procedure} assp proc alist
  637. @deffnx {Scheme Procedure} assoc obj alist
  638. @deffnx {Scheme Procedure} assv obj alist
  639. @deffnx {Scheme Procedure} assq obj alist
  640. @code{assoc}, @code{assv}, and @code{assq} are identical to the
  641. procedures provided by Guile's core library;
  642. @xref{Alist Key Equality}, for their documentation. @code{assp} uses
  643. the specified predicate function @code{proc} to test keys in the
  644. association list @var{alist}.
  645. @end deffn
  646. @deffn {Scheme Procedure} cons* obj1 ... obj
  647. @deffnx {Scheme Procedure} cons* obj
  648. This procedure is identical to the one exported by Guile's core
  649. library. @xref{List Constructors}, for documentation.
  650. @end deffn
  651. @node rnrs sorting
  652. @subsubsection rnrs sorting
  653. The @code{(rnrs sorting (6))} library provides procedures for sorting
  654. lists and vectors.
  655. @deffn {Scheme Procedure} list-sort proc list
  656. @deffnx {Scheme Procedure} vector-sort proc vector
  657. These procedures return their input sorted in ascending order, without
  658. modifying the original data. @var{proc} must be a procedure that takes
  659. two elements from the input list or vector as arguments, and returns a
  660. true value if the first is ``less'' than the second, @code{#f}
  661. otherwise. @code{list-sort} returns a list; @code{vector-sort} returns
  662. a vector.
  663. Both @code{list-sort} and @code{vector-sort} are implemented in terms of
  664. the @code{stable-sort} procedure from Guile's core library.
  665. @xref{Sorting}, for a discussion of the behavior of that procedure.
  666. @end deffn
  667. @deffn {Scheme Procedure} vector-sort! proc vector
  668. Performs a destructive, ``in-place'' sort of @var{vector}, using
  669. @var{proc} as described above to determine an ascending ordering of
  670. elements. @code{vector-sort!} returns an unspecified value.
  671. This procedure is implemented in terms of the @code{sort!} procedure
  672. from Guile's core library. @xref{Sorting}, for more information.
  673. @end deffn
  674. @node rnrs control
  675. @subsubsection rnrs control
  676. The @code{(rnrs control (6))} library provides syntactic forms useful
  677. for constructing conditional expressions and controlling the flow of
  678. execution.
  679. @deffn {Scheme Syntax} when test expression1 expression2 ...
  680. @deffnx {Scheme Syntax} unless test expression1 expression2 ...
  681. The @code{when} form is evaluated by evaluating the specified @var{test}
  682. expression; if the result is a true value, the @var{expression}s that
  683. follow it are evaluated in order, and the value of the final
  684. @var{expression} becomes the value of the entire @code{when} expression.
  685. The @code{unless} form behaves similarly, with the exception that the
  686. specified @var{expression}s are only evaluated if the value of
  687. @var{test} is false.
  688. @end deffn
  689. @deffn {Scheme Syntax} do ((variable init step) ...) (test expression ...) command ...
  690. This form is identical to the one provided by Guile's core library.
  691. @xref{while do}, for documentation.
  692. @end deffn
  693. @deffn {Scheme Syntax} case-lambda clause ...
  694. This form is identical to the one provided by Guile's core library.
  695. @xref{Case-lambda}, for documentation.
  696. @end deffn
  697. @node R6RS Records
  698. @subsubsection R6RS Records
  699. The manual sections below describe Guile's implementation of R6RS
  700. records, which provide support for user-defined data types. The R6RS
  701. records API provides a superset of the features provided by Guile's
  702. ``native'' records, as well as those of the SRFI-9 records API;
  703. @xref{Records}, and @ref{SRFI-9}, for a description of those
  704. interfaces.
  705. As with SRFI-9 and Guile's native records, R6RS records are constructed
  706. using a record-type descriptor that specifies attributes like the
  707. record's name, its fields, and the mutability of those fields.
  708. R6RS records extend this framework to support single inheritance via the
  709. specification of a ``parent'' type for a record type at definition time.
  710. Accessors and mutator procedures for the fields of a parent type may be
  711. applied to records of a subtype of this parent. A record type may be
  712. @dfn{sealed}, in which case it cannot be used as the parent of another
  713. record type.
  714. The inheritance mechanism for record types also informs the process of
  715. initializing the fields of a record and its parents. Constructor
  716. procedures that generate new instances of a record type are obtained
  717. from a record constructor descriptor, which encapsulates the record-type
  718. descriptor of the record to be constructed along with a @dfn{protocol}
  719. procedure that defines how constructors for record subtypes delegate to
  720. the constructors of their parent types.
  721. A protocol is a procedure used by the record system at construction time
  722. to bind arguments to the fields of the record being constructed. The
  723. protocol procedure is passed a procedure @var{n} that accepts the
  724. arguments required to construct the record's parent type; this
  725. procedure, when invoked, will return a procedure @var{p} that accepts
  726. the arguments required to construct a new instance of the record type
  727. itself and returns a new instance of the record type.
  728. The protocol should in turn return a procedure that uses @var{n} and
  729. @var{p} to initialize the fields of the record type and its parent
  730. type(s). This procedure will be the constructor returned by
  731. As a trivial example, consider the hypothetical record type
  732. @code{pixel}, which encapsulates an x-y location on a screen, and
  733. @code{voxel}, which has @code{pixel} as its parent type and stores an
  734. additional coordinate. The following protocol produces a constructor
  735. procedure that accepts all three coordinates, uses the first two to
  736. initialize the fields of @code{pixel}, and binds the third to the single
  737. field of @code{voxel}.
  738. @lisp
  739. (lambda (n)
  740. (lambda (x y z)
  741. (let ((p (n x y)))
  742. (p z))))
  743. @end lisp
  744. It may be helpful to think of protocols as ``constructor factories''
  745. that produce chains of delegating constructors glued together by the
  746. helper procedure @var{n}.
  747. An R6RS record type may be declared to be @dfn{nongenerative} via the
  748. use of a unique generated or user-supplied symbol---or
  749. @dfn{uid}---such that subsequent record type declarations with the same
  750. uid and attributes will return the previously-declared record-type
  751. descriptor.
  752. R6RS record types may also be declared to be @dfn{opaque}, in which case
  753. the various predicates and introspection procedures defined in
  754. @code{(rnrs records introspection)} will behave as if records of this
  755. type are not records at all.
  756. Note that while the R6RS records API shares much of its namespace with
  757. both the SRFI-9 and native Guile records APIs, it is not currently
  758. compatible with either.
  759. @node rnrs records syntactic
  760. @subsubsection rnrs records syntactic
  761. The @code{(rnrs records syntactic (6))} library exports the syntactic
  762. API for working with R6RS records.
  763. @deffn {Scheme Syntax} define-record-type name-spec record-clause @dots{}
  764. Defines a new record type, introducing bindings for a record-type
  765. descriptor, a record constructor descriptor, a constructor procedure,
  766. a record predicate, and accessor and mutator procedures for the new
  767. record type's fields.
  768. @var{name-spec} must either be an identifier or must take the form
  769. @code{(record-name constructor-name predicate-name)}, where
  770. @var{record-name}, @var{constructor-name}, and @var{predicate-name} are
  771. all identifiers and specify the names to which, respectively, the
  772. record-type descriptor, constructor, and predicate procedures will be
  773. bound. If @var{name-spec} is only an identifier, it specifies the name
  774. to which the generated record-type descriptor will be bound.
  775. Each @var{record-clause} must be one of the following:
  776. @itemize @bullet
  777. @item
  778. @code{(fields field-spec*)}, where each @var{field-spec} specifies a
  779. field of the new record type and takes one of the following forms:
  780. @itemize @bullet
  781. @item
  782. @code{(immutable field-name accessor-name)}, which specifies an
  783. immutable field with the name @var{field-name} and binds an accessor
  784. procedure for it to the name given by @var{accessor-name}
  785. @item
  786. @code{(mutable field-name accessor-name mutator-name)}, which specifies
  787. a mutable field with the name @var{field-name} and binds accessor and
  788. mutator procedures to @var{accessor-name} and @var{mutator-name},
  789. respectively
  790. @item
  791. @code{(immutable field-name)}, which specifies an immutable field with
  792. the name @var{field-name}; an accessor procedure for it will be created
  793. and named by appending record name and @var{field-name} with a hyphen
  794. separator
  795. @item
  796. @code{(mutable field-name}), which specifies a mutable field with the
  797. name @var{field-name}; an accessor procedure for it will be created and
  798. named as described above; a mutator procedure will also be created and
  799. named by appending @code{-set!} to the accessor name
  800. @item
  801. @code{field-name}, which specifies an immutable field with the name
  802. @var{field-name}; an access procedure for it will be created and named
  803. as described above
  804. @end itemize
  805. @item
  806. @code{(parent parent-name)}, where @var{parent-name} is a symbol giving
  807. the name of the record type to be used as the parent of the new record
  808. type
  809. @item
  810. @code{(protocol expression)}, where @var{expression} evaluates to a
  811. protocol procedure which behaves as described above, and is used to
  812. create a record constructor descriptor for the new record type
  813. @item
  814. @code{(sealed sealed?)}, where @var{sealed?} is a boolean value that
  815. specifies whether or not the new record type is sealed
  816. @item
  817. @code{(opaque opaque?)}, where @var{opaque?} is a boolean value that
  818. specifies whether or not the new record type is opaque
  819. @item
  820. @code{(nongenerative [uid])}, which specifies that the record type is
  821. nongenerative via the optional uid @var{uid}. If @var{uid} is not
  822. specified, a unique uid will be generated at expansion time
  823. @item
  824. @code{(parent-rtd parent-rtd parent-cd)}, a more explicit form of the
  825. @code{parent} form above; @var{parent-rtd} and @var{parent-cd} should
  826. evaluate to a record-type descriptor and a record constructor
  827. descriptor, respectively
  828. @end itemize
  829. @end deffn
  830. @deffn {Scheme Syntax} record-type-descriptor record-name
  831. Evaluates to the record-type descriptor associated with the type
  832. specified by @var{record-name}.
  833. @end deffn
  834. @deffn {Scheme Syntax} record-constructor-descriptor record-name
  835. Evaluates to the record-constructor descriptor associated with the type
  836. specified by @var{record-name}.
  837. @end deffn
  838. @node rnrs records procedural
  839. @subsubsection rnrs records procedural
  840. The @code{(rnrs records procedural (6))} library exports the procedural
  841. API for working with R6RS records.
  842. @deffn {Scheme Procedure} make-record-type-descriptor name parent uid sealed? opaque? fields
  843. Returns a new record-type descriptor with the specified characteristics:
  844. @var{name} must be a symbol giving the name of the new record type;
  845. @var{parent} must be either @code{#f} or a non-sealed record-type
  846. descriptor for the returned record type to extend; @var{uid} must be
  847. either @code{#f}, indicating that the record type is generative, or
  848. a symbol giving the type's nongenerative uid; @var{sealed?} and
  849. @var{opaque?} must be boolean values that specify the sealedness and
  850. opaqueness of the record type; @var{fields} must be a vector of zero or
  851. more field specifiers of the form @code{(mutable name)} or
  852. @code{(immutable name)}, where name is a symbol giving a name for the
  853. field.
  854. If @var{uid} is not @code{#f}, it must be a symbol
  855. @end deffn
  856. @deffn {Scheme Procedure} record-type-descriptor? obj
  857. Returns @code{#t} if @var{obj} is a record-type descriptor, @code{#f}
  858. otherwise.
  859. @end deffn
  860. @deffn {Scheme Procedure} make-record-constructor-descriptor rtd parent-constructor-descriptor protocol
  861. Returns a new record constructor descriptor that can be used to produce
  862. constructors for the record type specified by the record-type descriptor
  863. @var{rtd} and whose delegation and binding behavior are specified by the
  864. protocol procedure @var{protocol}.
  865. @var{parent-constructor-descriptor} specifies a record constructor
  866. descriptor for the parent type of @var{rtd}, if one exists. If
  867. @var{rtd} represents a base type, then
  868. @var{parent-constructor-descriptor} must be @code{#f}. If @var{rtd}
  869. is an extension of another type, @var{parent-constructor-descriptor} may
  870. still be @code{#f}, but protocol must also be @code{#f} in this case.
  871. @end deffn
  872. @deffn {Scheme Procedure} record-constructor rcd
  873. Returns a record constructor procedure by invoking the protocol
  874. defined by the record-constructor descriptor @var{rcd}.
  875. @end deffn
  876. @deffn {Scheme Procedure} record-predicate rtd
  877. Returns the record predicate procedure for the record-type descriptor
  878. @var{rtd}.
  879. @end deffn
  880. @deffn {Scheme Procedure} record-accessor rtd k
  881. Returns the record field accessor procedure for the @var{k}th field of
  882. the record-type descriptor @var{rtd}.
  883. @end deffn
  884. @deffn {Scheme Procedure} record-mutator rtd k
  885. Returns the record field mutator procedure for the @var{k}th field of
  886. the record-type descriptor @var{rtd}. An @code{&assertion} condition
  887. will be raised if this field is not mutable.
  888. @end deffn
  889. @node rnrs records inspection
  890. @subsubsection rnrs records inspection
  891. The @code{(rnrs records inspection (6))} library provides procedures
  892. useful for accessing metadata about R6RS records.
  893. @deffn {Scheme Procedure} record? obj
  894. Return @code{#t} if the specified object is a non-opaque R6RS record,
  895. @code{#f} otherwise.
  896. @end deffn
  897. @deffn {Scheme Procedure} record-rtd record
  898. Returns the record-type descriptor for @var{record}. An
  899. @code{&assertion} is raised if @var{record} is opaque.
  900. @end deffn
  901. @deffn {Scheme Procedure} record-type-name rtd
  902. Returns the name of the record-type descriptor @var{rtd}.
  903. @end deffn
  904. @deffn {Scheme Procedure} record-type-parent rtd
  905. Returns the parent of the record-type descriptor @var{rtd}, or @code{#f}
  906. if it has none.
  907. @end deffn
  908. @deffn {Scheme Procedure} record-type-uid rtd
  909. Returns the uid of the record-type descriptor @var{rtd}, or @code{#f} if
  910. it has none.
  911. @end deffn
  912. @deffn {Scheme Procedure} record-type-generative? rtd
  913. Returns @code{#t} if the record-type descriptor @var{rtd} is generative,
  914. @code{#f} otherwise.
  915. @end deffn
  916. @deffn {Scheme Procedure} record-type-sealed? rtd
  917. Returns @code{#t} if the record-type descriptor @var{rtd} is sealed,
  918. @code{#f} otherwise.
  919. @end deffn
  920. @deffn {Scheme Procedure} record-type-opaque? rtd
  921. Returns @code{#t} if the record-type descriptor @var{rtd} is opaque,
  922. @code{#f} otherwise.
  923. @end deffn
  924. @deffn {Scheme Procedure} record-type-field-names rtd
  925. Returns a vector of symbols giving the names of the fields defined by
  926. the record-type descriptor @var{rtd} (and not any of its sub- or
  927. supertypes).
  928. @end deffn
  929. @deffn {Scheme Procedure} record-field-mutable? rtd k
  930. Returns @code{#t} if the field at index @var{k} of the record-type
  931. descriptor @var{rtd} (and not any of its sub- or supertypes) is mutable.
  932. @end deffn
  933. @node rnrs exceptions
  934. @subsubsection rnrs exceptions
  935. The @code{(rnrs exceptions (6))} library provides functionality related
  936. to signaling and handling exceptional situations. This functionality is
  937. similar to the exception handling systems provided by Guile's core
  938. library @xref{Exceptions}, and by the SRFI-18 and SRFI-34
  939. modules---@xref{SRFI-18 Exceptions}, and @ref{SRFI-34},
  940. respectively---but there are some key differences in concepts and
  941. behavior.
  942. A raised exception may be @dfn{continuable} or @dfn{non-continuable}.
  943. When an exception is raised non-continuably, another exception, with the
  944. condition type @code{&non-continuable}, will be raised when the
  945. exception handler returns locally. Raising an exception continuably
  946. captures the current continuation and invokes it after a local return
  947. from the exception handler.
  948. Like SRFI-18 and SRFI-34, R6RS exceptions are implemented on top of
  949. Guile's native @code{throw} and @code{catch} forms, and use custom
  950. ``throw keys'' to identify their exception types. As a consequence,
  951. Guile's @code{catch} form can handle exceptions thrown by these APIs,
  952. but the reverse is not true: Handlers registered by the
  953. @code{with-exception-handler} procedure described below will only be
  954. called on exceptions thrown by the corresponding @code{raise} procedure.
  955. @deffn {Scheme Procedure} with-exception-handler handler thunk
  956. Installs @var{handler}, which must be a procedure taking one argument,
  957. as the current exception handler during the invocation of @var{thunk}, a
  958. procedure taking zero arguments. The handler in place at the time
  959. @code{with-exception-handler} is called is made current again once
  960. either @var{thunk} returns or @var{handler} is invoked after an
  961. exception is thrown from within @var{thunk}.
  962. This procedure is similar to the @code{with-throw-handler} procedure
  963. provided by Guile's code library; (@pxref{Throw Handlers}).
  964. @end deffn
  965. @deffn {Scheme Syntax} guard (variable clause1 clause2 ...) body
  966. Evaluates the expression given by @var{body}, first creating an ad hoc
  967. exception handler that binds a raised exception to @var{variable} and
  968. then evaluates the specified @var{clause}s as if they were part of a
  969. @code{cond} expression, with the value of the first matching clause
  970. becoming the value of the @code{guard} expression
  971. (@pxref{Conditionals}). If none of the clause's test expressions
  972. evaluates to @code{#t}, the exception is re-raised, with the exception
  973. handler that was current before the evaluation of the @code{guard} form.
  974. For example, the expression
  975. @lisp
  976. (guard (ex ((eq? ex 'foo) 'bar) ((eq? ex 'bar) 'baz))
  977. (raise 'bar))
  978. @end lisp
  979. evaluates to @code{baz}.
  980. @end deffn
  981. @deffn {Scheme Procedure} raise obj
  982. Raises a non-continuable exception by invoking the currently-installed
  983. exception handler on @var{obj}. If the handler returns, a
  984. @code{&non-continuable} exception will be raised in the dynamic context
  985. in which the handler was installed.
  986. @end deffn
  987. @deffn {Scheme Procedure} raise-continuable obj
  988. Raises a continuable exception by invoking currently-installed exception
  989. handler on @var{obj}.
  990. @end deffn
  991. @node rnrs conditions
  992. @subsubsection rnrs conditions
  993. The @code{(rnrs condition (6))} library provides forms and procedures
  994. for constructing new condition types, as well as a library of
  995. pre-defined condition types that represent a variety of common
  996. exceptional situations. Conditions are records of a subtype of the
  997. @code{&condition} record type, which is neither sealed nor opaque.
  998. @xref{R6RS Records}.
  999. Conditions may be manipulated singly, as @dfn{simple conditions}, or
  1000. when composed with other conditions to form @dfn{compound conditions}.
  1001. Compound conditions do not ``nest''---constructing a new compound
  1002. condition out of existing compound conditions will ``flatten'' them
  1003. into their component simple conditions. For example, making a new
  1004. condition out of a @code{&message} condition and a compound condition
  1005. that contains an @code{&assertion} condition and another @code{&message}
  1006. condition will produce a compound condition that contains two
  1007. @code{&message} conditions and one @code{&assertion} condition.
  1008. The record type predicates and field accessors described below can
  1009. operate on either simple or compound conditions. In the latter case,
  1010. the predicate returns @code{#t} if the compound condition contains a
  1011. component simple condition of the appropriate type; the field accessors
  1012. return the requisite fields from the first component simple condition
  1013. found to be of the appropriate type.
  1014. This library is quite similar to the SRFI-35 conditions module
  1015. (@pxref{SRFI-35}). Among other minor differences, the
  1016. @code{(rnrs conditions)} library features slightly different semantics
  1017. around condition field accessors, and comes with a larger number of
  1018. pre-defined condition types. The two APIs are not currently compatible,
  1019. however; the @code{condition?} predicate from one API will return
  1020. @code{#f} when applied to a condition object created in the other.
  1021. @deffn {Condition Type} &condition
  1022. @deffnx {Scheme Procedure} condition? obj
  1023. The base record type for conditions.
  1024. @end deffn
  1025. @deffn {Scheme Procedure} condition condition1 ...
  1026. @deffnx {Scheme Procedure} simple-conditions condition
  1027. The @code{condition} procedure creates a new compound condition out of
  1028. its condition arguments, flattening any specified compound conditions
  1029. into their component simple conditions as described above.
  1030. @code{simple-conditions} returns a list of the component simple
  1031. conditions of the compound condition @code{condition}, in the order in
  1032. which they were specified at construction time.
  1033. @end deffn
  1034. @deffn {Scheme Procedure} condition-predicate rtd
  1035. @deffnx {Scheme Procedure} condition-accessor rtd proc
  1036. These procedures return condition predicate and accessor procedures for
  1037. the specified condition record type @var{rtd}.
  1038. @end deffn
  1039. @deffn {Scheme Syntax} define-condition-type condition-type supertype constructor predicate field-spec ...
  1040. Evaluates to a new record type definition for a condition type with the
  1041. name @var{condition-type} that has the condition type @var{supertype} as
  1042. its parent. A default constructor, which binds its arguments to the
  1043. fields of this type and its parent types, will be bound to the
  1044. identifier @var{constructor}; a condition predicate will be bound to
  1045. @var{predicate}. The fields of the new type, which are immutable, are
  1046. specified by the @var{field-spec}s, each of which must be of the form:
  1047. @lisp
  1048. (field accessor)
  1049. @end lisp
  1050. where @var{field} gives the name of the field and @var{accessor} gives
  1051. the name for a binding to an accessor procedure created for this field.
  1052. @end deffn
  1053. @deffn {Condition Type} &message
  1054. @deffnx {Scheme Procedure} make-message-condition message
  1055. @deffnx {Scheme Procedure} message-condition? obj
  1056. @deffnx {Scheme Procedure} condition-message condition
  1057. A type that includes a message describing the condition that occurred.
  1058. @end deffn
  1059. @deffn {Condition Type} &warning
  1060. @deffnx {Scheme Procedure} make-warning
  1061. @deffnx {Scheme Procedure} warning? obj
  1062. A base type for representing non-fatal conditions during execution.
  1063. @end deffn
  1064. @deffn {Condition Type} &serious
  1065. @deffnx {Scheme Procedure} make-serious-condition
  1066. @deffnx {Scheme Procedure} serious-condition? obj
  1067. A base type for conditions representing errors serious enough that
  1068. cannot be ignored.
  1069. @end deffn
  1070. @deffn {Condition Type} &error
  1071. @deffnx {Scheme Procedure} make-error
  1072. @deffnx {Scheme Procedure} error? obj
  1073. A base type for conditions representing errors.
  1074. @end deffn
  1075. @deffn {Condition Type} &violation
  1076. @deffnx {Scheme Procedure} make-violation
  1077. @deffnx {Scheme Procedure} violation?
  1078. A subtype of @code{&serious} that can be used to represent violations
  1079. of a language or library standard.
  1080. @end deffn
  1081. @deffn {Condition Type} &assertion
  1082. @deffnx {Scheme Procedure} make-assertion-violation
  1083. @deffnx {Scheme Procedure} assertion-violation? obj
  1084. A subtype of @code{&violation} that indicates an invalid call to a
  1085. procedure.
  1086. @end deffn
  1087. @deffn {Condition Type} &irritants
  1088. @deffnx {Scheme Procedure} make-irritants-condition irritants
  1089. @deffnx {Scheme Procedure} irritants-condition? obj
  1090. @deffnx {Scheme Procedure} condition-irritants condition
  1091. A base type used for storing information about the causes of another
  1092. condition in a compound condition.
  1093. @end deffn
  1094. @deffn {Condition Type} &who
  1095. @deffnx {Scheme Procedure} make-who-condition who
  1096. @deffnx {Scheme Procedure} who-condition? obj
  1097. @deffnx {Scheme Procedure} condition-who condition
  1098. A base type used for storing the identity, a string or symbol, of the
  1099. entity responsible for another condition in a compound condition.
  1100. @end deffn
  1101. @deffn {Condition Type} &non-continuable
  1102. @deffnx {Scheme Procedure} make-non-continuable-violation
  1103. @deffnx {Scheme Procedure} non-continuable-violation? obj
  1104. A subtype of @code{&violation} used to indicate that an exception
  1105. handler invoked by @code{raise} has returned locally.
  1106. @end deffn
  1107. @deffn {Condition Type} &implementation-restriction
  1108. @deffnx {Scheme Procedure} make-implementation-restriction-violation
  1109. @deffnx {Scheme Procedure} implementation-restriction-violation? obj
  1110. A subtype of @code{&violation} used to indicate a violation of an
  1111. implementation restriction.
  1112. @end deffn
  1113. @deffn {Condition Type} &lexical
  1114. @deffnx {Scheme Procedure} make-lexical-violation
  1115. @deffnx {Scheme Procedure} lexical-violation? obj
  1116. A subtype of @code{&violation} used to indicate a syntax violation at
  1117. the level of the datum syntax.
  1118. @end deffn
  1119. @deffn {Condition Type} &syntax
  1120. @deffnx {Scheme Procedure} make-syntax-violation form subform
  1121. @deffnx {Scheme Procedure} syntax-violation? obj
  1122. @deffnx {Scheme Procedure} syntax-violation-form condition
  1123. @deffnx {Scheme Procedure} syntax-violation-subform condition
  1124. A subtype of @code{&violation} that indicates a syntax violation. The
  1125. @var{form} and @var{subform} fields, which must be datum values,
  1126. indicate the syntactic form responsible for the condition.
  1127. @end deffn
  1128. @deffn {Condition Type} &undefined
  1129. @deffnx {Scheme Procedure} make-undefined-violation
  1130. @deffnx {Scheme Procedure} undefined-violation? obj
  1131. A subtype of @code{&violation} that indicates a reference to an unbound
  1132. identifier.
  1133. @end deffn
  1134. @node I/O Conditions
  1135. @subsubsection I/O Conditions
  1136. These condition types are exported by both the
  1137. @code{(rnrs io ports (6))} and @code{(rnrs io simple (6))} libraries.
  1138. @deffn {Condition Type} &i/o
  1139. @deffnx {Scheme Procedure} make-i/o-error
  1140. @deffnx {Scheme Procedure} i/o-error? obj
  1141. A condition supertype for more specific I/O errors.
  1142. @end deffn
  1143. @deffn {Condition Type} &i/o-read
  1144. @deffnx {Scheme Procedure} make-i/o-read-error
  1145. @deffnx {Scheme Procedure} i/o-read-error? obj
  1146. A subtype of @code{&i/o}; represents read-related I/O errors.
  1147. @end deffn
  1148. @deffn {Condition Type} &i/o-write
  1149. @deffnx {Scheme Procedure} make-i/o-write-error
  1150. @deffnx {Scheme Procedure} i/o-write-error? obj
  1151. A subtype of @code{&i/o}; represents write-related I/O errors.
  1152. @end deffn
  1153. @deffn {Condition Type} &i/o-invalid-position
  1154. @deffnx {Scheme Procedure} make-i/o-invalid-position-error position
  1155. @deffnx {Scheme Procedure} i/o-invalid-position-error? obj
  1156. @deffnx {Scheme Procedure} i/o-error-position condition
  1157. A subtype of @code{&i/o}; represents an error related to an attempt to
  1158. set the file position to an invalid position.
  1159. @end deffn
  1160. @deffn {Condition Type} &i/o-filename
  1161. @deffnx {Scheme Procedure} make-io-filename-error filename
  1162. @deffnx {Scheme Procedure} i/o-filename-error? obj
  1163. @deffnx {Scheme Procedure} i/o-error-filename condition
  1164. A subtype of @code{&i/o}; represents an error related to an operation on
  1165. a named file.
  1166. @end deffn
  1167. @deffn {Condition Type} &i/o-file-protection
  1168. @deffnx {Scheme Procedure} make-i/o-file-protection-error filename
  1169. @deffnx {Scheme Procedure} i/o-file-protection-error? obj
  1170. A subtype of @code{&i/o-filename}; represents an error resulting from an
  1171. attempt to access a named file for which the caller had insufficient
  1172. permissions.
  1173. @end deffn
  1174. @deffn {Condition Type} &i/o-file-is-read-only
  1175. @deffnx {Scheme Procedure} make-i/o-file-is-read-only-error filename
  1176. @deffnx {Scheme Procedure} i/o-file-is-read-only-error? obj
  1177. A subtype of @code{&i/o-file-protection}; represents an error related to
  1178. an attempt to write to a read-only file.
  1179. @end deffn
  1180. @deffn {Condition Type} &i/o-file-already-exists
  1181. @deffnx {Scheme Procedure} make-i/o-file-already-exists-error filename
  1182. @deffnx {Scheme Procedure} i/o-file-already-exists-error? obj
  1183. A subtype of @code{&i/o-filename}; represents an error related to an
  1184. operation on an existing file that was assumed not to exist.
  1185. @end deffn
  1186. @deffn {Condition Type} &i/o-file-does-not-exist
  1187. @deffnx {Scheme Procedure} make-i/o-file-does-not-exist-error
  1188. @deffnx {Scheme Procedure} i/o-file-does-not-exist-error? obj
  1189. A subtype of @code{&i/o-filename}; represents an error related to an
  1190. operation on a non-existent file that was assumed to exist.
  1191. @end deffn
  1192. @deffn {Condition Type} &i/o-port
  1193. @deffnx {Scheme Procedure} make-i/o-port-error port
  1194. @deffnx {Scheme Procedure} i/o-port-error? obj
  1195. @deffnx {Scheme Procedure} i/o-error-port condition
  1196. A subtype of @code{&i/o}; represents an error related to an operation on
  1197. the port @var{port}.
  1198. @end deffn
  1199. @node rnrs io ports
  1200. @subsubsection rnrs io ports
  1201. The @code{(rnrs io ports (6))} library provides various procedures and
  1202. syntactic forms for use in writing to and reading from ports. This
  1203. functionality is documented in its own section of the manual;
  1204. (@pxref{R6RS I/O Ports}).
  1205. @node rnrs io simple
  1206. @subsubsection rnrs io simple
  1207. The @code{(rnrs io simple (6))} library provides convenience functions
  1208. for performing textual I/O on ports. This library also exports all of
  1209. the condition types and associated procedures described in (@pxref{I/O
  1210. Conditions}). In the context of this section, when stating that a
  1211. procedure behaves ``identically'' to the corresponding procedure in
  1212. Guile's core library, this is modulo the behavior wrt. conditions: such
  1213. procedures raise the appropriate R6RS conditions in case of error, but
  1214. otherwise behave identically.
  1215. @c FIXME: remove the following note when proper condition behavior has
  1216. @c been verified.
  1217. @quotation Note
  1218. There are still known issues regarding condition-correctness; some
  1219. errors may still be thrown as native Guile exceptions instead of the
  1220. appropriate R6RS conditions.
  1221. @end quotation
  1222. @deffn {Scheme Procedure} eof-object
  1223. @deffnx {Scheme Procedure} eof-object? obj
  1224. These procedures are identical to the ones provided by the
  1225. @code{(rnrs io ports (6))} library. @xref{R6RS I/O Ports}, for
  1226. documentation.
  1227. @end deffn
  1228. @deffn {Scheme Procedure} input-port? obj
  1229. @deffnx {Scheme Procedure} output-port? obj
  1230. These procedures are identical to the ones provided by Guile's core
  1231. library. @xref{Ports}, for documentation.
  1232. @end deffn
  1233. @deffn {Scheme Procedure} call-with-input-file filename proc
  1234. @deffnx {Scheme Procedure} call-with-output-file filename proc
  1235. @deffnx {Scheme Procedure} open-input-file filename
  1236. @deffnx {Scheme Procedure} open-output-file filename
  1237. @deffnx {Scheme Procedure} with-input-from-file filename thunk
  1238. @deffnx {Scheme Procedure} with-output-to-file filename thunk
  1239. These procedures are identical to the ones provided by Guile's core
  1240. library. @xref{File Ports}, for documentation.
  1241. @end deffn
  1242. @deffn {Scheme Procedure} close-input-port input-port
  1243. @deffnx {Scheme Procedure} close-output-port output-port
  1244. These procedures are identical to the ones provided by Guile's core
  1245. library. @xref{Closing}, for documentation.
  1246. @end deffn
  1247. @deffn {Scheme Procedure} peek-char
  1248. @deffnx {Scheme Procedure} peek-char textual-input-port
  1249. @deffnx {Scheme Procedure} read-char
  1250. @deffnx {Scheme Procedure} read-char textual-input-port
  1251. These procedures are identical to the ones provided by Guile's core
  1252. library. @xref{Reading}, for documentation.
  1253. @end deffn
  1254. @deffn {Scheme Procedure} read
  1255. @deffnx {Scheme Procedure} read textual-input-port
  1256. This procedure is identical to the one provided by Guile's core library.
  1257. @xref{Scheme Read}, for documentation.
  1258. @end deffn
  1259. @deffn {Scheme Procedure} display obj
  1260. @deffnx {Scheme Procedure} display obj textual-output-port
  1261. @deffnx {Scheme Procedure} newline
  1262. @deffnx {Scheme Procedure} newline textual-output-port
  1263. @deffnx {Scheme Procedure} write obj
  1264. @deffnx {Scheme Procedure} write obj textual-output-port
  1265. @deffnx {Scheme Procedure} write-char char
  1266. @deffnx {Scheme Procedure} write-char char textual-output-port
  1267. These procedures are identical to the ones provided by Guile's core
  1268. library. @xref{Writing}, for documentation.
  1269. @end deffn
  1270. @node rnrs files
  1271. @subsubsection rnrs files
  1272. The @code{(rnrs files (6))} library provides the @code{file-exists?} and
  1273. @code{delete-file} procedures, which test for the existence of a file
  1274. and allow the deletion of files from the file system, respectively.
  1275. These procedures are identical to the ones provided by Guile's core
  1276. library. @xref{File System}, for documentation.
  1277. @node rnrs programs
  1278. @subsubsection rnrs programs
  1279. The @code{(rnrs programs (6))} library provides procedures for
  1280. process management and introspection.
  1281. @deffn {Scheme Procedure} command-line
  1282. This procedure is identical to the one provided by Guile's core library.
  1283. @xref{Runtime Environment}, for documentation.
  1284. @end deffn
  1285. @deffn {Scheme Procedure} exit
  1286. @deffnx {Scheme Procedure} exit obj
  1287. This procedure is identical to the one provided by Guile's core library.
  1288. @end deffn
  1289. @node rnrs arithmetic fixnums
  1290. @subsubsection rnrs arithmetic fixnums
  1291. The @code{(rnrs arithmetic fixnums (6))} library provides procedures for
  1292. performing arithmetic operations on an implementation-dependent range of
  1293. exact integer values, which R6RS refers to as @dfn{fixnums}. In Guile,
  1294. the size of a fixnum is determined by the size of the @code{SCM} type; a
  1295. single SCM struct is guaranteed to be able to hold an entire fixnum,
  1296. making fixnum computations particularly
  1297. efficient---(@pxref{The SCM Type}). On 32-bit systems, the most
  1298. negative and most positive fixnum values are, respectively, -536870912
  1299. and 536870911.
  1300. Unless otherwise specified, all of the procedures below take fixnums as
  1301. arguments, and will raise an @code{&assertion} condition if passed a
  1302. non-fixnum argument or an @code{&implementation-restriction} condition
  1303. if their result is not itself a fixnum.
  1304. @deffn {Scheme Procedure} fixnum? obj
  1305. Returns @code{#t} if @var{obj} is a fixnum, @code{#f} otherwise.
  1306. @end deffn
  1307. @deffn {Scheme Procedure} fixnum-width
  1308. @deffnx {Scheme Procedure} least-fixnum
  1309. @deffnx {Scheme Procedure} greatest-fixnum
  1310. These procedures return, respectively, the maximum number of bits
  1311. necessary to represent a fixnum value in Guile, the minimum fixnum
  1312. value, and the maximum fixnum value.
  1313. @end deffn
  1314. @deffn {Scheme Procedure} fx=? fx1 fx2 fx3 ...
  1315. @deffnx {Scheme Procedure} fx>? fx1 fx2 fx3 ...
  1316. @deffnx {Scheme Procedure} fx<? fx1 fx2 fx3 ...
  1317. @deffnx {Scheme Procedure} fx>=? fx1 fx2 fx3 ...
  1318. @deffnx {Scheme Procedure} fx<=? fx1 fx2 fx3 ...
  1319. These procedures return @code{#t} if their fixnum arguments are
  1320. (respectively): equal, monotonically increasing, monotonically
  1321. decreasing, monotonically nondecreasing, or monotonically nonincreasing;
  1322. @code{#f} otherwise.
  1323. @end deffn
  1324. @deffn {Scheme Procedure} fxzero? fx
  1325. @deffnx {Scheme Procedure} fxpositive? fx
  1326. @deffnx {Scheme Procedure} fxnegative? fx
  1327. @deffnx {Scheme Procedure} fxodd? fx
  1328. @deffnx {Scheme Procedure} fxeven? fx
  1329. These numerical predicates return @code{#t} if @var{fx} is,
  1330. respectively, zero, greater than zero, less than zero, odd, or even;
  1331. @code{#f} otherwise.
  1332. @end deffn
  1333. @deffn {Scheme Procedure} fxmax fx1 fx2 ...
  1334. @deffnx {Scheme Procedure} fxmin fx1 fx2 ...
  1335. These procedures return the maximum or minimum of their arguments.
  1336. @end deffn
  1337. @deffn {Scheme Procedure} fx+ fx1 fx2
  1338. @deffnx {Scheme Procedure} fx* fx1 fx2
  1339. These procedures return the sum or product of their arguments.
  1340. @end deffn
  1341. @deffn {Scheme Procedure} fx- fx1 fx2
  1342. @deffnx {Scheme Procedure} fx- fx
  1343. Returns the difference of @var{fx1} and @var{fx2}, or the negation of
  1344. @var{fx}, if called with a single argument.
  1345. An @code{&assertion} condition is raised if the result is not itself a
  1346. fixnum.
  1347. @end deffn
  1348. @deffn {Scheme Procedure} fxdiv-and-mod fx1 fx2
  1349. @deffnx {Scheme Procedure} fxdiv fx1 fx2
  1350. @deffnx {Scheme Procedure} fxmod fx1 fx2
  1351. @deffnx {Scheme Procedure} fxdiv0-and-mod0 fx1 fx2
  1352. @deffnx {Scheme Procedure} fxdiv0 fx1 fx2
  1353. @deffnx {Scheme Procedure} fxmod0 fx1 fx2
  1354. These procedures implement number-theoretic division on fixnums;
  1355. @xref{(rnrs base)}, for a description of their semantics.
  1356. @end deffn
  1357. @deffn {Scheme Procedure} fx+/carry fx1 fx2 fx3
  1358. Returns the two fixnum results of the following computation:
  1359. @lisp
  1360. (let* ((s (+ fx1 fx2 fx3))
  1361. (s0 (mod0 s (expt 2 (fixnum-width))))
  1362. (s1 (div0 s (expt 2 (fixnum-width)))))
  1363. (values s0 s1))
  1364. @end lisp
  1365. @end deffn
  1366. @deffn {Scheme Procedure} fx-/carry fx1 fx2 fx3
  1367. Returns the two fixnum results of the following computation:
  1368. @lisp
  1369. (let* ((d (- fx1 fx2 fx3))
  1370. (d0 (mod0 d (expt 2 (fixnum-width))))
  1371. (d1 (div0 d (expt 2 (fixnum-width)))))
  1372. (values d0 d1))
  1373. @end lisp
  1374. @end deffn
  1375. @deffn {Scheme Procedure} fx*/carry fx1 fx2 fx3
  1376. @lisp
  1377. Returns the two fixnum results of the following computation:
  1378. (let* ((s (+ (* fx1 fx2) fx3))
  1379. (s0 (mod0 s (expt 2 (fixnum-width))))
  1380. (s1 (div0 s (expt 2 (fixnum-width)))))
  1381. (values s0 s1))
  1382. @end lisp
  1383. @end deffn
  1384. @deffn {Scheme Procedure} fxnot fx
  1385. @deffnx {Scheme Procedure} fxand fx1 ...
  1386. @deffnx {Scheme Procedure} fxior fx1 ...
  1387. @deffnx {Scheme Procedure} fxxor fx1 ...
  1388. These procedures are identical to the @code{lognot}, @code{logand},
  1389. @code{logior}, and @code{logxor} procedures provided by Guile's core
  1390. library. @xref{Bitwise Operations}, for documentation.
  1391. @end deffn
  1392. @deffn {Scheme Procedure} fxif fx1 fx2 fx3
  1393. Returns the bitwise ``if'' of its fixnum arguments. The bit at position
  1394. @code{i} in the return value will be the @code{i}th bit from @var{fx2}
  1395. if the @code{i}th bit of @var{fx1} is 1, the @code{i}th bit from
  1396. @var{fx3}.
  1397. @end deffn
  1398. @deffn {Scheme Procedure} fxbit-count fx
  1399. Returns the number of 1 bits in the two's complement representation of
  1400. @var{fx}.
  1401. @end deffn
  1402. @deffn {Scheme Procedure} fxlength fx
  1403. Returns the number of bits necessary to represent @var{fx}.
  1404. @end deffn
  1405. @deffn {Scheme Procedure} fxfirst-bit-set fx
  1406. Returns the index of the least significant 1 bit in the two's complement
  1407. representation of @var{fx}.
  1408. @end deffn
  1409. @deffn {Scheme Procedure} fxbit-set? fx1 fx2
  1410. Returns @code{#t} if the @var{fx2}th bit in the two's complement
  1411. representation of @var{fx1} is 1, @code{#f} otherwise.
  1412. @end deffn
  1413. @deffn {Scheme Procedure} fxcopy-bit fx1 fx2 fx3
  1414. Returns the result of setting the @var{fx2}th bit of @var{fx1} to the
  1415. @var{fx2}th bit of @var{fx3}.
  1416. @end deffn
  1417. @deffn {Scheme Procedure} fxbit-field fx1 fx2 fx3
  1418. Returns the integer representation of the contiguous sequence of bits in
  1419. @var{fx1} that starts at position @var{fx2} (inclusive) and ends at
  1420. position @var{fx3} (exclusive).
  1421. @end deffn
  1422. @deffn {Scheme Procedure} fxcopy-bit-field fx1 fx2 fx3 fx4
  1423. Returns the result of replacing the bit field in @var{fx1} with start
  1424. and end positions @var{fx2} and @var{fx3} with the corresponding bit
  1425. field from @var{fx4}.
  1426. @end deffn
  1427. @deffn {Scheme Procedure} fxarithmetic-shift fx1 fx2
  1428. @deffnx {Scheme Procedure} fxarithmetic-shift-left fx1 fx2
  1429. @deffnx {Scheme Procedure} fxarithmetic-shift-right fx1 fx2
  1430. Returns the result of shifting the bits of @var{fx1} right or left by
  1431. the @var{fx2} positions. @code{fxarithmetic-shift} is identical
  1432. to @code{fxarithmetic-shift-left}.
  1433. @end deffn
  1434. @deffn {Scheme Procedure} fxrotate-bit-field fx1 fx2 fx3 fx4
  1435. Returns the result of cyclically permuting the bit field in @var{fx1}
  1436. with start and end positions @var{fx2} and @var{fx3} by @var{fx4} bits
  1437. in the direction of more significant bits.
  1438. @end deffn
  1439. @deffn {Scheme Procedure} fxreverse-bit-field fx1 fx2 fx3
  1440. Returns the result of reversing the order of the bits of @var{fx1}
  1441. between position @var{fx2} (inclusive) and position @var{fx3}
  1442. (exclusive).
  1443. @end deffn
  1444. @node rnrs arithmetic flonums
  1445. @subsubsection rnrs arithmetic flonums
  1446. The @code{(rnrs arithmetic flonums (6))} library provides procedures for
  1447. performing arithmetic operations on inexact representations of real
  1448. numbers, which R6RS refers to as @dfn{flonums}.
  1449. Unless otherwise specified, all of the procedures below take flonums as
  1450. arguments, and will raise an @code{&assertion} condition if passed a
  1451. non-flonum argument.
  1452. @deffn {Scheme Procedure} flonum? obj
  1453. Returns @code{#t} if @var{obj} is a flonum, @code{#f} otherwise.
  1454. @end deffn
  1455. @deffn {Scheme Procedure} real->flonum x
  1456. Returns the flonum that is numerically closest to the real number
  1457. @var{x}.
  1458. @end deffn
  1459. @deffn {Scheme Procedure} fl=? fl1 fl2 fl3 ...
  1460. @deffnx {Scheme Procedure} fl<? fl1 fl2 fl3 ...
  1461. @deffnx {Scheme Procedure} fl<=? fl1 fl2 fl3 ...
  1462. @deffnx {Scheme Procedure} fl>? fl1 fl2 fl3 ...
  1463. @deffnx {Scheme Procedure} fl>=? fl1 fl2 fl3 ...
  1464. These procedures return @code{#t} if their flonum arguments are
  1465. (respectively): equal, monotonically increasing, monotonically
  1466. decreasing, monotonically nondecreasing, or monotonically nonincreasing;
  1467. @code{#f} otherwise.
  1468. @end deffn
  1469. @deffn {Scheme Procedure} flinteger? fl
  1470. @deffnx {Scheme Procedure} flzero? fl
  1471. @deffnx {Scheme Procedure} flpositive? fl
  1472. @deffnx {Scheme Procedure} flnegative? fl
  1473. @deffnx {Scheme Procedure} flodd? fl
  1474. @deffnx {Scheme Procedure} fleven? fl
  1475. These numerical predicates return @code{#t} if @var{fl} is,
  1476. respectively, an integer, zero, greater than zero, less than zero, odd,
  1477. even, @code{#f} otherwise. In the case of @code{flodd?} and
  1478. @code{fleven?}, @var{fl} must be an integer-valued flonum.
  1479. @end deffn
  1480. @deffn {Scheme Procedure} flfinite? fl
  1481. @deffnx {Scheme Procedure} flinfinite? fl
  1482. @deffnx {Scheme Procedure} flnan? fl
  1483. These numerical predicates return @code{#t} if @var{fl} is,
  1484. respectively, not infinite, infinite, or a @code{NaN} value.
  1485. @end deffn
  1486. @deffn {Scheme Procedure} flmax fl1 fl2 ...
  1487. @deffnx {Scheme Procedure} flmin fl1 fl2 ...
  1488. These procedures return the maximum or minimum of their arguments.
  1489. @end deffn
  1490. @deffn {Scheme Procedure} fl+ fl1 ...
  1491. @deffnx {Scheme Procedure} fl* fl ...
  1492. These procedures return the sum or product of their arguments.
  1493. @end deffn
  1494. @deffn {Scheme Procedure} fl- fl1 fl2 ...
  1495. @deffnx {Scheme Procedure} fl- fl
  1496. @deffnx {Scheme Procedure} fl/ fl1 fl2 ...
  1497. @deffnx {Scheme Procedure} fl/ fl
  1498. These procedures return, respectively, the difference or quotient of
  1499. their arguments when called with two arguments; when called with a
  1500. single argument, they return the additive or multiplicative inverse of
  1501. @var{fl}.
  1502. @end deffn
  1503. @deffn {Scheme Procedure} flabs fl
  1504. Returns the absolute value of @var{fl}.
  1505. @end deffn
  1506. @deffn {Scheme Procedure} fldiv-and-mod fl1 fl2
  1507. @deffnx {Scheme Procedure} fldiv fl1 fl2
  1508. @deffnx {Scheme Procedure} fldmod fl1 fl2
  1509. @deffnx {Scheme Procedure} fldiv0-and-mod0 fl1 fl2
  1510. @deffnx {Scheme Procedure} fldiv0 fl1 fl2
  1511. @deffnx {Scheme Procedure} flmod0 fl1 fl2
  1512. These procedures implement number-theoretic division on flonums;
  1513. @xref{(rnrs base)}, for a description for their semantics.
  1514. @end deffn
  1515. @deffn {Scheme Procedure} flnumerator fl
  1516. @deffnx {Scheme Procedure} fldenominator fl
  1517. These procedures return the numerator or denominator of @var{fl} as a
  1518. flonum.
  1519. @end deffn
  1520. @deffn {Scheme Procedure} flfloor fl1
  1521. @deffnx {Scheme Procedure} flceiling fl
  1522. @deffnx {Scheme Procedure} fltruncate fl
  1523. @deffnx {Scheme Procedure} flround fl
  1524. These procedures are identical to the @code{floor}, @code{ceiling},
  1525. @code{truncate}, and @code{round} procedures provided by Guile's core
  1526. library. @xref{Arithmetic}, for documentation.
  1527. @end deffn
  1528. @deffn {Scheme Procedure} flexp fl
  1529. @deffnx {Scheme Procedure} fllog fl
  1530. @deffnx {Scheme Procedure} fllog fl1 fl2
  1531. @deffnx {Scheme Procedure} flsin fl
  1532. @deffnx {Scheme Procedure} flcos fl
  1533. @deffnx {Scheme Procedure} fltan fl
  1534. @deffnx {Scheme Procedure} flasin fl
  1535. @deffnx {Scheme Procedure} flacos fl
  1536. @deffnx {Scheme Procedure} flatan fl
  1537. @deffnx {Scheme Procedure} flatan fl1 fl2
  1538. These procedures, which compute the usual transcendental functions, are
  1539. the flonum variants of the procedures provided by the R6RS base library
  1540. (@pxref{(rnrs base)}).
  1541. @end deffn
  1542. @deffn {Scheme Procedure} flsqrt fl
  1543. Returns the square root of @var{fl}. If @var{fl} is @code{-0.0},
  1544. @var{-0.0} is returned; for other negative values, a @code{NaN} value
  1545. is returned.
  1546. @end deffn
  1547. @deffn {Scheme Procedure} flexpt fl1 fl2
  1548. Returns the value of @var{fl1} raised to the power of @var{fl2}.
  1549. @end deffn
  1550. The following condition types are provided to allow Scheme
  1551. implementations that do not support infinities or @code{NaN} values
  1552. to indicate that a computation resulted in such a value. Guile supports
  1553. both of these, so these conditions will never be raised by Guile's
  1554. standard libraries implementation.
  1555. @deffn {Condition Type} &no-infinities
  1556. @deffnx {Scheme Procedure} make-no-infinities-violation obj
  1557. @deffnx {Scheme Procedure} no-infinities-violation?
  1558. A condition type indicating that a computation resulted in an infinite
  1559. value on a Scheme implementation incapable of representing infinities.
  1560. @end deffn
  1561. @deffn {Condition Type} &no-nans
  1562. @deffnx {Scheme Procedure} make-no-nans-violation obj
  1563. @deffnx {Scheme Procedure} no-nans-violation? obj
  1564. A condition type indicating that a computation resulted in a @code{NaN}
  1565. value on a Scheme implementation incapable of representing @code{NaN}s.
  1566. @end deffn
  1567. @deffn {Scheme Procedure} fixnum->flonum fx
  1568. Returns the flonum that is numerically closest to the fixnum @var{fx}.
  1569. @end deffn
  1570. @node rnrs arithmetic bitwise
  1571. @subsubsection rnrs arithmetic bitwise
  1572. The @code{(rnrs arithmetic bitwise (6))} library provides procedures for
  1573. performing bitwise arithmetic operations on the two's complement
  1574. representations of fixnums.
  1575. This library and the procedures it exports share functionality with
  1576. SRFI-60, which provides support for bitwise manipulation of integers
  1577. (@pxref{SRFI-60}).
  1578. @deffn {Scheme Procedure} bitwise-not ei
  1579. @deffnx {Scheme Procedure} bitwise-and ei1 ...
  1580. @deffnx {Scheme Procedure} bitwise-ior ei1 ...
  1581. @deffnx {Scheme Procedure} bitwise-xor ei1 ...
  1582. These procedures are identical to the @code{lognot}, @code{logand},
  1583. @code{logior}, and @code{logxor} procedures provided by Guile's core
  1584. library. @xref{Bitwise Operations}, for documentation.
  1585. @end deffn
  1586. @deffn {Scheme Procedure} bitwise-if ei1 ei2 ei3
  1587. Returns the bitwise ``if'' of its arguments. The bit at position
  1588. @code{i} in the return value will be the @code{i}th bit from @var{ei2}
  1589. if the @code{i}th bit of @var{ei1} is 1, the @code{i}th bit from
  1590. @var{ei3}.
  1591. @end deffn
  1592. @deffn {Scheme Procedure} bitwise-bit-count ei
  1593. Returns the number of 1 bits in the two's complement representation of
  1594. @var{ei}.
  1595. @end deffn
  1596. @deffn {Scheme Procedure} bitwise-length ei
  1597. Returns the number of bits necessary to represent @var{ei}.
  1598. @end deffn
  1599. @deffn {Scheme Procedure} bitwise-first-bit-set ei
  1600. Returns the index of the least significant 1 bit in the two's complement
  1601. representation of @var{ei}.
  1602. @end deffn
  1603. @deffn {Scheme Procedure} bitwise-bit-set? ei1 ei2
  1604. Returns @code{#t} if the @var{ei2}th bit in the two's complement
  1605. representation of @var{ei1} is 1, @code{#f} otherwise.
  1606. @end deffn
  1607. @deffn {Scheme Procedure} bitwise-copy-bit ei1 ei2 ei3
  1608. Returns the result of setting the @var{ei2}th bit of @var{ei1} to the
  1609. @var{ei2}th bit of @var{ei3}.
  1610. @end deffn
  1611. @deffn {Scheme Procedure} bitwise-bit-field ei1 ei2 ei3
  1612. Returns the integer representation of the contiguous sequence of bits in
  1613. @var{ei1} that starts at position @var{ei2} (inclusive) and ends at
  1614. position @var{ei3} (exclusive).
  1615. @end deffn
  1616. @deffn {Scheme Procedure} bitwise-copy-bit-field ei1 ei2 ei3 ei4
  1617. Returns the result of replacing the bit field in @var{ei1} with start
  1618. and end positions @var{ei2} and @var{ei3} with the corresponding bit
  1619. field from @var{ei4}.
  1620. @end deffn
  1621. @deffn {Scheme Procedure} bitwise-arithmetic-shift ei1 ei2
  1622. @deffnx {Scheme Procedure} bitwise-arithmetic-shift-left ei1 ei2
  1623. @deffnx {Scheme Procedure} bitwise-arithmetic-shift-right ei1 ei2
  1624. Returns the result of shifting the bits of @var{ei1} right or left by
  1625. the @var{ei2} positions. @code{bitwise-arithmetic-shift} is identical
  1626. to @code{bitwise-arithmetic-shift-left}.
  1627. @end deffn
  1628. @deffn {Scheme Procedure} bitwise-rotate-bit-field ei1 ei2 ei3 ei4
  1629. Returns the result of cyclically permuting the bit field in @var{ei1}
  1630. with start and end positions @var{ei2} and @var{ei3} by @var{ei4} bits
  1631. in the direction of more significant bits.
  1632. @end deffn
  1633. @deffn {Scheme Procedure} bitwise-reverse-bit-field ei1 ei2 ei3
  1634. Returns the result of reversing the order of the bits of @var{ei1}
  1635. between position @var{ei2} (inclusive) and position @var{ei3}
  1636. (exclusive).
  1637. @end deffn
  1638. @node rnrs syntax-case
  1639. @subsubsection rnrs syntax-case
  1640. The @code{(rnrs syntax-case (6))} library provides access to the
  1641. @code{syntax-case} system for writing hygienic macros. With one
  1642. exception, all of the forms and procedures exported by this library
  1643. are ``re-exports'' of Guile's native support for @code{syntax-case};
  1644. @xref{Syntax Case}, for documentation, examples, and rationale.
  1645. @deffn {Scheme Procedure} make-variable-transformer proc
  1646. Creates a new variable transformer out of @var{proc}, a procedure that
  1647. takes a syntax object as input and returns a syntax object. If an
  1648. identifier to which the result of this procedure is bound appears on the
  1649. left-hand side of a @code{set!} expression, @var{proc} will be called
  1650. with a syntax object representing the entire @code{set!} expression,
  1651. and its return value will replace that @code{set!} expression.
  1652. @end deffn
  1653. @deffn {Scheme Syntax} syntax-case expression (literal ...) clause ...
  1654. The @code{syntax-case} pattern matching form.
  1655. @end deffn
  1656. @deffn {Scheme Syntax} syntax template
  1657. @deffnx {Scheme Syntax} quasisyntax template
  1658. @deffnx {Scheme Syntax} unsyntax template
  1659. @deffnx {Scheme Syntax} unsyntax-splicing template
  1660. These forms allow references to be made in the body of a syntax-case
  1661. output expression subform to datum and non-datum values. They are
  1662. identical to the forms provided by Guile's core library;
  1663. @xref{Syntax Case}, for documentation.
  1664. @end deffn
  1665. @deffn {Scheme Procedure} identifier? obj
  1666. @deffnx {Scheme Procedure} bound-identifier=? id1 id2
  1667. @deffnx {Scheme Procedure} free-identifier=? id1 id2
  1668. These predicate procedures operate on syntax objects representing
  1669. Scheme identifiers. @code{identifier?} returns @code{#t} if @var{obj}
  1670. represents an identifier, @code{#f} otherwise.
  1671. @code{bound-identifier=?} returns @code{#t} if and only if a binding for
  1672. @var{id1} would capture a reference to @var{id2} in the transformer's
  1673. output, or vice-versa. @code{free-identifier=?} returns @code{#t} if
  1674. and only @var{id1} and @var{id2} would refer to the same binding in the
  1675. output of the transformer, independent of any bindings introduced by the
  1676. transformer.
  1677. @end deffn
  1678. @deffn {Scheme Procedure} generate-temporaries l
  1679. Returns a list, of the same length as @var{l}, which must be a list or
  1680. a syntax object representing a list, of globally unique symbols.
  1681. @end deffn
  1682. @deffn {Scheme Procedure} syntax->datum syntax-object
  1683. @deffnx {Scheme Procedure} datum->syntax template-id datum
  1684. These procedures convert wrapped syntax objects to and from Scheme datum
  1685. values. The syntax object returned by @code{datum->syntax} shares
  1686. contextual information with the syntax object @var{template-id}.
  1687. @end deffn
  1688. @deffn {Scheme Procedure} syntax-violation whom message form
  1689. @deffnx {Scheme Procedure} syntax-violation whom message form subform
  1690. Constructs a new compound condition that includes the following
  1691. simple conditions:
  1692. @itemize @bullet
  1693. @item
  1694. If @var{whom} is not @code{#f}, a @code{&who} condition with the
  1695. @var{whom} as its field
  1696. @item
  1697. A @code{&message} condition with the specified @var{message}
  1698. @item
  1699. A @code{&syntax} condition with the specified @var{form} and optional
  1700. @var{subform} fields
  1701. @end itemize
  1702. @end deffn
  1703. @node rnrs hashtables
  1704. @subsubsection rnrs hashtables
  1705. The @code{(rnrs hashtables (6))} library provides structures and
  1706. procedures for creating and accessing hash tables. The hash tables API
  1707. defined by R6RS is substantially similar to both Guile's native hash
  1708. tables implementation as well as the one provided by SRFI-69;
  1709. @xref{Hash Tables}, and @ref{SRFI-69}, respectively. Note that you can
  1710. write portable R6RS library code that manipulates SRFI-69 hash tables
  1711. (by importing the @code{(srfi :69)} library); however, hash tables
  1712. created by one API cannot be used by another.
  1713. Like SRFI-69 hash tables---and unlike Guile's native ones---R6RS hash
  1714. tables associate hash and equality functions with a hash table at the
  1715. time of its creation. Additionally, R6RS allows for the creation
  1716. (via @code{hashtable-copy}; see below) of immutable hash tables.
  1717. @deffn {Scheme Procedure} make-eq-hashtable
  1718. @deffnx {Scheme Procedure} make-eq-hashtable k
  1719. Returns a new hash table that uses @code{eq?} to compare keys and
  1720. Guile's @code{hashq} procedure as a hash function. If @var{k} is given,
  1721. it specifies the initial capacity of the hash table.
  1722. @end deffn
  1723. @deffn {Scheme Procedure} make-eqv-hashtable
  1724. @deffnx {Scheme Procedure} make-eqv-hashtable k
  1725. Returns a new hash table that uses @code{eqv?} to compare keys and
  1726. Guile's @code{hashv} procedure as a hash function. If @var{k} is given,
  1727. it specifies the initial capacity of the hash table.
  1728. @end deffn
  1729. @deffn {Scheme Procedure} make-hashtable hash-function equiv
  1730. @deffnx {Scheme Procedure} make-hashtable hash-function equiv k
  1731. Returns a new hash table that uses @var{equiv} to compare keys and
  1732. @var{hash-function} as a hash function. @var{equiv} must be a procedure
  1733. that accepts two arguments and returns a true value if they are
  1734. equivalent, @code{#f} otherwise; @var{hash-function} must be a procedure
  1735. that accepts one argument and returns a non-negative integer.
  1736. If @var{k} is given, it specifies the initial capacity of the hash
  1737. table.
  1738. @end deffn
  1739. @deffn {Scheme Procedure} hashtable? obj
  1740. Returns @code{#t} if @var{obj} is an R6RS hash table, @code{#f}
  1741. otherwise.
  1742. @end deffn
  1743. @deffn {Scheme Procedure} hashtable-size hashtable
  1744. Returns the number of keys currently in the hash table @var{hashtable}.
  1745. @end deffn
  1746. @deffn {Scheme Procedure} hashtable-ref hashtable key default
  1747. Returns the value associated with @var{key} in the hash table
  1748. @var{hashtable}, or @var{default} if none is found.
  1749. @end deffn
  1750. @deffn {Scheme Procedure} hashtable-set! hashtable key obj
  1751. Associates the key @var{key} with the value @var{obj} in the hash table
  1752. @var{hashtable}, and returns an unspecified value. An @code{&assertion}
  1753. condition is raised if @var{hashtable} is immutable.
  1754. @end deffn
  1755. @deffn {Scheme Procedure} hashtable-delete! hashtable key
  1756. Removes any association found for the key @var{key} in the hash table
  1757. @var{hashtable}, and returns an unspecified value. An @code{&assertion}
  1758. condition is raised if @var{hashtable} is immutable.
  1759. @end deffn
  1760. @deffn {Scheme Procedure} hashtable-contains? hashtable key
  1761. Returns @code{#t} if the hash table @var{hashtable} contains an
  1762. association for the key @var{key}, @code{#f} otherwise.
  1763. @end deffn
  1764. @deffn {Scheme Procedure} hashtable-update! hashtable key proc default
  1765. Associates with @var{key} in the hash table @var{hashtable} the result
  1766. of calling @var{proc}, which must be a procedure that takes one
  1767. argument, on the value currently associated @var{key} in
  1768. @var{hashtable}---or on @var{default} if no such association exists.
  1769. An @code{&assertion} condition is raised if @var{hashtable} is
  1770. immutable.
  1771. @end deffn
  1772. @deffn {Scheme Procedure} hashtable-copy hashtable
  1773. @deffnx {Scheme Procedure} hashtable-copy hashtable mutable
  1774. Returns a copy of the hash table @var{hashtable}. If the optional
  1775. argument @var{mutable} is a true value, the new hash table will be
  1776. immutable.
  1777. @end deffn
  1778. @deffn {Scheme Procedure} hashtable-clear! hashtable
  1779. @deffnx {Scheme Procedure} hashtable-clear! hashtable k
  1780. Removes all of the associations from the hash table @var{hashtable}.
  1781. The optional argument @var{k}, which specifies a new capacity for the
  1782. hash table, is accepted by Guile's @code{(rnrs hashtables)}
  1783. implementation, but is ignored.
  1784. @end deffn
  1785. @deffn {Scheme Procedure} hashtable-keys hashtable
  1786. Returns a vector of the keys with associations in the hash table
  1787. @var{hashtable}, in an unspecified order.
  1788. @end deffn
  1789. @deffn {Scheme Procedure} hashtable-entries hashtable
  1790. Return two values---a vector of the keys with associations in the hash
  1791. table @var{hashtable}, and a vector of the values to which these keys
  1792. are mapped, in corresponding but unspecified order.
  1793. @end deffn
  1794. @deffn {Scheme Procedure} hashtable-equivalence-function hashtable
  1795. Returns the equivalence predicated use by @var{hashtable}. This
  1796. procedure returns @code{eq?} and @code{eqv?}, respectively, for hash
  1797. tables created by @code{make-eq-hashtable} and
  1798. @code{make-eqv-hashtable}.
  1799. @end deffn
  1800. @deffn {Scheme Procedure} hashtable-hash-function hashtable
  1801. Returns the hash function used by @var{hashtable}. For hash tables
  1802. created by @code{make-eq-hashtable} or @code{make-eqv-hashtable},
  1803. @code{#f} is returned.
  1804. @end deffn
  1805. @deffn {Scheme Procedure} hashtable-mutable? hashtable
  1806. Returns @code{#t} if @var{hashtable} is mutable, @code{#f} otherwise.
  1807. @end deffn
  1808. A number of hash functions are provided for convenience:
  1809. @deffn {Scheme Procedure} equal-hash obj
  1810. Returns an integer hash value for @var{obj}, based on its structure and
  1811. current contents. This hash function is suitable for use with
  1812. @code{equal?} as an equivalence function.
  1813. @end deffn
  1814. @deffn {Scheme Procedure} string-hash string
  1815. @deffnx {Scheme Procedure} symbol-hash symbol
  1816. These procedures are identical to the ones provided by Guile's core
  1817. library. @xref{Hash Table Reference}, for documentation.
  1818. @end deffn
  1819. @deffn {Scheme Procedure} string-ci-hash string
  1820. Returns an integer hash value for @var{string} based on its contents,
  1821. ignoring case. This hash function is suitable for use with
  1822. @code{string-ci=?} as an equivalence function.
  1823. @end deffn
  1824. @node rnrs enums
  1825. @subsubsection rnrs enums
  1826. The @code{(rnrs enums (6))} library provides structures and procedures
  1827. for working with enumerable sets of symbols. Guile's implementation
  1828. defines an @dfn{enum-set} record type that encapsulates a finite set of
  1829. distinct symbols, the @dfn{universe}, and a subset of these symbols,
  1830. which define the enumeration set.
  1831. The SRFI-1 list library provides a number of procedures for performing
  1832. set operations on lists; Guile's @code{(rnrs enums)} implementation
  1833. makes use of several of them. @xref{SRFI-1 Set Operations}, for
  1834. more information.
  1835. @deffn {Scheme Procedure} make-enumeration symbol-list
  1836. Returns a new enum-set whose universe and enumeration set are both equal
  1837. to @var{symbol-list}, a list of symbols.
  1838. @end deffn
  1839. @deffn {Scheme Procedure} enum-set-universe enum-set
  1840. Returns an enum-set representing the universe of @var{enum-set},
  1841. an enum-set.
  1842. @end deffn
  1843. @deffn {Scheme Procedure} enum-set-indexer enum-set
  1844. Returns a procedure that takes a single argument and returns the
  1845. zero-indexed position of that argument in the universe of
  1846. @var{enum-set}, or @code{#f} if its argument is not a member of that
  1847. universe.
  1848. @end deffn
  1849. @deffn {Scheme Procedure} enum-set-constructor enum-set
  1850. Returns a procedure that takes a single argument, a list of symbols
  1851. from the universe of @var{enum-set}, an enum-set, and returns a new
  1852. enum-set with the same universe that represents a subset containing the
  1853. specified symbols.
  1854. @end deffn
  1855. @deffn {Scheme Procedure} enum-set->list enum-set
  1856. Returns a list containing the symbols of the set represented by
  1857. @var{enum-set}, an enum-set, in the order that they appear in the
  1858. universe of @var{enum-set}.
  1859. @end deffn
  1860. @deffn {Scheme Procedure} enum-set-member? symbol enum-set
  1861. @deffnx {Scheme Procedure} enum-set-subset? enum-set1 enum-set2
  1862. @deffnx {Scheme Procedure} enum-set=? enum-set1 enum-set2
  1863. These procedures test for membership of symbols and enum-sets in other
  1864. enum-sets. @code{enum-set-member?} returns @code{#t} if and only if
  1865. @var{symbol} is a member of the subset specified by @var{enum-set}.
  1866. @code{enum-set-subset?} returns @code{#t} if and only if the universe of
  1867. @var{enum-set1} is a subset of the universe of @var{enum-set2} and
  1868. every symbol in @var{enum-set1} is present in @var{enum-set2}.
  1869. @code{enum-set=?} returns @code{#t} if and only if @var{enum-set1} is a
  1870. subset, as per @code{enum-set-subset?} of @var{enum-set2} and vice
  1871. versa.
  1872. @end deffn
  1873. @deffn {Scheme Procedure} enum-set-union enum-set1 enum-set2
  1874. @deffnx {Scheme Procedure} enum-set-intersection enum-set1 enum-set2
  1875. @deffnx {Scheme Procedure} enum-set-difference enum-set1 enum-set2
  1876. These procedures return, respectively, the union, intersection, and
  1877. difference of their enum-set arguments.
  1878. @end deffn
  1879. @deffn {Scheme Procedure} enum-set-complement enum-set
  1880. Returns @var{enum-set}'s complement (an enum-set), with regard to its
  1881. universe.
  1882. @end deffn
  1883. @deffn {Scheme Procedure} enum-set-projection enum-set1 enum-set2
  1884. Returns the projection of the enum-set @var{enum-set1} onto the universe
  1885. of the enum-set @var{enum-set2}.
  1886. @end deffn
  1887. @deffn {Scheme Syntax} define-enumeration type-name (symbol ...) constructor-syntax
  1888. Evaluates to two new definitions: A constructor bound to
  1889. @var{constructor-syntax} that behaves similarly to constructors created
  1890. by @code{enum-set-constructor}, above, and creates new @var{enum-set}s
  1891. in the universe specified by @code{(symbol ...)}; and a ``predicate
  1892. macro'' bound to @var{type-name}, which has the following form:
  1893. @lisp
  1894. (@var{type-name} sym)
  1895. @end lisp
  1896. If @var{sym} is a member of the universe specified by the @var{symbol}s
  1897. above, this form evaluates to @var{sym}. Otherwise, a @code{&syntax}
  1898. condition is raised.
  1899. @end deffn
  1900. @node rnrs
  1901. @subsubsection rnrs
  1902. The @code{(rnrs (6))} library is a composite of all of the other R6RS
  1903. standard libraries---it imports and re-exports all of their exported
  1904. procedures and syntactic forms---with the exception of the following
  1905. libraries:
  1906. @itemize @bullet
  1907. @item @code{(rnrs eval (6))}
  1908. @item @code{(rnrs mutable-pairs (6))}
  1909. @item @code{(rnrs mutable-strings (6))}
  1910. @item @code{(rnrs r5rs (6))}
  1911. @end itemize
  1912. @node rnrs eval
  1913. @subsubsection rnrs eval
  1914. The @code{(rnrs eval (6)} library provides procedures for performing
  1915. ``on-the-fly'' evaluation of expressions.
  1916. @deffn {Scheme Procedure} eval expression environment
  1917. Evaluates @var{expression}, which must be a datum representation of a
  1918. valid Scheme expression, in the environment specified by
  1919. @var{environment}. This procedure is identical to the one provided by
  1920. Guile's code library; @xref{Fly Evaluation}, for documentation.
  1921. @end deffn
  1922. @deffn {Scheme Procedure} environment import-spec ...
  1923. Constructs and returns a new environment based on the specified
  1924. @var{import-spec}s, which must be datum representations of the import
  1925. specifications used with the @code{import} form. @xref{R6RS Libraries},
  1926. for documentation.
  1927. @end deffn
  1928. @node rnrs mutable-pairs
  1929. @subsubsection rnrs mutable-pairs
  1930. The @code{(rnrs mutable-pairs (6))} library provides the @code{set-car!}
  1931. and @code{set-cdr!} procedures, which allow the @code{car} and
  1932. @code{cdr} fields of a pair to be modified.
  1933. These procedures are identical to the ones provide by Guile's core
  1934. library. @xref{Pairs}, for documentation. All pairs in Guile are
  1935. mutable; consequently, these procedures will never throw the
  1936. @code{&assertion} condition described in the R6RS libraries
  1937. specification.
  1938. @node rnrs mutable-strings
  1939. @subsubsection rnrs mutable-strings
  1940. The @code{(rnrs mutable-strings (6))} library provides the
  1941. @code{string-set!} and @code{string-fill!} procedures, which allow the
  1942. content of strings to be modified ``in-place.''
  1943. These procedures are identical to the ones provided by Guile's core
  1944. library. @xref{String Modification}, for documentation. All strings in
  1945. Guile are mutable; consequently, these procedures will never throw the
  1946. @code{&assertion} condition described in the R6RS libraries
  1947. specification.
  1948. @node rnrs r5rs
  1949. @subsubsection rnrs r5rs
  1950. The @code{(rnrs r5rs (6))} library exports bindings for some procedures
  1951. present in R5RS but omitted from the R6RS base library specification.
  1952. @deffn {Scheme Procedure} exact->inexact z
  1953. @deffnx {Scheme Procedure} inexact->exact z
  1954. These procedures are identical to the ones provided by Guile's core
  1955. library. @xref{Exactness}, for documentation.
  1956. @end deffn
  1957. @deffn {Scheme Procedure} quotient n1 n2
  1958. @deffnx {Scheme Procedure} remainder n1 n2
  1959. @deffnx {Scheme Procedure} modulo n1 n2
  1960. These procedures are identical to the ones provided by Guile's core
  1961. library. @xref{Integer Operations}, for documentation.
  1962. @end deffn
  1963. @deffn {Scheme Syntax} delay expr
  1964. @deffnx {Scheme Procedure} force promise
  1965. The @code{delay} form and the @code{force} procedure are identical to
  1966. their counterparts in Guile's core library. @xref{Delayed Evaluation},
  1967. for documentation.
  1968. @end deffn
  1969. @deffn {Scheme Procedure} null-environment n
  1970. @deffnx {Scheme Procedure} scheme-report-environment n
  1971. These procedures are identical to the ones provided by the
  1972. @code{(ice-9 r5rs)} Guile module. @xref{Environments}, for
  1973. documentation.
  1974. @end deffn
  1975. @c r6rs.texi ends here
  1976. @c Local Variables:
  1977. @c TeX-master: "guile.texi"
  1978. @c End: