manual-Z-H-7.html 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840
  1. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!--
  4. Generated from manual.tex by tex2page, v 20050501
  5. (running on MzScheme 299.400, unix),
  6. (c) Dorai Sitaram,
  7. http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html
  8. -->
  9. <head>
  10. <title>
  11. The Incomplete Scheme 48 Reference Manual for release 1.6
  12. </title>
  13. <link rel="stylesheet" type="text/css" href="manual-Z-S.css" title=default>
  14. <meta name=robots content="noindex,follow">
  15. </head>
  16. <body>
  17. <div id=content>
  18. <div align=right class=navigation><i>[Go to <span><a href="manual.html">first</a>, <a href="manual-Z-H-6.html">previous</a></span><span>, <a href="manual-Z-H-8.html">next</a></span> page<span>; &nbsp;&nbsp;</span><span><a href="manual-Z-H-2.html#node_toc_start">contents</a></span><span><span>; &nbsp;&nbsp;</span><a href="manual-Z-H-13.html#node_index_start">index</a></span>]</i></div>
  19. <p></p>
  20. <a name="node_chap_5"></a>
  21. <h1 class=chapter>
  22. <div class=chapterheading><a href="manual-Z-H-2.html#node_toc_node_chap_5">Chapter 5</a></div><br>
  23. <a href="manual-Z-H-2.html#node_toc_node_chap_5">Libraries</a></h1>
  24. <p>Use the
  25. <tt>,open</tt> command (section&nbsp;<a href="manual-Z-H-5.html#node_sec_3.4">3.4</a>)
  26. or
  27. the module language (chapter&nbsp;<a href="manual-Z-H-4.html#node_sec_2.6">2.6</a>)
  28. to open the structures described below.</p>
  29. <p>
  30. </p>
  31. <a name="node_sec_5.1"></a>
  32. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.1">5.1&nbsp;&nbsp;General utilities</a></h2>
  33. <p></p>
  34. <p>
  35. </p>
  36. <p>
  37. These are in the <tt>big-util</tt> structure.</p>
  38. <p>
  39. </p>
  40. <ul>
  41. <li><p><tt>(atom?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_14"></a>
  42. </p>
  43. </ul><p>
  44. <tt>(atom? <i>x</i>)</tt> is the same as <tt>(not (pair? <i>x</i>))</tt>.</p>
  45. <p>
  46. </p>
  47. <ul>
  48. <li><p><tt>(null-list?<i> list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_16"></a>
  49. </p>
  50. </ul><p>
  51. Returns true for the empty list, false for a pair, and signals an
  52. error otherwise.</p>
  53. <p>
  54. </p>
  55. <ul>
  56. <li><p><tt>(neq?<i> value value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_18"></a>
  57. </p>
  58. </ul><p>
  59. <tt>(neq? <i>x</i> <i>y</i>)</tt> is the same as <tt>(not (eq? <i>x</i>
  60. <i>y</i>))</tt>.</p>
  61. <p>
  62. </p>
  63. <ul>
  64. <li><p><tt>(n=<i> number number</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_20"></a>
  65. </p>
  66. </ul><p>
  67. <tt>(n= <i>x</i> <i>y</i>)</tt> is the same as <tt>(not (= <i>x</i>
  68. <i>y</i>))</tt>.</p>
  69. <p>
  70. </p>
  71. <ul>
  72. <li><p><tt>(identity<i> value</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_22"></a>
  73. </p>
  74. <li><p><tt>(no-op<i> value</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_24"></a>
  75. </p>
  76. </ul><p>
  77. These both just return their argument. <tt>No-op</tt> is guaranteed not to
  78. be compiled in-line, <tt>identity</tt> may be.</p>
  79. <p>
  80. </p>
  81. <ul>
  82. <li><p><tt>(memq?<i> value list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_26"></a>
  83. </p>
  84. </ul><p>
  85. Returns true if <i>value</i> is in <i>list</i>, false otherwise.</p>
  86. <p>
  87. </p>
  88. <ul>
  89. <li><p><tt>(any?<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_28"></a>
  90. </p>
  91. </ul><p>
  92. Returns true if <i>predicate</i> is true for any element of <i>list</i>.</p>
  93. <p>
  94. </p>
  95. <ul>
  96. <li><p><tt>(every?<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_30"></a>
  97. </p>
  98. </ul><p>
  99. Returns true if <i>predicate</i> is true for every element of <i>list</i>.</p>
  100. <p>
  101. </p>
  102. <ul>
  103. <li><p><tt>(any<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_32"></a>
  104. </p>
  105. <li><p><tt>(first<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_34"></a>
  106. </p>
  107. </ul><p>
  108. <tt>Any</tt> returns some element of <i>list</i> for which <i>predicate</i> is true, or
  109. false if there are none. <tt>First</tt> does the same except that it returns
  110. the first element for which <i>predicate</i> is true.</p>
  111. <p>
  112. </p>
  113. <ul>
  114. <li><p><tt>(filter<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_36"></a>
  115. </p>
  116. <li><p><tt>(filter!<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_38"></a>
  117. </p>
  118. </ul><p>
  119. Returns a list containing all of the elements of <i>list</i> for which
  120. <i>predicate</i> is true. The order of the elements is preserved.
  121. <tt>Filter!</tt> may reuse the storage of <i>list</i>.</p>
  122. <p>
  123. </p>
  124. <ul>
  125. <li><p><tt>(filter-map<i> procedure list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_40"></a>
  126. </p>
  127. </ul><p>
  128. The same as <tt>filter</tt> except the returned list contains the results of
  129. applying <i>procedure</i> instead of elements of <i>list</i>. <tt>(filter-map <i>p</i>
  130. <i>l</i>)</tt> is the same as <tt>(filter identity (map <i>p</i> <i>l</i>))</tt>.</p>
  131. <p>
  132. </p>
  133. <ul>
  134. <li><p><tt>(partition-list<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>list list</i></tt><a name="node_idx_42"></a>
  135. </p>
  136. <li><p><tt>(partition-list!<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>list list</i></tt><a name="node_idx_44"></a>
  137. </p>
  138. </ul><p>
  139. The first return value contains those elements <i>list</i> for which
  140. <i>predicate</i> is true, the second contains the remaining elements.
  141. The order of the elements is preserved. <tt>Partition-list!</tt> may
  142. reuse the storage of the <i>list</i>.</p>
  143. <p>
  144. </p>
  145. <ul>
  146. <li><p><tt>(remove-duplicates<i> list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_46"></a>
  147. </p>
  148. </ul><p>
  149. Returns its argument with all duplicate elements removed. The first
  150. instance of each element is preserved.</p>
  151. <p>
  152. </p>
  153. <ul>
  154. <li><p><tt>(delq<i> value list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_48"></a>
  155. </p>
  156. <li><p><tt>(delq!<i> value list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_50"></a>
  157. </p>
  158. <li><p><tt>(delete<i> predicate list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_52"></a>
  159. </p>
  160. </ul><p>
  161. All three of these return <i>list</i> with some elements removed.
  162. <tt>Delq</tt> removes all elements <tt>eq?</tt> to <i>value</i>. <tt>Delq!</tt>
  163. does the same and may modify the list argument. <tt>Delete</tt> removes
  164. all elements for which <i>predicate</i> is true. Both <tt>delq</tt> and
  165. <tt>delete</tt> may reuse some of the storage in the list argument, but
  166. won't modify it.</p>
  167. <p>
  168. </p>
  169. <ul>
  170. <li><p><tt>(reverse!<i> list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_54"></a>
  171. </p>
  172. </ul><p>
  173. Destructively reverses <i>list</i>.</p>
  174. <p>
  175. </p>
  176. <ul>
  177. <li><p><tt>(concatenate-symbol<i> value <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>symbol</i></tt><a name="node_idx_56"></a>
  178. </p>
  179. </ul><p>
  180. Returns the symbol whose name is produced by concatenating the
  181. <tt>display</tt>ed
  182. representations of <i>value</i>&nbsp;<tt>...</tt>.</p>
  183. <p>
  184. </p>
  185. <pre class=verbatim>(concatenate-symbol 'abc &quot;-&quot; 4) ===&gt; 'abc-4
  186. </pre><p></p>
  187. <p>
  188. </p>
  189. <a name="node_sec_5.2"></a>
  190. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.2">5.2&nbsp;&nbsp;Pretty-printing</a></h2>
  191. <p>These are in the <tt>pp</tt> structure.</p>
  192. <p>
  193. </p>
  194. <ul>
  195. <li><p><tt>(p<i> value</i>)</tt><a name="node_idx_58"></a>
  196. </p>
  197. <li><p><tt>(p<i> value output-port</i>)</tt><a name="node_idx_60"></a>
  198. </p>
  199. <li><p><tt>(pretty-print<i> value output-port position</i>)</tt><a name="node_idx_62"></a>
  200. </p>
  201. </ul><p>
  202. Pretty-print <i>value</i> The current output port is used if no port is
  203. specified. <i>Position</i> is the starting offset. <i>Value</i> will be
  204. pretty-printed to the right of this column.</p>
  205. <p>
  206. </p>
  207. <a name="node_sec_5.3"></a>
  208. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.3">5.3&nbsp;&nbsp;Bitwise integer operations</a></h2>
  209. <p>These functions use the two's-complement representation for integers.
  210. There is no limit to the number of bits in an integer.
  211. They are in the structures <tt>bitwise</tt> and <tt>big-scheme</tt>.</p>
  212. <p>
  213. </p>
  214. <ul>
  215. <li><p><tt>(bitwise-and<i> integer integer</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_64"></a>
  216. </p>
  217. <li><p><tt>(bitwise-ior<i> integer integer</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_66"></a>
  218. </p>
  219. <li><p><tt>(bitwise-xor<i> integer integer</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_68"></a>
  220. </p>
  221. <li><p><tt>(bitwise-not<i> integer</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_70"></a>
  222. </p>
  223. </ul><p>
  224. These perform various logical operations on integers on a bit-by-bit
  225. basis. `<tt>ior</tt>' is inclusive OR and `<tt>xor</tt>' is exclusive OR.</p>
  226. <p>
  227. </p>
  228. <ul>
  229. <li><p><tt>(arithmetic-shift<i> integer bit-count</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_72"></a>
  230. </p>
  231. </ul><p>
  232. Shifts the integer by the given bit count, which must be an integer,
  233. shifting left for positive counts and right for negative ones.
  234. Shifting preserves the integer's sign.</p>
  235. <p>
  236. </p>
  237. <ul>
  238. <li><p><tt>(bit-count<i> integer</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_74"></a>
  239. </p>
  240. </ul><p>
  241. Counts the number of bits set in the integer.
  242. If the argument is negative a bitwise NOT operation is performed
  243. before counting.</p>
  244. <p>
  245. </p>
  246. <a name="node_sec_5.4"></a>
  247. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.4">5.4&nbsp;&nbsp;Byte vectors</a></h2>
  248. <p>These are homogeneous vectors of small integers (0 <u>&lt;</u> <em>i</em> <u>&lt;</u> 255).
  249. The functions that operate on them are analogous to those for vectors.
  250. They are in the structure <tt>byte-vectors</tt>.</p>
  251. <p>
  252. </p>
  253. <ul>
  254. <li><p><tt>(byte-vector?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_76"></a>
  255. </p>
  256. <li><p><tt>(make-byte-vector<i> k fill</i>)&nbsp;-&gt;&nbsp;<i>byte-vector</i></tt><a name="node_idx_78"></a>
  257. </p>
  258. <li><p><tt>(byte-vector<i> b <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>byte-vector</i></tt><a name="node_idx_80"></a>
  259. </p>
  260. <li><p><tt>(byte-vector-length<i> byte-vector</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_82"></a>
  261. </p>
  262. <li><p><tt>(byte-vector-ref<i> byte-vector k</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_84"></a>
  263. </p>
  264. <li><p><tt>(byte-vector-set!<i> byte-vector k b</i>)</tt><a name="node_idx_86"></a>
  265. </p>
  266. </ul><p></p>
  267. <p>
  268. </p>
  269. <a name="node_sec_5.5"></a>
  270. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.5">5.5&nbsp;&nbsp;Sparse vectors</a></h2>
  271. <p>These are vectors that grow as large as they need to. That is, they
  272. can be indexed by arbitrarily large nonnegative integers. The
  273. implementation allows for arbitrarily large gaps by arranging the
  274. entries in a tree. They are in the structure <tt>sparse-vectors</tt>.</p>
  275. <p>
  276. </p>
  277. <ul>
  278. <li><p><tt>(make-sparse-vector<i></i>)&nbsp;-&gt;&nbsp;<i>sparse-vector</i></tt><a name="node_idx_88"></a>
  279. </p>
  280. <li><p><tt>(sparse-vector-ref<i> sparse-vector k</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_90"></a>
  281. </p>
  282. <li><p><tt>(sparse-vector-set!<i> sparse-vector k value</i>)</tt><a name="node_idx_92"></a>
  283. </p>
  284. <li><p><tt>(sparse-vector-&gt;list<i> sparse-vector</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_94"></a>
  285. </p>
  286. </ul><p>
  287. <tt>Make-sparse-vector</tt>, <tt>sparse-vector-ref</tt>, and
  288. <tt>sparse-vector-set!</tt> are analogous to <tt>make-vector</tt>,
  289. <tt>vector-ref</tt>, and <tt>vector-set!</tt>, except that the indices
  290. passed to <tt>sparse-vector-ref</tt> and <tt>sparse-vector-set!</tt> can
  291. be arbitrarily large. For indices whose elements have not been set in
  292. a sparse vector, <tt>sparse-vector-ref</tt> returns <tt>#f</tt>.</p>
  293. <p>
  294. <tt>Sparse-vector-&gt;list</tt> is for debugging: It returns a list of the
  295. consecutive elements in a sparse vector from 0 to the highest element
  296. that has been set. Note that the list will also include all the
  297. <tt>#f</tt> elements for the unset elements.</p>
  298. <p>
  299. </p>
  300. <a name="node_sec_5.6"></a>
  301. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.6">5.6&nbsp;&nbsp;Cells</a></h2>
  302. <p></p>
  303. <p>
  304. These hold a single value and are useful when a simple indirection is
  305. required.
  306. The system uses these to hold the values of lexical variables that
  307. may be <tt>set!</tt>.</p>
  308. <p>
  309. </p>
  310. <ul>
  311. <li><p><tt>(cell?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_96"></a>
  312. </p>
  313. <li><p><tt>(make-cell<i> value</i>)&nbsp;-&gt;&nbsp;<i>cell</i></tt><a name="node_idx_98"></a>
  314. </p>
  315. <li><p><tt>(cell-ref<i> cell</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_100"></a>
  316. </p>
  317. <li><p><tt>(cell-set!<i> cell value</i>)</tt><a name="node_idx_102"></a>
  318. </p>
  319. </ul><p></p>
  320. <p>
  321. </p>
  322. <a name="node_sec_5.7"></a>
  323. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.7">5.7&nbsp;&nbsp;Queues</a></h2>
  324. <p>These are ordinary first-in, first-out queues.
  325. The procedures are in structure <tt>queues</tt>.</p>
  326. <p>
  327. </p>
  328. <ul>
  329. <li><p><tt>(make-queue<i></i>)&nbsp;-&gt;&nbsp;<i>queue</i></tt><a name="node_idx_104"></a>
  330. </p>
  331. <li><p><tt>(queue?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_106"></a>
  332. </p>
  333. <li><p><tt>(queue-empty?<i> queue</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_108"></a>
  334. </p>
  335. <li><p><tt>(enqueue!<i> queue value</i>)</tt><a name="node_idx_110"></a>
  336. </p>
  337. <li><p><tt>(dequeue!<i> queue</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_112"></a>
  338. </p>
  339. </ul><p>
  340. <tt>Make-queue</tt> creates an empty queue, <tt>queue?</tt> is a predicate for
  341. identifying queues, <tt>queue-empty?</tt> tells you if a queue is empty,
  342. <tt>enqueue!</tt> and <tt>dequeue!</tt> add and remove values.</p>
  343. <p>
  344. </p>
  345. <ul>
  346. <li><p><tt>(queue-length<i> queue</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_114"></a>
  347. </p>
  348. <li><p><tt>(queue-&gt;list<i> queue</i>)&nbsp;-&gt;&nbsp;<i>values</i></tt><a name="node_idx_116"></a>
  349. </p>
  350. <li><p><tt>(list-&gt;queue<i> values</i>)&nbsp;-&gt;&nbsp;<i>queue</i></tt><a name="node_idx_118"></a>
  351. </p>
  352. <li><p><tt>(delete-from-queue!<i> queue value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_120"></a>
  353. </p>
  354. </ul><p>
  355. <tt>Queue-length</tt> returns the number of values in <i>queue</i>.
  356. <tt>Queue-&gt;list</tt> returns the values in <i>queue</i> as a list, in the
  357. order in which the values were added.
  358. <tt>List-&gt;queue</tt> returns a queue containing <i>values</i>, preserving
  359. their order.
  360. <tt>Delete-from-queue</tt> removes the first instance of <i>value</i> from
  361. <tt>queue</tt>, using <tt>eq?</tt> for comparisons.
  362. <tt>Delete-from-queue</tt> returns <tt>#t</tt> if <i>value</i> is found and
  363. <tt>#f</tt> if it is not.</p>
  364. <p>
  365. </p>
  366. <a name="node_sec_5.8"></a>
  367. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.8">5.8&nbsp;&nbsp;Arrays</a></h2>
  368. <p>These provide N-dimensional, zero-based arrays and
  369. are in the structure <tt>arrays</tt>.
  370. The array interface is derived from one invented by Alan Bawden.</p>
  371. <p>
  372. </p>
  373. <ul>
  374. <li><p><tt>(make-array<i> value dimension<sub>0</sub> <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>array</i></tt><a name="node_idx_122"></a>
  375. </p>
  376. <li><p><tt>(array<i> dimensions element<sub>0</sub> <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>array</i></tt><a name="node_idx_124"></a>
  377. </p>
  378. <li><p><tt>(copy-array<i> array</i>)&nbsp;-&gt;&nbsp;<i>array</i></tt><a name="node_idx_126"></a>
  379. </p>
  380. </ul><p>
  381. <tt>Make-array</tt> makes a new array with the given dimensions, each of which
  382. must be a non-negative integer.
  383. Every element is initially set to <i>value</i>.
  384. <tt>Array</tt> Returns a new array with the given dimensions and elements.
  385. <i>Dimensions</i> must be a list of non-negative integers,
  386. The number of elements should be the equal to the product of the
  387. dimensions.
  388. The elements are stored in row-major order.
  389. </p>
  390. <pre class=verbatim>(make-array 'a 2 3) <code class=verbatim>=&gt; </code>{Array 2 3}
  391. (array '(2 3) 'a 'b 'c 'd 'e 'f)
  392. <code class=verbatim>=&gt; </code>{Array 2 3}
  393. </pre><p></p>
  394. <p>
  395. <tt>Copy-array</tt> returns a copy of <i>array</i>.
  396. The copy is identical to the <i>array</i> but does not share storage with it.</p>
  397. <p>
  398. </p>
  399. <ul>
  400. <li><p><tt>(array?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_128"></a>
  401. </p>
  402. </ul><p>
  403. Returns <tt>#t</tt> if <i>value</i> is an array.</p>
  404. <p>
  405. </p>
  406. <ul>
  407. <li><p><tt>(array-ref<i> array index<sub>0</sub> <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_130"></a>
  408. </p>
  409. <li><p><tt>(array-set!<i> array value index<sub>0</sub> <tt>...</tt></i>)</tt><a name="node_idx_132"></a>
  410. </p>
  411. <li><p><tt>(array-&gt;vector<i> array</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_134"></a>
  412. </p>
  413. <li><p><tt>(array-shape<i> array</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_136"></a>
  414. </p>
  415. </ul><p>
  416. <tt>Array-ref</tt> returns the specified array element and <tt>array-set!</tt>
  417. replaces the element with <i>value</i>.
  418. </p>
  419. <pre class=verbatim>(let ((a (array '(2 3) 'a 'b 'c 'd 'e 'f)))
  420. (let ((x (array-ref a 0 1)))
  421. (array-set! a 'g 0 1)
  422. (list x (array-ref a 0 1))))
  423. <code class=verbatim>=&gt; </code>'(b g)
  424. </pre><p></p>
  425. <p>
  426. <tt>Array-&gt;vector</tt> returns a vector containing the elements of <i>array</i>
  427. in row-major order.
  428. <tt>Array-shape</tt> returns the dimensions of
  429. the array as a list.</p>
  430. <p>
  431. </p>
  432. <ul>
  433. <li><p><tt>(make-shared-array<i> array linear-map dimension<sub>0</sub> <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>array</i></tt><a name="node_idx_138"></a>
  434. </p>
  435. </ul><p>
  436. <tt>Make-shared-array</tt> makes a new array that shares storage with <i>array</i>
  437. and uses <i>linear-map</i> to map indexes to elements.
  438. <i>Linear-map</i> must accept as many arguments as the number of
  439. <i>dimension</i>s given and must return a list of non-negative integers
  440. that are valid indexes into <i>array</i>.
  441. </p>
  442. <pre class=verbatim>(array-ref (make-shared-array a f i0 i1 ...)
  443. j0 j1 ...)
  444. </pre><p>
  445. is equivalent to
  446. </p>
  447. <pre class=verbatim>(apply array-ref a (f j0 j1 ...))
  448. </pre><p></p>
  449. <p>
  450. As an example, the following function makes the transpose of a two-dimensional
  451. array:
  452. </p>
  453. <pre class=verbatim>(define (transpose array)
  454. (let ((shape (array-shape array)))
  455. (make-shared-array array
  456. (lambda (x y)
  457. (list y x))
  458. (cadr shape)
  459. (car shape))))
  460. (array-&gt;vector
  461. (transpose
  462. (array '(2 3) 'a 'b 'c 'd 'e 'f)))
  463. <code class=verbatim>=&gt; </code>'(a d b e c f)
  464. </pre><p></p>
  465. <p>
  466. </p>
  467. <a name="node_sec_5.9"></a>
  468. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.9">5.9&nbsp;&nbsp;Records</a></h2>
  469. <p></p>
  470. <p>
  471. New types can be constructed using the <tt>define-record-type</tt> macro
  472. from the <tt>define-record-types</tt> structure
  473. The general syntax is:
  474. </p>
  475. <pre class=verbatim>(define-record-type <i>tag</i> <i>type-name</i>
  476. (<i>constructor-name</i> <i>field-tag</i> <tt>...</tt>)
  477. <i>predicate-name</i>
  478. (<i>field-tag</i> <i>accessor-name</i> [<i>modifier-name</i>])
  479. <tt>...</tt>)
  480. </pre><p>
  481. This makes the following definitions:
  482. </p>
  483. <ul>
  484. <li><p><tt><i>type-name</i></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(type)
  485. </p>
  486. <li><p><tt>(<i>constructor-name</i><i> field-init <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>type-name</i></tt>
  487. </p>
  488. <li><p><tt>(<i>predicate-name</i><i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt>
  489. </p>
  490. <li><p><tt>(<i>accessor-name</i><i> type-name</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt>
  491. </p>
  492. <li><p><tt>(<i>modifier-name</i><i> type-name value</i>)</tt>
  493. </p>
  494. </ul><p>
  495. <i>Type-name</i> is the record type itself, and can be used to
  496. specify a print method (see below).
  497. <i>Constructor-name</i> is a constructor that accepts values
  498. for the fields whose tags are specified.
  499. <i>Predicate-name</i> is a predicate that returns <tt>#t</tt> for
  500. elements of the type and <tt>#f</tt> for everything else.
  501. The <i>accessor-name</i>s retrieve the values of fields,
  502. and the <i>modifier-name</i>'s update them.
  503. <i>Tag</i> is used in printing instances of the record type and
  504. the <i>field-tag</i>s are used in the inspector and to match
  505. constructor arguments with fields.</p>
  506. <p>
  507. </p>
  508. <ul>
  509. <li><p><tt>(define-record-discloser<i> type discloser</i>)</tt><a name="node_idx_140"></a>
  510. </p>
  511. </ul><p>
  512. <tt>Define-record-discloser</tt> determines how
  513. records of type <i>type</i> are printed.
  514. <i>Discloser</i> should be procedure which takes a single
  515. record of type <i>type</i> and returns a list whose car is
  516. a symbol.
  517. The record will be printed as the value returned by <i>discloser</i>
  518. with curly braces used instead of the usual parenthesis.</p>
  519. <p>
  520. For example
  521. </p>
  522. <pre class=verbatim>(define-record-type pare :pare
  523. (kons x y)
  524. pare?
  525. (x kar set-kar!)
  526. (y kdr))
  527. </pre><p>
  528. defines <tt>kons</tt> to be a constructor, <tt>kar</tt> and <tt>kdr</tt> to be
  529. accessors, <tt>set-kar!</tt> to be a modifier, and <tt>pare?</tt> to be a predicate
  530. for a new type of object.
  531. The type itself is named <tt>:pare</tt>.
  532. <tt>Pare</tt> is a tag used in printing the new objects.</p>
  533. <p>
  534. By default, the new objects print as <tt>#{Pare}</tt>.
  535. The print method can be modified using <tt>define-record-discloser</tt>:
  536. </p>
  537. <pre class=verbatim>(define-record-discloser :pare
  538. (lambda (p) `(pare ,(kar p) ,(kdr p))))
  539. </pre><p>
  540. will cause the result of <tt>(kons 1 2)</tt> to print as
  541. <tt>#{Pare 1 2}</tt>.</p>
  542. <p>
  543. <tt>Define-record-resumer</tt> (section&nbsp;<a href="manual-Z-H-10.html#node_sec_8.8.3">8.8.3</a>)
  544. can be used to control how records are stored in heap images.</p>
  545. <p>
  546. </p>
  547. <a name="node_sec_5.9.1"></a>
  548. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.9.1">5.9.1&nbsp;&nbsp;Low-level access to records</a></h3>
  549. <p>Records are implemented using primitive objects exactly analogous
  550. to vectors.
  551. Every record has a record type (which is another record) in the first slot.
  552. Note that use of these procedures, especially <tt>record-set!</tt>, breaks
  553. the record abstraction described above; caution is advised.</p>
  554. <p>
  555. These procedures are in the structure <tt>records</tt>.</p>
  556. <p>
  557. </p>
  558. <ul>
  559. <li><p><tt>(make-record<i> n value</i>)&nbsp;-&gt;&nbsp;<i>record</i></tt><a name="node_idx_142"></a>
  560. </p>
  561. <li><p><tt>(record<i> value <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>record-vector</i></tt><a name="node_idx_144"></a>
  562. </p>
  563. <li><p><tt>(record?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_146"></a>
  564. </p>
  565. <li><p><tt>(record-length<i> record</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_148"></a>
  566. </p>
  567. <li><p><tt>(record-type<i> record</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_150"></a>
  568. </p>
  569. <li><p><tt>(record-ref<i> record i</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_152"></a>
  570. </p>
  571. <li><p><tt>(record-set!<i> record i value</i>)</tt><a name="node_idx_154"></a>
  572. </p>
  573. </ul><p>
  574. These the same as the standard <tt>vector-</tt> procedures except that they
  575. operate on records.
  576. The value returned by <tt>record-length</tt> includes the slot holding the
  577. record's type.
  578. <tt>(record-type <i>x</i>)</tt> is equivalent to <tt>(record-ref <i>x</i> 0)</tt>.</p>
  579. <p>
  580. </p>
  581. <a name="node_sec_5.9.2"></a>
  582. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.9.2">5.9.2&nbsp;&nbsp;Record types</a></h3>
  583. <p>Record types are themselves records of a particular type (the first slot
  584. of <tt>:record-type</tt> points to itself).
  585. A record type contains four values: the name of the record type, a list of
  586. the names its fields, and procedures for disclosing and resuming records
  587. of that type.
  588. Procedures for manipulating them are in the structure <tt>record-types</tt>.</p>
  589. <p>
  590. </p>
  591. <ul>
  592. <li><p><tt>(make-record-type<i> name field-names</i>)&nbsp;-&gt;&nbsp;<i>record-type</i></tt><a name="node_idx_156"></a>
  593. </p>
  594. <li><p><tt>(record-type?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_158"></a>
  595. </p>
  596. <li><p><tt>(record-type-name<i> record-type</i>)&nbsp;-&gt;&nbsp;<i>symbol</i></tt><a name="node_idx_160"></a>
  597. </p>
  598. <li><p><tt>(record-type-field-names<i> record-type</i>)&nbsp;-&gt;&nbsp;<i>symbols</i></tt><a name="node_idx_162"></a>
  599. </p>
  600. </ul><p>
  601. </p>
  602. <p>
  603. </p>
  604. <ul>
  605. <li><p><tt>(record-constructor<i> record-type field-names</i>)&nbsp;-&gt;&nbsp;<i>procedure</i></tt><a name="node_idx_164"></a>
  606. </p>
  607. <li><p><tt>(record-predicate<i> record-type</i>)&nbsp;-&gt;&nbsp;<i>procedure</i></tt><a name="node_idx_166"></a>
  608. </p>
  609. <li><p><tt>(record-accessor<i> record-type field-name</i>)&nbsp;-&gt;&nbsp;<i>procedure</i></tt><a name="node_idx_168"></a>
  610. </p>
  611. <li><p><tt>(record-modifier<i> record-type field-name</i>)&nbsp;-&gt;&nbsp;<i>procedure</i></tt><a name="node_idx_170"></a>
  612. </p>
  613. </ul><p>
  614. These procedures construct the usual record-manipulating procedures.
  615. <tt>Record-constructor</tt> returns a constructor that is passed the initial
  616. values for the fields specified and returns a new record.
  617. <tt>Record-predicate</tt> returns a predicate that return true when passed
  618. a record of type <i>record-type</i> and false otherwise.
  619. <tt>Record-accessor</tt> and <tt>record-modifier</tt> return procedures that
  620. reference and set the given field in records of the approriate type.</p>
  621. <p>
  622. </p>
  623. <ul>
  624. <li><p><tt>(define-record-discloser<i> record-type discloser</i>)</tt><a name="node_idx_172"></a>
  625. </p>
  626. <li><p><tt>(define-record-resumer<i> record-type resumer</i>)</tt><a name="node_idx_174"></a>
  627. </p>
  628. </ul><p>
  629. <tt>Record-types</tt> is the initial exporter of
  630. <tt>define-record-discloser</tt>
  631. (re-exported by <tt>define-record-types</tt> described above)
  632. and
  633. <tt>define-record-resumer</tt>
  634. (re-exported by
  635. <tt>external-calls</tt> (section&nbsp;<a href="manual-Z-H-10.html#node_sec_8.8.3">8.8.3</a>)).</p>
  636. <p>
  637. The procedures described in this section can be used to define new
  638. record-type-defining macros.
  639. </p>
  640. <pre class=verbatim>(define-record-type pare :pare
  641. (kons x y)
  642. pare?
  643. (x kar set-kar!)
  644. (y kdr))
  645. </pre><p>
  646. is (sematically) equivalent to
  647. </p>
  648. <pre class=verbatim>(define :pare (make-record-type 'pare '(x y)))
  649. (define kons (record-constructor :pare '(x y)))
  650. (define kar (record-accessor :pare 'x))
  651. (define set-kar! (record-modifier :pare 'x))
  652. (define kdr (record-accessor :pare 'y))
  653. </pre><p></p>
  654. <p>
  655. The ``(semantically)'' above is because <tt>define-record-type</tt> adds
  656. declarations, which allows the type checker to detect some misuses of records,
  657. and uses more efficient definitions for the constructor, accessors, and
  658. modifiers.
  659. Ignoring the declarations, which will have to wait for another edition of
  660. the manual, what the above example actually expands into is:
  661. </p>
  662. <pre class=verbatim>(define :pare (make-record-type 'pare '(x y)))
  663. (define (kons x y) (record :pare x y))
  664. (define (kar r) (checked-record-ref r :pare 1))
  665. (define (set-kar! r new)
  666. (checked-record-set! r :pare 1 new))
  667. (define (kdr r) (checked-record-ref r :pare 2))
  668. </pre><p>
  669. <tt>Checked-record-ref</tt> and <tt>Checked-record-set!</tt> are
  670. low-level procedures that check the type of the
  671. record and access or modify it using a single VM instruction.</p>
  672. <p>
  673. </p>
  674. <a name="node_sec_5.10"></a>
  675. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.10">5.10&nbsp;&nbsp;Finite record types</a></h2>
  676. <p>The structure <tt>finite-types</tt> has
  677. two macros for defining `finite' record types.
  678. These are record types for which there are a fixed number of instances,
  679. all of which are created at the same time as the record type itself.
  680. The syntax for defining an enumerated type is:
  681. </p>
  682. <pre class=verbatim>(define-enumerated-type <i>tag</i> <i>type-name</i>
  683. <i>predicate-name</i>
  684. <i>vector-of-instances-name</i>
  685. <i>name-accessor</i>
  686. <i>index-accessor</i>
  687. (<i>instance-name</i> <tt>...</tt>))
  688. </pre><p>
  689. This defines a new record type, bound to <i>type-name</i>, with as many
  690. instances as there are <i>instance-name</i>'s.
  691. <i>Vector-of-instances-name</i> is bound to a vector containing the instances
  692. of the type in the same order as the <i>instance-name</i> list.
  693. <i>Tag</i> is bound to a macro that when given an <i>instance-name</i> expands
  694. into an expression that returns corresponding instance.
  695. The name lookup is done at macro expansion time.
  696. <i>Predicate-name</i> is a predicate for the new type.
  697. <i>Name-accessor</i> and <i>index-accessor</i> are accessors for the
  698. name and index (in <i>vector-of-instances</i>) of instances of the type.</p>
  699. <p>
  700. </p>
  701. <pre class=verbatim>(define-enumerated-type color :color
  702. color?
  703. colors
  704. color-name
  705. color-index
  706. (black white purple maroon))
  707. (color-name (vector-ref colors 0)) <code class=verbatim>=&gt; </code>black
  708. (color-name (color white)) <code class=verbatim>=&gt; </code>white
  709. (color-index (color purple)) <code class=verbatim>=&gt; </code>2
  710. </pre><p></p>
  711. <p>
  712. Finite types are enumerations that allow the user to add additional
  713. fields in the type.
  714. The syntax for defining a finite type is:
  715. </p>
  716. <pre class=verbatim>(define-finite-type <i>tag</i> <i>type-name</i>
  717. (<i>field-tag</i> <tt>...</tt>)
  718. <i>predicate-name</i>
  719. <i>vector-of-instances-name</i>
  720. <i>name-accessor</i>
  721. <i>index-accessor</i>
  722. (<i>field-tag</i> <i>accessor-name</i> [<i>modifier-name</i>])
  723. <tt>...</tt>((<i>instance-name</i> <i>field-value</i> <tt>...</tt>)
  724. <tt>...</tt>))
  725. </pre><p>
  726. The additional fields are specified exactly as with <tt>define-record-type</tt>.
  727. The field arguments to the constructor are listed after the <i>type-name</i>;
  728. these do not include the name and index fields.
  729. The form ends with the names and the initial field values for
  730. the instances of the type.
  731. The instances are constructed by applying the (unnamed) constructor to
  732. these initial field values.
  733. The name must be first and
  734. the remaining values must match the <i>field-tag</i>s in the constructor's
  735. argument list.</p>
  736. <p>
  737. </p>
  738. <p>
  739. </p>
  740. <pre class=verbatim>(define-finite-type color :color
  741. (red green blue)
  742. color?
  743. colors
  744. color-name
  745. color-index
  746. (red color-red)
  747. (green color-green)
  748. (blue color-blue)
  749. ((black 0 0 0)
  750. (white 255 255 255)
  751. (purple 160 32 240)
  752. (maroon 176 48 96)))
  753. (color-name (color black)) <code class=verbatim>=&gt; </code>black
  754. (color-name (vector-ref colors 1)) <code class=verbatim>=&gt; </code>white
  755. (color-index (color purple)) <code class=verbatim>=&gt; </code>2
  756. (color-red (color maroon)) <code class=verbatim>=&gt; </code>176
  757. </pre><p></p>
  758. <p>
  759. </p>
  760. <a name="node_sec_5.11"></a>
  761. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.11">5.11&nbsp;&nbsp;Sets over finite types</a></h2>
  762. <p></p>
  763. <p>
  764. The structure <tt>enum-sets</tt> has a macro for defining types for sets
  765. of elements of finite types. These work naturally with the finite
  766. types defined by the <tt>finite-types</tt> structure, but are not tied
  767. to them. The syntax for defining such a type is:</p>
  768. <p>
  769. </p>
  770. <pre class=verbatim>(define-enum-set-type <i>id</i> <i>type-name</i> <i>predicate</i> <i>constructor</i>
  771. <i>element-syntax</i> <i>element-predicate</i> <i>all-elements</i> <i>element-index-ref</i>)
  772. </pre><p>
  773. This defines <i>id</i> to be syntax for constructing sets,
  774. <i>type-name</i> to be a value representing the type,
  775. <i>predicate</i> to be a predicate for those sets, and
  776. <i>constructor</i> a procedure for constructing one from a list.</p>
  777. <p>
  778. <i>Element-syntax</i> must be the name of a macro for constructing set
  779. elements from names (akin to the <i>tag</i> argument to
  780. <tt>define-enumerated-type</tt>). <i>Element-predicate</i> must be a
  781. predicate for the element type, <i>all-elements</i> a vector of all
  782. values of the element type, and <i>element-index-ref</i> must return
  783. the index of an element within the <i>all-elements</i> vector.</p>
  784. <p>
  785. </p>
  786. <ul>
  787. <li><p><tt>(enum-set-&gt;list<i> enum-set</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_176"></a>
  788. </p>
  789. <li><p><tt>(enum-set-member?<i> enum-set enumerand</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_178"></a>
  790. </p>
  791. <li><p><tt>(enum-set=?<i> enum-set enum-set</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_180"></a>
  792. </p>
  793. <li><p><tt>(enum-set-union<i> enum-set enum-set</i>)&nbsp;-&gt;&nbsp;<i>enum-set</i></tt><a name="node_idx_182"></a>
  794. </p>
  795. <li><p><tt>(enum-set-intersection<i> enum-set enum-set</i>)&nbsp;-&gt;&nbsp;<i> enum-set</i></tt><a name="node_idx_184"></a>
  796. </p>
  797. <li><p><tt>(enum-set-negation<i> enum-set</i>)&nbsp;-&gt;&nbsp;<i>enum-set</i></tt><a name="node_idx_186"></a>
  798. </p>
  799. </ul><p>
  800. <tt>Enum-set-&gt;list</tt> converts a set into a list of its elements.
  801. <tt>Enum-set-member?</tt> tests for membership. <tt>Enum-set=?</tt> tests
  802. two sets of equal type for equality. (If its arguments are not of the
  803. same type, <tt>enum-set=?</tt> raises an exception.)
  804. <tt>Enum-set-union</tt> computes the union of two sets of equal type,
  805. <tt>enum-set-intersection</tt> computes the intersection, and
  806. <tt>enum-set-negation</tt> computes the complement of a set.</p>
  807. <p>
  808. Here is an example. Given an enumerated type:</p>
  809. <p>
  810. </p>
  811. <pre class=verbatim>(define-enumerated-type color :color
  812. color?
  813. colors
  814. color-name
  815. color-index
  816. (red blue green))
  817. </pre><p></p>
  818. <p>
  819. we can define sets of colors:</p>
  820. <p>
  821. </p>
  822. <pre class=verbatim>(define-enum-set-type color-set :color-set
  823. color-set?
  824. make-color-set
  825. color color? colors color-index)
  826. </pre><p></p>
  827. <p>
  828. </p>
  829. <pre class=verbatim>&gt; (enum-set-&gt;list (color-set red blue))
  830. (#{Color red} #{Color blue})
  831. &gt; (enum-set-&gt;list (enum-set-negation (color-set red blue)))
  832. (#{Color green})
  833. &gt; (enum-set-member? (color-set red blue) (color blue))
  834. #t
  835. </pre><p></p>
  836. <p>
  837. </p>
  838. <a name="node_sec_5.12"></a>
  839. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.12">5.12&nbsp;&nbsp;Hash tables</a></h2>
  840. <p>These are generic hash tables, and are in the structure <tt>tables</tt>.
  841. Strictly speaking they are more maps than tables, as every table has a
  842. value for every possible key (for that type of table).
  843. All but a finite number of those values are <tt>#f</tt>.</p>
  844. <p>
  845. </p>
  846. <ul>
  847. <li><p><tt>(make-table<i></i>)&nbsp;-&gt;&nbsp;<i>table</i></tt><a name="node_idx_188"></a>
  848. </p>
  849. <li><p><tt>(make-symbol-table<i></i>)&nbsp;-&gt;&nbsp;<i>symbol-table</i></tt><a name="node_idx_190"></a>
  850. </p>
  851. <li><p><tt>(make-string-table<i></i>)&nbsp;-&gt;&nbsp;<i>string-table</i></tt><a name="node_idx_192"></a>
  852. </p>
  853. <li><p><tt>(make-integer-table<i></i>)&nbsp;-&gt;&nbsp;<i>integer-table</i></tt><a name="node_idx_194"></a>
  854. </p>
  855. <li><p><tt>(make-table-maker<i> compare-proc hash-proc</i>)&nbsp;-&gt;&nbsp;<i>procedure</i></tt><a name="node_idx_196"></a>
  856. </p>
  857. <li><p><tt>(make-table-immutable!<i> table</i>)</tt><a name="node_idx_198"></a>
  858. </p>
  859. </ul><p>
  860. The first four functions listed make various kinds of tables.
  861. <tt>Make-table</tt> returns a table whose keys may be symbols, integer,
  862. characters, booleans, or the empty list (these are also the values
  863. that may be used in <tt>case</tt> expressions).
  864. As with <tt>case</tt>, comparison is done using <tt>eqv?</tt>.
  865. The comparison procedures used in symbol, string, and integer tables are
  866. <tt>eq?</tt>, <tt>string=?</tt>, and <tt>=</tt>.</p>
  867. <p>
  868. <tt>Make-table-maker</tt> takes two procedures as arguments and returns
  869. a nullary table-making procedure.
  870. <i>Compare-proc</i> should be a two-argument equality predicate.
  871. <i>Hash-proc</i> should be a one argument procedure that takes a key
  872. and returns a non-negative integer hash value.
  873. If <tt>(<i>compare-proc</i> <i>x</i> <i>y</i>)</tt> returns true,
  874. then <tt>(= (<i>hash-proc</i> <i>x</i>) (<i>hash-proc</i> <i>y</i>))</tt>
  875. must also return true.
  876. For example, <tt>make-integer-table</tt> could be defined
  877. as <tt>(make-table-maker = abs)</tt>.</p>
  878. <p>
  879. <tt>Make-table-immutable!</tt> prohibits future modification to its argument.</p>
  880. <p>
  881. </p>
  882. <ul>
  883. <li><p><tt>(table?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_200"></a>
  884. </p>
  885. <li><p><tt>(table-ref<i> table key</i>)&nbsp;-&gt;&nbsp;<i>value or <tt>#f</tt></i></tt><a name="node_idx_202"></a>
  886. </p>
  887. <li><p><tt>(table-set!<i> table key value</i>)</tt><a name="node_idx_204"></a>
  888. </p>
  889. <li><p><tt>(table-walk<i> procedure table</i>)</tt><a name="node_idx_206"></a>
  890. </p>
  891. </ul><p>
  892. <tt>Table?</tt> is the predicate for tables.
  893. <tt>Table-ref</tt> and <tt>table-set!</tt> access and modify the value of <i>key</i>
  894. in <i>table</i>.
  895. <tt>Table-walk</tt> applies <i>procedure</i>, which must accept two arguments,
  896. to every associated key and non-<tt>#f</tt> value in <tt>table</tt>.</p>
  897. <p>
  898. </p>
  899. <ul>
  900. <li><p><tt>(default-hash-function<i> value</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_208"></a>
  901. </p>
  902. <li><p><tt>(string-hash<i> string</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_210"></a>
  903. </p>
  904. </ul><p>
  905. <tt>Default-hash-function</tt> is the hash function used in the tables
  906. returned by <tt>make-table</tt>, and <tt>string-hash</tt> it the one used
  907. by <tt>make-string-table</tt>.</p>
  908. <p>
  909. </p>
  910. <a name="node_sec_5.13"></a>
  911. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.13">5.13&nbsp;&nbsp;Port extensions</a></h2>
  912. <p>These procedures are in structure <tt>extended-ports</tt>.</p>
  913. <p>
  914. </p>
  915. <ul>
  916. <li><p><tt>(make-string-input-port<i> string</i>)&nbsp;-&gt;&nbsp;<i>input-port</i></tt><a name="node_idx_212"></a>
  917. </p>
  918. <li><p><tt>(make-string-output-port<i></i>)&nbsp;-&gt;&nbsp;<i>output-port</i></tt><a name="node_idx_214"></a>
  919. </p>
  920. <li><p><tt>(string-output-port-output<i> string-output-port</i>)&nbsp;-&gt;&nbsp;<i>string</i></tt><a name="node_idx_216"></a>
  921. </p>
  922. </ul><p>
  923. <tt>Make-string-input-port</tt> returns an input port that
  924. that reads characters from the supplied string. An end-of-file
  925. object is returned if the user reads past the end of the string.
  926. <tt>Make-string-output-port</tt> returns an output port that saves
  927. the characters written to it.
  928. These are then returned as a string by <tt>string-output-port-output</tt>.</p>
  929. <p>
  930. </p>
  931. <pre class=verbatim>(read (make-string-input-port &quot;(a b)&quot;))
  932. <code class=verbatim>=&gt; </code>'(a b)
  933. (let ((p (make-string-output-port)))
  934. (write '(a b) p)
  935. (let ((s (string-output-port-output p)))
  936. (display &quot;c&quot; p)
  937. (list s (string-output-port-output p))))
  938. <code class=verbatim>=&gt; </code>'(&quot;(a b)&quot; &quot;(a b)c&quot;)
  939. </pre><p></p>
  940. <p>
  941. </p>
  942. <ul>
  943. <li><p><tt>(limit-output<i> output-port n procedure</i>)</tt><a name="node_idx_218"></a>
  944. </p>
  945. </ul><p>
  946. <i>Procedure</i> is called on an output port.
  947. Output written to that port is copied to <i>output-port</i> until <i>n</i>
  948. characters have been written, at which point <tt>limit-output</tt> returns.
  949. If <i>procedure</i> returns before writing <i>n</i> characters, then
  950. <tt>limit-output</tt> also returns at that time, regardless of how many
  951. characters have been written.</p>
  952. <p>
  953. </p>
  954. <ul>
  955. <li><p><tt>(make-tracking-input-port<i> input-port</i>)&nbsp;-&gt;&nbsp;<i>input-port</i></tt><a name="node_idx_220"></a>
  956. </p>
  957. <li><p><tt>(make-tracking-output-port<i> output-port</i>)&nbsp;-&gt;&nbsp;<i>output-port</i></tt><a name="node_idx_222"></a>
  958. </p>
  959. <li><p><tt>(current-row<i> port</i>)&nbsp;-&gt;&nbsp;<i>integer or <tt>#f</tt></i></tt><a name="node_idx_224"></a>
  960. </p>
  961. <li><p><tt>(current-column<i> port</i>)&nbsp;-&gt;&nbsp;<i>integer or <tt>#f</tt></i></tt><a name="node_idx_226"></a>
  962. </p>
  963. <li><p><tt>(fresh-line<i> output-port</i>)</tt><a name="node_idx_228"></a>
  964. </p>
  965. </ul><p>
  966. <tt>Make-tracking-input-port</tt> and <tt>make-tracking-output-port</tt>
  967. return ports that keep track of the current row and column and
  968. are otherwise identical to their arguments.
  969. Closing a tracking port does not close the underlying port.
  970. <tt>Current-row</tt> and <tt>current-column</tt> return
  971. <i>port</i>'s current read or write location.
  972. They return <tt>#f</tt> if <i>port</i> does not keep track of its location.
  973. <tt>Fresh-line</tt> writes a newline character to <i>output-port</i> if
  974. <tt>(current-row <i>port</i>)</tt> is not 0.</p>
  975. <p>
  976. </p>
  977. <pre class=verbatim>(define p (open-output-port &quot;/tmp/temp&quot;))
  978. (list (current-row p) (current-column p))
  979. <code class=verbatim>=&gt; </code>'(0 0)
  980. (display &quot;012&quot; p)
  981. (list (current-row p) (current-column p))
  982. <code class=verbatim>=&gt; </code>'(0 3)
  983. (fresh-line p)
  984. (list (current-row p) (current-column p))
  985. <code class=verbatim>=&gt; </code>'(1 0)
  986. (fresh-line p)
  987. (list (current-row p) (current-column p))
  988. <code class=verbatim>=&gt; </code>'(1 0)
  989. </pre><p></p>
  990. <p>
  991. </p>
  992. <a name="node_sec_5.14"></a>
  993. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.14">5.14&nbsp;&nbsp;Fluid bindings</a></h2>
  994. <p>These procedures implement dynamic binding and are in structure <tt>fluids</tt>.
  995. A <i>fluid</i> is a cell whose value can be bound dynamically.
  996. Each fluid has a top-level value that is used when the fluid
  997. is unbound in the current dynamic environment.</p>
  998. <p>
  999. </p>
  1000. <ul>
  1001. <li><p><tt>(make-fluid<i> value</i>)&nbsp;-&gt;&nbsp;<i>fluid</i></tt><a name="node_idx_230"></a>
  1002. </p>
  1003. <li><p><tt>(fluid<i> fluid</i>)&nbsp;-&gt;&nbsp;<i>value</i></tt><a name="node_idx_232"></a>
  1004. </p>
  1005. <li><p><tt>(let-fluid<i> fluid value thunk</i>)&nbsp;-&gt;&nbsp;<i>value(s)</i></tt><a name="node_idx_234"></a>
  1006. </p>
  1007. <li><p><tt>(let-fluids<i> fluid<sub>0</sub> value<sub>0</sub> fluid<sub>1</sub> value<sub>1</sub> <tt>...</tt>thunk</i>)&nbsp;-&gt;&nbsp;<i>value(s)</i></tt><a name="node_idx_236"></a>
  1008. </p>
  1009. </ul><p>
  1010. <tt>Make-fluid</tt> returns a new fluid with <i>value</i> as its initial
  1011. top-level value.
  1012. <tt>Fluid</tt> returns <tt>fluid</tt>'s current value.
  1013. <tt>Let-fluid</tt> calls <tt>thunk</tt>, with <i>fluid</i> bound to <i>value</i>
  1014. until <tt>thunk</tt> returns.
  1015. Using a continuation to throw out of the call to <tt>thunk</tt> causes
  1016. <i>fluid</i> to revert to its original value, while throwing back
  1017. in causes <i>fluid</i> to be rebound to <i>value</i>.
  1018. <tt>Let-fluid</tt> returns the value(s) returned by <i>thunk</i>.
  1019. <tt>Let-fluids</tt> is identical to <tt>let-fluid</tt> except that it binds
  1020. an arbitrary number of fluids to new values.</p>
  1021. <p>
  1022. </p>
  1023. <pre class=verbatim>(let* ((f (make-fluid 'a))
  1024. (v0 (fluid f))
  1025. (v1 (let-fluid f 'b
  1026. (lambda ()
  1027. (fluid f))))
  1028. (v2 (fluid f)))
  1029. (list v0 v1 v2))
  1030. <code class=verbatim>=&gt; </code>'(a b a)
  1031. </pre><p></p>
  1032. <p>
  1033. </p>
  1034. <pre class=verbatim>(let ((f (make-fluid 'a))
  1035. (path '())
  1036. (c #f))
  1037. (let ((add (lambda ()
  1038. (set! path (cons (fluid f) path)))))
  1039. (add)
  1040. (let-fluid f 'b
  1041. (lambda ()
  1042. (call-with-current-continuation
  1043. (lambda (c0)
  1044. (set! c c0)))
  1045. (add)))
  1046. (add)
  1047. (if (&lt; (length path) 5)
  1048. (c)
  1049. (reverse path))))
  1050. <code class=verbatim>=&gt; </code>'(a b a b a)
  1051. </pre><p></p>
  1052. <p>
  1053. </p>
  1054. <a name="node_sec_5.15"></a>
  1055. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.15">5.15&nbsp;&nbsp;OS strings</a></h2>
  1056. <p></p>
  1057. <p>
  1058. <a name="node_idx_238"></a>
  1059. On common operating systems such as Unix and Windows, various
  1060. parameters to OS functionality -- such as file names, user names,
  1061. command-line arguments etc. -- appear as text in most contexts, but are
  1062. really byte sequences: On Unix, the byte sequence may be interpreted
  1063. as text through some locale-determined encoding. On Windows, such
  1064. parameters are typically represented as sequences of UTF-16 code
  1065. units. In both cases, not every such byte sequence has a string
  1066. equivalent: On Unix, a byte sequence encoding a file name using
  1067. Latin-1 often cannot be decoded using UTF-8. On Windows, unpaired
  1068. UTF-16 surrogates are admissible in encodings, and no lossless text
  1069. decoding for them exists.</p>
  1070. <p>
  1071. For representing such string-like parameters, Scheme&nbsp;48 uses an
  1072. abstraction called <i>OS strings</i>. An OS string is created from
  1073. either a string or a NUL-terminated byte sequence stored in a byte
  1074. vector, and has an associated text codec (see
  1075. section&nbsp;<a href="manual-Z-H-8.html#node_sec_6.6.1">6.6.1</a>) that is able to convert from one
  1076. representation to the other. The exact meaning of a NUL-terminated
  1077. byte sequence is dependent on this text codec. However, only codecs
  1078. for encodings that are a conservative extension of ASCII (such as
  1079. ASCII itself, Latin-1, or UTF-8) should be used here, to allow a
  1080. minimal set of portable file names. (The Windows port uses a special
  1081. synthetic encoding called UTF-8of16 compatible with UTF-8 but capable
  1082. of encoding even invalid UTF-16 internally, but uses the UTF-8 codec
  1083. at the Scheme level.)</p>
  1084. <p>
  1085. Most procedures accepting OS strings also accept strings or byte
  1086. vectors, which are then used to construct a OS string. In the headers
  1087. of the specifications of these procedures, such arguments occur as
  1088. <i>os-string-thing</i>.<a name="node_idx_240"></a>
  1089. The standard Scheme procedures such as <tt>open-input-file</tt> that
  1090. take file names all accept <i>os-string-thing</i> arguments. OS
  1091. strings are in the <tt>os-strings</tt> structure.</p>
  1092. <p>
  1093. </p>
  1094. <ul>
  1095. <li><p><tt>(string-&gt;os-string<i> string</i>)&nbsp;-&gt;&nbsp;<i>os-string</i></tt><a name="node_idx_242"></a>
  1096. </p>
  1097. <li><p><tt>(byte-vector-&gt;os-string<i> byte-vector</i>)&nbsp;-&gt;&nbsp;<i>os-string</i></tt><a name="node_idx_244"></a>
  1098. </p>
  1099. <li><p><tt>(x-&gt;os-string<i> os-string-thing</i>)&nbsp;-&gt;&nbsp;<i>os-string</i></tt><a name="node_idx_246"></a>
  1100. </p>
  1101. </ul><p>
  1102. These procedures create an OS string from a string, a byte-vector
  1103. (whose last value should be 0), and an <i>os-string-thing</i> argument,
  1104. respectively, always using the standard OS-string text codec (see
  1105. below).</p>
  1106. <p>
  1107. </p>
  1108. <ul>
  1109. <li><p><tt>(os-string-&gt;byte-vector<i> os-string</i>)&nbsp;-&gt;&nbsp;<i>byte-vector</i></tt><a name="node_idx_248"></a>
  1110. </p>
  1111. <li><p><tt>(os-string-&gt;string<i> os-string</i>)&nbsp;-&gt;&nbsp;<i>string</i></tt><a name="node_idx_250"></a>
  1112. </p>
  1113. </ul><p>
  1114. These procedures yield the contents of an OS string. For an OS string
  1115. created from a string, <tt>os-string-&gt;string</tt> will return a string
  1116. with the same contents; for an OS string created from a byte vector,
  1117. <tt>os-string-&gt;byte-vector</tt> will return a byte vector with the same
  1118. contents. For the other cases, data loss as determined by the text
  1119. codec is possible.</p>
  1120. <p>
  1121. </p>
  1122. <ul>
  1123. <li><p><tt>(current-os-string-text-codec<i></i>)&nbsp;-&gt;&nbsp;<i>text-codec</i></tt><a name="node_idx_252"></a>
  1124. </p>
  1125. <li><p><tt>(call-with-os-string-text-codec<i> text-codec thunk</i>)&nbsp;-&gt;&nbsp;<i> value(s)</i></tt><a name="node_idx_254"></a>
  1126. </p>
  1127. </ul><p>
  1128. The <tt>current-os-string-text-codec</tt> returns the current text codec
  1129. used for creating new OS strings. The initial default is determined
  1130. by the operating system. (On Unix, this is the text codec determined
  1131. by the locale. On Windows, this is UTF-8.) The
  1132. <tt>call-with-os-string-text-codec</tt> procedure dynamically binds the
  1133. current text codec to <i>text-codec</i> during the invocation of
  1134. <i>thunk</i>.</p>
  1135. <p>
  1136. </p>
  1137. <a name="node_sec_5.16"></a>
  1138. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.16">5.16&nbsp;&nbsp;Shell commands</a></h2>
  1139. <p>Structure <tt>c-system-function</tt> provides access to the C <tt>system()</tt>
  1140. function.</p>
  1141. <p>
  1142. </p>
  1143. <ul>
  1144. <li><p><tt>(have-system?<i></i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_256"></a>
  1145. </p>
  1146. <li><p><tt>(system<i> os-string-thing</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_258"></a>
  1147. </p>
  1148. </ul><p>
  1149. <tt>Have-system?</tt> returns true if the underlying C implementation
  1150. has a command processor.
  1151. <tt>(System <i>string</i>)</tt> passes <i>string</i> to the C
  1152. <tt>system()</tt> function and returns the result.</p>
  1153. <p>
  1154. </p>
  1155. <pre class=verbatim>(begin
  1156. (system &quot;echo foo &gt; test-file&quot;)
  1157. (call-with-input-file &quot;test-file&quot; read))
  1158. <code class=verbatim>=&gt; </code>'foo
  1159. </pre><p></p>
  1160. <p>
  1161. </p>
  1162. <a name="node_sec_5.17"></a>
  1163. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.17">5.17&nbsp;&nbsp;Sockets</a></h2>
  1164. <p></p>
  1165. <p>
  1166. Structure <tt>sockets</tt> provides access to TCP/IP sockets for interprocess
  1167. and network communication.</p>
  1168. <p>
  1169. </p>
  1170. <ul>
  1171. <li><p><tt>(open-socket<i></i>)&nbsp;-&gt;&nbsp;<i>socket</i></tt><a name="node_idx_260"></a>
  1172. </p>
  1173. <li><p><tt>(open-socket<i> port-number</i>)&nbsp;-&gt;&nbsp;<i>socket</i></tt><a name="node_idx_262"></a>
  1174. </p>
  1175. <li><p><tt>(socket-port-number<i> socket</i>)&nbsp;-&gt;&nbsp;<i>integer</i></tt><a name="node_idx_264"></a>
  1176. </p>
  1177. <li><p><tt>(close-socket<i> socket</i>)</tt><a name="node_idx_266"></a>
  1178. </p>
  1179. <li><p><tt>(socket-accept<i> socket</i>)&nbsp;-&gt;&nbsp;<i>input-port output-port</i></tt><a name="node_idx_268"></a>
  1180. </p>
  1181. <li><p><tt>(get-host-name<i></i>)&nbsp;-&gt;&nbsp;<i>string</i></tt><a name="node_idx_270"></a>
  1182. </p>
  1183. </ul><p>
  1184. <tt>Open-socket</tt> creates a new socket.
  1185. If no <i>port-number</i> is supplied the system picks one at random.
  1186. <tt>Socket-port-number</tt> returns a socket's port number.
  1187. <tt>Close-socket</tt> closes a socket, preventing any further connections.
  1188. <tt>Socket-accept</tt> accepts a single connection on <i>socket</i>, returning
  1189. an input port and an output port for communicating with the client.
  1190. If no client is waiting <tt>socket-accept</tt> blocks until one appears.
  1191. <tt>Get-host-name</tt> returns the network name of the machine.</p>
  1192. <p>
  1193. </p>
  1194. <ul>
  1195. <li><p><tt>(socket-client<i> host-name port-number</i>)&nbsp;-&gt;&nbsp;<i>input-port output-port</i></tt><a name="node_idx_272"></a>
  1196. </p>
  1197. </ul><p>
  1198. <tt>Socket-client</tt> connects to the server at <i>port-number</i> on
  1199. the machine named <i>host-name</i>.
  1200. <tt>Socket-client</tt> blocks until the server accepts the connection.</p>
  1201. <p>
  1202. The following simple example shows a server and client for a centralized UID
  1203. service.
  1204. </p>
  1205. <pre class=verbatim>(define (id-server)
  1206. (let ((socket (open-socket)))
  1207. (display &quot;Waiting on port &quot;)
  1208. (display (socket-port-number socket))
  1209. (newline)
  1210. (let loop ((next-id 0))
  1211. (call-with-values
  1212. (lambda ()
  1213. (socket-accept socket))
  1214. (lambda (in out)
  1215. (display next-id out)
  1216. (close-input-port in)
  1217. (close-output-port out)
  1218. (loop (+ next-id 1)))))))
  1219. (define (get-id machine port-number)
  1220. (call-with-values
  1221. (lambda ()
  1222. (socket-client machine port-number))
  1223. (lambda (in out)
  1224. (let ((id (read in)))
  1225. (close-input-port in)
  1226. (close-output-port out)
  1227. id))))
  1228. </pre><p></p>
  1229. <p>
  1230. </p>
  1231. <a name="node_sec_5.18"></a>
  1232. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.18">5.18&nbsp;&nbsp;Macros for writing loops</a></h2>
  1233. <p></p>
  1234. <p>
  1235. <tt>Iterate</tt> and <tt>reduce</tt> are extensions of named-<tt>let</tt> for
  1236. writing loops that walk down one or more sequences,
  1237. such as the elements of a list or vector, the
  1238. characters read from a port, or an arithmetic series.
  1239. Additional sequences can be defined by the user.
  1240. <tt>Iterate</tt> and <tt>reduce</tt> are in structure <tt>reduce</tt>.</p>
  1241. <p>
  1242. </p>
  1243. <a name="node_sec_5.18.1"></a>
  1244. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.1">5.18.1&nbsp;&nbsp;<tt>Iterate</tt></a></h3>
  1245. <p>The syntax of <tt>iterate</tt> is:
  1246. </p>
  1247. <pre class=verbatim> (iterate <i>loop-name</i>
  1248. ((<i>sequence-type</i> <i>element-variable</i> <i>sequence-data</i> <tt>...</tt>)
  1249. <tt>...</tt>)
  1250. ((<i>state-variable</i> <i>initial-value</i>)
  1251. <tt>...</tt>)
  1252. <i>body-expression</i>
  1253. [<i>final-expression</i>])
  1254. </pre><p></p>
  1255. <p>
  1256. <tt>Iterate</tt> steps the <i>element-variable</i>s in parallel through the
  1257. sequences, while each <i>state-variable</i> has the corresponding
  1258. <i>initial-value</i> for the first iteration and have later values
  1259. supplied by <i>body-expression</i>.
  1260. If any sequence has reached its limit the value of the <tt>iterate</tt>
  1261. expression is
  1262. the value of <i>final-expression</i>, if present, or the current values of
  1263. the <i>state-variable</i>s, returned as multiple values.
  1264. If no sequence has reached
  1265. its limit, <i>body-expression</i> is evaluated and either calls <i>loop-name</i> with
  1266. new values for the <i>state-variable</i>s, or returns some other value(s).</p>
  1267. <p>
  1268. The <i>loop-name</i> and the <i>state-variable</i>s and <i>initial-value</i>s behave
  1269. exactly as in named-<tt>let</tt>. The named-<tt>let</tt> expression
  1270. </p>
  1271. <pre class=verbatim> (let loop-name ((state-variable initial-value) ...)
  1272. body ...)
  1273. </pre><p>
  1274. is equivalent to an <tt>iterate</tt> expression with no sequences
  1275. (and with an explicit
  1276. <tt>let</tt> wrapped around the body expressions to take care of any
  1277. internal <tt>define</tt>s):
  1278. </p>
  1279. <pre class=verbatim> (iterate loop-name
  1280. ()
  1281. ((state-variable initial-value) ...)
  1282. (let () body ...))
  1283. </pre><p></p>
  1284. <p>
  1285. The <i>sequence-type</i>s are keywords (they are actually macros of a particular
  1286. form; it is easy to add additional types of sequences).
  1287. Examples are <tt>list*</tt> which walks down the elements of a list and
  1288. <tt>vector*</tt> which does the same for vectors.
  1289. For each iteration, each <i>element-variable</i> is bound to the next
  1290. element of the sequence.
  1291. The <i>sequence-data</i> gives the actual list or vector or whatever.</p>
  1292. <p>
  1293. If there is a <i>final-expression</i>, it is evaluated when the end of one or more
  1294. sequences is reached.
  1295. If the <i>body-expression</i> does not call <i>loop-name</i> the
  1296. <i>final-expression</i> is not evaluated.
  1297. The <i>state-variable</i>s are visible in
  1298. <i>final-expression</i> but the <i>sequence-variable</i>s are not. </p>
  1299. <p>
  1300. The <i>body-expression</i> and the <i>final-expression</i> are in tail-position within
  1301. the <tt>iterate</tt>.
  1302. Unlike named-<tt>let</tt>, the behavior of a non-tail-recursive call to
  1303. <i>loop-name</i> is unspecified (because iterating down a sequence may involve side
  1304. effects, such as reading characters from a port).</p>
  1305. <p>
  1306. </p>
  1307. <a name="node_sec_5.18.2"></a>
  1308. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.2">5.18.2&nbsp;&nbsp;<tt>Reduce</tt></a></h3>
  1309. <p>If an <tt>iterate</tt> expression is not meant to terminate before a sequence
  1310. has reached its end,
  1311. <i>body-expression</i> will always end with a tail call to <i>loop-name</i>.
  1312. <tt>Reduce</tt> is a macro that makes this common case explicit.
  1313. The syntax of <tt>reduce</tt> is
  1314. the same as that of <tt>iterate</tt>, except that there is no <i>loop-name</i>.
  1315. The <i>body-expression</i> returns new values of the <i>state-variable</i>s
  1316. instead of passing them to <i>loop-name</i>.
  1317. Thus <i>body-expression</i> must return as many values as there are state
  1318. variables.
  1319. By special dispensation, if there are
  1320. no state variables then <i>body-expression</i> may return any number of values,
  1321. all of which are ignored.</p>
  1322. <p>
  1323. The syntax of <tt>reduce</tt> is:
  1324. </p>
  1325. <pre class=verbatim> (reduce ((<i>sequence-type</i> <i>element-variable</i> <i>sequence-data</i> <tt>...</tt>)
  1326. <tt>...</tt>)
  1327. ((<i>state-variable</i> <i>initial-value</i>)
  1328. <tt>...</tt>)
  1329. <i>body-expression</i>
  1330. [<i>final-expression</i>])
  1331. </pre><p></p>
  1332. <p>
  1333. The value(s) returned by an instance of <tt>reduce</tt> is the value(s) returned
  1334. by the <i>final-expression</i>, if present, or the current value(s) of the state
  1335. variables when the end of one or more sequences is reached.</p>
  1336. <p>
  1337. A <tt>reduce</tt> expression can be rewritten as an equivalent <tt>iterate</tt>
  1338. expression by adding a <i>loop-var</i> and a wrapper for the
  1339. <i>body-expression</i> that calls the <i>loop-var</i>.
  1340. </p>
  1341. <pre class=verbatim>(iterate loop
  1342. ((<i>sequence-type</i> <i>element-variable</i> <i>sequence-data</i> <tt>...</tt>)
  1343. <tt>...</tt>)
  1344. ((<i>state-variable</i> <i>initial-value</i>)
  1345. <tt>...</tt>)
  1346. (call-with-values (lambda ()
  1347. <i>body-expression</i>)
  1348. loop)
  1349. [<i>final-expression</i>])
  1350. </pre><p></p>
  1351. <p>
  1352. </p>
  1353. <a name="node_sec_5.18.3"></a>
  1354. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.3">5.18.3&nbsp;&nbsp;Sequence types</a></h3>
  1355. <p>The predefined sequence types are:
  1356. </p>
  1357. <ul>
  1358. <li><p><tt>(list* <i>elt-var</i> <i>list</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1359. </p>
  1360. <li><p><tt>(vector* <i>elt-var</i> <i>vector</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1361. </p>
  1362. <li><p><tt>(string* <i>elt-var</i> <i>string</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1363. </p>
  1364. <li><p><tt>(count* <i>elt-var</i> <i>start</i> [<i>end</i> [<i>step</i>]])</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1365. </p>
  1366. <li><p><tt>(input* <i>elt-var</i> <i>input-port</i> <i>read-procedure</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1367. </p>
  1368. <li><p><tt>(stream* <i>elt-var</i> <i>procedure</i> <i>initial-data</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1369. </p>
  1370. </ul><p></p>
  1371. <p>
  1372. For lists, vectors, and strings the element variable is bound to the
  1373. successive elements of the list or vector, or the characters in the
  1374. string.</p>
  1375. <p>
  1376. For <tt>count*</tt> the element variable is bound to the elements of the sequence
  1377. </p>
  1378. <pre class=verbatim> <i>start</i>, <i>start</i> + <i>step</i>, <i>start</i> + 2<i>step</i>, <tt>...</tt>, <i>end</i>
  1379. </pre><p>
  1380. inclusive of <i>start</i> and exclusive of <i>end</i>.
  1381. The default <i>step</i> is 1.
  1382. The sequence does not terminate if no <i>end</i> is given or if there
  1383. is no <em>N</em> &gt; 0 such that <i>end</i> = <i>start</i> + N<i>step</i>
  1384. (<tt>=</tt> is used to test for termination).
  1385. For example, <tt>(count* i 0 -1)</tt> doesn't terminate
  1386. because it begins past the <i>end</i> value and <tt>(count* i 0 1 2)</tt> doesn't
  1387. terminate because it skips over the <i>end</i> value.</p>
  1388. <p>
  1389. For <tt>input*</tt> the elements are the results of successive applications
  1390. of <i>read-procedure</i> to <i>input-port</i>.
  1391. The sequence ends when <i>read-procedure</i> returns an end-of-file object.</p>
  1392. <p>
  1393. For a stream, the <i>procedure</i> takes the current data value as an argument
  1394. and returns two values, the next value of the sequence and a new data value.
  1395. If the new data is <tt>#f</tt> then the previous element was the last
  1396. one. For example,
  1397. </p>
  1398. <pre class=verbatim> (list* elt my-list)
  1399. </pre><p>
  1400. is the same as
  1401. </p>
  1402. <pre class=verbatim> (stream* elt list-&gt;stream my-list)
  1403. </pre><p>
  1404. where <tt>list-&gt;stream</tt> is
  1405. </p>
  1406. <pre class=verbatim> (lambda (list)
  1407. (if (null? list)
  1408. (values 'ignored #f)
  1409. (values (car list) (cdr list))))
  1410. </pre><p></p>
  1411. <p>
  1412. </p>
  1413. <a name="node_sec_5.18.4"></a>
  1414. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.4">5.18.4&nbsp;&nbsp;Synchronous sequences</a></h3>
  1415. <p>When using the sequence types described above, a loop terminates when any of
  1416. its sequences reaches its end. To help detect bugs it is useful to have
  1417. sequence types that check to see if two or more sequences end on the same
  1418. iteration. For this purpose there is second set of sequence types called
  1419. synchronous sequences. These are identical to the ones listed above except
  1420. that they cause an error to be signalled if a loop is terminated by a
  1421. synchronous sequence and some other synchronous sequence did not reach its
  1422. end on the same iteration.</p>
  1423. <p>
  1424. Sequences are checked for termination in order, from left to right, and
  1425. if a loop is terminated by a non-synchronous sequence no further checking
  1426. is done.</p>
  1427. <p>
  1428. The synchronous sequences are:</p>
  1429. <p>
  1430. </p>
  1431. <ul>
  1432. <li><p><tt>(list% <i>elt-var</i> <i>list</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1433. </p>
  1434. <li><p><tt>(vector% <i>elt-var</i> <i>vector</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1435. </p>
  1436. <li><p><tt>(string% <i>elt-var</i> <i>string</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1437. </p>
  1438. <li><p><tt>(count% <i>elt-var</i> <i>start</i> <i>end</i> [<i>step</i>])</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1439. </p>
  1440. <li><p><tt>(input% <i>elt-var</i> <i>input-port</i> <i>read-procedure</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1441. </p>
  1442. <li><p><tt>(stream% <i>elt-var</i> <i>procedure</i> <i>initial-data</i>)</tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(syntax)
  1443. </p>
  1444. </ul><p></p>
  1445. <p>
  1446. Note that the synchronous <tt>count%</tt> must have an <i>end</i>, unlike the
  1447. nonsynchronous <tt>count%</tt>.</p>
  1448. <p>
  1449. </p>
  1450. <a name="node_sec_5.18.5"></a>
  1451. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.5">5.18.5&nbsp;&nbsp;Examples</a></h3>
  1452. <p>Gathering the indexes of list elements that answer true to some
  1453. predicate.
  1454. </p>
  1455. <pre class=verbatim>(lambda (my-list predicate)
  1456. (reduce ((list* elt my-list)
  1457. (count* i 0))
  1458. ((hits '()))
  1459. (if (predicate elt)
  1460. (cons i hits)
  1461. hits)
  1462. (reverse hits))
  1463. </pre><p></p>
  1464. <p>
  1465. Looking for the index of an element of a list.
  1466. </p>
  1467. <pre class=verbatim>(lambda (my-list predicate)
  1468. (iterate loop
  1469. ((list* elt my-list)
  1470. (count* i 0))
  1471. () ; no state
  1472. (if (predicate elt)
  1473. i
  1474. (loop))))
  1475. </pre><p></p>
  1476. <p>
  1477. Reading one line.
  1478. </p>
  1479. <pre class=verbatim>(define (read-line port)
  1480. (iterate loop
  1481. ((input* c port read-char))
  1482. ((chars '()))
  1483. (if (char=? c #<code class=verbatim>\</code>newline)
  1484. (list-&gt;string (reverse chars))
  1485. (loop (cons c chars)))
  1486. (if (null? chars)
  1487. (eof-object)
  1488. ; no newline at end of file
  1489. (list-&gt;string (reverse chars)))))
  1490. </pre><p></p>
  1491. <p>
  1492. Counting the lines in a file. We can't use <tt>count*</tt> because we
  1493. need the value of the count after the loop has finished.
  1494. </p>
  1495. <pre class=verbatim>(define (line-count name)
  1496. (call-with-input-file name
  1497. (lambda (in)
  1498. (reduce ((input* l in read-line))
  1499. ((i 0))
  1500. (+ i 1)))))
  1501. </pre><p></p>
  1502. <p>
  1503. </p>
  1504. <a name="node_sec_5.18.6"></a>
  1505. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.6">5.18.6&nbsp;&nbsp;Defining sequence types</a></h3>
  1506. <p>The sequence types are object-oriented macros similar to enumerations.
  1507. A non-synchronous sequence macro needs to supply three values:
  1508. <tt>#f</tt> to indicate that it isn't synchronous, a list of state variables
  1509. and their initializers, and the code for one iteration.
  1510. The first
  1511. two methods are CPS'ed: they take another macro and argument to
  1512. which to pass their result.
  1513. The <tt>synchronized?</tt> method gets no additional arguments.
  1514. The <tt>state-vars</tt> method is passed a list of names which
  1515. will be bound to the arguments to the sequence.
  1516. The final method, for the step, is passed the list of names bound to
  1517. the arguments and the list of state variables.
  1518. In addition there is
  1519. a variable to be bound to the next element of the sequence, the
  1520. body expression for the loop, and an expression for terminating the
  1521. loop.</p>
  1522. <p>
  1523. The definition of <tt>list*</tt> is
  1524. </p>
  1525. <pre class=verbatim>(define-syntax list*
  1526. (syntax-rules (synchronized? state-vars step)
  1527. ((list* synchronized? (next more))
  1528. (next #f more))
  1529. ((list* state-vars (start-list) (next more))
  1530. (next ((list-var start-list)) more))
  1531. ((list* step (start-list) (list-var)
  1532. value-var loop-body final-exp)
  1533. (if (null? list-var)
  1534. final-exp
  1535. (let ((value-var (car list-var))
  1536. (list-var (cdr list-var)))
  1537. loop-body)))))
  1538. </pre><p></p>
  1539. <p>
  1540. Synchronized sequences are the same, except that they need to
  1541. provide a termination test to be used when some other synchronized
  1542. method terminates the loop.
  1543. </p>
  1544. <pre class=verbatim>(define-syntax list%
  1545. (syntax-rules (sync done)
  1546. ((list% sync (next more))
  1547. (next #t more))
  1548. ((list% done (start-list) (list-var))
  1549. (null? list-var))
  1550. ((list% stuff ...)
  1551. (list* stuff ...))))
  1552. </pre><p></p>
  1553. <p>
  1554. </p>
  1555. <a name="node_sec_5.18.7"></a>
  1556. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.18.7">5.18.7&nbsp;&nbsp;Expanded code</a></h3>
  1557. <p>The expansion of
  1558. </p>
  1559. <pre class=verbatim> (reduce ((list* x '(1 2 3)))
  1560. ((r '()))
  1561. (cons x r))
  1562. </pre><p>
  1563. is
  1564. </p>
  1565. <pre class=verbatim> (let ((final (lambda (r) (values r)))
  1566. (list '(1 2 3))
  1567. (r '()))
  1568. (let loop ((list list) (r r))
  1569. (if (null? list)
  1570. (final r)
  1571. (let ((x (car list))
  1572. (list (cdr list)))
  1573. (let ((continue (lambda (r)
  1574. (loop list r))))
  1575. (continue (cons x r)))))))
  1576. </pre><p></p>
  1577. <p>
  1578. The only inefficiencies in this code are the <tt>final</tt> and <tt>continue</tt>
  1579. procedures, both of which could be substituted in-line.
  1580. The macro expander could do the substitution for <tt>continue</tt> when there
  1581. is no explicit proceed variable, as in this case, but not in general.</p>
  1582. <p>
  1583. </p>
  1584. <a name="node_sec_5.19"></a>
  1585. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.19">5.19&nbsp;&nbsp;Sorting lists and vectors</a></h2>
  1586. <p></p>
  1587. <p>
  1588. (This section, as the libraries it describes, was written mostly by
  1589. Olin Shivers for the draft of SRFI&nbsp;32.)</p>
  1590. <p>
  1591. </p>
  1592. <p>
  1593. </p>
  1594. <p>
  1595. The sort libraries in Scheme&nbsp;48 include
  1596. </p>
  1597. <ul>
  1598. <li><p>vector insert sort (stable)
  1599. </p>
  1600. <li><p>vector heap sort
  1601. </p>
  1602. <li><p>vector merge sort (stable)
  1603. </p>
  1604. <li><p>pure and destructive list merge sort (stable)
  1605. </p>
  1606. <li><p>stable vector and list merge
  1607. </p>
  1608. <li><p>miscellaneous sort-related procedures: vector and list merging,
  1609. sorted predicates, vector binary search, vector and list
  1610. delete-equal-neighbor procedures.
  1611. </p>
  1612. <li><p>a general, non-algorithmic set of procedure names for general sorting
  1613. and merging
  1614. </p>
  1615. </ul><p></p>
  1616. <p>
  1617. </p>
  1618. <a name="node_sec_5.19.1"></a>
  1619. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.19.1">5.19.1&nbsp;&nbsp;Design rules</a></h3>
  1620. <p></p>
  1621. <a name="node_sec_Temp_4"></a>
  1622. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_4">What vs. how</a></h5>
  1623. <p>There are two different interfaces: ``what'' (simple) and ``how'' (detailed).</p>
  1624. <p>
  1625. </p>
  1626. <dl><dt></dt><dd>
  1627. </dd><dt><b>Simple</b></dt><dd> you specify semantics: datatype (list or vector),
  1628. mutability, and stability.<p>
  1629. </p>
  1630. </dd><dt><b>Detailed</b></dt><dd> you specify the actual algorithm (quick, heap,
  1631. insert, merge). Different algorithms have different properties,
  1632. both semantic and pragmatic, so these exports are necessary.<p>
  1633. It is necessarily the case that the specifications of these procedures
  1634. make statements about execution ``pragmatics.'' For example, the sole
  1635. distinction between heap sort and quick sort -- both of which are
  1636. provided by this library -- -is one of execution time, which is not a
  1637. ``semantic'' distinction. Similar resource-use statements are made about
  1638. ``iterative'' procedures, meaning that they can execute on input of
  1639. arbitrary size in a constant number of stack frames.
  1640. </p>
  1641. </dd></dl><p></p>
  1642. <p>
  1643. </p>
  1644. <a name="node_sec_Temp_5"></a>
  1645. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_5">Consistency across procedure signatures</a></h5>
  1646. <p>The two interfaces share common procedure signatures wherever
  1647. possible, to facilitate switching a given call from one procedure
  1648. to another.</p>
  1649. <p>
  1650. </p>
  1651. <a name="node_sec_Temp_6"></a>
  1652. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_6">Less-than parameter first, data parameter after</a></h5>
  1653. <p>These procedures uniformly observe the following parameter order:
  1654. the data to be sorted comes after the comparison procedure.
  1655. That is, we write</p>
  1656. <p>
  1657. </p>
  1658. <pre class=verbatim> (sort &lt; <i>list</i>)
  1659. </pre><p></p>
  1660. <p>
  1661. not</p>
  1662. <p>
  1663. </p>
  1664. <pre class=verbatim> (sort <i>list</i> &lt;)
  1665. </pre><p>
  1666. </p>
  1667. <p>
  1668. </p>
  1669. <a name="node_sec_Temp_7"></a>
  1670. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_7">Ordering, comparison procedures and stability</a></h5>
  1671. <p>These routines take a &lt; comparison procedure, not a <u>&lt;</u> comparison
  1672. procedure, and they sort into increasing order. The difference between
  1673. a &lt; spec and a <u>&lt;</u> spec comes up in two places: </p>
  1674. <p>
  1675. </p>
  1676. <ul>
  1677. <li><p>the definition of an ordered or sorted data set, and
  1678. </p>
  1679. <li><p>the definition of a stable sorting algorithm.
  1680. </p>
  1681. </ul><p>
  1682. </p>
  1683. <p>
  1684. We say that a data set (a list or vector) is <i>sorted</i> or
  1685. <i>ordered</i> if it contains no adjacent pair of values <tt>...</tt> <em>x</em>,
  1686. <em>y</em> <tt>...</tt> such that <em>y</em> &lt; <em>x</em>.</p>
  1687. <p>
  1688. In other words, scanning across the data never takes a ``downwards'' step.</p>
  1689. <p>
  1690. If you use a <u>&lt;</u> procedure where these algorithms expect a &lt;
  1691. procedure, you may not get the answers you expect. For example,
  1692. the <tt>list-sorted?</tt> procedure will return false if you pass it a <u>&lt;</u> comparison
  1693. procedure and an ordered list containing adjacent equal elements.</p>
  1694. <p>
  1695. A ``stable'' sort is one that preserves the pre-existing order of equal
  1696. elements. Suppose, for example, that we sort a list of numbers by
  1697. comparing their absolute values, i.e., using comparison procedure
  1698. </p>
  1699. <pre class=verbatim>(lambda (x y) (&lt; (abs x) (abs y)))
  1700. </pre><p>
  1701. If we sort a list that contains both 3 and -3: </p>
  1702. <div align=center><table><tr><td><tt>...</tt> 3, <tt>...</tt>, <tt>-</tt> 3 <tt>...</tt></td></tr></table></div><p>
  1703. then a stable sort is an algorithm that will not swap the order
  1704. of these two elements, that is, the answer is guaranteed to to look like
  1705. </p>
  1706. <div align=center><table><tr><td><tt>...</tt> 3, <tt>-</tt> 3 <tt>...</tt></td></tr></table></div><p>
  1707. not
  1708. </p>
  1709. <div align=center><table><tr><td><tt>...</tt> <tt>-</tt> 3, 3 <tt>...</tt></td></tr></table></div><p>
  1710. Choosing &lt; for the comparison procedure instead of <u>&lt;</u> affects
  1711. how stability is coded. Given an adjacent pair <em>x</em>, <em>y</em>, <tt>(&lt;
  1712. <em>y</em> <em>x</em>)</tt> means ``<em>x</em> should be moved in front of <em>x</em>'' -- otherwise,
  1713. leave things as they are. So using a <u>&lt;</u> procedure where a &lt;
  1714. procedure is expected will <em>invert</em> stability.</p>
  1715. <p>
  1716. This is due to the definition of equality, given a &lt; comparator:
  1717. </p>
  1718. <pre class=verbatim> (and (not (&lt; x y))
  1719. (not (&lt; y x)))
  1720. </pre><p>
  1721. The definition is rather different, given a <u>&lt;</u> comparator:
  1722. </p>
  1723. <pre class=verbatim> (and (&lt;= x y)
  1724. (&lt;= y x))
  1725. </pre><p>
  1726. A ``stable'' merge is one that reliably favors one of its data sets
  1727. when equal items appear in both data sets. <em>All merge operations in
  1728. this library are stable</em>, breaking ties between data sets in favor
  1729. of the first data set -- elements of the first list come before equal
  1730. elements in the second list.</p>
  1731. <p>
  1732. So, if we are merging two lists of numbers ordered by absolute value,
  1733. the stable merge operation <tt>list-merge</tt>
  1734. </p>
  1735. <pre class=verbatim> (list-merge (lambda (x y) (&lt; (abs x) (abs y)))
  1736. '(0 -2 4 8 -10) '(-1 3 -4 7))
  1737. </pre><p>
  1738. reliably places the 4 of the first list before the equal-comparing -4
  1739. of the second list:
  1740. </p>
  1741. <pre class=verbatim> (0 -1 -2 4 -4 7 8 -10)
  1742. </pre><p>
  1743. Some sort algorithms will <em>not work correctly</em> if given a <u>&lt;</u>
  1744. when they expect a &lt; comparison (or vice-versa).</p>
  1745. <p>
  1746. </p>
  1747. <p>
  1748. In short, if your comparison procedure <em>f</em> answers true to <tt>(<em>f</em> x x)</tt>, then
  1749. </p>
  1750. <ul>
  1751. <li><p>using a stable sorting or merging algorithm will not give you a
  1752. stable sort or merge,
  1753. </p>
  1754. <li><p><tt>list-sorted?</tt> may surprise you.
  1755. </p>
  1756. </ul><p>
  1757. Note that you can synthesize a &lt; procedure from a <u>&lt;</u> procedure with
  1758. </p>
  1759. <pre class=verbatim> (lambda (x y) (not (&lt;= y x)))
  1760. </pre><p>
  1761. if need be. </p>
  1762. <p>
  1763. Precise definitions give sharp edges to tools, but require care in use.
  1764. ``Measure twice, cut once.''</p>
  1765. <p>
  1766. </p>
  1767. <p>
  1768. </p>
  1769. <a name="node_sec_Temp_8"></a>
  1770. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_8">All vector operations accept optional subrange parameters</a></h5>
  1771. <p>The vector operations specified below all take optional
  1772. <tt>start</tt>/<tt>end</tt> arguments indicating a selected subrange
  1773. of a vector's elements. If a <tt>start</tt> parameter or
  1774. <tt>start</tt>/<tt>end</tt> parameter pair is given to such a
  1775. procedure, they must be exact, non-negative integers, such that
  1776. </p>
  1777. <div align=center><table><tr><td>
  1778. 0 <u>&lt;</u> <i>start</i> <u>&lt;</u> <i>end</i> <u>&lt;</u> <tt>(vector-length <i>vector</i>)</tt>
  1779. </td></tr></table></div><p>
  1780. where <i>vector</i> is the related vector parameter. If not specified,
  1781. they default to 0 and the length of the vector, respectively. They are
  1782. interpreted to select the range [<i>start</i>,<i>end</i>), that
  1783. is, all elements from index <i>start</i> (inclusive) up to, but not
  1784. including, index <i>end</i>.</p>
  1785. <p>
  1786. </p>
  1787. <a name="node_sec_Temp_9"></a>
  1788. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_9">Required vs. allowed side-effects</a></h5>
  1789. <p><tt>List-sort!</tt> and <tt>List-stable-sort!</tt> are allowed, but
  1790. not required, to alter their arguments' cons cells to construct the
  1791. result list. This is consistent with the what-not-how character of the
  1792. group of procedures to which they belong (the <tt>sorting</tt> structure).</p>
  1793. <p>
  1794. The <tt>list-delete-neighbor-dups!</tt>, <tt>list-merge!</tt> and
  1795. <tt>list-merge-sort!</tt> procedures, on the other hand, provide
  1796. specific algorithms, and, as such, explicitly commit to the use of
  1797. side-effects on their input lists in order to guarantee their key
  1798. algorithmic properties (e.g., linear-time operation).</p>
  1799. <p>
  1800. </p>
  1801. <a name="node_sec_5.19.2"></a>
  1802. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.19.2">5.19.2&nbsp;&nbsp;Procedure specification</a></h3>
  1803. <p></p>
  1804. <div align=center><table><tr><td>
  1805. <table border=0><tr><td valign=top >Structure name </td><td valign=top >Functionality</td></tr>
  1806. <tr><td valign=top ><tt>sorting</tt> </td><td valign=top >General sorting for lists and vectors</td></tr>
  1807. <tr><td valign=top ><tt>sorted</tt> </td><td valign=top >Sorted predicates for lists and vectors</td></tr>
  1808. <tr><td valign=top ><tt>list-merge-sort</tt></td><td valign=top >List merge sort</td></tr>
  1809. <tr><td valign=top ><tt>vector-merge-sort</tt> </td><td valign=top >Vector merge sort</td></tr>
  1810. <tr><td valign=top ><tt>vector-heap-sort</tt> </td><td valign=top >Vector heap sort</td></tr>
  1811. <tr><td valign=top ><tt>vector-insert-sort</tt> </td><td valign=top >Vector insertion sort</td></tr>
  1812. <tr><td valign=top ><tt>delete-neighbor-duplicates</tt> </td><td valign=top >List and vector delete neighbor duplicates</td></tr>
  1813. <tr><td valign=top ><tt>binary-searches</tt> </td><td valign=top >Vector binary search
  1814. </td></tr></table>
  1815. </td></tr></table></div>
  1816. Note that there is no ``list insert sort'' package, as you might as well always
  1817. use list merge sort. The reference implementation's destructive list merge
  1818. sort will do fewer <tt>set-cdr!</tt>s than a destructive insert sort.<p>
  1819. </p>
  1820. <a name="node_sec_Temp_10"></a>
  1821. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_10">Procedure naming and functionality</a></h5>
  1822. <p>Almost all of the procedures described below are variants of two basic
  1823. operations: sorting and merging. These procedures are consistently named
  1824. by composing a set of basic lexemes to indicate what they do.
  1825. </p>
  1826. <div align=center><table><tr><td>
  1827. </td></tr><tr><td>
  1828. <p>
  1829. </p>
  1830. <table border=0><tr><td valign=top >Lexeme </td><td valign=top >Meaning</td></tr>
  1831. <tr><td valign=top ><tt>sort</tt></td><td valign=top >The procedure sorts its input data set by some &lt; comparison procedure.
  1832. </td></tr>
  1833. <tr><td valign=top ><tt>merge</tt></td><td valign=top >The procedure merges two ordered data sets into a single ordered
  1834. result.
  1835. </td></tr>
  1836. <tr><td valign=top ><tt>stable</tt> </td><td valign=top >This lexeme indicates that the sort is a stable one.
  1837. </td></tr>
  1838. <tr><td valign=top ><tt>vector</tt></td><td valign=top >The procedure operates upon vectors.
  1839. </td></tr>
  1840. <tr><td valign=top ><tt>list</tt> </td><td valign=top >The procedure operates upon lists.
  1841. </td></tr>
  1842. <tr><td valign=top ><tt>!</tt> </td><td valign=top >Procedures that end in <tt>!</tt> are allowed, and sometimes required,
  1843. to reuse their input storage to construct their answer.
  1844. </td></tr></table>
  1845. </td></tr></table></div>
  1846. <p>
  1847. </p>
  1848. <a name="node_sec_Temp_11"></a>
  1849. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_11">Types of parameters and return values</a></h5>
  1850. <p>In the procedures specified below,
  1851. </p>
  1852. <ul>
  1853. <li><p>A <tt>&lt;</tt> or <tt>=</tt> parameter is a procedure accepting
  1854. two arguments taken from the specified procedure's data set(s), and
  1855. returning a boolean;
  1856. </p>
  1857. <li><p><tt>Start</tt> and <tt>end</tt> parameters are exact, non-negative integers that
  1858. serve as vector indices selecting a subrange of some associated vector.
  1859. When specified, they must satisfy the relation
  1860. </p>
  1861. <div align=center><table><tr><td>
  1862. 0 <u>&lt;</u> <i>start</i> <u>&lt;</u> <i>end</i> <u>&lt;</u> <tt>(vector-length <i>vector</i>)</tt>
  1863. </td></tr></table></div><p>
  1864. where <i>vector</i> is the associated vector.
  1865. </p>
  1866. </ul><p>
  1867. Passing values to procedures with these parameters that do not satisfy
  1868. these types is an error.</p>
  1869. <p>
  1870. If a procedure is said to return ``unspecified,'' this means that
  1871. nothing at all is said about what the procedure returns, not even the
  1872. number of return values. Such a procedure is not even required to be
  1873. consistent from call to call in the nature or number of its return
  1874. values. It is simply required to return a value (or values) that may
  1875. be passed to a command continuation, e.g. as the value of an
  1876. expression appearing as a non-terminal subform of a <tt>begin</tt>
  1877. expression. Note that in R<sup>5</sup>RS, this restricts such a procedure to
  1878. returning a single value; non-R<sup>5</sup>RS systems may not even provide this
  1879. restriction.</p>
  1880. <p>
  1881. </p>
  1882. <a name="node_sec_5.19.2.1"></a>
  1883. <h4><a href="manual-Z-H-2.html#node_toc_node_sec_5.19.2.1">5.19.2.1&nbsp;&nbsp;<tt>sorting</tt> -- general sorting package</a></h4>
  1884. <p>This library provides basic sorting and merging functionality suitable for
  1885. general programming. The procedures are named by their semantic properties,
  1886. i.e., what they do to the data (sort, stable sort, merge, and so forth).</p>
  1887. <p>
  1888. </p>
  1889. <ul>
  1890. <li><p><tt>(list-sorted?<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_274"></a>
  1891. </p>
  1892. <li><p><tt>(list-merge<i> &lt; list<sub>1</sub> list<sub>2</sub></i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_276"></a>
  1893. </p>
  1894. <li><p><tt>(list-merge!<i> &lt; list<sub>1</sub> list<sub>2</sub></i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_278"></a>
  1895. </p>
  1896. <li><p><tt>(list-sort<i> &lt; lis</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_280"></a>
  1897. </p>
  1898. <li><p><tt>(list-sort!<i> &lt; lis</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_282"></a>
  1899. </p>
  1900. <li><p><tt>(list-stable-sort<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_284"></a>
  1901. </p>
  1902. <li><p><tt>(list-stable-sort!<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_286"></a>
  1903. </p>
  1904. <li><p><tt>(list-delete-neighbor-dups<i> = list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_288"></a>
  1905. </p>
  1906. <li><p><tt>(vector-sorted?<i> &lt; v [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_290"></a>
  1907. </p>
  1908. <li><p><tt>(vector-merge<i> &lt; v<sub>1</sub> v<sub>2</sub> [start1 [end1 [start2 [end2]]]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_292"></a>
  1909. </p>
  1910. <li><p><tt>(vector-merge!<i> &lt; v v<sub>1</sub> v<sub>2</sub> [start [start1 [end1 [start2 [end2]]]]]</i>)</tt><a name="node_idx_294"></a>
  1911. </p>
  1912. <li><p><tt>(vector-sort<i> &lt; v [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_296"></a>
  1913. </p>
  1914. <li><p><tt>(vector-sort!<i> &lt; v [start [end]]</i>)</tt><a name="node_idx_298"></a>
  1915. </p>
  1916. <li><p><tt>(vector-stable-sort<i> &lt; v [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_300"></a>
  1917. </p>
  1918. <li><p><tt>(vector-stable-sort!<i> &lt; v [start [end]]</i>)</tt><a name="node_idx_302"></a>
  1919. </p>
  1920. <li><p><tt>(vector-delete-neighbor-dups<i> = v [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_304"></a>
  1921. </p>
  1922. </ul><p></p>
  1923. <p>
  1924. </p>
  1925. <div align=center><table><tr><td>
  1926. <table border=0><tr><td valign=top >Procedure </td><td valign=top >Suggested algorithm
  1927. </td></tr>
  1928. <tr><td valign=top ><tt>list-sort</tt> </td><td valign=top >vector heap or quick</td></tr>
  1929. <tr><td valign=top ><tt>list-sort!</tt> </td><td valign=top >list merge sort</td></tr>
  1930. <tr><td valign=top ><tt>list-stable-sort</tt> </td><td valign=top >vector merge sort</td></tr>
  1931. <tr><td valign=top ><tt>list-stable-sort!</tt> </td><td valign=top >list merge sort</td></tr>
  1932. <tr><td valign=top ><tt>vector-sort</tt> </td><td valign=top >heap or quick sort</td></tr>
  1933. <tr><td valign=top ><tt>vector-sort!</tt> or quick sort</td></tr>
  1934. <tr><td valign=top ><tt>vector-stable-sort</tt> </td><td valign=top >vector merge sort</td></tr>
  1935. <tr><td valign=top ><tt>vector-stable-sort!</tt> merge sort
  1936. </td></tr></table>
  1937. </td></tr></table></div>
  1938. <tt>List-Sorted?</tt> and <tt>vector-sorted?</tt> return true if their
  1939. input list or vector is in sorted order, as determined by their <i>&lt;</i>
  1940. comparison parameter.<p>
  1941. All four merge operations are stable: an element of the initial list
  1942. <i>list<sub>1</sub></i> or vector <i>vector<sub>1</sub></i> will come before an
  1943. equal-comparing element in the second list <i>list<sub>2</sub></i> or vector
  1944. <i>vector<sub>2</sub></i> in the result.</p>
  1945. <p>
  1946. The procedures
  1947. </p>
  1948. <ul>
  1949. <li><p><tt>list-merge</tt>
  1950. </p>
  1951. <li><p><tt>list-sort</tt>
  1952. </p>
  1953. <li><p><tt>list-stable-sort</tt>
  1954. </p>
  1955. <li><p><tt>list-delete-neighbor-dups</tt>
  1956. </p>
  1957. </ul><p>
  1958. do not alter their inputs and are allowed to return a value that shares
  1959. a common tail with a list argument.</p>
  1960. <p>
  1961. The procedure
  1962. </p>
  1963. <ul>
  1964. <li><p><tt>list-sort!</tt>
  1965. </p>
  1966. <li><p><tt>list-stable-sort!</tt>
  1967. </p>
  1968. </ul><p>
  1969. are ``linear update'' operators -- they are allowed, but not required, to
  1970. alter the cons cells of their arguments to produce their results. </p>
  1971. <p>
  1972. On the other hand, the <tt>list-merge!</tt> procedure
  1973. make only a single, iterative, linear-time pass over its argument
  1974. list, using <tt>set-cdr!</tt>s to rearrange the cells of the list
  1975. into the final result -- it works ``in place.'' Hence, any cons cell
  1976. appearing in the result must have originally appeared in an input. The
  1977. intent of this iterative-algorithm commitment is to allow the
  1978. programmer to be sure that if, for example, <tt>list-merge!</tt> is asked to
  1979. merge two ten-million-element lists, the operation will complete
  1980. without performing some extremely (possibly twenty-million) deep
  1981. recursion.</p>
  1982. <p>
  1983. The vector procedures
  1984. </p>
  1985. <ul>
  1986. <li><p><tt>vector-sort</tt>
  1987. </p>
  1988. <li><p><tt>vector-stable-sort</tt>
  1989. </p>
  1990. <li><p><tt>vector-delete-neighbor-dups</tt>
  1991. </p>
  1992. </ul><p>
  1993. do not alter their inputs, but allocate a fresh vector for their result,
  1994. of length <i>end</i> <tt>-</tt> <i>start</i>. </p>
  1995. <p>
  1996. The vector procedures
  1997. </p>
  1998. <ul>
  1999. <li><p><tt>vector-sort!</tt>
  2000. </p>
  2001. <li><p><tt>vector-stable-sort!</tt>
  2002. </p>
  2003. </ul><p>
  2004. sort their data in-place. (But note that <tt>vector-stable-sort!</tt>
  2005. may allocate temporary storage proportional to the size of the
  2006. input
  2007. .)</p>
  2008. <p>
  2009. <tt>Vector-merge</tt> returns a vector of length (<i>end<sub>1</sub></i> <tt>-</tt> <i>start<sub>1</sub></i> + (<i>end<sub>2</sub></i> <tt>-</tt> <i>start<sub>2</sub></i>).</p>
  2010. <p>
  2011. <tt>Vector-merge!</tt> writes its result into vector <i>v</i>,
  2012. beginning at index <i>start</i>, for indices less than <i>end</i> =
  2013. <i>start</i> + (<i>end<sub>1</sub></i> <tt>-</tt> <i>start<sub>1</sub></i>) +
  2014. (<i>end<sub>2</sub></i> <tt>-</tt> <i>start<sub>2</sub></i>). The target subvector
  2015. <i>v</i>[<i>start</i>,<i>end</i>) may not overlap either source
  2016. subvector <i>vector<sub>1</sub></i>[<i>start<sub>1</sub></i>,<i>end<sub>1</sub></i>) <i>vector<sub>2</sub></i>[<i>start<sub>2</sub></i>,<i>end<sub>2</sub></i>).</p>
  2017. <p>
  2018. The <tt><tt>...</tt>-delete-neighbor-dups-<tt>...</tt></tt> procedures:
  2019. These procedures delete adjacent duplicate elements from a list or a
  2020. vector, using a given element-equality procedure. The first/leftmost
  2021. element of a run of equal elements is the one that survives. The list or
  2022. vector is not otherwise disordered.</p>
  2023. <p>
  2024. These procedures are linear time -- much faster than the <em>O</em>(<em>n</em><sup>2</sup>) general
  2025. duplicate-element deletors that do not assume any ``bunching'' of elements
  2026. (such as the ones provided by SRFI&nbsp;1). If you want to delete duplicate
  2027. elements from a large list or vector, you can sort the elements to bring
  2028. equal items together, then use one of these procedures, for a total time
  2029. of <em>O</em>(<em>n</em>log(<em>n</em>)).</p>
  2030. <p>
  2031. The comparison procedure = passed to these procedures is always
  2032. applied
  2033. <tt>( = <em>x</em> <em>y</em>)</tt>
  2034. where <em>x</em> comes before <em>y</em> in the containing list or vector.</p>
  2035. <p>
  2036. </p>
  2037. <ul>
  2038. <li><p><tt>List-delete-neighbor-dups</tt> does not alter its input list; its answer
  2039. may share storage with the input list.
  2040. </p>
  2041. <li><p><tt>Vector-delete-neighbor-dups</tt> does not alter its input vector, but
  2042. rather allocates a fresh vector to hold the result.
  2043. </p>
  2044. </ul><p>
  2045. Examples:</p>
  2046. <p>
  2047. </p>
  2048. <pre class=verbatim>(list-delete-neighbor-dups = '(1 1 2 7 7 7 0 -2 -2))
  2049. ===&gt; (1 2 7 0 -2)
  2050. (vector-delete-neighbor-dups = '#(1 1 2 7 7 7 0 -2 -2))
  2051. ===&gt; #(1 2 7 0 -2)
  2052. (vector-delete-neighbor-dups = '#(1 1 2 7 7 7 0 -2 -2) 3 7)
  2053. ===&gt; #(7 0 -2)
  2054. </pre><p></p>
  2055. <p>
  2056. </p>
  2057. <a name="node_sec_5.19.2.2"></a>
  2058. <h4><a href="manual-Z-H-2.html#node_toc_node_sec_5.19.2.2">5.19.2.2&nbsp;&nbsp;Algorithm-specific sorting packages</a></h4>
  2059. <p>These packages provide more specific sorting functionality, that is,
  2060. specific committment to particular algorithms that have particular
  2061. pragmatic consequences (such as memory locality, asymptotic running time)
  2062. beyond their semantic behaviour (sorting, stable sorting, merging, etc.).
  2063. Programmers that need a particular algorithm can use one of these packages.</p>
  2064. <p>
  2065. </p>
  2066. <a name="node_sec_Temp_12"></a>
  2067. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_12"><tt>sorted</tt> -- sorted predicates</a></h5>
  2068. <p></p>
  2069. <ul>
  2070. <li><p><tt>(list-sorted?<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_306"></a>
  2071. </p>
  2072. <li><p><tt>(vector-sorted?<i> &lt; vector</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_308"></a>
  2073. </p>
  2074. <li><p><tt>(vector-sorted?<i> &lt; vector start</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_310"></a>
  2075. </p>
  2076. <li><p><tt>(vector-sorted?<i> &lt; vector start end</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_312"></a>
  2077. </p>
  2078. </ul><p></p>
  2079. <p>
  2080. Return <tt>#f</tt> iff there is an adjacent pair <tt>...</tt> <em>x</em>, <em>y</em> <tt>...</tt> in the input
  2081. list or vector such that <em>y</em> &lt; <em>x</em>. The optional <i>start</i>/<i>end</i> range
  2082. arguments restrict <tt>vector-sorted?</tt> to the indicated subvector.</p>
  2083. <p>
  2084. </p>
  2085. <a name="node_sec_Temp_13"></a>
  2086. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_13"><tt>list-merge-sort</tt> -- list merge sort</a></h5>
  2087. <p></p>
  2088. <ul>
  2089. <li><p><tt>(list-merge-sort<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_314"></a>
  2090. </p>
  2091. <li><p><tt>(list-merge-sort!<i> &lt; list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_316"></a>
  2092. </p>
  2093. <li><p><tt>(list-merge<i> list<sub>1</sub> &lt; list<sub>2</sub></i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_318"></a>
  2094. </p>
  2095. <li><p><tt>(list-merge!<i> list<sub>1</sub> &lt; list<sub>2</sub></i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_320"></a>
  2096. </p>
  2097. </ul><p>
  2098. The sort procedures sort their data using a list merge sort, which is
  2099. stable. (The reference implementation is, additionally, a ``natural'' sort.
  2100. See below for the properties of this algorithm.)</p>
  2101. <p>
  2102. The <tt>!</tt> procedures are destructive -- they use <tt>set-cdr!</tt>s to
  2103. rearrange the cells of the lists into the proper order. As such, they
  2104. do not allocate any extra cons cells -- they are ``in place'' sorts.
  2105. </p>
  2106. <p>
  2107. The merge operations are stable: an element of <i>list<sub>1</sub></i> will
  2108. come before an equal-comparing element in <i>list<sub>2</sub></i> in the result
  2109. list.</p>
  2110. <p>
  2111. </p>
  2112. <a name="node_sec_Temp_14"></a>
  2113. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_14"><tt>vector-merge-sort</tt> -- vector merge sort</a></h5>
  2114. <p></p>
  2115. <ul>
  2116. <li><p><tt>(vector-merge-sort<i> &lt; vector [start [end [temp]]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_322"></a>
  2117. </p>
  2118. <li><p><tt>(vector-merge-sort!<i> &lt; vector [start [end [temp]]]</i>)</tt><a name="node_idx_324"></a>
  2119. </p>
  2120. <li><p><tt>(vector-merge<i> &lt; vector<sub>1</sub> vector<sub>2</sub> [start<sub>1</sub> [end<sub>1</sub> [start<sub>2</sub> [end<sub>2</sub>]]]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_326"></a>
  2121. </p>
  2122. <li><p><tt>(vector-merge!<i> &lt; vector vector<sub>1</sub> vector<sub>2</sub> [start [start<sub>1</sub> [end<sub>1</sub> [start<sub>2</sub> [end<sub>2</sub>]]]]]</i>)</tt><a name="node_idx_328"></a>
  2123. </p>
  2124. </ul><p>
  2125. The sort procedures sort their data using vector merge sort, which is
  2126. stable. (The reference implementation is, additionally, a ``natural'' sort.
  2127. See below for the properties of this algorithm.)</p>
  2128. <p>
  2129. The optional <i>start</i>/<i>end</i> arguments provide for sorting of subranges, and
  2130. default to 0 and the length of the corresponding vector.</p>
  2131. <p>
  2132. Merge-sorting a vector requires the allocation of a temporary
  2133. ``scratch'' work vector for the duration of the sort. This scratch
  2134. vector can be passed in by the client as the optional <i>temp</i>
  2135. argument; if so, the supplied vector must be of size <u>&lt;</u> <i>end</i>,
  2136. and will not be altered outside the range [start,end). If not
  2137. supplied, the sort routines allocate one themselves.</p>
  2138. <p>
  2139. The merge operations are stable: an element of <i>vector<sub>1</sub></i> will
  2140. come before an equal-comparing element in <i>vector<sub>2</sub></i> in the
  2141. result vector.</p>
  2142. <p>
  2143. </p>
  2144. <ul>
  2145. <li><p><tt>Vector-merge-sort!</tt> leaves its result in
  2146. <i>vector</i>[<i>start</i>,<i>end</i>).
  2147. </p>
  2148. <li><p><tt>Vector-merge-sort</tt> returns a vector of length
  2149. <i>end</i> <tt>-</tt> <i>start</i>.
  2150. </p>
  2151. <li><p><tt>Vector-merge</tt> returns a vector of length
  2152. (<i>end<sub>1</sub></i> <tt>-</tt> <i>start<sub>1</sub></i>) + (<i>end<sub>2</sub></i> <tt>-</tt> <i>start<sub>2</sub></i>).
  2153. </p>
  2154. <li><p><tt>Vector-merge!</tt> writes its result into <i>vector</i>, beginning
  2155. at index <i>start</i>,
  2156. for indices less than <i>end</i> = <i>start</i> +
  2157. (<i>end<sub>1</sub></i> <tt>-</tt> <i>start<sub>1</sub></i>) + (<i>end<sub>2</sub></i> <tt>-</tt> <i>start<sub>2</sub></i>).
  2158. The target subvector
  2159. </p>
  2160. <div align=center><table><tr><td><i>vector</i>[<i>start</i>,<i>end</i>)</td></tr></table></div><p>
  2161. may not overlap either source subvector
  2162. </p>
  2163. <div align=center><table><tr><td><i>vector<sub>1</sub></i>[<i>start<sub>1</sub></i>,<i>end<sub>1</sub></i>), or
  2164. <i>vector<sub>2</sub></i>[<i>start<sub>2</sub></i>,<i>end<sub>2</sub></i>).</td></tr></table></div><p>
  2165. </p>
  2166. </ul><p></p>
  2167. <p>
  2168. </p>
  2169. <a name="node_sec_Temp_15"></a>
  2170. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_15"><tt>vector-heap-sort</tt> -- vector heap sort</a></h5>
  2171. <p></p>
  2172. <ul>
  2173. <li><p><tt>(vector-heap-sort<i> &lt; vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_330"></a>
  2174. </p>
  2175. <li><p><tt>(vector-heap-sort!<i> &lt; vector [start [end]]</i>)</tt><a name="node_idx_332"></a>
  2176. </p>
  2177. </ul><p>
  2178. These procedures sort their data using heap sort,
  2179. which is not a stable sorting algorithm.</p>
  2180. <p>
  2181. <tt>Vector-heap-sort</tt> returns a vector of length <i>end</i> <tt>-</tt> <i>start</i>.
  2182. <tt>Vector-heap-sort!</tt> is in-place, leaving its result in
  2183. <i>vector</i>[<i>start</i>,<i>end</i>).</p>
  2184. <p>
  2185. </p>
  2186. <p>
  2187. </p>
  2188. <p>
  2189. </p>
  2190. <p>
  2191. </p>
  2192. <p>
  2193. </p>
  2194. <p>
  2195. </p>
  2196. <p>
  2197. </p>
  2198. <p>
  2199. </p>
  2200. <p>
  2201. </p>
  2202. <a name="node_sec_Temp_16"></a>
  2203. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_16"><tt>vector-insert-sort</tt> -- vector insertion sort</a></h5>
  2204. <p></p>
  2205. <ul>
  2206. <li><p><tt>(vector-insert-sort<i> &lt; vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_334"></a>
  2207. </p>
  2208. <li><p><tt>(vector-insert-sort!<i> &lt; vector [start [end]]</i>)</tt><a name="node_idx_336"></a>
  2209. </p>
  2210. </ul><p>
  2211. These procedures stably sort their data using insertion sort.
  2212. </p>
  2213. <ul>
  2214. <li><p><tt>Vector-insert-sort</tt> returns a vector of length <i>end</i> <tt>-</tt> <i>start</i>.
  2215. </p>
  2216. <li><p><tt>Vector-insert-sort!</tt> is in-place, leaving its result in
  2217. <i>vector</i>[<i>start</i>,<i>end</i>).
  2218. </p>
  2219. </ul><p></p>
  2220. <p>
  2221. </p>
  2222. <a name="node_sec_Temp_17"></a>
  2223. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_17"><tt>delete-neighbor-duplicates</tt> -- list and vector
  2224. delete neighbor duplicates</a></h5>
  2225. <p></p>
  2226. <ul>
  2227. <li><p><tt>(list-delete-neighbor-dups<i> = list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_338"></a>
  2228. </p>
  2229. <li><p><tt>(list-delete-neighbor-dups!<i> = list</i>)&nbsp;-&gt;&nbsp;<i>list</i></tt><a name="node_idx_340"></a>
  2230. </p>
  2231. <li><p><tt>(vector-delete-neighbor-dups<i> = vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>vector</i></tt><a name="node_idx_342"></a>
  2232. </p>
  2233. <li><p><tt>(vector-delete-neighbor-dups!<i> = vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>end'</i></tt><a name="node_idx_344"></a>
  2234. </p>
  2235. </ul><p>
  2236. These procedures delete adjacent duplicate elements from a list or
  2237. a vector, using a given element-equality procedure = . The first/leftmost
  2238. element of a run of equal elements is the one that survives. The list
  2239. or vector is not otherwise disordered.</p>
  2240. <p>
  2241. These procedures are linear time -- much faster than the <em>O</em>(<em>n</em><sup>2</sup>) general
  2242. duplicate-element deletors that do not assume any ``bunching'' of elements
  2243. (such as the ones provided by SRFI&nbsp;1). If you want to delete duplicate
  2244. elements from a large list or vector, you can sort the elements to bring
  2245. equal items together, then use one of these procedures, for a total time
  2246. of <em>O</em>(<em>n</em>log(<em>n</em>)).</p>
  2247. <p>
  2248. The comparison procedure = passed to these procedures is always
  2249. applied</p>
  2250. <p>
  2251. </p>
  2252. <pre class=verbatim>( = <em>x</em> <em>y</em>)
  2253. </pre><p></p>
  2254. <p>
  2255. where <em>x</em> comes before <em>y</em> in the containing list or vector.
  2256. </p>
  2257. <ul>
  2258. <li><p><tt>List-delete-neighbor-dups</tt> does not alter its input list; its
  2259. answer may share storage with the input list.
  2260. </p>
  2261. <li><p><tt>Vector-delete-neighbor-dups</tt> does not alter its input vector, but
  2262. rather allocates a fresh vector to hold the result.
  2263. </p>
  2264. <li><p><tt>List-delete-neighbor-dups!</tt> is permitted, but not required, to
  2265. mutate its input list in order to construct its answer.
  2266. </p>
  2267. <li><p><tt>Vector-delete-neighbor-dups!</tt> reuses its input vector to hold the
  2268. answer, packing its answer into the index range
  2269. [<i>start</i>,<i>end'</i>), where
  2270. <i>end'</i> is the non-negative exact integer returned as its value. It
  2271. returns <i>end'</i> as its result. The vector is not altered outside the range
  2272. [<i>start</i>,<i>end'</i>).
  2273. </p>
  2274. </ul><p>
  2275. Examples:</p>
  2276. <p>
  2277. </p>
  2278. <pre class=verbatim>(list-delete-neighbor-dups = '(1 1 2 7 7 7 0 -2 -2))
  2279. ===&gt; (1 2 7 0 -2)
  2280. (vector-delete-neighbor-dups = '#(1 1 2 7 7 7 0 -2 -2))
  2281. ===&gt; #(1 2 7 0 -2)
  2282. (vector-delete-neighbor-dups = '#(1 1 2 7 7 7 0 -2 -2) 3 7)
  2283. ===&gt; #(7 0 -2)
  2284. ;; Result left in v[3,9):
  2285. (let ((v (vector 0 0 0 1 1 2 2 3 3 4 4 5 5 6 6)))
  2286. (cons (vector-delete-neighbor-dups! = v 3)
  2287. v))
  2288. ===&gt; (9 . #(0 0 0 1 2 3 4 5 6 4 4 5 5 6 6))
  2289. </pre><p></p>
  2290. <p>
  2291. </p>
  2292. <a name="node_sec_Temp_18"></a>
  2293. <h5><a href="manual-Z-H-2.html#node_toc_node_sec_Temp_18"><tt>binary-searches</tt> -- vector binary search</a></h5>
  2294. <p></p>
  2295. <ul>
  2296. <li><p><tt>(vector-binary-search<i> &lt; elt-&gt;key key vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>integer or <tt>#f</tt></i></tt><a name="node_idx_346"></a>
  2297. </p>
  2298. <li><p><tt>(vector-binary-search3<i> compare-proc vector [start [end]]</i>)&nbsp;-&gt;&nbsp;<i>integer or <tt>#f</tt></i></tt><a name="node_idx_348"></a>
  2299. </p>
  2300. </ul><p></p>
  2301. <p>
  2302. <tt>vector-binary-search</tt> searches <i>vector</i> in range
  2303. [<i>start</i>,<i>end</i>) (which default to 0 and the length of
  2304. <i>vector</i>, respectively) for an element whose
  2305. associated key is equal to <i>key</i>. The procedure <i>elt-&gt;key</i> is used to map
  2306. an element to its associated key. The elements of the vector are assumed
  2307. to be ordered by the &lt; relation on these keys. That is, </p>
  2308. <p>
  2309. </p>
  2310. <pre class=verbatim>(vector-sorted? (lambda (x y) (&lt; (<i>elt-&gt;key</i> x) (<i>elt-&gt;key</i> y)))
  2311. <i>vector</i> <i>start</i> <i>end</i>) ===&gt; true
  2312. </pre><p></p>
  2313. <p>
  2314. An element <i>e</i> of <i>vector</i> is a match for <i>key</i> if it's
  2315. neither less nor greater than the key:</p>
  2316. <p>
  2317. </p>
  2318. <pre class=verbatim>(and (not (&lt; (<i>elt-&gt;key</i> <i>e</i>) <i>key</i>))
  2319. (not (&lt; <i>key</i> (<i>elt-&gt;key</i> <i>e</i>))))
  2320. </pre><p></p>
  2321. <p>
  2322. If there is such an element, the procedure returns its index in the
  2323. vector as an exact integer. If there is no such element in the searched
  2324. range, the procedure returns false.</p>
  2325. <p>
  2326. </p>
  2327. <pre class=verbatim>(vector-binary-search &lt; car 4 '#((1 . one) (3 . three)
  2328. (4 . four) (25 . twenty-five)))
  2329. ===&gt; 2
  2330. (vector-binary-search &lt; car 7 '#((1 . one) (3 . three)
  2331. (4 . four) (25 . twenty-five)))
  2332. ===&gt; #f
  2333. </pre><p> </p>
  2334. <p>
  2335. <tt>Vector-binary-search3</tt> is a variant that uses a three-way comparison
  2336. procedure <i>compare-proc</i>. <i>Compare-proc</i> compares its
  2337. parameter to the search key, and returns an
  2338. exact integer whose sign indicates its relationship to the search key.
  2339. </p>
  2340. <div align=center><table><tr><td>
  2341. array<em>r</em><em>c</em><em>l</em><em>c</em><em>r</em><em>c</em><em>l</em>
  2342. (<i>compare-proc</i>&nbsp;<em>x</em>) &amp;&lt;&amp; 0&amp; ==&gt;&amp; <em>x</em> &amp;&lt;&amp; <i>search-key</i><br>
  2343. (<i>compare-proc</i>&nbsp;<em>x</em>) &amp; = &amp; 0&amp; ==&gt;&amp; <em>x</em> &amp; = &amp; <i>search-key</i><br>
  2344. (<i>compare-proc</i>&nbsp;<em>x</em>) &amp;&gt;&amp; 0&amp; ==&gt;&amp; <em>x</em> &amp;&gt;&amp; <i>search-key</i>
  2345. endarray
  2346. </td></tr></table></div><p></p>
  2347. <p>
  2348. </p>
  2349. <pre class=verbatim>(vector-binary-search3 (lambda (elt) (- (car elt) 4))
  2350. '#((1 . one) (3 . three)
  2351. (4 . four) (25 . twenty-five)))
  2352. ===&gt; 2
  2353. </pre><p></p>
  2354. <p>
  2355. </p>
  2356. <p>
  2357. </p>
  2358. <a name="node_sec_5.19.3"></a>
  2359. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.19.3">5.19.3&nbsp;&nbsp;Algorithmic properties</a></h3>
  2360. <p>Different sort and merge algorithms have different properties.
  2361. Choose the algorithm that matches your needs:</p>
  2362. <p>
  2363. </p>
  2364. <dl><dt></dt><dd>
  2365. </dd><dt><b>Vector insert sort</b></dt><dd>
  2366. Stable, but only suitable for small vectors -- <em>O</em>(<em>n</em><sup>2</sup>).
  2367. </dd><dt><b>Vector heap sort</b></dt><dd>
  2368. Not stable. Guaranteed fast -- <em>O</em>(<em>n</em>log(<em>n</em>)) <em>worst</em> case. Poor
  2369. locality on large vectors. A very reliable workhorse.
  2370. </dd><dt><b>Vector merge sort</b></dt><dd>
  2371. Stable. Not in-place -- requires a temporary buffer of equal size.
  2372. Fast -- <em>O</em>(<em>n</em>log(<em>n</em>)) -- and has good memory locality for large vectors.<p>
  2373. The implementation of vector merge sort provided by this
  2374. implementation is, additionally, a ``natural'' sort, meaning that it
  2375. exploits existing order in the input data, providing <em>O</em>(<em>n</em>) best case.
  2376. </p>
  2377. </dd><dt><b>Destructive list merge sort</b></dt><dd>
  2378. Stable, fast and in-place (i.e., allocates no new cons cells). ``Fast''
  2379. means <em>O</em>(<em>n</em>log(<em>n</em>)) worse-case, and substantially better if the data
  2380. is already mostly ordered, all the way down to linear time for
  2381. a completely-ordered input list (i.e., it is a ``natural'' sort).<p>
  2382. Note that sorting lists involves chasing pointers through memory, which
  2383. can be a loser on modern machine architectures because of poor cache and
  2384. page locality.
  2385. Sorting vectors has inherently better locality.</p>
  2386. <p>
  2387. This implementation's destructive list merge and merge sort
  2388. implementations are opportunistic -- they avoid redundant
  2389. <tt>set-cdr!</tt>s, and try to take long
  2390. already-ordered runs of list structure as-is when doing the merges.
  2391. </p>
  2392. </dd><dt><b>Pure list merge sort</b></dt><dd>
  2393. Stable and fast -- <em>O</em>(<em>n</em>log(<em>n</em>)) worst-case, and possibly <em>O</em>(<em>n</em>),
  2394. depending upon the input list (see discussion above).
  2395. </dd></dl><p></p>
  2396. <p>
  2397. </p>
  2398. <div align=center><table><tr><td>
  2399. <table border=0><tr><td valign=top >Algorithm </td><td valign=top >Stable? </td><td valign=top >Worst case </td><td valign=top >Average case </td><td valign=top >In-place</td></tr>
  2400. <tr><td valign=top >Vector insert </td><td valign=top >Yes</td><td valign=top ><em>O</em>(<em>n</em><sup>2</sup>) </td><td valign=top ><em>O</em>(<em>n</em><sup>2</sup>)</td><td valign=top >Yes</td></tr>
  2401. <tr><td valign=top >Vector quick </td><td valign=top >No </td><td valign=top ><em>O</em>(<em>n</em><sup>2</sup>) </td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top >Yes</td></tr>
  2402. <tr><td valign=top >Vector heap </td><td valign=top >No </td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top >Yes</td></tr>
  2403. <tr><td valign=top >Vector merge </td><td valign=top >Yes</td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top >No</td></tr>
  2404. <tr><td valign=top >List merge </td><td valign=top >Yes</td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top ><em>O</em>(<em>n</em>log(<em>n</em>))</td><td valign=top >Either
  2405. </td></tr></table>
  2406. </td></tr></table></div>
  2407. <p>
  2408. </p>
  2409. <a name="node_sec_5.20"></a>
  2410. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.20">5.20&nbsp;&nbsp;Regular expressions</a></h2>
  2411. <p></p>
  2412. <p>
  2413. This section describes a functional interface for building regular
  2414. expressions and matching them against strings.
  2415. The matching is done using the POSIX regular expression package.
  2416. Regular expressions are in the structure <tt>regexps</tt>.</p>
  2417. <p>
  2418. A regular expression is either a character set, which matches any character
  2419. in the set, or a composite expression containing one or more subexpressions.
  2420. A regular expression can be matched against a string to determine success
  2421. or failure, and to determine the substrings matched by particular subexpressions.</p>
  2422. <p>
  2423. </p>
  2424. <ul>
  2425. <li><p><tt>(regexp?<i> value</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_350"></a>
  2426. </p>
  2427. </ul><p>
  2428. Returns <tt>#t</tt> if <i>value</i> is a regular expression created
  2429. using the functional interface for regular expressions, and <tt>#f</tt>
  2430. otherwise.</p>
  2431. <p>
  2432. </p>
  2433. <a name="node_sec_5.20.1"></a>
  2434. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.20.1">5.20.1&nbsp;&nbsp;Character sets</a></h3>
  2435. <p>Character sets may be defined using a list of characters and strings,
  2436. using a range or ranges of characters, or by using set operations on
  2437. existing character sets.</p>
  2438. <p>
  2439. </p>
  2440. <ul>
  2441. <li><p><tt>(set<i> character-or-string <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_352"></a>
  2442. </p>
  2443. <li><p><tt>(range<i> low-char high-char</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_354"></a>
  2444. </p>
  2445. <li><p><tt>(ranges<i> low-char high-char <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_356"></a>
  2446. </p>
  2447. <li><p><tt>(ascii-range<i> low-char high-char</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_358"></a>
  2448. </p>
  2449. <li><p><tt>(ascii-ranges<i> low-char high-char <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_360"></a>
  2450. </p>
  2451. </ul><p>
  2452. <tt>Set</tt> returns a set that contains the character arguments and the
  2453. characters in any string arguments. <tt>Range</tt> returns a character
  2454. set that contain all characters between <i>low-char</i> and <i>high-char</i>,
  2455. inclusive. <tt>Ranges</tt> returns a set that contains all characters in
  2456. the given ranges. <tt>Range</tt> and <tt>ranges</tt> use the ordering induced by
  2457. <tt>char-&gt;integer</tt>. <tt>Ascii-range</tt> and <tt>ascii-ranges</tt> use the
  2458. ASCII ordering.
  2459. It is an error for a <i>high-char</i> to be less than the preceding
  2460. <i>low-char</i> in the appropriate ordering.</p>
  2461. <p>
  2462. </p>
  2463. <ul>
  2464. <li><p><tt>(negate<i> char-set</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_362"></a>
  2465. </p>
  2466. <li><p><tt>(intersection<i> char-set char-set</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_364"></a>
  2467. </p>
  2468. <li><p><tt>(union<i> char-set char-set</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_366"></a>
  2469. </p>
  2470. <li><p><tt>(subtract<i> char-set char-set</i>)&nbsp;-&gt;&nbsp;<i>char-set</i></tt><a name="node_idx_368"></a>
  2471. </p>
  2472. </ul><p>
  2473. These perform the indicated operations on character sets.</p>
  2474. <p>
  2475. The following character sets are predefined:
  2476. </p>
  2477. <div align=center><table><tr><td>
  2478. <table border=0><tr><td valign=top ><tt>lower-case</tt> </td><td valign=top ><tt>(set &quot;abcdefghijklmnopqrstuvwxyz&quot;)</tt> </td></tr>
  2479. <tr><td valign=top ><tt>upper-case</tt> </td><td valign=top ><tt>(set &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;)</tt> </td></tr>
  2480. <tr><td valign=top ><tt>alphabetic</tt> </td><td valign=top ><tt>(union lower-case upper-case)</tt> </td></tr>
  2481. <tr><td valign=top ><tt>numeric</tt> </td><td valign=top ><tt>(set &quot;0123456789&quot;)</tt> </td></tr>
  2482. <tr><td valign=top ><tt>alphanumeric</tt> </td><td valign=top ><tt>(union alphabetic numeric)</tt> </td></tr>
  2483. <tr><td valign=top ><tt>punctuation</tt> </td><td valign=top ><tt>(set &quot;</tt><code class=verbatim>!\&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~</code><tt>&quot;)</tt> </td></tr>
  2484. <tr><td valign=top ><tt>graphic</tt> </td><td valign=top ><tt>(union alphanumeric punctuation)</tt> </td></tr>
  2485. <tr><td valign=top ><tt>printing</tt> </td><td valign=top ><tt>(union graphic (set #</tt><code class=verbatim>\</code><tt>space))</tt> </td></tr>
  2486. <tr><td valign=top ><tt>control</tt> </td><td valign=top ><tt>(negate printing)</tt> </td></tr>
  2487. <tr><td valign=top ><tt>blank</tt> </td><td valign=top ><tt>(set #</tt><code class=verbatim>\</code><tt>space (ascii-&gt;char 9))</tt> ; 9 is tab </td></tr>
  2488. <tr><td valign=top ><tt>whitespace</tt> </td><td valign=top ><tt>(union (set #</tt><code class=verbatim>\</code><tt>space) (ascii-range 9 13))</tt> </td></tr>
  2489. <tr><td valign=top ><tt>hexdigit</tt> </td><td valign=top ><tt>(set &quot;0123456789abcdefABCDEF&quot;)</tt> </td></tr>
  2490. <tr><td valign=top ></td></tr></table></td></tr></table></div>
  2491. The above are taken from the default locale in POSIX.
  2492. The characters in <tt>whitespace</tt> are <i>space</i>, <i>tab</i>,
  2493. <i>newline</i> (= <i>line feed</i>), <i>vertical tab</i>, <i>form feed</i>, and
  2494. <i>carriage return</i>.<p>
  2495. </p>
  2496. <a name="node_sec_5.20.2"></a>
  2497. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.20.2">5.20.2&nbsp;&nbsp;Anchoring</a></h3>
  2498. <p></p>
  2499. <ul>
  2500. <li><p><tt>(string-start<i></i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_370"></a>
  2501. </p>
  2502. <li><p><tt>(string-end<i></i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_372"></a>
  2503. </p>
  2504. </ul><p>
  2505. <tt>String-start</tt> returns a regular expression that matches the beginning
  2506. of the string being matched against; string-end returns one that matches
  2507. the end.</p>
  2508. <p>
  2509. </p>
  2510. <a name="node_sec_5.20.3"></a>
  2511. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.20.3">5.20.3&nbsp;&nbsp;Composite expressions</a></h3>
  2512. <p></p>
  2513. <ul>
  2514. <li><p><tt>(sequence<i> reg-exp <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_374"></a>
  2515. </p>
  2516. <li><p><tt>(one-of<i> reg-exp <tt>...</tt></i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_376"></a>
  2517. </p>
  2518. </ul><p>
  2519. <tt>Sequence</tt> matches the concatenation of its arguments, <tt>one-of</tt> matches
  2520. any one of its arguments.</p>
  2521. <p>
  2522. </p>
  2523. <ul>
  2524. <li><p><tt>(text<i> string</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_378"></a>
  2525. </p>
  2526. </ul><p>
  2527. <tt>Text</tt> returns a regular expression that matches the characters in
  2528. <i>string</i>, in order.</p>
  2529. <p>
  2530. </p>
  2531. <ul>
  2532. <li><p><tt>(repeat<i> reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_380"></a>
  2533. </p>
  2534. <li><p><tt>(repeat<i> count reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_382"></a>
  2535. </p>
  2536. <li><p><tt>(repeat<i> min max reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_384"></a>
  2537. </p>
  2538. </ul><p>
  2539. <tt>Repeat</tt> returns a regular expression that matches zero or more
  2540. occurences of its <i>reg-exp</i> argument. With no count the result
  2541. will match any number of times (<i>reg-exp</i>*). With a single
  2542. count the returned expression will match
  2543. <i>reg-exp</i> exactly that number of times.
  2544. The final case will match from <i>min</i> to <i>max</i>
  2545. repetitions, inclusive.
  2546. <i>Max</i> may be <tt>#f</tt>, in which case there
  2547. is no maximum number of matches.
  2548. <i>Count</i> and <i>min</i> should be exact, non-negative integers;
  2549. <i>max</i> should either be an exact non-negative integer or <tt>#f</tt>.</p>
  2550. <p>
  2551. </p>
  2552. <a name="node_sec_5.20.4"></a>
  2553. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.20.4">5.20.4&nbsp;&nbsp;Case sensitivity</a></h3>
  2554. <p>Regular expressions are normally case-sensitive.
  2555. </p>
  2556. <ul>
  2557. <li><p><tt>(ignore-case<i> reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_386"></a>
  2558. </p>
  2559. <li><p><tt>(use-case<i> reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_388"></a>
  2560. </p>
  2561. </ul><p>
  2562. The value returned by
  2563. <tt>ignore-case</tt> is identical its argument except that case will be
  2564. ignored when matching.
  2565. The value returned by <tt>use-case</tt> is protected
  2566. from future applications of <tt>ignore-case</tt>.
  2567. The expressions returned
  2568. by <tt>use-case</tt> and <tt>ignore-case</tt> are unaffected by later uses of the
  2569. these procedures.
  2570. By way of example, the following matches <tt>&quot;ab&quot;</tt> but not <tt>&quot;aB&quot;</tt>,
  2571. <tt>&quot;Ab&quot;</tt>, or <tt>&quot;AB&quot;</tt>.
  2572. </p>
  2573. <pre class=verbatim><tt>(text &quot;ab&quot;)</tt>
  2574. </pre><p>
  2575. while
  2576. </p>
  2577. <pre class=verbatim><tt>(ignore-case (test &quot;ab&quot;))</tt>
  2578. </pre><p>
  2579. matches <tt>&quot;ab&quot;</tt>, <tt>&quot;aB&quot;</tt>,
  2580. <tt>&quot;Ab&quot;</tt>, and <tt>&quot;AB&quot;</tt> and
  2581. </p>
  2582. <pre class=verbatim>(ignore-case (sequence (text &quot;a&quot;)
  2583. (use-case (text &quot;b&quot;))))
  2584. </pre><p>
  2585. matches <tt>&quot;ab&quot;</tt> and <tt>&quot;Ab&quot;</tt> but not <tt>&quot;aB&quot;</tt> or <tt>&quot;AB&quot;</tt>.</p>
  2586. <p>
  2587. </p>
  2588. <a name="node_sec_5.20.5"></a>
  2589. <h3><a href="manual-Z-H-2.html#node_toc_node_sec_5.20.5">5.20.5&nbsp;&nbsp;Submatches and matching</a></h3>
  2590. <p>A subexpression within a larger expression can be marked as a submatch.
  2591. When an expression is matched against a string, the success or failure
  2592. of each submatch within that expression is reported, as well as the
  2593. location of the substring matched be each successful submatch.</p>
  2594. <p>
  2595. </p>
  2596. <ul>
  2597. <li><p><tt>(submatch<i> key reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_390"></a>
  2598. </p>
  2599. <li><p><tt>(no-submatches<i> reg-exp</i>)&nbsp;-&gt;&nbsp;<i>reg-exp</i></tt><a name="node_idx_392"></a>
  2600. </p>
  2601. </ul><p>
  2602. <tt>Submatch</tt> returns a regular expression that matches its argument and
  2603. causes the result of matching its argument to be reported by the <tt>match</tt>
  2604. procedure.
  2605. <i>Key</i> is used to indicate the result of this particular submatch
  2606. in the alist of successful submatches returned by <tt>match</tt>.
  2607. Any value may be used as a <i>key</i>.
  2608. <tt>No-submatches</tt> returns an expression identical to its
  2609. argument, except that all submatches have been elided.</p>
  2610. <p>
  2611. </p>
  2612. <ul>
  2613. <li><p><tt>(any-match?<i> reg-exp string</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_394"></a>
  2614. </p>
  2615. <li><p><tt>(exact-match?<i> reg-exp string</i>)&nbsp;-&gt;&nbsp;<i>boolean</i></tt><a name="node_idx_396"></a>
  2616. </p>
  2617. <li><p><tt>(match<i> reg-exp string</i>)&nbsp;-&gt;&nbsp;<i>match or <tt>#f</tt></i></tt><a name="node_idx_398"></a>
  2618. </p>
  2619. <li><p><tt>(match-start<i> match</i>)&nbsp;-&gt;&nbsp;<i>index</i></tt><a name="node_idx_400"></a>
  2620. </p>
  2621. <li><p><tt>(match-end<i> match</i>)&nbsp;-&gt;&nbsp;<i>index</i></tt><a name="node_idx_402"></a>
  2622. </p>
  2623. <li><p><tt>(match-submatches<i> match</i>)&nbsp;-&gt;&nbsp;<i>alist</i></tt><a name="node_idx_404"></a>
  2624. </p>
  2625. </ul><p>
  2626. <tt>Any-match?</tt> returns <tt>#t</tt> if <i>string</i> matches <i>reg-exp</i> or
  2627. contains a substring that does, and <tt>#f</tt> otherwise.
  2628. <tt>Exact-match?</tt> returns <tt>#t</tt> if <i>string</i> matches
  2629. <i>reg-exp</i> and <tt>#f</tt> otherwise.</p>
  2630. <p>
  2631. <tt>Match</tt> returns <tt>#f</tt> if <i>reg-exp</i> does not match <i>string</i>
  2632. and a match record if it does match.
  2633. A match record contains three values: the beginning and end of the substring
  2634. that matched
  2635. the pattern and an a-list of submatch keys and corresponding match records
  2636. for any submatches that also matched.
  2637. <tt>Match-start</tt> returns the index of
  2638. the first character in the matching substring and <tt>match-end</tt> gives index
  2639. of the first character after the matching substring.
  2640. <tt>Match-submatches</tt> returns an alist of submatch keys and match records.
  2641. Only the top match record returned by <tt>match</tt> has a submatch alist.</p>
  2642. <p>
  2643. Matching occurs according to POSIX.
  2644. The match returned is the one with the lowest starting index in <i>string</i>.
  2645. If there is more than one such match, the longest is returned.
  2646. Within that match the longest possible submatches are returned.</p>
  2647. <p>
  2648. All three matching procedures cache a compiled version of <i>reg-exp</i>.
  2649. Subsequent calls with the same <i>reg-exp</i> will be more efficient.</p>
  2650. <p>
  2651. The C interface to the POSIX regular expression code uses ASCII <tt>nul</tt>
  2652. as an end-of-string marker.
  2653. The matching procedures will ignore any characters following an
  2654. embedded ASCII <tt>nul</tt>s in <i>string</i>.</p>
  2655. <p>
  2656. </p>
  2657. <pre class=verbatim>(define pattern (text &quot;abc&quot;))
  2658. (any-match? pattern &quot;abc&quot;) <code class=verbatim>=&gt; </code>#t
  2659. (any-match? pattern &quot;abx&quot;) <code class=verbatim>=&gt; </code>#f
  2660. (any-match? pattern &quot;xxabcxx&quot;) <code class=verbatim>=&gt; </code>#t
  2661. (exact-match? pattern &quot;abc&quot;) <code class=verbatim>=&gt; </code>#t
  2662. (exact-match? pattern &quot;abx&quot;) <code class=verbatim>=&gt; </code>#f
  2663. (exact-match? pattern &quot;xxabcxx&quot;) <code class=verbatim>=&gt; </code>#f
  2664. (match pattern &quot;abc&quot;) <code class=verbatim>=&gt; </code>(#{match 0 3})
  2665. (match pattern &quot;abx&quot;) <code class=verbatim>=&gt; </code>#f
  2666. (match pattern &quot;xxabcxx&quot;) <code class=verbatim>=&gt; </code>(#{match 2 5})
  2667. (let ((x (match (sequence (text &quot;ab&quot;)
  2668. (submatch 'foo (text &quot;cd&quot;))
  2669. (text &quot;ef&quot;))
  2670. &quot;xxxabcdefxx&quot;)))
  2671. (list x (match-submatches x)))
  2672. <code class=verbatim>=&gt; </code>(#{match 3 9} ((foo . #{match 5 7}))
  2673. (match-submatches
  2674. (match (sequence
  2675. (set &quot;a&quot;)
  2676. (one-of (submatch 'foo (text &quot;bc&quot;))
  2677. (submatch 'bar (text &quot;BC&quot;))))
  2678. &quot;xxxaBCd&quot;))
  2679. <code class=verbatim>=&gt; </code>((bar . #{match 4 6}))
  2680. </pre><p></p>
  2681. <p>
  2682. </p>
  2683. <a name="node_sec_5.21"></a>
  2684. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_5.21">5.21&nbsp;&nbsp;SRFIs</a></h2>
  2685. <p>`SRFI' stands for `Scheme Request For Implementation'.
  2686. An SRFI is a description of an extension to standard Scheme.
  2687. Draft and final SRFI documents, a FAQ, and other information about SRFIs
  2688. can be found at
  2689. <a href="http://srfi.schemers.org">the SRFI web site</a>.</p>
  2690. <p>
  2691. Scheme&nbsp;48 includes implementations of the following (final) SRFIs:
  2692. </p>
  2693. <ul>
  2694. <li><p>SRFI 1 - List Library
  2695. </p>
  2696. <li><p>SRFI 2 - <tt>and-let*</tt>
  2697. </p>
  2698. <li><p>SRFI 4 - Homogeneous numeric vector datatypes (see note below)
  2699. </p>
  2700. <li><p>SRFI 5 - <tt>let</tt> with signatures and rest arguments
  2701. </p>
  2702. <li><p>SRFI 6 - Basic string ports
  2703. </p>
  2704. <li><p>SRFI 7 - Program configuration
  2705. </p>
  2706. <li><p>SRFI 8 - <tt>receive</tt>
  2707. </p>
  2708. <li><p>SRFI 9 - Defining record types
  2709. </p>
  2710. <li><p>SRFI 11 - Syntax for receiving multiple values
  2711. </p>
  2712. <li><p>SRFI 13 - String Library
  2713. </p>
  2714. <li><p>SRFI 14 - Character-Set Library (see note below)
  2715. </p>
  2716. <li><p>SRFI 16 - Syntax for procedures of variable arity
  2717. </p>
  2718. <li><p>SRFI 17 - Generalized <tt>set!</tt>
  2719. </p>
  2720. <li><p>SRFI 19 - Time Data Types and Procedures
  2721. </p>
  2722. <li><p>SRFI 22 - Running Scheme Scripts on Unix
  2723. </p>
  2724. <li><p>SRFI 23 - Error reporting mechanism
  2725. </p>
  2726. <li><p>SRFI 25 - Multi-dimensional Array Primitives
  2727. </p>
  2728. <li><p>SRFI 26 - Notation for Specializing Parameters without Currying
  2729. </p>
  2730. <li><p>SRFI 27 - Sources of Random Bits
  2731. </p>
  2732. <li><p>SRFI 28 - Basic Format Strings
  2733. </p>
  2734. <li><p>SRFI 31 - A special form <tt>rec</tt> for recursive evaluation
  2735. </p>
  2736. <li><p>SRFI 34 - Exception Handling for Programs
  2737. </p>
  2738. <li><p>SRFI 35 - Conditions
  2739. </p>
  2740. <li><p>SRFI 36 - I/O Conditions
  2741. </p>
  2742. <li><p>SRFI 37 - args-fold: a program argument processor
  2743. </p>
  2744. <li><p>SRFI 40 - A Library of Streams
  2745. </p>
  2746. <li><p>SRFI 42 - Eager Comprehensions
  2747. </p>
  2748. <li><p>SRFI 43 - Vector library
  2749. </p>
  2750. <li><p>SRFI 45 - Primitives for Expressing Iterative Lazy Algorithms
  2751. </p>
  2752. <li><p>SRFI 60 - Integers as Bits
  2753. </p>
  2754. <li><p>SRFI 61 - A more general cond clause
  2755. </p>
  2756. <li><p>SRFI 63 - Homogeneous and Heterogeneous Arrays
  2757. </p>
  2758. <li><p>SRFI 66 - Octet Vectors
  2759. </p>
  2760. <li><p>SRFI 67 - Compare Procedures
  2761. </p>
  2762. <li><p>SRFI 74 - Octet-Addressed Binary Blocks
  2763. </p>
  2764. <li><p>SRFI 78 - Lightweight testing
  2765. </p>
  2766. </ul><p>
  2767. Documentation on these can be found at the web site mentioned above.</p>
  2768. <p>
  2769. SRFI&nbsp;4 specifies an external representation for homogeneous numeric
  2770. vectors that is incompatible with R<sup>5</sup>RS. The Scheme&nbsp;48 version of
  2771. SRFI&nbsp;4 does not support this external representation.</p>
  2772. <p>
  2773. SRFI&nbsp;14 includes the procedure <tt>-&gt;char-set</tt> which is not a standard
  2774. Scheme identifier (in R<sup>5</sup>RS the only required identifier starting
  2775. with <tt>-</tt> is <tt>-</tt> itself).
  2776. In the Scheme&nbsp;48 version of SRFI&nbsp;14 we have renamed <tt>-&gt;char-set</tt>
  2777. as <tt>x-&gt;char-set</tt>.</p>
  2778. <p>
  2779. With the exception of SRFI 62 (which is supported by default), the
  2780. SRFI bindings can be accessed
  2781. either by opening the appropriate structure
  2782. (the structure <tt>srfi-</tt><i>n</i> contains SRFI <i>n</i>)
  2783. or by loading structure <tt>srfi-7</tt> and then using
  2784. the <tt>,load-srfi-7-program</tt> command to load an SRFI 7-style program.
  2785. The syntax for the command is
  2786. </p>
  2787. <pre class=verbatim><tt>,load-srfi-7-program <i>name</i> <i>filename</i></tt>
  2788. </pre><p>
  2789. This creates a new structure and associated package, binds the structure
  2790. to <i>name</i> in the configuration package, and then loads the program
  2791. found in <i>filename</i> into the package.</p>
  2792. <p>
  2793. As an example, if the file <tt>test.scm</tt> contains
  2794. </p>
  2795. <pre class=verbatim>(program (code (define x 10)))
  2796. </pre><p>
  2797. this program can be loaded as follows:
  2798. </p>
  2799. <pre class=verbatim>&gt; ,load-package srfi-7
  2800. &gt; ,load-srfi-7-program test test.scm
  2801. [test]
  2802. &gt; ,in test
  2803. test&gt; x
  2804. 10
  2805. test&gt;
  2806. </pre><p></p>
  2807. <p>
  2808. </p>
  2809. <div align=right class=navigation><i>[Go to <span><a href="manual.html">first</a>, <a href="manual-Z-H-6.html">previous</a></span><span>, <a href="manual-Z-H-8.html">next</a></span> page<span>; &nbsp;&nbsp;</span><span><a href="manual-Z-H-2.html#node_toc_start">contents</a></span><span><span>; &nbsp;&nbsp;</span><a href="manual-Z-H-13.html#node_index_start">index</a></span>]</i></div>
  2810. <p></p>
  2811. </div>
  2812. </body>
  2813. </html>