r6rs.texi 89 KB

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