r6rs.texi 111 KB

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