r6rs.texi 89 KB

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