r6rs.texi 110 KB

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