r6rs.texi 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914
  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 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}. p(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. @xref{Ports}, for documentation.
  1416. @end deffn
  1417. @deffn {Scheme Procedure} port-transcoder port
  1418. Return a transcoder associated with the encoding of @var{port}.
  1419. @xref{Encoding}, and @xref{R6RS Transcoders}.
  1420. @end deffn
  1421. @deffn {Scheme Procedure} binary-port? port
  1422. Return @code{#t} if @var{port} appears to be a binary port, else return
  1423. @code{#f}. Note that Guile does not currently distinguish between
  1424. binary and textual ports, so this predicate is not a reliable indicator
  1425. of whether the port was created as a binary port. Currently, it returns
  1426. @code{#t} if and only if the port encoding is ``ISO-8859-1'', because
  1427. Guile uses this encoding when creating a binary port. @xref{Encoding},
  1428. for more details.
  1429. @end deffn
  1430. @deffn {Scheme Procedure} textual-port? port
  1431. Return @code{#t} if @var{port} appears to be a textual port, else return
  1432. @code{#f}. Note that Guile does not currently distinguish between
  1433. binary and textual ports, so this predicate is not a reliable indicator
  1434. of whether the port was created as a textual port. Currently, it always
  1435. returns @code{#t}, because all ports can be used for textual I/O in
  1436. Guile. @xref{Encoding}, for more details.
  1437. @end deffn
  1438. @deffn {Scheme Procedure} transcoded-port binary-port transcoder
  1439. The @code{transcoded-port} procedure
  1440. returns a new textual port with the specified @var{transcoder}.
  1441. Otherwise the new textual port's state is largely the same as
  1442. that of @var{binary-port}.
  1443. If @var{binary-port} is an input port, the new textual
  1444. port will be an input port and
  1445. will transcode the bytes that have not yet been read from
  1446. @var{binary-port}.
  1447. If @var{binary-port} is an output port, the new textual
  1448. port will be an output port and
  1449. will transcode output characters into bytes that are
  1450. written to the byte sink represented by @var{binary-port}.
  1451. As a side effect, however, @code{transcoded-port}
  1452. closes @var{binary-port} in
  1453. a special way that allows the new textual port to continue to
  1454. use the byte source or sink represented by @var{binary-port},
  1455. even though @var{binary-port} itself is closed and cannot
  1456. be used by the input and output operations described in this
  1457. chapter.
  1458. @end deffn
  1459. @deffn {Scheme Procedure} port-position port
  1460. Equivalent to @code{(seek @var{port} 0 SEEK_CUR)}. @xref{Random
  1461. Access}.
  1462. @end deffn
  1463. @deffn {Scheme Procedure} port-has-port-position? port
  1464. Return @code{#t} is @var{port} supports @code{port-position}.
  1465. @end deffn
  1466. @deffn {Scheme Procedure} set-port-position! port offset
  1467. Equivalent to @code{(seek @var{port} @var{offset} SEEK_SET)}.
  1468. @xref{Random Access}.
  1469. @end deffn
  1470. @deffn {Scheme Procedure} port-has-set-port-position!? port
  1471. Return @code{#t} is @var{port} supports @code{set-port-position!}.
  1472. @end deffn
  1473. @deffn {Scheme Procedure} call-with-port port proc
  1474. Call @var{proc}, passing it @var{port} and closing @var{port} upon exit
  1475. of @var{proc}. Return the return values of @var{proc}.
  1476. @end deffn
  1477. @deffn {Scheme Procedure} port-eof? input-port
  1478. Equivalent to @code{(eof-object? (lookahead-u8 @var{input-port}))}.
  1479. @end deffn
  1480. @deffn {Scheme Procedure} standard-input-port
  1481. @deffnx {Scheme Procedure} standard-output-port
  1482. @deffnx {Scheme Procedure} standard-error-port
  1483. Returns a fresh binary input port connected to standard input, or a
  1484. binary output port connected to the standard output or standard error,
  1485. respectively. Whether the port supports the @code{port-position} and
  1486. @code{set-port-position!} operations is implementation-dependent.
  1487. @end deffn
  1488. @deffn {Scheme Procedure} current-input-port
  1489. @deffnx {Scheme Procedure} current-output-port
  1490. @deffnx {Scheme Procedure} current-error-port
  1491. @xref{Default Ports}.
  1492. @end deffn
  1493. @deffn {Scheme Procedure} open-bytevector-input-port bv [transcoder]
  1494. @deffnx {Scheme Procedure} open-bytevector-output-port [transcoder]
  1495. @xref{Bytevector Ports}.
  1496. @end deffn
  1497. @deffn {Scheme Procedure} make-custom-binary-input-port id read! get-position set-position! close
  1498. @deffnx {Scheme Procedure} make-custom-binary-output-port id write! get-position set-position! close
  1499. @deffnx {Scheme Procedure} make-custom-binary-input/output-port id read! write! get-position set-position! close
  1500. @xref{Custom Ports}.
  1501. @end deffn
  1502. @deffn {Scheme Procedure} get-u8 port
  1503. @deffnx {Scheme Procedure} lookahead-u8 port
  1504. @deffnx {Scheme Procedure} get-bytevector-n port count
  1505. @deffnx {Scheme Procedure} get-bytevector-n! port bv start count
  1506. @deffnx {Scheme Procedure} get-bytevector-some port
  1507. @deffnx {Scheme Procedure} get-bytevector-all port
  1508. @deffnx {Scheme Procedure} put-u8 port octet
  1509. @deffnx {Scheme Procedure} put-bytevector port bv [start [count]]
  1510. @xref{Binary I/O}.
  1511. @end deffn
  1512. @deffn {Scheme Procedure} get-char textual-input-port
  1513. @deffnx {Scheme Procedure} lookahead-char textual-input-port
  1514. @deffnx {Scheme Procedure} get-string-n textual-input-port count
  1515. @deffnx {Scheme Procedure} get-string-n! textual-input-port string start count
  1516. @deffnx {Scheme Procedure} get-string-all textual-input-port
  1517. @deffnx {Scheme Procedure} get-line textual-input-port
  1518. @deffnx {Scheme Procedure} put-char port char
  1519. @deffnx {Scheme Procedure} put-string port string [start [count]]
  1520. @xref{Textual I/O}.
  1521. @end deffn
  1522. @deffn {Scheme Procedure} get-datum textual-input-port count
  1523. Reads an external representation from @var{textual-input-port} and returns the
  1524. datum it represents. The @code{get-datum} procedure returns the next
  1525. datum that can be parsed from the given @var{textual-input-port}, updating
  1526. @var{textual-input-port} to point exactly past the end of the external
  1527. representation of the object.
  1528. Any @emph{interlexeme space} (comment or whitespace, @pxref{Scheme
  1529. Syntax}) in the input is first skipped. If an end of file occurs after
  1530. the interlexeme space, the end-of-file object is returned.
  1531. If a character inconsistent with an external representation is
  1532. encountered in the input, an exception with condition types
  1533. @code{&lexical} and @code{&i/o-read} is raised. Also, if the end of
  1534. file is encountered after the beginning of an external representation,
  1535. but the external representation is incomplete and therefore cannot be
  1536. parsed, an exception with condition types @code{&lexical} and
  1537. @code{&i/o-read} is raised.
  1538. @end deffn
  1539. @deffn {Scheme Procedure} put-datum textual-output-port datum
  1540. @var{datum} should be a datum value. The @code{put-datum} procedure
  1541. writes an external representation of @var{datum} to
  1542. @var{textual-output-port}. The specific external representation is
  1543. implementation-dependent. However, whenever possible, an implementation
  1544. should produce a representation for which @code{get-datum}, when reading
  1545. the representation, will return an object equal (in the sense of
  1546. @code{equal?}) to @var{datum}.
  1547. @quotation Note
  1548. Not all datums may allow producing an external representation for which
  1549. @code{get-datum} will produce an object that is equal to the
  1550. original. Specifically, NaNs contained in @var{datum} may make
  1551. this impossible.
  1552. @end quotation
  1553. @quotation Note
  1554. The @code{put-datum} procedure merely writes the external
  1555. representation, but no trailing delimiter. If @code{put-datum} is
  1556. used to write several subsequent external representations to an
  1557. output port, care should be taken to delimit them properly so they can
  1558. be read back in by subsequent calls to @code{get-datum}.
  1559. @end quotation
  1560. @end deffn
  1561. @deffn {Scheme Procedure} flush-output-port port
  1562. @xref{Buffering}, for documentation on @code{force-output}.
  1563. @end deffn
  1564. @node R6RS File Ports
  1565. @subsubsection R6RS File Ports
  1566. The facilities described in this section are exported by the @code{(rnrs
  1567. io ports)} module.
  1568. @deffn {Scheme Syntax} buffer-mode @var{buffer-mode-symbol}
  1569. @var{buffer-mode-symbol} must be a symbol whose name is one of
  1570. @code{none}, @code{line}, and @code{block}. The result is the
  1571. corresponding symbol, and specifies the associated buffer mode.
  1572. @xref{Buffering}, for a discussion of these different buffer modes. To
  1573. control the amount of buffering, use @code{setvbuf} instead. Note that
  1574. only the name of @var{buffer-mode-symbol} is significant.
  1575. @xref{Buffering}, for a discussion of port buffering.
  1576. @end deffn
  1577. @deffn {Scheme Procedure} buffer-mode? obj
  1578. Returns @code{#t} if the argument is a valid buffer-mode symbol, and
  1579. returns @code{#f} otherwise.
  1580. @end deffn
  1581. When opening a file, the various procedures accept a @code{file-options}
  1582. object that encapsulates flags to specify how the file is to be
  1583. opened. A @code{file-options} object is an enum-set (@pxref{rnrs enums})
  1584. over the symbols constituting valid file options.
  1585. A @var{file-options} parameter name means that the corresponding
  1586. argument must be a file-options object.
  1587. @deffn {Scheme Syntax} file-options @var{file-options-symbol} ...
  1588. Each @var{file-options-symbol} must be a symbol.
  1589. The @code{file-options} syntax returns a file-options object that
  1590. encapsulates the specified options.
  1591. When supplied to an operation that opens a file for output, the
  1592. file-options object returned by @code{(file-options)} specifies that the
  1593. file is created if it does not exist and an exception with condition
  1594. type @code{&i/o-file-already-exists} is raised if it does exist. The
  1595. following standard options can be included to modify the default
  1596. behavior.
  1597. @table @code
  1598. @item no-create
  1599. If the file does not already exist, it is not created;
  1600. instead, an exception with condition type @code{&i/o-file-does-not-exist}
  1601. is raised.
  1602. If the file already exists, the exception with condition type
  1603. @code{&i/o-file-already-exists} is not raised
  1604. and the file is truncated to zero length.
  1605. @item no-fail
  1606. If the file already exists, the exception with condition type
  1607. @code{&i/o-file-already-exists} is not raised,
  1608. even if @code{no-create} is not included,
  1609. and the file is truncated to zero length.
  1610. @item no-truncate
  1611. If the file already exists and the exception with condition type
  1612. @code{&i/o-file-already-exists} has been inhibited by inclusion of
  1613. @code{no-create} or @code{no-fail}, the file is not truncated, but
  1614. the port's current position is still set to the beginning of the
  1615. file.
  1616. @end table
  1617. These options have no effect when a file is opened only for input.
  1618. Symbols other than those listed above may be used as
  1619. @var{file-options-symbol}s; they have implementation-specific meaning,
  1620. if any.
  1621. @quotation Note
  1622. Only the name of @var{file-options-symbol} is significant.
  1623. @end quotation
  1624. @end deffn
  1625. @deffn {Scheme Procedure} open-file-input-port filename
  1626. @deffnx {Scheme Procedure} open-file-input-port filename file-options
  1627. @deffnx {Scheme Procedure} open-file-input-port filename file-options buffer-mode
  1628. @deffnx {Scheme Procedure} open-file-input-port filename file-options buffer-mode maybe-transcoder
  1629. @var{maybe-transcoder} must be either a transcoder or @code{#f}.
  1630. The @code{open-file-input-port} procedure returns an
  1631. input port for the named file. The @var{file-options} and
  1632. @var{maybe-transcoder} arguments are optional.
  1633. The @var{file-options} argument, which may determine various aspects of
  1634. the returned port, defaults to the value of @code{(file-options)}.
  1635. The @var{buffer-mode} argument, if supplied,
  1636. must be one of the symbols that name a buffer mode.
  1637. The @var{buffer-mode} argument defaults to @code{block}.
  1638. If @var{maybe-transcoder} is a transcoder, it becomes the transcoder associated
  1639. with the returned port.
  1640. If @var{maybe-transcoder} is @code{#f} or absent,
  1641. the port will be a binary port and will support the
  1642. @code{port-position} and @code{set-port-position!} operations.
  1643. Otherwise the port will be a textual port, and whether it supports
  1644. the @code{port-position} and @code{set-port-position!} operations
  1645. is implementation-dependent (and possibly transcoder-dependent).
  1646. @end deffn
  1647. @deffn {Scheme Procedure} open-file-output-port filename
  1648. @deffnx {Scheme Procedure} open-file-output-port filename file-options
  1649. @deffnx {Scheme Procedure} open-file-output-port filename file-options buffer-mode
  1650. @deffnx {Scheme Procedure} open-file-output-port filename file-options buffer-mode maybe-transcoder
  1651. @var{maybe-transcoder} must be either a transcoder or @code{#f}.
  1652. The @code{open-file-output-port} procedure returns an output port for the named file.
  1653. The @var{file-options} argument, which may determine various aspects of
  1654. the returned port, defaults to the value of @code{(file-options)}.
  1655. The @var{buffer-mode} argument, if supplied,
  1656. must be one of the symbols that name a buffer mode.
  1657. The @var{buffer-mode} argument defaults to @code{block}.
  1658. If @var{maybe-transcoder} is a transcoder, it becomes the transcoder
  1659. associated with the port.
  1660. If @var{maybe-transcoder} is @code{#f} or absent,
  1661. the port will be a binary port and will support the
  1662. @code{port-position} and @code{set-port-position!} operations.
  1663. Otherwise the port will be a textual port, and whether it supports
  1664. the @code{port-position} and @code{set-port-position!} operations
  1665. is implementation-dependent (and possibly transcoder-dependent).
  1666. @end deffn
  1667. @node rnrs io simple
  1668. @subsubsection rnrs io simple
  1669. The @code{(rnrs io simple (6))} library provides convenience functions
  1670. for performing textual I/O on ports. This library also exports all of
  1671. the condition types and associated procedures described in (@pxref{R6RS
  1672. I/O Conditions}). In the context of this section, when stating that a
  1673. procedure behaves ``identically'' to the corresponding procedure in
  1674. Guile's core library, this is modulo the behavior wrt. conditions: such
  1675. procedures raise the appropriate R6RS conditions in case of error, but
  1676. otherwise behave identically.
  1677. @c FIXME: remove the following note when proper condition behavior has
  1678. @c been verified.
  1679. @quotation Note
  1680. There are still known issues regarding condition-correctness; some
  1681. errors may still be thrown as native Guile exceptions instead of the
  1682. appropriate R6RS conditions.
  1683. @end quotation
  1684. @deffn {Scheme Procedure} eof-object
  1685. @deffnx {Scheme Procedure} eof-object? obj
  1686. These procedures are identical to the ones provided by the @code{(rnrs
  1687. io ports (6))} library. @xref{rnrs io ports}, for documentation.
  1688. @end deffn
  1689. @deffn {Scheme Procedure} input-port? obj
  1690. @deffnx {Scheme Procedure} output-port? obj
  1691. These procedures are identical to the ones provided by Guile's core
  1692. library. @xref{Ports}, for documentation.
  1693. @end deffn
  1694. @deffn {Scheme Procedure} call-with-input-file filename proc
  1695. @deffnx {Scheme Procedure} call-with-output-file filename proc
  1696. @deffnx {Scheme Procedure} open-input-file filename
  1697. @deffnx {Scheme Procedure} open-output-file filename
  1698. @deffnx {Scheme Procedure} with-input-from-file filename thunk
  1699. @deffnx {Scheme Procedure} with-output-to-file filename thunk
  1700. These procedures are identical to the ones provided by Guile's core
  1701. library. @xref{File Ports}, for documentation.
  1702. @end deffn
  1703. @deffn {Scheme Procedure} close-input-port input-port
  1704. @deffnx {Scheme Procedure} close-output-port output-port
  1705. Closes the given @var{input-port} or @var{output-port}. These are
  1706. legacy interfaces; just use @code{close-port}.
  1707. @end deffn
  1708. @deffn {Scheme Procedure} peek-char
  1709. @deffnx {Scheme Procedure} peek-char textual-input-port
  1710. @deffnx {Scheme Procedure} read-char
  1711. @deffnx {Scheme Procedure} read-char textual-input-port
  1712. These procedures are identical to the ones provided by Guile's core
  1713. library. @xref{Venerable Port Interfaces}, for documentation.
  1714. @end deffn
  1715. @deffn {Scheme Procedure} read
  1716. @deffnx {Scheme Procedure} read textual-input-port
  1717. This procedure is identical to the one provided by Guile's core library.
  1718. @xref{Scheme Read}, for documentation.
  1719. @end deffn
  1720. @deffn {Scheme Procedure} display obj
  1721. @deffnx {Scheme Procedure} display obj textual-output-port
  1722. @deffnx {Scheme Procedure} newline
  1723. @deffnx {Scheme Procedure} newline textual-output-port
  1724. @deffnx {Scheme Procedure} write obj
  1725. @deffnx {Scheme Procedure} write obj textual-output-port
  1726. @deffnx {Scheme Procedure} write-char char
  1727. @deffnx {Scheme Procedure} write-char char textual-output-port
  1728. These procedures are identical to the ones provided by Guile's core
  1729. library. @xref{Venerable Port Interfaces}, and @xref{Scheme Write}, for
  1730. documentation.
  1731. @end deffn
  1732. @node rnrs files
  1733. @subsubsection rnrs files
  1734. The @code{(rnrs files (6))} library provides the @code{file-exists?} and
  1735. @code{delete-file} procedures, which test for the existence of a file
  1736. and allow the deletion of files from the file system, respectively.
  1737. These procedures are identical to the ones provided by Guile's core
  1738. library. @xref{File System}, for documentation.
  1739. @node rnrs programs
  1740. @subsubsection rnrs programs
  1741. The @code{(rnrs programs (6))} library provides procedures for
  1742. process management and introspection.
  1743. @deffn {Scheme Procedure} command-line
  1744. This procedure is identical to the one provided by Guile's core library.
  1745. @xref{Runtime Environment}, for documentation.
  1746. @end deffn
  1747. @deffn {Scheme Procedure} exit [status]
  1748. This procedure is identical to the one provided by Guile's core
  1749. library. @xref{Processes}, for documentation.
  1750. @end deffn
  1751. @node rnrs arithmetic fixnums
  1752. @subsubsection rnrs arithmetic fixnums
  1753. The @code{(rnrs arithmetic fixnums (6))} library provides procedures for
  1754. performing arithmetic operations on an implementation-dependent range of
  1755. exact integer values, which R6RS refers to as @dfn{fixnums}. In Guile,
  1756. the size of a fixnum is determined by the size of the @code{SCM} type; a
  1757. single SCM struct is guaranteed to be able to hold an entire fixnum,
  1758. making fixnum computations particularly
  1759. efficient---(@pxref{The SCM Type}). On 32-bit systems, the most
  1760. negative and most positive fixnum values are, respectively, -536870912
  1761. and 536870911.
  1762. Unless otherwise specified, all of the procedures below take fixnums as
  1763. arguments, and will raise an @code{&assertion} condition if passed a
  1764. non-fixnum argument or an @code{&implementation-restriction} condition
  1765. if their result is not itself a fixnum.
  1766. @deffn {Scheme Procedure} fixnum? obj
  1767. Returns @code{#t} if @var{obj} is a fixnum, @code{#f} otherwise.
  1768. @end deffn
  1769. @deffn {Scheme Procedure} fixnum-width
  1770. @deffnx {Scheme Procedure} least-fixnum
  1771. @deffnx {Scheme Procedure} greatest-fixnum
  1772. These procedures return, respectively, the maximum number of bits
  1773. necessary to represent a fixnum value in Guile, the minimum fixnum
  1774. value, and the maximum fixnum value.
  1775. @end deffn
  1776. @deffn {Scheme Procedure} fx=? fx1 fx2 fx3 ...
  1777. @deffnx {Scheme Procedure} fx>? fx1 fx2 fx3 ...
  1778. @deffnx {Scheme Procedure} fx<? fx1 fx2 fx3 ...
  1779. @deffnx {Scheme Procedure} fx>=? fx1 fx2 fx3 ...
  1780. @deffnx {Scheme Procedure} fx<=? fx1 fx2 fx3 ...
  1781. These procedures return @code{#t} if their fixnum arguments are
  1782. (respectively): equal, monotonically increasing, monotonically
  1783. decreasing, monotonically nondecreasing, or monotonically nonincreasing;
  1784. @code{#f} otherwise.
  1785. @end deffn
  1786. @deffn {Scheme Procedure} fxzero? fx
  1787. @deffnx {Scheme Procedure} fxpositive? fx
  1788. @deffnx {Scheme Procedure} fxnegative? fx
  1789. @deffnx {Scheme Procedure} fxodd? fx
  1790. @deffnx {Scheme Procedure} fxeven? fx
  1791. These numerical predicates return @code{#t} if @var{fx} is,
  1792. respectively, zero, greater than zero, less than zero, odd, or even;
  1793. @code{#f} otherwise.
  1794. @end deffn
  1795. @deffn {Scheme Procedure} fxmax fx1 fx2 ...
  1796. @deffnx {Scheme Procedure} fxmin fx1 fx2 ...
  1797. These procedures return the maximum or minimum of their arguments.
  1798. @end deffn
  1799. @deffn {Scheme Procedure} fx+ fx1 fx2
  1800. @deffnx {Scheme Procedure} fx* fx1 fx2
  1801. These procedures return the sum or product of their arguments.
  1802. @end deffn
  1803. @deffn {Scheme Procedure} fx- fx1 fx2
  1804. @deffnx {Scheme Procedure} fx- fx
  1805. Returns the difference of @var{fx1} and @var{fx2}, or the negation of
  1806. @var{fx}, if called with a single argument.
  1807. An @code{&assertion} condition is raised if the result is not itself a
  1808. fixnum.
  1809. @end deffn
  1810. @deffn {Scheme Procedure} fxdiv-and-mod fx1 fx2
  1811. @deffnx {Scheme Procedure} fxdiv fx1 fx2
  1812. @deffnx {Scheme Procedure} fxmod fx1 fx2
  1813. @deffnx {Scheme Procedure} fxdiv0-and-mod0 fx1 fx2
  1814. @deffnx {Scheme Procedure} fxdiv0 fx1 fx2
  1815. @deffnx {Scheme Procedure} fxmod0 fx1 fx2
  1816. These procedures implement number-theoretic division on fixnums;
  1817. @xref{(rnrs base)}, for a description of their semantics.
  1818. @end deffn
  1819. @deffn {Scheme Procedure} fx+/carry fx1 fx2 fx3
  1820. Returns the two fixnum results of the following computation:
  1821. @lisp
  1822. (let* ((s (+ fx1 fx2 fx3))
  1823. (s0 (mod0 s (expt 2 (fixnum-width))))
  1824. (s1 (div0 s (expt 2 (fixnum-width)))))
  1825. (values s0 s1))
  1826. @end lisp
  1827. @end deffn
  1828. @deffn {Scheme Procedure} fx-/carry fx1 fx2 fx3
  1829. Returns the two fixnum results of the following computation:
  1830. @lisp
  1831. (let* ((d (- fx1 fx2 fx3))
  1832. (d0 (mod0 d (expt 2 (fixnum-width))))
  1833. (d1 (div0 d (expt 2 (fixnum-width)))))
  1834. (values d0 d1))
  1835. @end lisp
  1836. @end deffn
  1837. @deffn {Scheme Procedure} fx*/carry fx1 fx2 fx3
  1838. @lisp
  1839. Returns the two fixnum results of the following computation:
  1840. (let* ((s (+ (* fx1 fx2) fx3))
  1841. (s0 (mod0 s (expt 2 (fixnum-width))))
  1842. (s1 (div0 s (expt 2 (fixnum-width)))))
  1843. (values s0 s1))
  1844. @end lisp
  1845. @end deffn
  1846. @deffn {Scheme Procedure} fxnot fx
  1847. @deffnx {Scheme Procedure} fxand fx1 ...
  1848. @deffnx {Scheme Procedure} fxior fx1 ...
  1849. @deffnx {Scheme Procedure} fxxor fx1 ...
  1850. These procedures are identical to the @code{lognot}, @code{logand},
  1851. @code{logior}, and @code{logxor} procedures provided by Guile's core
  1852. library. @xref{Bitwise Operations}, for documentation.
  1853. @end deffn
  1854. @deffn {Scheme Procedure} fxif fx1 fx2 fx3
  1855. Returns the bitwise ``if'' of its fixnum arguments. The bit at position
  1856. @code{i} in the return value will be the @code{i}th bit from @var{fx2}
  1857. if the @code{i}th bit of @var{fx1} is 1, the @code{i}th bit from
  1858. @var{fx3}.
  1859. @end deffn
  1860. @deffn {Scheme Procedure} fxbit-count fx
  1861. Returns the number of 1 bits in the two's complement representation of
  1862. @var{fx}.
  1863. @end deffn
  1864. @deffn {Scheme Procedure} fxlength fx
  1865. Returns the number of bits necessary to represent @var{fx}.
  1866. @end deffn
  1867. @deffn {Scheme Procedure} fxfirst-bit-set fx
  1868. Returns the index of the least significant 1 bit in the two's complement
  1869. representation of @var{fx}.
  1870. @end deffn
  1871. @deffn {Scheme Procedure} fxbit-set? fx1 fx2
  1872. Returns @code{#t} if the @var{fx2}th bit in the two's complement
  1873. representation of @var{fx1} is 1, @code{#f} otherwise.
  1874. @end deffn
  1875. @deffn {Scheme Procedure} fxcopy-bit fx1 fx2 fx3
  1876. Returns the result of setting the @var{fx2}th bit of @var{fx1} to the
  1877. @var{fx2}th bit of @var{fx3}.
  1878. @end deffn
  1879. @deffn {Scheme Procedure} fxbit-field fx1 fx2 fx3
  1880. Returns the integer representation of the contiguous sequence of bits in
  1881. @var{fx1} that starts at position @var{fx2} (inclusive) and ends at
  1882. position @var{fx3} (exclusive).
  1883. @end deffn
  1884. @deffn {Scheme Procedure} fxcopy-bit-field fx1 fx2 fx3 fx4
  1885. Returns the result of replacing the bit field in @var{fx1} with start
  1886. and end positions @var{fx2} and @var{fx3} with the corresponding bit
  1887. field from @var{fx4}.
  1888. @end deffn
  1889. @deffn {Scheme Procedure} fxarithmetic-shift fx1 fx2
  1890. @deffnx {Scheme Procedure} fxarithmetic-shift-left fx1 fx2
  1891. @deffnx {Scheme Procedure} fxarithmetic-shift-right fx1 fx2
  1892. Returns the result of shifting the bits of @var{fx1} right or left by
  1893. the @var{fx2} positions. @code{fxarithmetic-shift} is identical
  1894. to @code{fxarithmetic-shift-left}.
  1895. @end deffn
  1896. @deffn {Scheme Procedure} fxrotate-bit-field fx1 fx2 fx3 fx4
  1897. Returns the result of cyclically permuting the bit field in @var{fx1}
  1898. with start and end positions @var{fx2} and @var{fx3} by @var{fx4} bits
  1899. in the direction of more significant bits.
  1900. @end deffn
  1901. @deffn {Scheme Procedure} fxreverse-bit-field fx1 fx2 fx3
  1902. Returns the result of reversing the order of the bits of @var{fx1}
  1903. between position @var{fx2} (inclusive) and position @var{fx3}
  1904. (exclusive).
  1905. @end deffn
  1906. @node rnrs arithmetic flonums
  1907. @subsubsection rnrs arithmetic flonums
  1908. The @code{(rnrs arithmetic flonums (6))} library provides procedures for
  1909. performing arithmetic operations on inexact representations of real
  1910. numbers, which R6RS refers to as @dfn{flonums}.
  1911. Unless otherwise specified, all of the procedures below take flonums as
  1912. arguments, and will raise an @code{&assertion} condition if passed a
  1913. non-flonum argument.
  1914. @deffn {Scheme Procedure} flonum? obj
  1915. Returns @code{#t} if @var{obj} is a flonum, @code{#f} otherwise.
  1916. @end deffn
  1917. @deffn {Scheme Procedure} real->flonum x
  1918. Returns the flonum that is numerically closest to the real number
  1919. @var{x}.
  1920. @end deffn
  1921. @deffn {Scheme Procedure} fl=? fl1 fl2 fl3 ...
  1922. @deffnx {Scheme Procedure} fl<? fl1 fl2 fl3 ...
  1923. @deffnx {Scheme Procedure} fl<=? fl1 fl2 fl3 ...
  1924. @deffnx {Scheme Procedure} fl>? fl1 fl2 fl3 ...
  1925. @deffnx {Scheme Procedure} fl>=? fl1 fl2 fl3 ...
  1926. These procedures return @code{#t} if their flonum arguments are
  1927. (respectively): equal, monotonically increasing, monotonically
  1928. decreasing, monotonically nondecreasing, or monotonically nonincreasing;
  1929. @code{#f} otherwise.
  1930. @end deffn
  1931. @deffn {Scheme Procedure} flinteger? fl
  1932. @deffnx {Scheme Procedure} flzero? fl
  1933. @deffnx {Scheme Procedure} flpositive? fl
  1934. @deffnx {Scheme Procedure} flnegative? fl
  1935. @deffnx {Scheme Procedure} flodd? fl
  1936. @deffnx {Scheme Procedure} fleven? fl
  1937. These numerical predicates return @code{#t} if @var{fl} is,
  1938. respectively, an integer, zero, greater than zero, less than zero, odd,
  1939. even, @code{#f} otherwise. In the case of @code{flodd?} and
  1940. @code{fleven?}, @var{fl} must be an integer-valued flonum.
  1941. @end deffn
  1942. @deffn {Scheme Procedure} flfinite? fl
  1943. @deffnx {Scheme Procedure} flinfinite? fl
  1944. @deffnx {Scheme Procedure} flnan? fl
  1945. These numerical predicates return @code{#t} if @var{fl} is,
  1946. respectively, not infinite, infinite, or a @code{NaN} value.
  1947. @end deffn
  1948. @deffn {Scheme Procedure} flmax fl1 fl2 ...
  1949. @deffnx {Scheme Procedure} flmin fl1 fl2 ...
  1950. These procedures return the maximum or minimum of their arguments.
  1951. @end deffn
  1952. @deffn {Scheme Procedure} fl+ fl1 ...
  1953. @deffnx {Scheme Procedure} fl* fl ...
  1954. These procedures return the sum or product of their arguments.
  1955. @end deffn
  1956. @deffn {Scheme Procedure} fl- fl1 fl2 ...
  1957. @deffnx {Scheme Procedure} fl- fl
  1958. @deffnx {Scheme Procedure} fl/ fl1 fl2 ...
  1959. @deffnx {Scheme Procedure} fl/ fl
  1960. These procedures return, respectively, the difference or quotient of
  1961. their arguments when called with two arguments; when called with a
  1962. single argument, they return the additive or multiplicative inverse of
  1963. @var{fl}.
  1964. @end deffn
  1965. @deffn {Scheme Procedure} flabs fl
  1966. Returns the absolute value of @var{fl}.
  1967. @end deffn
  1968. @deffn {Scheme Procedure} fldiv-and-mod fl1 fl2
  1969. @deffnx {Scheme Procedure} fldiv fl1 fl2
  1970. @deffnx {Scheme Procedure} fldmod fl1 fl2
  1971. @deffnx {Scheme Procedure} fldiv0-and-mod0 fl1 fl2
  1972. @deffnx {Scheme Procedure} fldiv0 fl1 fl2
  1973. @deffnx {Scheme Procedure} flmod0 fl1 fl2
  1974. These procedures implement number-theoretic division on flonums;
  1975. @xref{(rnrs base)}, for a description for their semantics.
  1976. @end deffn
  1977. @deffn {Scheme Procedure} flnumerator fl
  1978. @deffnx {Scheme Procedure} fldenominator fl
  1979. These procedures return the numerator or denominator of @var{fl} as a
  1980. flonum.
  1981. @end deffn
  1982. @deffn {Scheme Procedure} flfloor fl1
  1983. @deffnx {Scheme Procedure} flceiling fl
  1984. @deffnx {Scheme Procedure} fltruncate fl
  1985. @deffnx {Scheme Procedure} flround fl
  1986. These procedures are identical to the @code{floor}, @code{ceiling},
  1987. @code{truncate}, and @code{round} procedures provided by Guile's core
  1988. library. @xref{Arithmetic}, for documentation.
  1989. @end deffn
  1990. @deffn {Scheme Procedure} flexp fl
  1991. @deffnx {Scheme Procedure} fllog fl
  1992. @deffnx {Scheme Procedure} fllog fl1 fl2
  1993. @deffnx {Scheme Procedure} flsin fl
  1994. @deffnx {Scheme Procedure} flcos fl
  1995. @deffnx {Scheme Procedure} fltan fl
  1996. @deffnx {Scheme Procedure} flasin fl
  1997. @deffnx {Scheme Procedure} flacos fl
  1998. @deffnx {Scheme Procedure} flatan fl
  1999. @deffnx {Scheme Procedure} flatan fl1 fl2
  2000. These procedures, which compute the usual transcendental functions, are
  2001. the flonum variants of the procedures provided by the R6RS base library
  2002. (@pxref{(rnrs base)}).
  2003. @end deffn
  2004. @deffn {Scheme Procedure} flsqrt fl
  2005. Returns the square root of @var{fl}. If @var{fl} is @code{-0.0},
  2006. @var{-0.0} is returned; for other negative values, a @code{NaN} value
  2007. is returned.
  2008. @end deffn
  2009. @deffn {Scheme Procedure} flexpt fl1 fl2
  2010. Returns the value of @var{fl1} raised to the power of @var{fl2}.
  2011. @end deffn
  2012. The following condition types are provided to allow Scheme
  2013. implementations that do not support infinities or @code{NaN} values
  2014. to indicate that a computation resulted in such a value. Guile supports
  2015. both of these, so these conditions will never be raised by Guile's
  2016. standard libraries implementation.
  2017. @deffn {Condition Type} &no-infinities
  2018. @deffnx {Scheme Procedure} make-no-infinities-violation obj
  2019. @deffnx {Scheme Procedure} no-infinities-violation?
  2020. A condition type indicating that a computation resulted in an infinite
  2021. value on a Scheme implementation incapable of representing infinities.
  2022. @end deffn
  2023. @deffn {Condition Type} &no-nans
  2024. @deffnx {Scheme Procedure} make-no-nans-violation obj
  2025. @deffnx {Scheme Procedure} no-nans-violation? obj
  2026. A condition type indicating that a computation resulted in a @code{NaN}
  2027. value on a Scheme implementation incapable of representing @code{NaN}s.
  2028. @end deffn
  2029. @deffn {Scheme Procedure} fixnum->flonum fx
  2030. Returns the flonum that is numerically closest to the fixnum @var{fx}.
  2031. @end deffn
  2032. @node rnrs arithmetic bitwise
  2033. @subsubsection rnrs arithmetic bitwise
  2034. The @code{(rnrs arithmetic bitwise (6))} library provides procedures for
  2035. performing bitwise arithmetic operations on the two's complement
  2036. representations of fixnums.
  2037. This library and the procedures it exports share functionality with
  2038. SRFI-60, which provides support for bitwise manipulation of integers
  2039. (@pxref{SRFI-60}).
  2040. @deffn {Scheme Procedure} bitwise-not ei
  2041. @deffnx {Scheme Procedure} bitwise-and ei1 ...
  2042. @deffnx {Scheme Procedure} bitwise-ior ei1 ...
  2043. @deffnx {Scheme Procedure} bitwise-xor ei1 ...
  2044. These procedures are identical to the @code{lognot}, @code{logand},
  2045. @code{logior}, and @code{logxor} procedures provided by Guile's core
  2046. library. @xref{Bitwise Operations}, for documentation.
  2047. @end deffn
  2048. @deffn {Scheme Procedure} bitwise-if ei1 ei2 ei3
  2049. Returns the bitwise ``if'' of its arguments. The bit at position
  2050. @code{i} in the return value will be the @code{i}th bit from @var{ei2}
  2051. if the @code{i}th bit of @var{ei1} is 1, the @code{i}th bit from
  2052. @var{ei3}.
  2053. @end deffn
  2054. @deffn {Scheme Procedure} bitwise-bit-count ei
  2055. Returns the number of 1 bits in the two's complement representation of
  2056. @var{ei}.
  2057. @end deffn
  2058. @deffn {Scheme Procedure} bitwise-length ei
  2059. Returns the number of bits necessary to represent @var{ei}.
  2060. @end deffn
  2061. @deffn {Scheme Procedure} bitwise-first-bit-set ei
  2062. Returns the index of the least significant 1 bit in the two's complement
  2063. representation of @var{ei}.
  2064. @end deffn
  2065. @deffn {Scheme Procedure} bitwise-bit-set? ei1 ei2
  2066. Returns @code{#t} if the @var{ei2}th bit in the two's complement
  2067. representation of @var{ei1} is 1, @code{#f} otherwise.
  2068. @end deffn
  2069. @deffn {Scheme Procedure} bitwise-copy-bit ei1 ei2 ei3
  2070. Returns the result of setting the @var{ei2}th bit of @var{ei1} to the
  2071. @var{ei2}th bit of @var{ei3}.
  2072. @end deffn
  2073. @deffn {Scheme Procedure} bitwise-bit-field ei1 ei2 ei3
  2074. Returns the integer representation of the contiguous sequence of bits in
  2075. @var{ei1} that starts at position @var{ei2} (inclusive) and ends at
  2076. position @var{ei3} (exclusive).
  2077. @end deffn
  2078. @deffn {Scheme Procedure} bitwise-copy-bit-field ei1 ei2 ei3 ei4
  2079. Returns the result of replacing the bit field in @var{ei1} with start
  2080. and end positions @var{ei2} and @var{ei3} with the corresponding bit
  2081. field from @var{ei4}.
  2082. @end deffn
  2083. @deffn {Scheme Procedure} bitwise-arithmetic-shift ei1 ei2
  2084. @deffnx {Scheme Procedure} bitwise-arithmetic-shift-left ei1 ei2
  2085. @deffnx {Scheme Procedure} bitwise-arithmetic-shift-right ei1 ei2
  2086. Returns the result of shifting the bits of @var{ei1} right or left by
  2087. the @var{ei2} positions. @code{bitwise-arithmetic-shift} is identical
  2088. to @code{bitwise-arithmetic-shift-left}.
  2089. @end deffn
  2090. @deffn {Scheme Procedure} bitwise-rotate-bit-field ei1 ei2 ei3 ei4
  2091. Returns the result of cyclically permuting the bit field in @var{ei1}
  2092. with start and end positions @var{ei2} and @var{ei3} by @var{ei4} bits
  2093. in the direction of more significant bits.
  2094. @end deffn
  2095. @deffn {Scheme Procedure} bitwise-reverse-bit-field ei1 ei2 ei3
  2096. Returns the result of reversing the order of the bits of @var{ei1}
  2097. between position @var{ei2} (inclusive) and position @var{ei3}
  2098. (exclusive).
  2099. @end deffn
  2100. @node rnrs syntax-case
  2101. @subsubsection rnrs syntax-case
  2102. The @code{(rnrs syntax-case (6))} library provides access to the
  2103. @code{syntax-case} system for writing hygienic macros. With one
  2104. exception, all of the forms and procedures exported by this library
  2105. are ``re-exports'' of Guile's native support for @code{syntax-case};
  2106. @xref{Syntax Case}, for documentation, examples, and rationale.
  2107. @deffn {Scheme Procedure} make-variable-transformer proc
  2108. Creates a new variable transformer out of @var{proc}, a procedure that
  2109. takes a syntax object as input and returns a syntax object. If an
  2110. identifier to which the result of this procedure is bound appears on the
  2111. left-hand side of a @code{set!} expression, @var{proc} will be called
  2112. with a syntax object representing the entire @code{set!} expression,
  2113. and its return value will replace that @code{set!} expression.
  2114. @end deffn
  2115. @deffn {Scheme Syntax} syntax-case expression (literal ...) clause ...
  2116. The @code{syntax-case} pattern matching form.
  2117. @end deffn
  2118. @deffn {Scheme Syntax} syntax template
  2119. @deffnx {Scheme Syntax} quasisyntax template
  2120. @deffnx {Scheme Syntax} unsyntax template
  2121. @deffnx {Scheme Syntax} unsyntax-splicing template
  2122. These forms allow references to be made in the body of a syntax-case
  2123. output expression subform to datum and non-datum values. They are
  2124. identical to the forms provided by Guile's core library;
  2125. @xref{Syntax Case}, for documentation.
  2126. @end deffn
  2127. @deffn {Scheme Procedure} identifier? obj
  2128. @deffnx {Scheme Procedure} bound-identifier=? id1 id2
  2129. @deffnx {Scheme Procedure} free-identifier=? id1 id2
  2130. These predicate procedures operate on syntax objects representing
  2131. Scheme identifiers. @code{identifier?} returns @code{#t} if @var{obj}
  2132. represents an identifier, @code{#f} otherwise.
  2133. @code{bound-identifier=?} returns @code{#t} if and only if a binding for
  2134. @var{id1} would capture a reference to @var{id2} in the transformer's
  2135. output, or vice-versa. @code{free-identifier=?} returns @code{#t} if
  2136. and only @var{id1} and @var{id2} would refer to the same binding in the
  2137. output of the transformer, independent of any bindings introduced by the
  2138. transformer.
  2139. @end deffn
  2140. @deffn {Scheme Procedure} generate-temporaries l
  2141. Returns a list, of the same length as @var{l}, which must be a list or
  2142. a syntax object representing a list, of globally unique symbols.
  2143. @end deffn
  2144. @deffn {Scheme Procedure} syntax->datum syntax-object
  2145. @deffnx {Scheme Procedure} datum->syntax template-id datum
  2146. These procedures convert wrapped syntax objects to and from Scheme datum
  2147. values. The syntax object returned by @code{datum->syntax} shares
  2148. contextual information with the syntax object @var{template-id}.
  2149. @end deffn
  2150. @deffn {Scheme Procedure} syntax-violation whom message form
  2151. @deffnx {Scheme Procedure} syntax-violation whom message form subform
  2152. Constructs a new compound condition that includes the following
  2153. simple conditions:
  2154. @itemize @bullet
  2155. @item
  2156. If @var{whom} is not @code{#f}, a @code{&who} condition with the
  2157. @var{whom} as its field
  2158. @item
  2159. A @code{&message} condition with the specified @var{message}
  2160. @item
  2161. A @code{&syntax} condition with the specified @var{form} and optional
  2162. @var{subform} fields
  2163. @end itemize
  2164. @end deffn
  2165. @node rnrs hashtables
  2166. @subsubsection rnrs hashtables
  2167. The @code{(rnrs hashtables (6))} library provides structures and
  2168. procedures for creating and accessing hash tables. The hash tables API
  2169. defined by R6RS is substantially similar to both Guile's native hash
  2170. tables implementation as well as the one provided by SRFI-69;
  2171. @xref{Hash Tables}, and @ref{SRFI-69}, respectively. Note that you can
  2172. write portable R6RS library code that manipulates SRFI-69 hash tables
  2173. (by importing the @code{(srfi :69)} library); however, hash tables
  2174. created by one API cannot be used by another.
  2175. Like SRFI-69 hash tables---and unlike Guile's native ones---R6RS hash
  2176. tables associate hash and equality functions with a hash table at the
  2177. time of its creation. Additionally, R6RS allows for the creation
  2178. (via @code{hashtable-copy}; see below) of immutable hash tables.
  2179. @deffn {Scheme Procedure} make-eq-hashtable
  2180. @deffnx {Scheme Procedure} make-eq-hashtable k
  2181. Returns a new hash table that uses @code{eq?} to compare keys and
  2182. Guile's @code{hashq} procedure as a hash function. If @var{k} is given,
  2183. it specifies the initial capacity of the hash table.
  2184. @end deffn
  2185. @deffn {Scheme Procedure} make-eqv-hashtable
  2186. @deffnx {Scheme Procedure} make-eqv-hashtable k
  2187. Returns a new hash table that uses @code{eqv?} to compare keys and
  2188. Guile's @code{hashv} procedure as a hash function. If @var{k} is given,
  2189. it specifies the initial capacity of the hash table.
  2190. @end deffn
  2191. @deffn {Scheme Procedure} make-hashtable hash-function equiv
  2192. @deffnx {Scheme Procedure} make-hashtable hash-function equiv k
  2193. Returns a new hash table that uses @var{equiv} to compare keys and
  2194. @var{hash-function} as a hash function. @var{equiv} must be a procedure
  2195. that accepts two arguments and returns a true value if they are
  2196. equivalent, @code{#f} otherwise; @var{hash-function} must be a procedure
  2197. that accepts one argument and returns a non-negative integer.
  2198. If @var{k} is given, it specifies the initial capacity of the hash
  2199. table.
  2200. @end deffn
  2201. @deffn {Scheme Procedure} hashtable? obj
  2202. Returns @code{#t} if @var{obj} is an R6RS hash table, @code{#f}
  2203. otherwise.
  2204. @end deffn
  2205. @deffn {Scheme Procedure} hashtable-size hashtable
  2206. Returns the number of keys currently in the hash table @var{hashtable}.
  2207. @end deffn
  2208. @deffn {Scheme Procedure} hashtable-ref hashtable key default
  2209. Returns the value associated with @var{key} in the hash table
  2210. @var{hashtable}, or @var{default} if none is found.
  2211. @end deffn
  2212. @deffn {Scheme Procedure} hashtable-set! hashtable key obj
  2213. Associates the key @var{key} with the value @var{obj} in the hash table
  2214. @var{hashtable}, and returns an unspecified value. An @code{&assertion}
  2215. condition is raised if @var{hashtable} is immutable.
  2216. @end deffn
  2217. @deffn {Scheme Procedure} hashtable-delete! hashtable key
  2218. Removes any association found for the key @var{key} in the hash table
  2219. @var{hashtable}, and returns an unspecified value. An @code{&assertion}
  2220. condition is raised if @var{hashtable} is immutable.
  2221. @end deffn
  2222. @deffn {Scheme Procedure} hashtable-contains? hashtable key
  2223. Returns @code{#t} if the hash table @var{hashtable} contains an
  2224. association for the key @var{key}, @code{#f} otherwise.
  2225. @end deffn
  2226. @deffn {Scheme Procedure} hashtable-update! hashtable key proc default
  2227. Associates with @var{key} in the hash table @var{hashtable} the result
  2228. of calling @var{proc}, which must be a procedure that takes one
  2229. argument, on the value currently associated @var{key} in
  2230. @var{hashtable}---or on @var{default} if no such association exists.
  2231. An @code{&assertion} condition is raised if @var{hashtable} is
  2232. immutable.
  2233. @end deffn
  2234. @deffn {Scheme Procedure} hashtable-copy hashtable
  2235. @deffnx {Scheme Procedure} hashtable-copy hashtable mutable
  2236. Returns a copy of the hash table @var{hashtable}. If the optional
  2237. argument @var{mutable} is provided and is a true value, the new hash
  2238. table will be mutable.
  2239. @end deffn
  2240. @deffn {Scheme Procedure} hashtable-clear! hashtable
  2241. @deffnx {Scheme Procedure} hashtable-clear! hashtable k
  2242. Removes all of the associations from the hash table @var{hashtable}.
  2243. The optional argument @var{k}, which specifies a new capacity for the
  2244. hash table, is accepted by Guile's @code{(rnrs hashtables)}
  2245. implementation, but is ignored.
  2246. @end deffn
  2247. @deffn {Scheme Procedure} hashtable-keys hashtable
  2248. Returns a vector of the keys with associations in the hash table
  2249. @var{hashtable}, in an unspecified order.
  2250. @end deffn
  2251. @deffn {Scheme Procedure} hashtable-entries hashtable
  2252. Return two values---a vector of the keys with associations in the hash
  2253. table @var{hashtable}, and a vector of the values to which these keys
  2254. are mapped, in corresponding but unspecified order.
  2255. @end deffn
  2256. @deffn {Scheme Procedure} hashtable-equivalence-function hashtable
  2257. Returns the equivalence predicated use by @var{hashtable}. This
  2258. procedure returns @code{eq?} and @code{eqv?}, respectively, for hash
  2259. tables created by @code{make-eq-hashtable} and
  2260. @code{make-eqv-hashtable}.
  2261. @end deffn
  2262. @deffn {Scheme Procedure} hashtable-hash-function hashtable
  2263. Returns the hash function used by @var{hashtable}. For hash tables
  2264. created by @code{make-eq-hashtable} or @code{make-eqv-hashtable},
  2265. @code{#f} is returned.
  2266. @end deffn
  2267. @deffn {Scheme Procedure} hashtable-mutable? hashtable
  2268. Returns @code{#t} if @var{hashtable} is mutable, @code{#f} otherwise.
  2269. @end deffn
  2270. A number of hash functions are provided for convenience:
  2271. @deffn {Scheme Procedure} equal-hash obj
  2272. Returns an integer hash value for @var{obj}, based on its structure and
  2273. current contents. This hash function is suitable for use with
  2274. @code{equal?} as an equivalence function.
  2275. @end deffn
  2276. @deffn {Scheme Procedure} string-hash string
  2277. @deffnx {Scheme Procedure} symbol-hash symbol
  2278. These procedures are identical to the ones provided by Guile's core
  2279. library. @xref{Hash Table Reference}, for documentation.
  2280. @end deffn
  2281. @deffn {Scheme Procedure} string-ci-hash string
  2282. Returns an integer hash value for @var{string} based on its contents,
  2283. ignoring case. This hash function is suitable for use with
  2284. @code{string-ci=?} as an equivalence function.
  2285. @end deffn
  2286. @node rnrs enums
  2287. @subsubsection rnrs enums
  2288. The @code{(rnrs enums (6))} library provides structures and procedures
  2289. for working with enumerable sets of symbols. Guile's implementation
  2290. defines an @dfn{enum-set} record type that encapsulates a finite set of
  2291. distinct symbols, the @dfn{universe}, and a subset of these symbols,
  2292. which define the enumeration set.
  2293. The SRFI-1 list library provides a number of procedures for performing
  2294. set operations on lists; Guile's @code{(rnrs enums)} implementation
  2295. makes use of several of them. @xref{SRFI-1 Set Operations}, for
  2296. more information.
  2297. @deffn {Scheme Procedure} make-enumeration symbol-list
  2298. Returns a new enum-set whose universe and enumeration set are both equal
  2299. to @var{symbol-list}, a list of symbols.
  2300. @end deffn
  2301. @deffn {Scheme Procedure} enum-set-universe enum-set
  2302. Returns an enum-set representing the universe of @var{enum-set},
  2303. an enum-set.
  2304. @end deffn
  2305. @deffn {Scheme Procedure} enum-set-indexer enum-set
  2306. Returns a procedure that takes a single argument and returns the
  2307. zero-indexed position of that argument in the universe of
  2308. @var{enum-set}, or @code{#f} if its argument is not a member of that
  2309. universe.
  2310. @end deffn
  2311. @deffn {Scheme Procedure} enum-set-constructor enum-set
  2312. Returns a procedure that takes a single argument, a list of symbols
  2313. from the universe of @var{enum-set}, an enum-set, and returns a new
  2314. enum-set with the same universe that represents a subset containing the
  2315. specified symbols.
  2316. @end deffn
  2317. @deffn {Scheme Procedure} enum-set->list enum-set
  2318. Returns a list containing the symbols of the set represented by
  2319. @var{enum-set}, an enum-set, in the order that they appear in the
  2320. universe of @var{enum-set}.
  2321. @end deffn
  2322. @deffn {Scheme Procedure} enum-set-member? symbol enum-set
  2323. @deffnx {Scheme Procedure} enum-set-subset? enum-set1 enum-set2
  2324. @deffnx {Scheme Procedure} enum-set=? enum-set1 enum-set2
  2325. These procedures test for membership of symbols and enum-sets in other
  2326. enum-sets. @code{enum-set-member?} returns @code{#t} if and only if
  2327. @var{symbol} is a member of the subset specified by @var{enum-set}.
  2328. @code{enum-set-subset?} returns @code{#t} if and only if the universe of
  2329. @var{enum-set1} is a subset of the universe of @var{enum-set2} and
  2330. every symbol in @var{enum-set1} is present in @var{enum-set2}.
  2331. @code{enum-set=?} returns @code{#t} if and only if @var{enum-set1} is a
  2332. subset, as per @code{enum-set-subset?} of @var{enum-set2} and vice
  2333. versa.
  2334. @end deffn
  2335. @deffn {Scheme Procedure} enum-set-union enum-set1 enum-set2
  2336. @deffnx {Scheme Procedure} enum-set-intersection enum-set1 enum-set2
  2337. @deffnx {Scheme Procedure} enum-set-difference enum-set1 enum-set2
  2338. These procedures return, respectively, the union, intersection, and
  2339. difference of their enum-set arguments.
  2340. @end deffn
  2341. @deffn {Scheme Procedure} enum-set-complement enum-set
  2342. Returns @var{enum-set}'s complement (an enum-set), with regard to its
  2343. universe.
  2344. @end deffn
  2345. @deffn {Scheme Procedure} enum-set-projection enum-set1 enum-set2
  2346. Returns the projection of the enum-set @var{enum-set1} onto the universe
  2347. of the enum-set @var{enum-set2}.
  2348. @end deffn
  2349. @deffn {Scheme Syntax} define-enumeration type-name (symbol ...) constructor-syntax
  2350. Evaluates to two new definitions: A constructor bound to
  2351. @var{constructor-syntax} that behaves similarly to constructors created
  2352. by @code{enum-set-constructor}, above, and creates new @var{enum-set}s
  2353. in the universe specified by @code{(symbol ...)}; and a ``predicate
  2354. macro'' bound to @var{type-name}, which has the following form:
  2355. @lisp
  2356. (@var{type-name} sym)
  2357. @end lisp
  2358. If @var{sym} is a member of the universe specified by the @var{symbol}s
  2359. above, this form evaluates to @var{sym}. Otherwise, a @code{&syntax}
  2360. condition is raised.
  2361. @end deffn
  2362. @node rnrs
  2363. @subsubsection rnrs
  2364. The @code{(rnrs (6))} library is a composite of all of the other R6RS
  2365. standard libraries---it imports and re-exports all of their exported
  2366. procedures and syntactic forms---with the exception of the following
  2367. libraries:
  2368. @itemize @bullet
  2369. @item @code{(rnrs eval (6))}
  2370. @item @code{(rnrs mutable-pairs (6))}
  2371. @item @code{(rnrs mutable-strings (6))}
  2372. @item @code{(rnrs r5rs (6))}
  2373. @end itemize
  2374. @node rnrs eval
  2375. @subsubsection rnrs eval
  2376. The @code{(rnrs eval (6)} library provides procedures for performing
  2377. ``on-the-fly'' evaluation of expressions.
  2378. @deffn {Scheme Procedure} eval expression environment
  2379. Evaluates @var{expression}, which must be a datum representation of a
  2380. valid Scheme expression, in the environment specified by
  2381. @var{environment}. This procedure is identical to the one provided by
  2382. Guile's code library; @xref{Fly Evaluation}, for documentation.
  2383. @end deffn
  2384. @deffn {Scheme Procedure} environment import-spec ...
  2385. Constructs and returns a new environment based on the specified
  2386. @var{import-spec}s, which must be datum representations of the import
  2387. specifications used with the @code{import} form. @xref{R6RS Libraries},
  2388. for documentation.
  2389. @end deffn
  2390. @node rnrs mutable-pairs
  2391. @subsubsection rnrs mutable-pairs
  2392. The @code{(rnrs mutable-pairs (6))} library provides the @code{set-car!}
  2393. and @code{set-cdr!} procedures, which allow the @code{car} and
  2394. @code{cdr} fields of a pair to be modified.
  2395. These procedures are identical to the ones provide by Guile's core
  2396. library. @xref{Pairs}, for documentation. All pairs in Guile are
  2397. mutable; consequently, these procedures will never throw the
  2398. @code{&assertion} condition described in the R6RS libraries
  2399. specification.
  2400. @node rnrs mutable-strings
  2401. @subsubsection rnrs mutable-strings
  2402. The @code{(rnrs mutable-strings (6))} library provides the
  2403. @code{string-set!} and @code{string-fill!} procedures, which allow the
  2404. content of strings to be modified ``in-place.''
  2405. These procedures are identical to the ones provided by Guile's core
  2406. library. @xref{String Modification}, for documentation. All strings in
  2407. Guile are mutable; consequently, these procedures will never throw the
  2408. @code{&assertion} condition described in the R6RS libraries
  2409. specification.
  2410. @node rnrs r5rs
  2411. @subsubsection rnrs r5rs
  2412. The @code{(rnrs r5rs (6))} library exports bindings for some procedures
  2413. present in R5RS but omitted from the R6RS base library specification.
  2414. @deffn {Scheme Procedure} exact->inexact z
  2415. @deffnx {Scheme Procedure} inexact->exact z
  2416. These procedures are identical to the ones provided by Guile's core
  2417. library. @xref{Exactness}, for documentation.
  2418. @end deffn
  2419. @deffn {Scheme Procedure} quotient n1 n2
  2420. @deffnx {Scheme Procedure} remainder n1 n2
  2421. @deffnx {Scheme Procedure} modulo n1 n2
  2422. These procedures are identical to the ones provided by Guile's core
  2423. library. @xref{Integer Operations}, for documentation.
  2424. @end deffn
  2425. @deffn {Scheme Syntax} delay expr
  2426. @deffnx {Scheme Procedure} force promise
  2427. The @code{delay} form and the @code{force} procedure are identical to
  2428. their counterparts in Guile's core library. @xref{Delayed Evaluation},
  2429. for documentation.
  2430. @end deffn
  2431. @deffn {Scheme Procedure} null-environment n
  2432. @deffnx {Scheme Procedure} scheme-report-environment n
  2433. These procedures are identical to the ones provided by the
  2434. @code{(ice-9 r5rs)} Guile module. @xref{Environments}, for
  2435. documentation.
  2436. @end deffn
  2437. @c r6rs.texi ends here
  2438. @c Local Variables:
  2439. @c TeX-master: "guile.texi"
  2440. @c End: