dict-streams.tex 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147
  1. % -*- Mode: TeX -*-
  2. \def\ExplainRecursiveP{If \param{recursive-p} is \term{true},
  3. this call is expected to be embedded in a higher-level call to \funref{read}
  4. or a similar \term{function} used by the \term{Lisp reader}.}
  5. % Streams
  6. % Stream I/O
  7. % Binary I/O
  8. % Byte I/O
  9. % Text I/O
  10. % Character I/O
  11. % String I/O
  12. % General I/O
  13. % File Position
  14. % File Opening
  15. % Stream Closing
  16. % Stream Buffering
  17. % Query Functions
  18. % File Streams
  19. % Synonym Streams
  20. % Broadcast Streams
  21. % Two-Way-Streams
  22. % Echo Streams
  23. % Concatenated Streams
  24. % String Streams
  25. % Stream Variables
  26. %-------------------- Stream Types --------------------
  27. %% 2.10.0 1
  28. \begincom{stream}\ftype{System Class}
  29. \label Class Precedence List::
  30. \typeref{stream},
  31. \typeref{t}
  32. \label Description::
  33. A \term{stream} is an \term{object} that can be used with an input or output
  34. function to identify an appropriate source or sink of \term{characters} or
  35. \term{bytes} for that operation.
  36. For more complete information, \seesection\StreamConcepts.
  37. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  38. % \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  39. % The types
  40. % \typeref{broadcast-stream},
  41. % \typeref{concatenated-stream},
  42. % \typeref{echo-stream},
  43. % \typeref{file-stream},
  44. % \typeref{string-stream},
  45. % \typeref{synonym-stream}, and
  46. % \typeref{two-way-stream} are \term{pairwise} \term{disjoint} \subtypesof{stream}.
  47. % \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  48. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  49. \label See Also::
  50. {\secref\StreamConcepts},
  51. {\secref\PrintingOtherObjects},
  52. {\chapref\Printer},
  53. {\chapref\Reader}
  54. \endcom%{stream}\ftype{System Class}
  55. \begincom{broadcast-stream}\ftype{System Class}
  56. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  57. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  58. \label Class Precedence List::
  59. \typeref{broadcast-stream},
  60. \typeref{stream},
  61. \typeref{t}
  62. \label Description::
  63. A \term{broadcast stream} is an \term{output} \term{stream} which
  64. has associated with it a set of zero or more \term{output} \term{streams}
  65. such that any output sent to the \term{broadcast stream} gets passed on
  66. as output to each of the associated \term{output} \term{streams}.
  67. (If a \term{broadcast stream} has no \term{component streams},
  68. then all output to the \term{broadcast stream} is discarded.)
  69. The set of operations that may be performed on a \term{broadcast stream}
  70. is the intersection of those for its associated \term{output} \term{streams}.
  71. % Except as explicitly stated otherwise,
  72. % the values returned by a stream operation are
  73. % the values resulting from performing the operation
  74. % on the last of its \term{component streams};
  75. % the values resulting from performing the operation
  76. % on all preceding \term{streams} are discarded.
  77. % %Barmar: What if no streams are supplied?
  78. % %Sandra: Actually, aren't the results of functions that operate on streams
  79. % % specified explicitly in the descriptions of those functions?
  80. % %KMP: I'm not sure this answers the question for objects of type BROADCAST-STREAM.
  81. % %Sandra: CLOSE is a stream operation and this statement is certainly not
  82. % % true for CLOSE -- the component streams are not closed.
  83. %% Trying to untangle all the mail on this. -kmp 11-Feb-92
  84. Some output operations (\eg \funref{fresh-line}) return \term{values} based on the
  85. state of the \term{stream} at the time of the operation.
  86. \issue{BROADCAST-STREAM-RETURN-VALUES:CLARIFY-MINIMALLY}
  87. Since these \term{values} might differ for each of the \term{component streams},
  88. it is necessary to describe their return value specifically:
  89. \beginlist
  90. \itemitem{\bull}
  91. \funref{stream-element-type} returns
  92. the value from the last component stream,
  93. or \typeref{t} if there are no component streams.
  94. \itemitem{\bull}
  95. \funref{fresh-line} returns
  96. the value from the last component stream,
  97. or \nil\ if there are no component streams.
  98. \itemitem{\bull}
  99. The functions
  100. \funref{file-length},
  101. \funref{file-position},
  102. \funref{file-string-length},
  103. and \funref{stream-external-format}
  104. return the value from the last component stream;
  105. if there are no component streams,
  106. \funref{file-length} and \funref{file-position} return \f{0},
  107. \funref{file-string-length} returns \f{1},
  108. and \funref{stream-external-format} returns \kwd{default}.
  109. \itemitem{\bull}
  110. The functions \funref{streamp} and \funref{output-stream-p}
  111. always return \term{true} for \term{broadcast streams}.
  112. \itemitem{\bull}
  113. The functions \funref{open-stream-p} tests whether the \term{broadcast stream}
  114. is \term{open}\meaning{2}, not whether its component streams are \term{open}.
  115. \itemitem{\bull}
  116. The functions \funref{input-stream-p} and \term{interactive-stream-p}
  117. return an \term{implementation-defined}, \term{generalized boolean} value.
  118. \itemitem{\bull}
  119. For the input operations
  120. \funref{clear-input}
  121. \funref{listen},
  122. \funref{peek-char},
  123. \funref{read-byte},
  124. \funref{read-char-no-hang},
  125. \funref{read-char},
  126. \funref{read-line},
  127. and \funref{unread-char},
  128. the consequences are undefined if the indicated operation is performed.
  129. However, an \term{implementation} is permitted
  130. to define such a behavior as an \term{implementation-dependent} extension.
  131. \endlist
  132. For any output operations not having their return values explicitly specified above
  133. or elsewhere in this document, it is defined that
  134. the \term{values} returned by such an operation are
  135. the \term{values} resulting from performing the operation
  136. on the last of its \term{component streams};
  137. the \term{values} resulting from performing the operation
  138. on all preceding \term{streams} are discarded.
  139. If there are no \term{component streams},
  140. the value is \term{implementation-dependent}.
  141. \endissue{BROADCAST-STREAM-RETURN-VALUES:CLARIFY-MINIMALLY}
  142. \label See Also::
  143. \funref{broadcast-stream-streams},
  144. \funref{make-broadcast-stream}
  145. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  146. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  147. \endcom%{broadcast-stream}\ftype{System Class}
  148. \begincom{concatenated-stream}\ftype{System Class}
  149. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  150. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  151. \label Class Precedence List::
  152. \typeref{concatenated-stream},
  153. \typeref{stream},
  154. \typeref{t}
  155. \label Description::
  156. A \term{concatenated stream} is an \term{input} \term{stream} which
  157. is a \term{composite stream} of zero or more other \term{input} \term{streams},
  158. such that the sequence of data which can be read from the
  159. \term{concatenated stream} is the same as the concatenation of the
  160. sequences of data which could be read from each of the
  161. constituent \term{streams}.
  162. Input from a \term{concatenated stream} is taken from the first
  163. of the associated \term{input streams} until it reaches \term{end of file}\meaning{1};
  164. then that \term{stream} is discarded, and subsequent input is taken
  165. from the next \term{input stream}, and so on.
  166. %I added the following to round things out. -kmp 22-Apr-91
  167. An \term{end of file} on the associated \term{input streams} is always managed
  168. invisibly by the \term{concatenated stream}---the only time a client of
  169. a \term{concatenated stream} sees an \term{end of file} is when an attempt is
  170. made to obtain data from the \term{concatenated stream} but it has no
  171. remaining \term{input streams} from which to obtain such data.
  172. %!!!
  173. %Moon:
  174. % I'm not sure about a concatenated stream with no streams. Presumably the
  175. % valid set of operations for a concatenated stream is the intersection of
  176. % the valid set of operations for the component streams (this is never
  177. % specified, though). Maybe an empty concatenated stream accepts all
  178. % operations, both character and binary, and always gives eof? Or maybe
  179. % it shouldn't be allowed?
  180. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  181. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  182. \label See Also::
  183. \funref{concatenated-stream-streams},
  184. \funref{make-concatenated-stream}
  185. \endcom%{concatenated-stream}\ftype{System Class}
  186. \begincom{echo-stream}\ftype{System Class}
  187. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  188. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  189. \label Class Precedence List::
  190. \typeref{echo-stream},
  191. \typeref{stream},
  192. \typeref{t}
  193. \label Description::
  194. An \term{echo stream} is a \term{bidirectional} \term{stream}
  195. that gets its input from an associated \term{input} \term{stream}
  196. and sends its output to an associated \term{output} \term{stream}.
  197. All input taken from the \term{input} \term{stream}
  198. is echoed to the \term{output} \term{stream}.
  199. Whether the input is echoed immediately after it is encountered,
  200. or after it has been read from the \term{input stream}
  201. is \term{implementation-dependent}.
  202. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  203. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  204. \label See Also::
  205. \funref{echo-stream-input-stream},
  206. \funref{echo-stream-output-stream},
  207. \funref{make-echo-stream}
  208. \endcom%{echo-stream}\ftype{System Class}
  209. \begincom{file-stream}\ftype{System Class}
  210. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  211. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  212. \label Class Precedence List::
  213. \typeref{file-stream},
  214. \typeref{stream},
  215. \typeref{t}
  216. \label Description::
  217. An \term{object} \oftype{file-stream} is a \term{stream} the direct
  218. source or sink of which is a \term{file}. Such a \term{stream} is
  219. created explicitly by \funref{open} and \macref{with-open-file}, and
  220. implicitly by \term{functions} such as \funref{load} that process \term{files}.
  221. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  222. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  223. \label See Also::
  224. \funref{load},
  225. \funref{open},
  226. \macref{with-open-file}
  227. \endcom%{file-stream}\ftype{System Class}
  228. \begincom{string-stream}\ftype{System Class}
  229. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  230. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  231. \label Class Precedence List::
  232. \typeref{string-stream},
  233. \typeref{stream},
  234. \typeref{t}
  235. \label Description::
  236. A \term{string stream} is a \term{stream}
  237. which reads input from or writes output to an associated \term{string}.
  238. The \term{stream element type} of a \term{string stream} is always
  239. a \subtypeof{character}.
  240. \label See Also::
  241. \funref{make-string-input-stream},
  242. \funref{make-string-output-stream},
  243. \macref{with-input-from-string},
  244. \macref{with-output-to-string}
  245. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  246. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  247. \endcom%{string-stream}\ftype{Type}
  248. \begincom{synonym-stream}\ftype{System Class}
  249. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  250. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  251. \label Class Precedence List::
  252. \typeref{synonym-stream},
  253. \typeref{stream},
  254. \typeref{t}
  255. \label Description::
  256. A \term{stream} that is an alias for another \term{stream},
  257. which is the \term{value} of a \term{dynamic variable}
  258. whose \term{name} is the \term{synonym stream symbol} of the \term{synonym stream}.
  259. Any operations on a \term{synonym stream} will be performed
  260. on the \term{stream} that is then the \term{value} of the
  261. \term{dynamic variable} named by the \term{synonym stream symbol}.
  262. If the \term{value} of the \term{variable} should change,
  263. or if the \term{variable} should be \term{bound},
  264. then the \term{stream} will operate on the new \term{value} of the \term{variable}.
  265. \label See Also::
  266. \funref{make-synonym-stream},
  267. \funref{synonym-stream-symbol}
  268. %% This should go without saying.
  269. % \label Notes::
  270. %
  271. % A \term{synonym stream} is created by \funref{make-synonym-stream}.
  272. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  273. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  274. \endcom%{synonym-stream}\ftype{System Class}
  275. \begincom{two-way-stream}\ftype{System Class}
  276. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  277. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  278. \label Class Precedence List::
  279. \typeref{two-way-stream},
  280. \typeref{stream},
  281. \typeref{t}
  282. \label Description::
  283. A \term{bidirectional} \term{composite stream} that
  284. receives its input from an associated \term{input} \term{stream}
  285. and sends its output to an associated \term{output} \term{stream}.
  286. \label See Also::
  287. \funref{make-two-way-stream},
  288. \funref{two-way-stream-input-stream},
  289. \funref{two-way-stream-output-stream}
  290. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  291. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  292. \endcom%{two-way-stream}\ftype{System Class}
  293. %-------------------- Streams --------------------
  294. %%% ========== INPUT-STREAM-P
  295. %%% ========== OUTPUT-STREAM-P
  296. \begincom{input-stream-p, output-stream-p}\ftype{Function}
  297. \label Syntax::
  298. \DefunWithValues input-stream-p {stream} {generalized-boolean}
  299. \DefunWithValues output-stream-p {stream} {generalized-boolean}
  300. \label Arguments and Values::
  301. \param{stream}---a \term{stream}.
  302. \param{generalized-boolean}---a \term{generalized boolean}.
  303. \label Description::
  304. %% 21.3.0 4
  305. \NamedPredicate{input-stream-p}{stream}{an \term{input} \term{stream}}
  306. %% 21.3.0 5
  307. \NamedPredicate{output-stream-p}{stream}{an \term{output} \term{stream}}
  308. \label Examples::
  309. \code
  310. (input-stream-p *standard-input*) \EV \term{true}
  311. (input-stream-p *terminal-io*) \EV \term{true}
  312. (input-stream-p (make-string-output-stream)) \EV \term{false}
  313. (output-stream-p *standard-output*) \EV \term{true}
  314. (output-stream-p *terminal-io*) \EV \term{true}
  315. (output-stream-p (make-string-input-stream "jr")) \EV \term{false}
  316. \endcode
  317. \label Side Effects:\None!
  318. \label Affected By:\None.
  319. \label Exceptional Situations::
  320. \Shouldchecktype{stream}{a \term{stream}}
  321. \label See Also:\None.
  322. \label Notes:\None.
  323. \endcom
  324. %%% ========== INTERACTIVE-STREAM-P
  325. \begincom{interactive-stream-p}\ftype{Function}
  326. \issue{STREAM-CAPABILITIES:INTERACTIVE-STREAM-P}
  327. \label Syntax::
  328. \DefunWithValues interactive-stream-p {stream} {generalized-boolean}
  329. \label Arguments and Values::
  330. \param{stream}---a \term{stream}.
  331. \param{generalized-boolean}---a \term{generalized boolean}.
  332. \label Description::
  333. \Predicate{stream}{an \term{interactive stream}}
  334. \label Examples::
  335. \code
  336. (when (> measured limit)
  337. (let ((error (round (* (- measured limit) 100)
  338. limit)))
  339. (unless (if (interactive-stream-p *query-io*)
  340. (yes-or-no-p "The frammis is out of tolerance by ~D%.~@
  341. Is it safe to proceed? " error)
  342. (< error 15)) ;15% is acceptable
  343. (error "The frammis is out of tolerance by ~D%." error))))
  344. \endcode
  345. \label Affected By:\None.
  346. \label Exceptional Situations::
  347. % The cleanup said "signals", but that's stylistically inconsistent.
  348. % Barrett and I decided to just ignore the cleanup and fix things up. -kmp 22-Jan-92
  349. \Shouldchecktype{stream}{a \term{stream}}
  350. \label See Also::
  351. {\secref\StreamConcepts}
  352. \label Notes:\None.
  353. \endissue{STREAM-CAPABILITIES:INTERACTIVE-STREAM-P}
  354. \endcom
  355. %%% ========== OPEN-STREAM-P
  356. \begincom{open-stream-p}\ftype{Function}
  357. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  358. \label Syntax::
  359. \DefunWithValues open-stream-p {stream} {generalized-boolean}
  360. \label Arguments and Values::
  361. \param{stream}---a \term{stream}.
  362. \param{generalized-boolean}---a \term{generalized boolean}.
  363. \label Description::
  364. \Predicate{stream}{an \term{open} \term{stream}}
  365. \term{Streams} are open until they have been explicitly closed with \funref{close},
  366. or until they are implicitly closed due to exit from a
  367. \macref{with-output-to-string},
  368. \macref{with-open-file},
  369. \macref{with-input-from-string}, or
  370. \macref{with-open-stream} \term{form}.
  371. \label Examples::
  372. \code
  373. (open-stream-p *standard-input*) \EV \term{true}
  374. \endcode
  375. \label Side Effects:\None!
  376. \label Affected By::
  377. \funref{close}.
  378. \label Exceptional Situations::
  379. \Shouldchecktype{stream}{a \term{stream}}
  380. \label See Also:\None.
  381. \label Notes:\None.
  382. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  383. \endcom
  384. %%% ========== STREAM-ELEMENT-TYPE
  385. \begincom{stream-element-type}\ftype{Function}
  386. \label Syntax::
  387. \DefunWithValues stream-element-type {stream} {typespec}
  388. \label Arguments and Values::
  389. \param{stream}---a \term{stream}.
  390. \param{typespec}---a \term{type specifier}.
  391. \label Description::
  392. %% 21.3.0 6
  393. \funref{stream-element-type} returns a \term{type specifier} that
  394. indicates the \term{types} of \term{objects} that may be read from
  395. or written to \param{stream}.
  396. \term{Streams} created by \funref{open} have an \term{element type}
  397. restricted to \typeref{integer} or a \subtypeof{character}.
  398. %%KMP (2-Jan-91): How?? What would it mean? Does this have formal impact?
  399. % but in principle a \term{stream} may conduct transactions using any
  400. % \term{objects}.
  401. %% Removed on instruction of Barrett, who concurred, saying:
  402. %% I'm not convinced this is even true, since OPEN just says "acceptable",
  403. %% which I read as saying undefined consequences, which permits an implementation
  404. %% to extend to allow other kinds of objects. Even without that, the statement
  405. %% isn't all that interesting, since OPEN only defined to deal with filestreams,
  406. %% and an implementation could provide other kinds of streams which pass aribitrary objects.
  407. \label Examples::
  408. \code
  409. ;; Note that the stream must accomodate at least the specified type,
  410. ;; but might accomodate other types. Further note that even if it does
  411. ;; accomodate exactly the specified type, the type might be specified in
  412. ;; any of several ways.
  413. (with-open-file (s "test" :element-type '(integer 0 1)
  414. :if-exists :error
  415. :direction :output)
  416. (stream-element-type s))
  417. \EV INTEGER
  418. \OV (UNSIGNED-BYTE 16)
  419. \OV (UNSIGNED-BYTE 8)
  420. \OV BIT
  421. \OV (UNSIGNED-BYTE 1)
  422. \OV (INTEGER 0 1)
  423. \OV (INTEGER 0 (2))
  424. \endcode
  425. \label Side Effects:\None.
  426. \label Affected By:\None.
  427. \label Exceptional Situations::
  428. \Shouldchecktype{stream}{a \term{stream}}
  429. \label See Also:\None.
  430. \label Notes:\None.
  431. \endcom
  432. %%% ========== STREAMP
  433. \begincom{streamp}\ftype{Function}
  434. \label Syntax::
  435. \DefunWithValues {streamp} {object} {generalized-boolean}
  436. \label Arguments and Values::
  437. \param{object}---an \term{object}.
  438. \param{generalized-boolean}---a \term{generalized boolean}.
  439. \label Description::
  440. %% 21.3.0 3
  441. \TypePredicate{object}{stream}
  442. \issue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  443. \funref{streamp} is unaffected by whether \param{object},
  444. if it is a \term{stream}, is \term{open} or closed.
  445. \endissue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  446. \label Examples::
  447. \code
  448. (streamp *terminal-io*) \EV \term{true}
  449. (streamp 1) \EV \term{false}
  450. \endcode
  451. \label Side Effects:\None.
  452. \label Affected By:\None.
  453. \label Exceptional Situations:\None!
  454. \label See Also:\None.
  455. \label Notes::
  456. \code
  457. (streamp \param{object}) \EQ (typep \param{object} 'stream)
  458. \endcode
  459. \endcom
  460. %-------------------- Byte Io --------------------
  461. %%% ========== READ-BYTE
  462. \begincom{read-byte}\ftype{Function}
  463. \label Syntax::
  464. \DefunWithValues {read-byte} {stream {\opt} eof-error-p eof-value} {byte}
  465. \label Arguments and Values::
  466. \param{stream}---a \term{binary} \term{input} \term{stream}.
  467. \param{eof-error-p}---a \term{generalized boolean}.
  468. \Default{\term{true}}
  469. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  470. \param{eof-value}---an \term{object}.
  471. \Default{\nil}
  472. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  473. \param{byte}---an \term{integer},
  474. %% Removed by KMP because in the presence of stream element type upgrading,
  475. %% this won't necessarily work as expected if the file was written with an
  476. %% incompatible element type.
  477. % of the \term{stream element type}
  478. % of \term{stream}
  479. or the \param{eof-value}.
  480. \label Description::
  481. %% 22.2.2 3
  482. \funref{read-byte} reads and returns one byte from \param{stream}.
  483. If an \term{end of file}\meaning{2} occurs and \param{eof-error-p} is \term{false},
  484. the \param{eof-value} is returned.
  485. \label Examples::
  486. \code
  487. (with-open-file (s "temp-bytes"
  488. :direction :output
  489. :element-type 'unsigned-byte)
  490. (write-byte 101 s)) \EV 101
  491. (with-open-file (s "temp-bytes" :element-type 'unsigned-byte)
  492. (format t "~S ~S" (read-byte s) (read-byte s nil 'eof)))
  493. \OUT 101 EOF
  494. \EV NIL
  495. \endcode
  496. \label Side Effects::
  497. Modifies \param{stream}.
  498. \label Affected By:\None.
  499. \label Exceptional Situations::
  500. \Shouldchecktype{stream}{a \term{stream}}
  501. Should signal an error \oftype{error}
  502. if \param{stream} is not a \term{binary} \term{input} \term{stream}.
  503. If there are no \term{bytes} remaining in the \param{stream}
  504. and \param{eof-error-p} is \term{true}, an error \oftype{end-of-file} is signaled.
  505. \label See Also::
  506. \funref{read-char},
  507. \issue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  508. \funref{read-sequence},
  509. \endissue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  510. \funref{write-byte}
  511. \label Notes:\None.
  512. \endcom
  513. %%% ========== WRITE-BYTE
  514. \begincom{write-byte}\ftype{Function}
  515. \label Syntax::
  516. \DefunWithValues {write-byte} {byte stream} {byte}
  517. \label Arguments and Values::
  518. \param{byte}---an \term{integer} of the \term{stream element type}
  519. of \term{stream}.
  520. \param{stream}---a \term{binary} \term{output} \term{stream}.
  521. \label Description::
  522. %% 22.3.2 4
  523. \funref{write-byte} writes one byte, \param{byte}, to \param{stream}.
  524. %The size of the byte written depends on the {\bf :element-type} argument
  525. %from \funref{open} or \macref{with-open-file}.
  526. %Unless the byte size of that
  527. %element type is one, two, or four bits, each call to \funref{write-byte}
  528. %generates an integral number of 8-bit bytes, namely the minimum number
  529. %necessary to hold the number of bits indicated by the given element type.
  530. %If the byte size of the element type is one, two, or four bits, then as many
  531. %elements as possible (eight, four, or two respectively) are packed into
  532. %each 8-bit byte.
  533. \label Examples::
  534. \code
  535. (with-open-file (s "temp-bytes"
  536. :direction :output
  537. :element-type 'unsigned-byte)
  538. (write-byte 101 s)) \EV 101
  539. \endcode
  540. \label Side Effects::
  541. \param{stream} is modified.
  542. \label Affected By::
  543. The \term{element type} of the \param{stream}.
  544. \label Exceptional Situations::
  545. \Shouldchecktype{stream}{a \term{stream}}
  546. Should signal an error \oftype{error}
  547. if \param{stream} is not a \term{binary} \term{output} \term{stream}.
  548. Might signal an error \oftype{type-error} if \param{byte} is not
  549. an \term{integer} of the \term{stream element type} of \term{stream}.
  550. \label See Also::
  551. \funref{read-byte},
  552. \funref{write-char},
  553. \issue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  554. \funref{write-sequence}
  555. \endissue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  556. \label Notes:\None.
  557. \endcom
  558. %-------------------- Character Io --------------------
  559. %%% ========== PEEK-CHAR
  560. \begincom{peek-char}\ftype{Function}
  561. \label Syntax::
  562. \DefunWithValues {peek-char}
  563. {{\opt} \vtop{\hbox{peek-type input-stream eof-error-p}
  564. \hbox{eof-value recursive-p}}}
  565. {char}
  566. \label Arguments and Values::
  567. \param{peek-type}---a \term{character} or \t\ or \nil.
  568. \param{input-stream}---\term{input} \term{stream designator}.
  569. \Default{\term{standard input}}
  570. \param{eof-error-p}---a \term{generalized boolean}.
  571. \Default{\term{true}}
  572. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  573. \param{eof-value}---an \term{object}.
  574. \Default{\nil}
  575. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  576. \param{recursive-p}---a \term{generalized boolean}.
  577. \Default{\term{false}}
  578. \param{char}---a \term{character} or the \param{eof-value}.
  579. \label Description::
  580. \funref{peek-char} obtains the next character in \param{input-stream}
  581. without actually reading it, thus leaving the character
  582. to be read at a later time. It can
  583. also be used to skip over and discard intervening
  584. characters in the \param{input-stream}
  585. until a particular character is found.
  586. %% 22.2.1 33
  587. If \param{peek-type} is not supplied or \nil,
  588. \funref{peek-char} returns the next character to be read from
  589. \param{input-stream}, without actually removing it from
  590. \param{input-stream}.
  591. The next time input is done from \param{input-stream}, the character will still
  592. be there.
  593. %% 22.2.1 34
  594. If \param{peek-type} is \t,
  595. then \funref{peek-char} skips over \term{whitespace}\meaning{2} \term{characters},
  596. but not comments,
  597. and then performs the peeking operation on the next
  598. character.
  599. The last character examined, the one that starts an \term{object},
  600. is not removed from \param{input-stream}.
  601. %% 22.2.1 35
  602. If \param{peek-type} is a \term{character},
  603. then \funref{peek-char} skips
  604. over input characters until a character that
  605. is \funref{char=} to that \term{character} is found;
  606. that character is left in \param{input-stream}.
  607. If an \term{end of file}\meaning{2} occurs and \param{eof-error-p} is \term{false},
  608. \param{eof-value} is returned.
  609. {$ $}{\ExplainRecursiveP}
  610. \issue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  611. When \param{input-stream} is an \term{echo stream},
  612. characters that are only peeked at are not echoed. In the
  613. case that \param{peek-type} is not \nil,
  614. the characters that are passed by \funref{peek-char}
  615. are treated as if by \funref{read-char},
  616. and so are echoed unless they have been marked otherwise by \funref{unread-char}.
  617. \endissue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  618. \label Examples::
  619. \code
  620. (with-input-from-string (input-stream " 1 2 3 4 5")
  621. (format t "~S ~S ~S"
  622. (peek-char t input-stream)
  623. (peek-char #\\4 input-stream)
  624. (peek-char nil input-stream)))
  625. \OUT #\\1 #\\4 #\\4
  626. \EV NIL
  627. \endcode
  628. \label Affected By::
  629. \varref{*readtable*},
  630. \varref{*standard-input*},
  631. \varref{*terminal-io*}.
  632. \label Exceptional Situations::
  633. If \param{eof-error-p} is \term{true} and an \term{end of file}\meaning{2} occurs
  634. an error \oftype{end-of-file} is signaled.
  635. If \param{peek-type} is a \term{character},
  636. an \term{end of file}\meaning{2} occurs,
  637. and \param{eof-error-p} is \term{true},
  638. an error \oftype{end-of-file} is signaled.
  639. %!!! Barrett is concerned about the case of eof-error-p here.
  640. If \param{recursive-p} is \term{true}
  641. and an \term{end of file}\meaning{2} occurs,
  642. an error \oftype{end-of-file} is signaled.
  643. \label See Also:\None.
  644. \label Notes:\None.
  645. \endcom
  646. %%% ========== READ-CHAR
  647. \begincom{read-char}\ftype{Function}
  648. \label Syntax::
  649. \DefunWithValues {read-char}
  650. {{\opt} input-stream eof-error-p eof-value recursive-p}
  651. {char}
  652. \label Arguments and Values::
  653. \param{input-stream}---an \term{input} \term{stream designator}.
  654. \Default{\term{standard input}}
  655. \param{eof-error-p}---a \term{generalized boolean}.
  656. \Default{\term{true}}
  657. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  658. \param{eof-value}---an \term{object}.
  659. \Default{\nil}
  660. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  661. \param{recursive-p}---a \term{generalized boolean}.
  662. \Default{\term{false}}
  663. \param{char}---a \term{character} or the \param{eof-value}.
  664. \label Description::
  665. %% 22.2.1 28
  666. \funref{read-char} returns the next \term{character} from \param{input-stream}.
  667. \issue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  668. When \param{input-stream} is an \param{echo stream},
  669. the character is echoed on \param{input-stream} the first time the character is
  670. %Sandra: "seen"? awfully vague.
  671. seen.
  672. Characters that are not echoed by \funref{read-char}
  673. are those that were
  674. put there by \funref{unread-char}
  675. and hence are assumed to have been echoed
  676. already by a previous call to \funref{read-char}.
  677. \endissue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  678. {$ $}{\ExplainRecursiveP}
  679. If an \term{end of file}\meaning{2} occurs and \param{eof-error-p} is \term{false},
  680. \param{eof-value} is returned.
  681. \label Examples::
  682. \code
  683. (with-input-from-string (is "0123")
  684. (do ((c (read-char is) (read-char is nil 'the-end)))
  685. ((not (characterp c)))
  686. (format t "~S " c)))
  687. \OUT #\\0 #\\1 #\\2 #\\3
  688. \EV NIL
  689. \endcode
  690. \label Affected By::
  691. \varref{*standard-input*},
  692. \varref{*terminal-io*}.
  693. \label Exceptional Situations::
  694. If an \term{end of file}\meaning{2} occurs before a character can be read, and
  695. \param{eof-error-p} is \term{true},
  696. an error \oftype{end-of-file} is signaled.
  697. \label See Also::
  698. \funref{read-byte},
  699. \issue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  700. \funref{read-sequence},
  701. \endissue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  702. \funref{write-char},
  703. \funref{read}
  704. \label Notes::
  705. %% 22.2.1 29
  706. The corresponding output function is \funref{write-char}.
  707. \endcom
  708. %%% ========== READ-CHAR-NO-HANG
  709. \begincom{read-char-no-hang}\ftype{Function}
  710. \label Syntax::
  711. \DefunWithValues read-char-no-hang
  712. {{\opt} \vtop{\hbox{input-stream eof-error-p}
  713. \hbox{eof-value recursive-p}}}
  714. {char}
  715. \label Arguments and Values::
  716. \param{input-stream} -- an \term{input} \term{stream designator}.
  717. \Default{\term{standard input}}
  718. \param{eof-error-p}---a \term{generalized boolean}.
  719. \Default{\term{true}}
  720. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  721. \param{eof-value}---an \term{object}.
  722. \Default{\nil}
  723. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  724. \param{recursive-p}---a \term{generalized boolean}.
  725. \Default{\term{false}}
  726. \param{char}---a \term{character} or \nil\ or the \param{eof-value}.
  727. \label Description::
  728. \funref{read-char-no-hang} returns a character
  729. from \param{input-stream} if such a character is available. If no character
  730. is available, \funref{read-char-no-hang} returns \nil.
  731. {$ $}{\ExplainRecursiveP}
  732. If an \term{end of file}\meaning{2} occurs and \param{eof-error-p} is \term{false},
  733. \param{eof-value} is returned.
  734. \label Examples::
  735. %!!! This example suffers from the `newline problem' -kmp 8-May-91
  736. \code
  737. ;; This code assumes an implementation in which a newline is not
  738. ;; required to terminate input from the console.
  739. (defun test-it ()
  740. (unread-char (read-char))
  741. (list (read-char-no-hang)
  742. (read-char-no-hang)
  743. (read-char-no-hang)))
  744. \EV TEST-IT
  745. ;; Implementation A, where a Newline is not required to terminate
  746. ;; interactive input on the console.
  747. (test-it)
  748. \OUT \IN{a}
  749. \EV (#\\a NIL NIL)
  750. ;; Implementation B, where a Newline is required to terminate
  751. ;; interactive input on the console, and where that Newline remains
  752. ;; on the input stream.
  753. (test-it)
  754. \OUT \IN{a\CRLF}
  755. \EV (#\\a #\\Newline NIL)
  756. \endcode
  757. \label Affected By::
  758. \varref{*standard-input*},
  759. \varref{*terminal-io*}.
  760. \label Exceptional Situations::
  761. If an \term{end of file}\meaning{2} occurs
  762. when \param{eof-error-p} is \term{true},
  763. an error \oftype{end-of-file} is signaled .
  764. \label See Also::
  765. \funref{listen}
  766. \label Notes::
  767. %% 22.2.1 37
  768. \funref{read-char-no-hang} is exactly like \funref{read-char}, except
  769. that if it would be necessary to wait in order to get a character (as
  770. from a keyboard), \nil\ is immediately returned without waiting.
  771. %!!! Symbolics doesn't echo the char from this. Should it? -kmp
  772. \endcom
  773. %%% ========== TERPRI
  774. %%% ========== FRESH-LINE
  775. \begincom{terpri, fresh-line}\ftype{Function}
  776. \label Syntax::
  777. \DefunWithValues {terpri} {{\opt} output-stream} {\nil}
  778. \DefunWithValues {fresh-line} {{\opt} output-stream} {generalized-boolean}
  779. \label Arguments and Values::
  780. \param{output-stream} -- an \term{output} \term{stream designator}.
  781. \Default{\term{standard output}}
  782. \param{generalized-boolean}---a \term{generalized boolean}.
  783. \label Description::
  784. \funref{terpri} outputs a \term{newline} to \param{output-stream}.
  785. %% 22.3.1 18
  786. \funref{fresh-line} is similar to \funref{terpri} but outputs a \term{newline}
  787. only if the \param{output-stream} is not already at the start of a line.
  788. If for some reason this cannot be determined, then a \term{newline} is output anyway.
  789. \funref{fresh-line} returns \term{true} if it outputs a \term{newline};
  790. otherwise it returns \term{false}.
  791. \label Examples::
  792. \code
  793. (with-output-to-string (s)
  794. (write-string "some text" s)
  795. (terpri s)
  796. (terpri s)
  797. (write-string "more text" s))
  798. \EV "some text
  799. more text"
  800. (with-output-to-string (s)
  801. (write-string "some text" s)
  802. (fresh-line s)
  803. (fresh-line s)
  804. (write-string "more text" s))
  805. \EV "some text
  806. more text"
  807. \endcode
  808. \label Side Effects::
  809. The \param{output-stream} is modified.
  810. \label Affected By::
  811. \varref{*standard-output*},
  812. \varref{*terminal-io*}.
  813. \label Exceptional Situations::
  814. None.
  815. \reviewer{Barmar: What if stream is closed?}%!!!
  816. \label See Also:\None.
  817. \label Notes::
  818. \funref{terpri} is identical in effect to
  819. \code
  820. (write-char #\\Newline output-stream)
  821. \endcode
  822. \endcom
  823. %%% ========== UNREAD-CHAR
  824. \begincom{unread-char}\ftype{Function}
  825. \label Syntax::
  826. %% 22.2.1 30
  827. \DefunWithValues {unread-char} {character {\opt} input-stream} {\nil}
  828. \label Arguments and Values::
  829. %% 22.2.1 31
  830. \param{character}---a \term{character};
  831. must be the last \term{character} that was read from \param{input-stream}.
  832. \param{input-stream}---an \term{input} \term{stream designator}.
  833. \Default{\term{standard input}}
  834. \label Description::
  835. \funref{unread-char} places \param{character} back onto the front of
  836. \param{input-stream} so that it will again be the next character
  837. in \param{input-stream}.
  838. \issue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  839. When \param{input-stream} is an \term{echo stream},
  840. no attempt is made to undo any echoing of the character that might already
  841. have been done on \param{input-stream}. However, characters placed on
  842. \param{input-stream} by \funref{unread-char} are marked in such a way
  843. as to inhibit later re-echo by \funref{read-char}.
  844. \endissue{PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR}
  845. It is an error to invoke \funref{unread-char}
  846. twice consecutively on the same \term{stream}
  847. without an intervening call to \funref{read-char}
  848. (or some other input operation which implicitly reads characters)
  849. on that \term{stream}.
  850. \issue{UNREAD-CHAR-AFTER-PEEK-CHAR:DONT-ALLOW}
  851. Invoking \funref{peek-char} or \funref{read-char} commits all previous characters.
  852. The consequences of invoking \funref{unread-char}
  853. on any character preceding that which is returned by
  854. \funref{peek-char} (including those passed over by
  855. \funref{peek-char} that has a \term{non-nil} \param{peek-type})
  856. are unspecified.
  857. In particular, the consequences of
  858. invoking \funref{unread-char} after \funref{peek-char}
  859. are unspecified.
  860. \endissue{UNREAD-CHAR-AFTER-PEEK-CHAR:DONT-ALLOW}
  861. \label Examples::
  862. \code
  863. (with-input-from-string (is "0123")
  864. (dotimes (i 6)
  865. (let ((c (read-char is)))
  866. (if (evenp i) (format t "~&~S ~S~%" i c) (unread-char c is)))))
  867. \OUT 0 #\\0
  868. \OUT 2 #\\1
  869. \OUT 4 #\\2
  870. \EV NIL
  871. \endcode
  872. \label Affected By::
  873. \varref{*standard-input*},
  874. \varref{*terminal-io*}.
  875. \label Exceptional Situations:\None.
  876. \label See Also::
  877. \funref{peek-char},
  878. \funref{read-char},
  879. {\secref\StreamConcepts}
  880. \label Notes::
  881. %% 22.2.1 32
  882. \funref{unread-char} is intended to be an efficient mechanism for allowing
  883. the \term{Lisp reader} and other parsers to perform one-character lookahead
  884. in \param{input-stream}.
  885. \endcom
  886. %%% ========== WRITE-CHAR
  887. \begincom{write-char}\ftype{Function}
  888. \label Syntax::
  889. \DefunWithValues {write-char} {character {\opt} output-stream} {character}
  890. \label Arguments and Values::
  891. \param{character}---a \term{character}.
  892. \param{output-stream} -- an \term{output} \term{stream designator}.
  893. \Default{\term{standard output}}
  894. \label Description::
  895. %% 22.3.1 12
  896. \funref{write-char} outputs \param{character} to \param{output-stream}.
  897. \label Examples::
  898. \code
  899. (write-char #\\a)
  900. \OUT a
  901. \EV #\\a
  902. (with-output-to-string (s)
  903. (write-char #\\a s)
  904. (write-char #\\Space s)
  905. (write-char #\\b s))
  906. \EV "a b"
  907. \endcode
  908. \label Side Effects::
  909. The \param{output-stream} is modified.
  910. \label Affected By::
  911. \varref{*standard-output*},
  912. \varref{*terminal-io*}.
  913. \label Exceptional Situations:\None.
  914. \label See Also::
  915. \funref{read-char},
  916. \funref{write-byte},
  917. \issue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  918. \funref{write-sequence}
  919. \endissue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  920. \label Notes:\None.
  921. \endcom
  922. %-------------------- String I/O --------------------
  923. %%% ========== READ-LINE
  924. \begincom{read-line}\ftype{Function}
  925. \label Syntax::
  926. \DefunWithValuesNewline read-line
  927. {{\opt} input-stream eof-error-p eof-value recursive-p}
  928. {line, missing-newline-p}
  929. %!!! Barrett wonders if the second return value should really be required
  930. % when the first value is an eof-value...
  931. \label Arguments and Values::
  932. \param{input-stream}---an \term{input} \term{stream designator}.
  933. \Default{\term{standard input}}
  934. \param{eof-error-p}---a \term{generalized boolean}.
  935. \Default{\term{true}}
  936. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  937. \param{eof-value}---an \term{object}.
  938. \Default{\nil}
  939. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  940. \param{recursive-p}---a \term{generalized boolean}.
  941. \Default{\term{false}}
  942. \param{line}---a \term{string} or the \param{eof-value}.
  943. \param{missing-newline-p}---a \term{generalized boolean}.
  944. \label Description::
  945. %% 22.2.1 26
  946. Reads from \param{input-stream} a line of text
  947. that is terminated by a \term{newline} or \term{end of file}.
  948. %% This should follow without saying. -kmp 11-Feb-92
  949. %Interactively, this \term{function} can be used to get a line of input from the \term{user}.
  950. {$ $}{\ExplainRecursiveP}
  951. The \term{primary value}, \param{line}, is the line that is read,
  952. represented as a \term{string} (without the trailing \term{newline}, if any).
  953. If \param{eof-error-p} is \term{false}
  954. and the \term{end of file} for \param{input-stream} is reached
  955. before any \term{characters} are read,
  956. \param{eof-value} is returned as the \param{line}.
  957. The \term{secondary value}, \param{missing-newline-p},
  958. is a \term{generalized boolean} that is
  959. \term{false} if the \param{line} was terminated by a \term{newline},
  960. or \term{true} if the \param{line} was terminated by
  961. the \term{end of file} for \param{input-stream}
  962. %KMP: What's the right second value when the first return value is the eof flag?
  963. %Moon: Surely true, since there was no newline.
  964. %KMP: Added the following:
  965. (or if the \param{line} is the \param{eof-value}).
  966. \label Examples::
  967. \code
  968. (setq a "line 1
  969. line2")
  970. \EV "line 1
  971. line2"
  972. (read-line (setq input-stream (make-string-input-stream a)))
  973. \EV "line 1", \term{false}
  974. (read-line input-stream)
  975. \EV "line2", \term{true}
  976. (read-line input-stream nil nil)
  977. \EV NIL, \term{true}
  978. \endcode
  979. \label Side Effects:\None.
  980. \label Affected By::
  981. \varref{*standard-input*},
  982. \varref{*terminal-io*}.
  983. \label Exceptional Situations::
  984. If an \term{end of file}\meaning{2} occurs before any characters are read in the line,
  985. an error is signaled if \param{eof-error-p} is \term{true}.
  986. \label See Also::
  987. \funref{read}
  988. \label Notes::
  989. %% 22.2.1 27
  990. The corresponding output function is \funref{write-line}.
  991. \endcom
  992. %%% ========== WRITE-STRING
  993. %%% ========== WRITE-LINE
  994. \begincom{write-string, write-line}\ftype{Function}
  995. \label Syntax::
  996. \DefunWithValues {write-string} {string {\opt} output-stream {\key} start end} {string}
  997. \DefunWithValues {write-line} {string {\opt} output-stream {\key} start end} {string}
  998. \label Arguments and Values::
  999. \param{string}---a \term{string}.
  1000. \param{output-stream} -- an \term{output} \term{stream designator}.
  1001. \Default{\term{standard output}}
  1002. \issue{SUBSEQ-OUT-OF-BOUNDS}
  1003. \issue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  1004. \param{start}, \param{end}---\term{bounding index designators} of \param{string}.
  1005. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  1006. \endissue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  1007. \endissue{SUBSEQ-OUT-OF-BOUNDS}
  1008. \label Description::
  1009. %% 22.3.1 13
  1010. \funref{write-string} writes the \term{characters} of
  1011. the subsequence of \param{string} \term{bounded} by \param{start} and \param{end}
  1012. to \param{output-stream}.
  1013. \funref{write-line} does the same thing,
  1014. but then outputs a newline afterwards.
  1015. %% Redundant with "bounded by" above. -kmp 23-Jan-92
  1016. % \param{start} specifies the offset into \param{string}.
  1017. % \param{end} marks the the position following the last element of the substring.
  1018. %% 22.3.1 16
  1019. %% this paragraph was left out
  1020. \label Examples::
  1021. \code
  1022. (prog1 (write-string "books" nil :end 4) (write-string "worms"))
  1023. \OUT bookworms
  1024. \EV "books"
  1025. (progn (write-char #\\*)
  1026. (write-line "test12" *standard-output* :end 5)
  1027. (write-line "*test2")
  1028. (write-char #\\*)
  1029. nil)
  1030. \OUT *test1
  1031. \OUT *test2
  1032. \OUT *
  1033. \EV NIL
  1034. \endcode
  1035. \label Side Effects:\None.
  1036. \label Affected By::
  1037. \varref{*standard-output*},
  1038. \varref{*terminal-io*}.
  1039. \label Exceptional Situations:\None.
  1040. \label See Also::
  1041. \funref{read-line}, \funref{write-char}
  1042. \label Notes::
  1043. \funref{write-line} and \funref{write-string} return \param{string},
  1044. not the substring \term{bounded} by \param{start} and \param{end}.
  1045. \code
  1046. (write-string string)
  1047. \EQ (dotimes (i (length string)
  1048. (write-char (char string i)))
  1049. (write-line string)
  1050. \EQ (prog1 (write-string string) (terpri))
  1051. \endcode
  1052. %The WRITE-LINE equivalence supplied by Barmar.
  1053. \endcom
  1054. %-------------------- Block-Mode I/O --------------------
  1055. \issue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  1056. %%% ========== READ-SEQUENCE
  1057. \begincom{read-sequence}\ftype{Function}
  1058. \label Syntax::
  1059. \DefunWithValues {read-sequence} {sequence stream {\key} start end} {position}
  1060. \param{sequence}---a \term{sequence}.
  1061. \param{stream}---an \term{input} \term{stream}.
  1062. \param{start}, \param{end}---\term{bounding index designators} of
  1063. \param{sequence}. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  1064. \param{position}---an \term{integer} greater than or equal to zero, and
  1065. less than or equal to the \term{length} of the \param{sequence}.
  1066. \label Description::
  1067. Destructively modifies \param{sequence} by replacing the \term{elements}
  1068. of \param{sequence} \term{bounded} by \param{start} and \param{end} with
  1069. \term{elements} read from \param{stream}.
  1070. \param{Sequence} is destructively modified by copying successive
  1071. \term{elements} into it from \param{stream}. If the \term{end of file} for
  1072. \param{stream} is reached before copying all \term{elements} of the
  1073. subsequence, then the extra \term{elements} near the end of \param{sequence}
  1074. are not updated.
  1075. \param{Position} is the index of the first \term{element} of \param{sequence}
  1076. that was not updated, which might be less than \param{end} because the
  1077. \term{end of file} was reached.
  1078. \label Examples::
  1079. \code
  1080. (defvar *data* (make-array 15 :initial-element nil))
  1081. (values (read-sequence *data* (make-string-input-stream "test string")) *data*)
  1082. \EV 11, #(#\\t #\\e #\\s #\\t #\\Space #\\s #\\t #\\r #\\i #\\n #\\g NIL NIL NIL NIL)
  1083. \endcode
  1084. \label Side Effects::
  1085. Modifies \param{stream} and \param{sequence}.
  1086. \label Affected By:\None.
  1087. \label Exceptional Situations::
  1088. \Lazychecktype{sequence}{a \term{proper sequence}}
  1089. \Shouldchecktype{start}{a non-negative \term{integer}}
  1090. \Shouldchecktype{end}{a non-negative \term{integer} or \nil}
  1091. Might signal an error \oftype{type-error} if an \term{element} read from
  1092. the \param{stream} is not a member of the \term{element type} of the
  1093. \param{sequence}.
  1094. \label See Also::
  1095. {\secref\ConstantModification},
  1096. \funref{write-sequence},
  1097. \funref{read-line}
  1098. \label Notes::
  1099. \funref{read-sequence} is identical in effect to iterating over the indicated
  1100. subsequence and reading one \term{element} at a time from \param{stream} and
  1101. storing it into \param{sequence}, but may be more efficient than the
  1102. equivalent loop. An efficient implementation is more likely to exist
  1103. for the case where the \param{sequence} is a \term{vector} with the same
  1104. \term{element type} as the \param{stream}.
  1105. \endcom
  1106. %%% ========== WRITE-SEQUENCE
  1107. \begincom{write-sequence}\ftype{Function}
  1108. \label Syntax::
  1109. \DefunWithValues {write-sequence} {sequence stream {\key} start end} {sequence}
  1110. \param{sequence}---a \term{sequence}.
  1111. \param{stream}---an \term{output} \term{stream}.
  1112. \param{start}, \param{end}---\term{bounding index designators} of
  1113. \param{sequence}. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  1114. \label Description::
  1115. \funref{write-sequence} writes the \term{elements} of the subsequence
  1116. of \param{sequence} \term{bounded} by \param{start} and \param{end} to
  1117. \param{stream}.
  1118. \label Examples::
  1119. \code
  1120. (write-sequence "bookworms" *standard-output* :end 4)
  1121. \OUT book
  1122. \EV "bookworms"
  1123. \endcode
  1124. \label Side Effects::
  1125. Modifies \param{stream}.
  1126. \label Affected By:\None.
  1127. \label Exceptional Situations::
  1128. \Lazychecktype{sequence}{a \term{proper sequence}}
  1129. \Shouldchecktype{start}{a non-negative \term{integer}}
  1130. \Shouldchecktype{end}{a non-negative \term{integer} or \nil}
  1131. Might signal an error \oftype{type-error} if an \term{element} of the
  1132. \term{bounded} \term{sequence} is not a member of the
  1133. \term{stream element type} of the \param{stream}.
  1134. \label See Also::
  1135. {\secref\ConstantModification},
  1136. \funref{read-sequence},
  1137. \funref{write-string},
  1138. \funref{write-line}
  1139. \label Notes::
  1140. \funref{write-sequence} is identical in effect to iterating over the indicated
  1141. subsequence and writing one \term{element} at a time to \param{stream}, but
  1142. may be more efficient than the equivalent loop. An efficient implementation
  1143. is more likely to exist for the case where the \param{sequence} is a
  1144. \term{vector} with the same \term{element type} as the \param{stream}.
  1145. \endcom
  1146. \endissue{READ-AND-WRITE-BYTES:NEW-FUNCTIONS}
  1147. %-------------------- File Position --------------------
  1148. %%% ========== FILE-LENGTH
  1149. \begincom{file-length}\ftype{Function}
  1150. \label Syntax::
  1151. \DefunWithValues file-length {stream} {length}
  1152. \label Arguments and Values::
  1153. \param{stream}---a \term{stream associated with a file}.
  1154. \param{length}---a non-negative \term{integer} or \nil.
  1155. \label Description::
  1156. %% 23.3.0 21
  1157. \funref{file-length} returns the length of \param{stream},
  1158. or \nil\ if the length cannot be determined.
  1159. For a binary file, the length is measured in units of
  1160. the \term{element type} of the \param{stream}.
  1161. \label Examples::
  1162. \code
  1163. (with-open-file (s "decimal-digits.text"
  1164. :direction :output :if-exists :error)
  1165. (princ "0123456789" s)
  1166. (truename s))
  1167. \EV #P"A:>Joe>decimal-digits.text.1"
  1168. (with-open-file (s "decimal-digits.text")
  1169. (file-length s))
  1170. \EV 10
  1171. \endcode
  1172. \label Side Effects:\None.
  1173. \label Affected By:\None.
  1174. \label Exceptional Situations::
  1175. \Shouldchecktype{stream}{a \term{stream associated with a file}}
  1176. %!!! Is this going to run into trouble in cases like:
  1177. % (with-input-from-string (s "foo") (file-length s))
  1178. % which an implementation might want to support even thought it's not required?
  1179. % -kmp 26-Apr-91
  1180. \label See Also::
  1181. \funref{open}
  1182. \label Notes:\None.
  1183. \endcom
  1184. %%% ========== FILE-POSITION
  1185. \begincom{file-position}\ftype{Function}
  1186. \label Syntax::
  1187. \DefunWithValues file-position {stream} {position}
  1188. \DefunWithValues file-position {stream position-spec} {success-p}
  1189. \label Arguments and Values::
  1190. \param{stream}---a \term{stream}.
  1191. \param{position-spec}---a \term{file position designator}.
  1192. \param{position}---a \term{file position} or \nil.
  1193. \param{success-p}---a \term{generalized boolean}.
  1194. \label Description::
  1195. %% 23.3.0 16
  1196. Returns or changes the current position within a \param{stream}.
  1197. %% 23.3.0 17
  1198. When \param{position-spec} is not supplied,
  1199. \funref{file-position} returns the current \term{file position} in the \param{stream},
  1200. or \nil\ if this cannot be determined.
  1201. %% 23.3.0 18
  1202. When \param{position-spec} is supplied,
  1203. the \term{file position} in \param{stream} is set to that \term{file position} (if possible).
  1204. \funref{file-position} returns \term{true}
  1205. if the repositioning is performed successfully,
  1206. or \term{false} if it is not.
  1207. %%KMP: I could find no reference which supported this claim. It looks well-defined to me.
  1208. %
  1209. % The consequences are undefined if \param{file-stream}
  1210. % is not a \term{stream} that is open to a random-access file.
  1211. An \term{integer} returned by \funref{file-position} of one argument
  1212. should be acceptable as \param{position-spec} for use with the same file.
  1213. For a character file,
  1214. performing a single \funref{read-char} or \funref{write-char} operation
  1215. may cause the file position to be increased by more than 1 because of
  1216. character-set translations (such as translating between the \clisp\
  1217. \f{\#\\Newline} character and an external ASCII
  1218. carriage-return/line-feed sequence) and other aspects of the
  1219. implementation. For a binary file, every \funref{read-byte}
  1220. or \funref{write-byte}
  1221. operation increases the file position by 1.
  1222. \label Examples::
  1223. \code
  1224. (defun tester ()
  1225. (let ((noticed '()) file-written)
  1226. (flet ((notice (x) (push x noticed) x))
  1227. (with-open-file (s "test.bin"
  1228. :element-type '(unsigned-byte 8)
  1229. :direction :output
  1230. :if-exists :error)
  1231. (notice (file-position s)) ;1
  1232. (write-byte 5 s)
  1233. (write-byte 6 s)
  1234. (let ((p (file-position s)))
  1235. (notice p) ;2
  1236. (notice (when p (file-position s (1- p))))) ;3
  1237. (write-byte 7 s)
  1238. (notice (file-position s)) ;4
  1239. (setq file-written (truename s)))
  1240. (with-open-file (s file-written
  1241. :element-type '(unsigned-byte 8)
  1242. :direction :input)
  1243. (notice (file-position s)) ;5
  1244. (let ((length (file-length s)))
  1245. (notice length) ;6
  1246. (when length
  1247. (dotimes (i length)
  1248. (notice (read-byte s)))))) ;7,...
  1249. (nreverse noticed))))
  1250. \EV tester
  1251. (tester)
  1252. \EV (0 2 T 2 0 2 5 7)
  1253. \OV (0 2 NIL 3 0 3 5 6 7)
  1254. \OV (NIL NIL NIL NIL NIL NIL)
  1255. \endcode
  1256. \label Side Effects::
  1257. When the \param{position-spec} argument is supplied,
  1258. the \term{file position} in the \param{stream} might be moved.
  1259. \label Affected By::
  1260. The value returned by \funref{file-position} increases monotonically
  1261. as input or output operations are performed.
  1262. \label Exceptional Situations::
  1263. %Note: KMP thinks there are implemetantions which might provide extensions to allow
  1264. % non-integer position specs and that we should use special error terminology here
  1265. % in order to give them some latitude.
  1266. If \param{position-spec} is supplied, but is too large or otherwise inappropriate,
  1267. an error is signaled.
  1268. \label See Also::
  1269. \funref{file-length},
  1270. \funref{file-string-length},
  1271. \funref{open}
  1272. \label Notes::
  1273. %% 23.3.0 19
  1274. Implementations that have character files represented
  1275. as a sequence of records of bounded size might choose to encode the
  1276. file position as, for example,
  1277. \metavar{record-number}*\metavar{max-record-size}+\metavar{character-within-record}.
  1278. This is a valid encoding because it increases monotonically as
  1279. each character is read or written, though not necessarily by 1 at
  1280. each step. An \term{integer} might then be considered ``inappropriate''
  1281. as \param{position-spec} to \funref{file-position} if, when decoded into
  1282. record number and character number, it turned out that the
  1283. supplied record was too short for the specified character number.
  1284. \endcom
  1285. %%% ========== FILE-STRING-LENGTH
  1286. \begincom{file-string-length}\ftype{Function}
  1287. \issue{CHARACTER-PROPOSAL:2-5-7}
  1288. \label Syntax::
  1289. \DefunWithValues file-string-length {stream object} {length}
  1290. \label Arguments and Values::
  1291. \param{stream}---an \term{output} \term{character} \term{file stream}.
  1292. \param{object}---a \term{string} or a \term{character}.
  1293. \param{length}---a non-negative \term{integer}, or \nil.
  1294. \label Description::
  1295. \funref{file-string-length} returns the difference between what
  1296. \f{(file-position \param{stream})} would be after writing
  1297. \param{object} and its current value, or \nil\ if this cannot be determined.
  1298. The returned value corresponds to the current state of \param{stream}
  1299. at the time of the call and might not be
  1300. % valid if it is called twice;
  1301. % two different values may occur.
  1302. the same if it is called again
  1303. when the state of the \term{stream} has changed.
  1304. \label Examples:\None.
  1305. \label Affected By:\None.
  1306. \label Exceptional Situations:\None.
  1307. \label See Also:\None.
  1308. \label Notes:\None.
  1309. \endissue{CHARACTER-PROPOSAL:2-5-7}
  1310. \endcom
  1311. %-------------------- File Opening --------------------
  1312. % %%% ========== OPEN
  1313. % \begincom{open}\ftype{Function}
  1314. %
  1315. % \label Syntax::
  1316. %
  1317. % \DefunWithValuesNewline open
  1318. % {filespec {\key} \vtop{\hbox{direction element-type}
  1319. % \hbox{if-exists if-does-not-exist
  1320. % external-format}}}
  1321. % {stream}
  1322. %
  1323. % \label Arguments and Values::
  1324. %
  1325. % \param{filespec}---a \term{pathname designator}.
  1326. %
  1327. % \param{direction}---one of \kwd{input}, \kwd{output}, \kwd{io}, or \kwd{probe}.
  1328. % \Default{\kwd{input}}
  1329. %
  1330. % %% 23.2.0 9
  1331. % %% 23.2.0 10
  1332. % %% 23.2.0 11
  1333. % %% 23.2.0 12
  1334. % %% 23.2.0 13
  1335. % %% 23.2.0 14
  1336. % %% 23.2.0 15
  1337. % %% 23.2.0 16
  1338. % %% 23.2.0 17
  1339. % %% 23.2.0 18
  1340. % %% 23.2.0 19
  1341. % \param{element-type}---a \term{type specifier}
  1342. % for \term{recognizable subtype} of \typeref{character};
  1343. % or a \term{type specifier}
  1344. % for a \term{finite} \term{recognizable subtype} of \term{integer};
  1345. % or one of the \term{symbols}
  1346. % \misc{signed-byte},
  1347. % \misc{unsigned-byte},
  1348. % or \kwd{default}.
  1349. % % \param{element-type}---\term{type specifier};
  1350. % % a \term{subtype} of \typeref{character} or \typeref{integer};
  1351. % % one of the following:
  1352. % % \typeref{character},
  1353. % % \f{(unsigned-byte \i{n})},
  1354. % % \typeref{unsigned-byte},
  1355. % % \f{(signed-byte \i{n})},
  1356. % % \typeref{signed-byte},
  1357. % % \typeref{bit},
  1358. % % \f{(mod \i{n})},
  1359. % % or \kwd{default},
  1360. % % where \i{n} is an \term{integer}.
  1361. % \Default{\typeref{character}}
  1362. %
  1363. % %% 23.2.0 21
  1364. % %% 23.2.0 22
  1365. % %% 23.2.0 23
  1366. % %% 23.2.0 24
  1367. % %% 23.2.0 25
  1368. % %% 23.2.0 26
  1369. % %% 23.2.0 27
  1370. % %% 23.2.0 28
  1371. % \param{if-exists}---one of \kwd{error}, \kwd{new-version}, \kwd{rename},
  1372. % \kwd{rename-and-delete}, \kwd{overwrite}, \kwd{append},
  1373. % \kwd{supersede}, or \nil.
  1374. %
  1375. % %% 23.2.0 35
  1376. % %% 23.2.0 36
  1377. % \param{if-does-not-exist}---one of \kwd{error}, \kwd{create}, or \nil.
  1378. %
  1379. % \issue{CHARACTER-PROPOSAL:2-5-2}
  1380. % \param{external-format}---an \term{external file format designator}.
  1381. % \Default{\kwd{default}}
  1382. % \endissue{CHARACTER-PROPOSAL:2-5-2}
  1383. %
  1384. % \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  1385. % \param{stream}---a \term{file stream} or \nil.
  1386. % \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  1387. %
  1388. % \label Description::
  1389. %
  1390. % %% 23.2.0 2
  1391. % %% 23.2.0 3
  1392. % \funref{open} creates, opens, and returns a \term{file stream}
  1393. % that is connected to the file specified by \param{filespec}.
  1394. % \param{Filespec} is the name of the file to be opened.
  1395. % %% Moon: Mostly redundant.
  1396. % % \issue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  1397. % % If \param{filespec} is a \term{stream},
  1398. % % \param{filespec} effectively
  1399. % % becomes {\tt (pathname \param{filespec})}. \funref{open}
  1400. % % can be used on either an open or a closed \term{stream},
  1401. % % \endissue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  1402. % % and the \term{stream} is not
  1403. % % closed first or otherwise affected.
  1404. % % \issue{PATHNAME-STREAM}
  1405. % % Also, if \param{filespec} is a \term{stream},
  1406. % % that \term{stream}
  1407. % % can only have been originally opened by
  1408. % % \funref{open} or \macref{with-open-file},
  1409. % % or is a \term{synonym stream} whose \term{symbol} is bound
  1410. % % to a \term{stream} originally opened by
  1411. % % \funref{open} or \macref{with-open-file}.
  1412. % % If \param{filespec} is a \term{pathname} (as returned by \funref{pathname})
  1413. % % it represents the name used to open the file. This might be, but is
  1414. % % not required to be, the actual name of the file.
  1415. % % \issue{PATHNAME-LOGICAL:ADD}
  1416. % % If \param{filespec} is a \term{logical pathname}, it is translated
  1417. % % into a physical pathname as if by calling \funref{translate-logical-pathname}.
  1418. % % \endissue{PATHNAME-LOGICAL:ADD}
  1419. % %% Salvaged from the above. -kmp 16-Feb-92
  1420. % If the \param{filespec} \term{designator} is a \term{stream},
  1421. % that \term{stream} is not closed first or otherwise affected.
  1422. %
  1423. % %% Implied by pathname designator. -kmp 16-Feb-92
  1424. % % It is an error if \param{filespec} is a \term{stream} that is
  1425. % % created with \funref{make-two-way-stream},
  1426. % % \funref{make-echo-stream},
  1427. % % \funref{make-broadcast-stream},
  1428. % % \funref{make-concatenated-stream}, \funref{make-string-input-stream},
  1429. % % \funref{make-string-output-stream}.
  1430. % %\endissue{PATHNAME-STREAM}
  1431. %
  1432. % The keyword arguments to \funref{open} specify the characteristics
  1433. % of the \term{file stream} that is returned, and how to handle errors.
  1434. %
  1435. % %% 23.2.0 30
  1436. % If \param{direction} is \kwd{input}
  1437. % %% Barrett: defaults
  1438. % %, not supplied,
  1439. % or \kwd{probe},
  1440. % or if \param{if-exists} is not \kwd{new-version}
  1441. % and the version component of the \param{filespec} is \kwd{newest},
  1442. % then the file opened is that file already existing in the file system
  1443. % that has a version greater than that of any other file in the file system
  1444. % whose other pathname components are the same as those of \param{filespec}.
  1445. %
  1446. %
  1447. % %% 23.2.0 31
  1448. % %% 23.2.0 32
  1449. % An implementation is required to recognize all of
  1450. % the \funref{open} keyword options
  1451. % and to do something reasonable in the context of the host operating
  1452. % system.
  1453. % For example, if a file system does not support distinct file
  1454. % versions and does not distinguish the notions of deletion and expunging,
  1455. % \kwd{new-version} might be treated the same as
  1456. % \kwd{rename} or \kwd{supersede}, and \kwd{rename-and-delete} might
  1457. % be treated the same as \kwd{supersede}.
  1458. %
  1459. % \beginlist
  1460. % \itemitem{\bf :direction}
  1461. %
  1462. %
  1463. % \Thenextfigure\ lists the possible values for \param{direction} options and their meanings.
  1464. % %% 23.2.0 4
  1465. % %% 23.2.0 5
  1466. % %% 23.2.0 6
  1467. % %% 23.2.0 7
  1468. % %% 23.2.0 8
  1469. % \boxfig
  1470. % {\dimen0=.75pc
  1471. % \tabskip \dimen0 plus .5 fil
  1472. % \halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1473. % \noalign{\vskip -9pt}
  1474. % \hfil{\bf Direction} & {\bf Result with respect to the created \term{stream}} \cr
  1475. % \noalign{\vskip 2pt\hrule\vskip 2pt}
  1476. % \kwd{input}
  1477. % % or not supplied
  1478. % & Creates an \term{input} \term{file stream}. \cr
  1479. % & \cr
  1480. % \kwd{output} & Creates an \term{output} \term{file stream}. \cr
  1481. % & \cr
  1482. % \kwd{io} & Creates a \term{bidirectional} \term{file stream}. \cr
  1483. % & \cr
  1484. % \kwd{probe} & Creates a no-directional \term{file stream};
  1485. % the \term{file stream} \cr
  1486. % & is in effect created and then closed. \cr
  1487. % \noalign{\vskip -9pt}
  1488. % }}
  1489. % \caption{Options for open---1}
  1490. % \endfig
  1491. %
  1492. %
  1493. % \itemitem{\bf :element-type}
  1494. %
  1495. % \param{element-type} specifies the unit of transaction for the \term{file stream}.
  1496. % %% This is the only salvaged info from the next block of commented out stuff. -kmp 14-Feb-92
  1497. % If it is \kwd{default}, the unit is determined by \term{file system},
  1498. % possibly based on the \term{file}.
  1499. % %
  1500. % % \Thenextfigure\ gives the correspondence between the listed values for
  1501. % % \param{element-type} and the unit of transaction.
  1502. % %
  1503. % % \boxfig
  1504. % % {\dimen0=.75pc
  1505. % % \tabskip \dimen0 plus .5 fil
  1506. % % \halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1507. % % \noalign{\vskip -9pt}
  1508. % % \hfil{\bf Element-type} & {\bf Unit of Transaction} \cr
  1509. % % \noalign{\vskip 2pt\hrule\vskip 2pt}
  1510. % % %{\tt string-char} or not supplied & a \term{string-char} \cr
  1511. % % %& \cr
  1512. % % {\tt character} & Any \term{character} \cr
  1513. % % & \cr
  1514. % % {\tt (unsigned-byte \i{n})} & A non-negative \term{integer} of size
  1515. % % \i{n} \cr
  1516. % % & \cr
  1517. % % {\tt unsigned-byte} & A non-negative \term{integer} (size determined
  1518. % % by file system) \cr
  1519. % % & \cr
  1520. % % {\tt (signed-byte \i{n})} & Signed byte of size \i{n} \cr
  1521. % % & \cr
  1522. % % {\tt signed-byte} & Signed byte (size determined by file system) \cr
  1523. % % & \cr
  1524. % % {\tt bit} & Values \f{0} and \f{1} \cr
  1525. % % & \cr
  1526. % % {\tt (mod \i{n})} & A non-negative \term{integer} less than \i{n}
  1527. % % \cr
  1528. % % & \cr
  1529. % % \kwd{default} & Determined by file system based on the file \cr
  1530. % % \noalign{\vskip -9pt}
  1531. % % }}
  1532. % % \caption{Options for open---2}
  1533. % % \endfig
  1534. %
  1535. % \itemitem{\bf :if-exists}
  1536. %
  1537. % \param{if-exists} specifies the action to be taken if \param{direction} is
  1538. % \kwd{output} or \kwd{io} and a file of the name \param{filespec}
  1539. % already exists.
  1540. % If \param{direction} is \kwd{input}, not supplied, or \kwd{probe},
  1541. % \param{if-exists} is ignored.
  1542. % \Thenextfigure\ gives the result of \funref{open} as modified
  1543. % by \param{if-exists}.
  1544. % %% 23.2.0 29
  1545. % %% 23.2.0 20
  1546. %
  1547. % \boxfig
  1548. % {\dimen0=.75pc
  1549. % \tabskip \dimen0 plus .5 fil
  1550. % \halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1551. % \noalign{\vskip -9pt}
  1552. % \hfil{\bf If-exists} & {\bf Result with respect to file named \param{filespec}} \cr
  1553. % \noalign{\vskip 2pt\hrule\vskip 2pt}
  1554. % \kwd{error} or not supplied & An error \oftype{file-error} is signaled. \cr
  1555. % when the version component of & \cr
  1556. % \param{filespec} is not \kwd{newest} & \cr
  1557. % & \cr
  1558. % \kwd{new-version} or not supplied & A new file is created \cr
  1559. % when the version component of & with a larger version number. \cr
  1560. % \param{filespec} is \kwd{newest} & \cr
  1561. % & \cr
  1562. % \kwd{rename} & The existing file is renamed \cr
  1563. % & to some other name and then a new file is created. \cr
  1564. % & \cr
  1565. % \kwd{rename-and-delete} & The existing file is renamed \cr
  1566. % & to some other name, then it is deleted \cr
  1567. % & but not expunged, and then a new file is created. \cr
  1568. % & \cr
  1569. % \kwd{overwrite} & Output operations on the \term{stream} \cr
  1570. % & destructively modify the existing file. \cr
  1571. % & If \param{direction} is \kwd{io} the file is \cr
  1572. % & opened in a bidirectional mode that allows both \cr
  1573. % & reading and writing. The file pointer is initially \cr
  1574. % & positioned at the beginning of the file; however, \cr
  1575. % & the file is not truncated back to length zero \cr
  1576. % & when it is opened. \cr
  1577. % & \cr
  1578. % \kwd{append} & Output operations on the \term{stream} \cr
  1579. % & destructively modify the existing file. \cr
  1580. % & The file pointer is initially positioned at \cr
  1581. % & the end of the file. \cr
  1582. % & If \param{direction} is \kwd{io}, \cr
  1583. % & the file is opened in a bidirectional mode that \cr
  1584. % & allows both reading and writing. \cr
  1585. % & \cr
  1586. % \kwd{supersede} & The existing file is superseded, \cr
  1587. % & \ie a new file with the same name as the old \cr
  1588. % & one is created. If possible, the implementation \cr
  1589. % & should not destroy the old file until the new \cr
  1590. % & \term{stream} is closed. \cr
  1591. % & \cr
  1592. % \nil\ & No file or \term{stream} is created. \cr
  1593. % & \nil\ is returned to indicate failure. \cr
  1594. % \noalign{\vskip -9pt}
  1595. % }}
  1596. % \caption{Options for open---3}
  1597. % \endfig
  1598. %
  1599. % \itemitem{\bf :if-does-not-exist}
  1600. %
  1601. % %% 23.2.0 34
  1602. % \param{if-does-not-exist}
  1603. % specifies the action to be taken if
  1604. % a file of name \param{filespec} does not already exist.
  1605. % \Thenextfigure\ gives the result of \funref{open} as modified by
  1606. % \param{if-does-not-exist}.
  1607. %
  1608. %
  1609. % %% 23.2.0 37
  1610. % \boxfig
  1611. % {\dimen0=.75pc
  1612. % \tabskip \dimen0 plus .5 fil
  1613. % \halign to \hsize {#\hfil\tabskip \dimen0 plus 1fil&#\hfil\cr
  1614. % \noalign{\vskip -9pt}
  1615. % \hfil{\bf If-does-not-exist} & {\bf Result with respect to file named \param{filespec}} \cr
  1616. % \noalign{\vskip 2pt\hrule\vskip 2pt}
  1617. % \kwd{error} or not supplied & An error \oftype{file-error} is signaled. \cr
  1618. % and \param{direction} is \kwd{input}, & \cr
  1619. % or if \param{if-exists} is & \cr
  1620. % \kwd{overwrite} or \kwd{append}. & \cr
  1621. % & \cr
  1622. % \kwd{create} or not supplied & An empty file is created. \cr
  1623. % when \param{direction} is \kwd{output}& Processing continues as if the file \cr
  1624. % or \kwd{io}, and \param{if-exists} & had already existed but no processing as \cr
  1625. % is anything but \kwd{overwrite} & directed by \param{if-exists} is performed. \cr
  1626. % or \kwd{append}. & \cr
  1627. % & \cr
  1628. % \nil\ or not supplied & No file or \term{stream} is created. \cr
  1629. % when \param{direction} is \kwd{probe}.& \nil\ is returned to indicate failure. \cr
  1630. % \noalign{\vskip -9pt}
  1631. % }}
  1632. % \caption{Options for open---4}
  1633. % \endfig
  1634. %
  1635. % \issue{CHARACTER-PROPOSAL:2-5-2}
  1636. % \itemitem{\kwd{external-format}}
  1637. %
  1638. % This option selects an \term{external file format} for the \term{file}:
  1639. % % There are no conforming
  1640. % % \term{values} for \param{external-format} other than the default \term{value},
  1641. % % \kwd{default}, which selects a format that can accomodate at least the
  1642. % % \term{base characters}. \term{Implementations} are permitted to define
  1643. % % additional external file formats.
  1644. % The only \term{standardized} value for this option is \kwd{default},
  1645. % although \term{implementations} are permitted to define additional
  1646. % \term{external file formats} and \term{implementation-dependent} values
  1647. % returned by \funref{stream-external-format} can also be used by \term{conforming programs}.
  1648. %
  1649. % % The \param{external-format} is meaningful for
  1650. % % \term{input},
  1651. % % \term{output},
  1652. % % and \term{bidirectional} \term{streams}.
  1653. % %% Rewritten by KMP based on discussions with RWK:
  1654. % The \param{external-format} is meaningful for
  1655. % any kind of \term{file stream} whose \term{element type}
  1656. % is a \term{subtype} of \term{character}.
  1657. % This option is ignored for \term{streams} for which it is not meaningful;
  1658. % however, \term{implementations} may define other \term{element types}
  1659. % for which it is meaningful.
  1660. % %End of rewrite.
  1661. % The consequences are unspecified if a \term{character} is written
  1662. % that cannot be represented by the given \term{external file format}.
  1663. % \endissue{CHARACTER-PROPOSAL:2-5-2}
  1664. %
  1665. % \endlist
  1666. %
  1667. % %% 23.2.0 1
  1668. % When a file is opened, a \term{file stream} is constructed to serve
  1669. % as the file system's ambassador to the \Lisp\ environment;
  1670. % operations on the \term{file stream} are reflected by operations on the file
  1671. % in the file system.
  1672. %
  1673. % A file can be deleted, renamed, or destructively modified by \funref{open}.
  1674. %
  1675. % For information about opening relative pathnames,
  1676. % \seesection\MergingPathnames.
  1677. %
  1678. % \label Examples::
  1679. %
  1680. % \code
  1681. % (open \i{filespec} :direction :probe) \EV #<Closed Probe File Stream...>
  1682. % (setq q (merge-pathnames (user-homedir-pathname) "test"))
  1683. % \EV #<PATHNAME :HOST NIL :DEVICE \i{device-name} :DIRECTORY \i{directory-name}
  1684. % :NAME "test" :TYPE NIL :VERSION :NEWEST>
  1685. % (open \i{filespec} :if-does-not-exist :create) \EV #<Input File Stream...>
  1686. % (setq s (open \i{filespec} :direction :probe)) \EV #<Closed Probe File Stream...>
  1687. % (truename s) \EV #<PATHNAME :HOST NIL :DEVICE \i{device-name} :DIRECTORY
  1688. % \i{directory-name} :NAME \i{filespec} :TYPE \i{extension} :VERSION 1>
  1689. % (open s :direction :output :if-exists nil) \EV NIL
  1690. % \endcode
  1691. %
  1692. % \label Affected By::
  1693. %
  1694. % The nature and state of the host computer's \term{file system}.
  1695. %
  1696. % \label Exceptional Situations::
  1697. %
  1698. % If \param{if-exists} is \kwd{error}, (subject to the
  1699. % constraints on the meaning of \param{if-exists} listed above),
  1700. % an error \oftype{file-error} is signaled.
  1701. %
  1702. % If \param{if-does-not-exist} is \kwd{error} (subject to the
  1703. % constraints on the meaning of \param{if-does-not-exist} listed above),
  1704. % an error \oftype{file-error} is signaled.
  1705. %
  1706. % %% 23.2.0 33
  1707. % If it is impossible for an implementation to handle some option
  1708. % in a manner close to what is specified here,
  1709. % an error \oftype{error} might be signaled.
  1710. %
  1711. % \issue{PATHNAME-WILD:NEW-FUNCTIONS}
  1712. % % !!! Moon: I would have assumed type-error rather than file-error for this one.
  1713. % % I have no strong opinion, though.
  1714. % An error \oftype{file-error} is signaled if
  1715. % {\tt (wild-pathname-p \param{filespec})} returns true.
  1716. % \endissue{PATHNAME-WILD:NEW-FUNCTIONS}
  1717. %
  1718. % \issue{CHARACTER-PROPOSAL:2-5-2}
  1719. % An error \oftype{error} is signaled if the \param{external-format}
  1720. % is not understood by the \term{implementation}.
  1721. % \endissue{CHARACTER-PROPOSAL:2-5-2}
  1722. %
  1723. % % Refer to minutes of Dec-91 meeting (issue STREAM-ELEMENT-TYPE-UPGRADING) for
  1724. % % an explanation of where this came from. -kmp 12-Feb-92
  1725. % The various \term{file systems} in existence today have widely differing capabilities,
  1726. % and some aspects of the \term{file system} are beyond the scope of this specification
  1727. % to define. A given \term{implementation} might not be able to support all of these options
  1728. % in exactly the manner stated. An \term{implementation} is required to recognize all of
  1729. % these option keywords and to try to do something ``reasonable'' in the context of the
  1730. % host \term{file system}. Where necessary to accomodate the \term{file system},
  1731. % an \term{implementation} deviate slightly from the semantics specified here without
  1732. % being disqualified for consideration as a \term{conforming implementation}.
  1733. % If it is utterly impossible for an \term{implementation} to handle some option
  1734. % in a manner similar to what is specified here, it may simply signal an error.
  1735. %
  1736. % With regard to the \kwd{element-type} option, if a \term{type} is
  1737. % requested that is not supported by the \term{file system}, a substitution of types
  1738. % such as that which goes on in \term{upgrading} is permissible. As a minimum
  1739. % requirement, it should be the case that opening an \term{output} \term{stream}
  1740. % to a \term{file} in a given \term{element type} and later opening
  1741. % an \term{input} \term{stream} to the same \term{file} in the same \term{element type}
  1742. % should work compatibly.
  1743. %
  1744. % \label See Also::
  1745. %
  1746. % \issue{PATHNAME-LOGICAL:ADD}
  1747. % \funref{with-open-file},
  1748. % \funref{close},
  1749. % \typeref{pathname},
  1750. % \typeref{logical-pathname},
  1751. % \endissue{PATHNAME-LOGICAL:ADD}
  1752. % {\secref\MergingPathnames}
  1753. %
  1754. % \label Notes::
  1755. %
  1756. % \issue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  1757. % % \issue{PATHNAME-LOGICAL:ADD}
  1758. % % Whether or not \funref{open} recognizes \term{logical pathname} \term{namestrings}
  1759. % % is \term{implementation-defined}.
  1760. % % \endissue{PATHNAME-LOGICAL:ADD}
  1761. % \endissue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  1762. %
  1763. % %% 23.2.0 38
  1764. % \funref{open} does not automatically close the file when an abnormal
  1765. % exit occurs.
  1766. %
  1767. % When \param{element-type} is a \term{subtype} of \typeref{character},
  1768. % \funref{read-char} and/or \funref{write-char} can be
  1769. % used on the resulting \term{file stream}.
  1770. %
  1771. % When \param{element-type} is a \term{subtype} of \term{integer},
  1772. % \funref{read-byte} and/or \funref{write-byte} can be used on the resulting \term{file stream}.
  1773. %
  1774. % % When \param{element-type} is
  1775. % % \typeref{unsigned-byte},
  1776. % % {\tt (unsigned-byte \i{n})},
  1777. % % \typeref{signed-byte},
  1778. % % {\tt (signed-byte \i{n})},
  1779. % % \typeref{bit},
  1780. % % or {\tt (mod \i{n})},
  1781. % % \funref{read-byte} and/or \funref{write-byte} can be
  1782. % % used on the resulting \term{file stream}.
  1783. %
  1784. % When \param{element-type} is \kwd{default},
  1785. % the \term{type} can be determined by using \funref{stream-element-type}.
  1786. %
  1787. % \endcom
  1788. %%% ========== OPEN
  1789. \begincom{open}\ftype{Function}
  1790. \label Syntax::
  1791. \DefunWithValuesNewline open
  1792. {filespec {\key} \vtop{\hbox{direction element-type}
  1793. \hbox{if-exists if-does-not-exist
  1794. external-format}}}
  1795. {stream}
  1796. \label Arguments and Values::
  1797. \param{filespec}---a \term{pathname designator}.
  1798. \param{direction}---one of \kwd{input}, \kwd{output}, \kwd{io}, or \kwd{probe}.
  1799. \Default{\kwd{input}}
  1800. %% 23.2.0 9
  1801. %% 23.2.0 10
  1802. %% 23.2.0 11
  1803. %% 23.2.0 12
  1804. %% 23.2.0 13
  1805. %% 23.2.0 14
  1806. %% 23.2.0 15
  1807. %% 23.2.0 16
  1808. %% 23.2.0 17
  1809. %% 23.2.0 18
  1810. %% 23.2.0 19
  1811. \param{element-type}---a \term{type specifier}
  1812. for \term{recognizable subtype} of \typeref{character};
  1813. or a \term{type specifier}
  1814. for a \term{finite} \term{recognizable subtype} of \term{integer};
  1815. or one of the \term{symbols}
  1816. \misc{signed-byte},
  1817. \misc{unsigned-byte},
  1818. or \kwd{default}.
  1819. \Default{\typeref{character}}
  1820. %% 23.2.0 21
  1821. %% 23.2.0 22
  1822. %% 23.2.0 23
  1823. %% 23.2.0 24
  1824. %% 23.2.0 25
  1825. %% 23.2.0 26
  1826. %% 23.2.0 27
  1827. %% 23.2.0 28
  1828. \param{if-exists}---one of \kwd{error}, \kwd{new-version}, \kwd{rename},
  1829. \kwd{rename-and-delete}, \kwd{overwrite}, \kwd{append},
  1830. \kwd{supersede}, or \nil.
  1831. \Default{\kwd{new-version} if the version component of \param{filespec} is \kwd{newest},
  1832. or \kwd{error} otherwise}
  1833. %% 23.2.0 35
  1834. %% 23.2.0 36
  1835. \param{if-does-not-exist}---one of \kwd{error}, \kwd{create}, or \nil.
  1836. \Default{\kwd{error} if \param{direction} is \kwd{input}
  1837. or \param{if-exists} is \kwd{overwrite} or \kwd{append};
  1838. \kwd{create} if \param{direction} is \kwd{output} or \kwd{io},
  1839. and \param{if-exists} is neither \kwd{overwrite} nor \kwd{append};
  1840. or \nil\ when \param{direction} is \kwd{probe}}
  1841. \issue{CHARACTER-PROPOSAL:2-5-2}
  1842. \param{external-format}---an \term{external file format designator}.
  1843. \Default{\kwd{default}}
  1844. \endissue{CHARACTER-PROPOSAL:2-5-2}
  1845. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  1846. \param{stream}---a \term{file stream} or \nil.
  1847. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  1848. \label Description::
  1849. %% 23.2.0 2
  1850. %% 23.2.0 3
  1851. \funref{open} creates, opens, and returns a \term{file stream}
  1852. that is connected to the file specified by \param{filespec}.
  1853. \param{Filespec} is the name of the file to be opened.
  1854. %% Moon: Mostly redundant.
  1855. % \issue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  1856. % If \param{filespec} is a \term{stream},
  1857. % \param{filespec} effectively
  1858. % becomes {\tt (pathname \param{filespec})}. \funref{open}
  1859. % can be used on either an open or a closed \term{stream},
  1860. % \endissue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  1861. % and the \term{stream} is not
  1862. % closed first or otherwise affected.
  1863. % \issue{PATHNAME-STREAM}
  1864. % Also, if \param{filespec} is a \term{stream},
  1865. % that \term{stream}
  1866. % can only have been originally opened by
  1867. % \funref{open} or \macref{with-open-file},
  1868. % or is a \term{synonym stream} whose \term{symbol} is bound
  1869. % to a \term{stream} originally opened by
  1870. % \funref{open} or \macref{with-open-file}.
  1871. % If \param{filespec} is a \term{pathname} (as returned by \funref{pathname})
  1872. % it represents the name used to open the file. This might be, but is
  1873. % not required to be, the actual name of the file.
  1874. % \issue{PATHNAME-LOGICAL:ADD}
  1875. % If \param{filespec} is a \term{logical pathname}, it is translated
  1876. % into a physical pathname as if by calling \funref{translate-logical-pathname}.
  1877. % \endissue{PATHNAME-LOGICAL:ADD}
  1878. %% Salvaged from the above. -kmp 16-Feb-92
  1879. If the \param{filespec} \term{designator} is a \term{stream},
  1880. that \term{stream} is not closed first or otherwise affected.
  1881. The keyword arguments to \funref{open} specify the characteristics
  1882. of the \term{file stream} that is returned, and how to handle errors.
  1883. %% 23.2.0 30
  1884. If \param{direction} is \kwd{input}
  1885. %% Barrett: defaults
  1886. %, not supplied,
  1887. or \kwd{probe},
  1888. or if \param{if-exists} is not \kwd{new-version}
  1889. and the version component of the \param{filespec} is \kwd{newest},
  1890. then the file opened is that file already existing in the file system
  1891. that has a version greater than that of any other file in the file system
  1892. whose other pathname components are the same as those of \param{filespec}.
  1893. %% 23.2.0 31
  1894. %% 23.2.0 32
  1895. An implementation is required to recognize all of
  1896. the \funref{open} keyword options
  1897. and to do something reasonable in the context of the host operating
  1898. system.
  1899. For example, if a file system does not support distinct file
  1900. versions and does not distinguish the notions of deletion and expunging,
  1901. \kwd{new-version} might be treated the same as
  1902. \kwd{rename} or \kwd{supersede}, and \kwd{rename-and-delete} might
  1903. be treated the same as \kwd{supersede}.
  1904. \beginlist
  1905. \itemitem{\kwd{direction}}
  1906. These are the possible values for \param{direction},
  1907. and how they affect the nature of the \term{stream} that is created:
  1908. \beginlist
  1909. %% 23.2.0 4
  1910. %% 23.2.0 5
  1911. %% 23.2.0 6
  1912. %% 23.2.0 7
  1913. %% 23.2.0 8
  1914. \itemitem{\kwd{input}}
  1915. Causes the creation of an \term{input} \term{file stream}.
  1916. \itemitem{\kwd{output}}
  1917. Causes the creation of an \term{output} \term{file stream}.
  1918. \itemitem{\kwd{io}}
  1919. Causes the creation of a \term{bidirectional} \term{file stream}.
  1920. \itemitem{\kwd{probe}}
  1921. Causes the creation of a ``no-directional'' \term{file stream};
  1922. in effect, the \term{file stream} is created
  1923. and then closed prior to being returned by \funref{open}.
  1924. \endlist
  1925. \itemitem{\kwd{element-type}}
  1926. The \param{element-type} specifies the unit of transaction for the \term{file stream}.
  1927. %% This is the only salvaged info from the next block of commented out stuff. -kmp 14-Feb-92
  1928. If it is \kwd{default},
  1929. the unit is determined by \term{file system},
  1930. possibly based on the \term{file}.
  1931. \itemitem{\kwd{if-exists}}
  1932. \param{if-exists} specifies the action to be taken if \param{direction} is
  1933. \kwd{output} or \kwd{io} and a file of the name \param{filespec}
  1934. already exists.
  1935. If \param{direction} is \kwd{input}, not supplied, or \kwd{probe},
  1936. \param{if-exists} is ignored.
  1937. These are the results of \funref{open} as modified by \param{if-exists}:
  1938. %% 23.2.0 29
  1939. %% 23.2.0 20
  1940. \beginlist
  1941. \itemitem{\kwd{error}}
  1942. An error \oftype{file-error} is signaled.
  1943. \itemitem{\kwd{new-version}}
  1944. A new file is created with a larger version number.
  1945. \itemitem{\kwd{rename}}
  1946. The existing file is renamed to some other name and then a new file is created.
  1947. \itemitem{\kwd{rename-and-delete}}
  1948. The existing file is renamed to some other name,
  1949. then it is deleted but not expunged, and then a new file is created.
  1950. \itemitem{\kwd{overwrite}}
  1951. Output operations on the \term{stream} destructively modify the existing file.
  1952. If \param{direction} is \kwd{io} the file is opened in a bidirectional mode
  1953. that allows both reading and writing. The file pointer is initially
  1954. positioned at the beginning of the file; however, the file is not truncated
  1955. back to length zero when it is opened.
  1956. \itemitem{\kwd{append}}
  1957. Output operations on the \term{stream} destructively modify the existing file.
  1958. The file pointer is initially positioned at the end of the file.
  1959. If \param{direction} is \kwd{io},
  1960. the file is opened in a bidirectional mode that allows both reading and writing.
  1961. \itemitem{\kwd{supersede}}
  1962. The existing file is superseded;
  1963. that is, a new file with the same name as the old one is created.
  1964. If possible, the implementation should not destroy the old file until the new
  1965. \term{stream} is closed.
  1966. \itemitem{\nil}
  1967. No file or \term{stream} is created;
  1968. instead, \nil\ is returned to indicate failure.
  1969. \endlist
  1970. \itemitem{\kwd{if-does-not-exist}}
  1971. %% 23.2.0 34
  1972. \param{if-does-not-exist}
  1973. specifies the action to be taken if
  1974. a file of name \param{filespec} does not already exist.
  1975. These are the results of \funref{open} as modified by \param{if-does-not-exist}:
  1976. %% 23.2.0 37
  1977. \beginlist
  1978. \itemitem{\kwd{error}}
  1979. An error \oftype{file-error} is signaled.
  1980. \itemitem{\kwd{create}}
  1981. An empty file is created.
  1982. Processing continues as if the file
  1983. had already existed but no processing as
  1984. directed by \param{if-exists} is performed.
  1985. \itemitem{\nil}
  1986. No file or \term{stream} is created;
  1987. instead, \nil\ is returned to indicate failure.
  1988. \endlist
  1989. \issue{CHARACTER-PROPOSAL:2-5-2}
  1990. \itemitem{\kwd{external-format}}
  1991. This option selects an \term{external file format} for the \term{file}:
  1992. % There are no conforming
  1993. % \term{values} for \param{external-format} other than the default \term{value},
  1994. % \kwd{default}, which selects a format that can accomodate at least the
  1995. % \term{base characters}. \term{Implementations} are permitted to define
  1996. % additional external file formats.
  1997. The only \term{standardized} value for this option is \kwd{default},
  1998. although \term{implementations} are permitted to define additional
  1999. \term{external file formats} and \term{implementation-dependent} values
  2000. returned by \funref{stream-external-format} can also be used by \term{conforming programs}.
  2001. % The \param{external-format} is meaningful for
  2002. % \term{input},
  2003. % \term{output},
  2004. % and \term{bidirectional} \term{streams}.
  2005. %% Rewritten by KMP based on discussions with RWK:
  2006. The \param{external-format} is meaningful for
  2007. any kind of \term{file stream} whose \term{element type}
  2008. is a \term{subtype} of \term{character}.
  2009. This option is ignored for \term{streams} for which it is not meaningful;
  2010. however, \term{implementations} may define other \term{element types}
  2011. for which it is meaningful.
  2012. %End of rewrite.
  2013. The consequences are unspecified if a \term{character} is written
  2014. that cannot be represented by the given \term{external file format}.
  2015. \endissue{CHARACTER-PROPOSAL:2-5-2}
  2016. \endlist
  2017. %% 23.2.0 1
  2018. When a file is opened, a \term{file stream} is constructed to serve
  2019. as the file system's ambassador to the \Lisp\ environment;
  2020. operations on the \term{file stream} are reflected by operations on the file
  2021. in the file system.
  2022. A file can be deleted, renamed, or destructively modified by \funref{open}.
  2023. For information about opening relative pathnames,
  2024. \seesection\MergingPathnames.
  2025. \label Examples::
  2026. \code
  2027. (open \i{filespec} :direction :probe) \EV #<Closed Probe File Stream...>
  2028. (setq q (merge-pathnames (user-homedir-pathname) "test"))
  2029. \EV #<PATHNAME :HOST NIL :DEVICE \i{device-name} :DIRECTORY \i{directory-name}
  2030. :NAME "test" :TYPE NIL :VERSION :NEWEST>
  2031. (open \i{filespec} :if-does-not-exist :create) \EV #<Input File Stream...>
  2032. (setq s (open \i{filespec} :direction :probe)) \EV #<Closed Probe File Stream...>
  2033. (truename s) \EV #<PATHNAME :HOST NIL :DEVICE \i{device-name} :DIRECTORY
  2034. \i{directory-name} :NAME \i{filespec} :TYPE \i{extension} :VERSION 1>
  2035. (open s :direction :output :if-exists nil) \EV NIL
  2036. \endcode
  2037. \label Affected By::
  2038. The nature and state of the host computer's \term{file system}.
  2039. \label Exceptional Situations::
  2040. If \param{if-exists} is \kwd{error}, (subject to the
  2041. constraints on the meaning of \param{if-exists} listed above),
  2042. an error \oftype{file-error} is signaled.
  2043. If \param{if-does-not-exist} is \kwd{error} (subject to the
  2044. constraints on the meaning of \param{if-does-not-exist} listed above),
  2045. an error \oftype{file-error} is signaled.
  2046. %% 23.2.0 33
  2047. If it is impossible for an implementation to handle some option
  2048. in a manner close to what is specified here,
  2049. an error \oftype{error} might be signaled.
  2050. \issue{PATHNAME-WILD:NEW-FUNCTIONS}
  2051. % !!! Moon: I would have assumed type-error rather than file-error for this one.
  2052. % I have no strong opinion, though.
  2053. An error \oftype{file-error} is signaled if
  2054. {\tt (wild-pathname-p \param{filespec})} returns true.
  2055. \endissue{PATHNAME-WILD:NEW-FUNCTIONS}
  2056. \issue{CHARACTER-PROPOSAL:2-5-2}
  2057. An error \oftype{error} is signaled if the \param{external-format}
  2058. is not understood by the \term{implementation}.
  2059. \endissue{CHARACTER-PROPOSAL:2-5-2}
  2060. % Refer to minutes of Dec-91 meeting (issue STREAM-ELEMENT-TYPE-UPGRADING) for
  2061. % an explanation of where this came from. -kmp 12-Feb-92
  2062. The various \term{file systems} in existence today have widely differing capabilities,
  2063. and some aspects of the \term{file system} are beyond the scope of this specification
  2064. to define. A given \term{implementation} might not be able to support all of these options
  2065. in exactly the manner stated. An \term{implementation} is required to recognize all of
  2066. these option keywords and to try to do something ``reasonable'' in the context of the
  2067. host \term{file system}. Where necessary to accomodate the \term{file system},
  2068. an \term{implementation} deviate slightly from the semantics specified here without
  2069. being disqualified for consideration as a \term{conforming implementation}.
  2070. If it is utterly impossible for an \term{implementation} to handle some option
  2071. in a manner similar to what is specified here, it may simply signal an error.
  2072. With regard to the \kwd{element-type} option, if a \term{type} is
  2073. requested that is not supported by the \term{file system}, a substitution of types
  2074. such as that which goes on in \term{upgrading} is permissible. As a minimum
  2075. requirement, it should be the case that opening an \term{output} \term{stream}
  2076. to a \term{file} in a given \term{element type} and later opening
  2077. an \term{input} \term{stream} to the same \term{file} in the same \term{element type}
  2078. should work compatibly.
  2079. \label See Also::
  2080. \issue{PATHNAME-LOGICAL:ADD}
  2081. \funref{with-open-file},
  2082. \funref{close},
  2083. \typeref{pathname},
  2084. \typeref{logical-pathname},
  2085. \endissue{PATHNAME-LOGICAL:ADD}
  2086. {\secref\MergingPathnames},
  2087. \issue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2088. {\secref\PathnamesAsFilenames}
  2089. \endissue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2090. \label Notes::
  2091. \issue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  2092. % \issue{PATHNAME-LOGICAL:ADD}
  2093. % Whether or not \funref{open} recognizes \term{logical pathname} \term{namestrings}
  2094. % is \term{implementation-defined}.
  2095. % \endissue{PATHNAME-LOGICAL:ADD}
  2096. \endissue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  2097. %% 23.2.0 38
  2098. \funref{open} does not automatically close the file when an abnormal
  2099. exit occurs.
  2100. When \param{element-type} is a \term{subtype} of \typeref{character},
  2101. \funref{read-char} and/or \funref{write-char} can be
  2102. used on the resulting \term{file stream}.
  2103. When \param{element-type} is a \term{subtype} of \term{integer},
  2104. \funref{read-byte} and/or \funref{write-byte} can be used on the resulting \term{file stream}.
  2105. % When \param{element-type} is
  2106. % \typeref{unsigned-byte},
  2107. % {\tt (unsigned-byte \i{n})},
  2108. % \typeref{signed-byte},
  2109. % {\tt (signed-byte \i{n})},
  2110. % \typeref{bit},
  2111. % or {\tt (mod \i{n})},
  2112. % \funref{read-byte} and/or \funref{write-byte} can be
  2113. % used on the resulting \term{file stream}.
  2114. When \param{element-type} is \kwd{default},
  2115. the \term{type} can be determined by using \funref{stream-element-type}.
  2116. \endcom
  2117. %%% ========== STREAM-EXTERNAL-FORMAT
  2118. \begincom{stream-external-format}\ftype{Function}
  2119. \label Syntax::
  2120. \DefunWithValues stream-external-format {stream} {format}
  2121. \label Arguments and Values::
  2122. \param{stream}---a \term{file stream}.
  2123. \param{format}---an \term{external file format}.
  2124. \label Description::
  2125. Returns an \term{external file format designator} for the \param{stream}.
  2126. \label Examples::
  2127. \code
  2128. (with-open-file (stream "test" :direction :output)
  2129. (stream-external-format stream))
  2130. \EV :DEFAULT
  2131. \OV :ISO8859/1-1987
  2132. \OV (:ASCII :SAIL)
  2133. \OV ACME::PROPRIETARY-FILE-FORMAT-17
  2134. \OV #<FILE-FORMAT :ISO646-1983 2343673>
  2135. \endcode
  2136. \label Side Effects:\None!
  2137. \label Affected By:\None!
  2138. \label Exceptional Situations:\None.
  2139. \label See Also::
  2140. the \kwd{external-format} \term{argument} to \thefunction{open} and
  2141. \themacro{with-open-file}.
  2142. \label Notes::
  2143. The \param{format} returned is not necessarily meaningful
  2144. to other \term{implementations}.
  2145. \endcom
  2146. %%% ========== WITH-OPEN-FILE
  2147. \begincom{with-open-file}\ftype{macro}
  2148. \issue{DECLS-AND-DOC}
  2149. \label Syntax::
  2150. \DefmacWithValuesNewline with-open-file
  2151. {\paren{stream filespec \starparam{options}}
  2152. \starparam{declaration}
  2153. \starparam{form}}
  2154. {results}
  2155. \label Arguments and Values::
  2156. \param{stream} -- a variable.
  2157. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2158. \param{filespec}---a \term{pathname designator}.
  2159. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2160. %!!! I doubt this can be right. -kmp 22-Apr-91
  2161. \param{options} -- \term{forms}; \eval.
  2162. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  2163. \param{forms}---an \term{implicit progn}.
  2164. \param{results}---the \term{values} returned by the \param{forms}.
  2165. \label Description::
  2166. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2167. \macref{with-open-file} uses \funref{open} to create a \term{file stream}
  2168. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2169. to \term{file} named by \param{filespec}.
  2170. %% 23.2.0 41
  2171. \param{Filespec} is the name of the file to be opened.
  2172. \param{Options} are used as keyword arguments to \funref{open}.
  2173. %% Moon thought this was "drivel". -kmp 11-Feb-92
  2174. % Then \macref{with-open-file} performs a
  2175. % specified series of actions on the open file.
  2176. %% This is implied by "pathname designator". -kmp 16-Feb-92
  2177. % \issue{PATHNAME-STREAM}
  2178. % If \param{filespec} is a \term{file stream}, that \term{file stream}
  2179. % can only have been originally opened by
  2180. % \funref{open} or \macref{with-open-file},
  2181. % or is a \term{synonym stream} whose \term{symbol} is bound
  2182. % to a \term{file stream} originally opened by
  2183. % \funref{open} or \macref{with-open-file}.
  2184. % If \param{filespec} is a \term{pathname} (as returned by \funref{pathname}
  2185. % it represents the name used to open the file. This may be, but is
  2186. % not required to be, the actual name of the file.
  2187. % \endissue{PATHNAME-STREAM}
  2188. % \issue{PATHNAME-LOGICAL:ADD}
  2189. % If \param{filespec} is a \term{logical pathname}, it is translated
  2190. % into a physical pathname as if by calling \funref{translate-logical-pathname}.
  2191. % \endissue{PATHNAME-LOGICAL:ADD}
  2192. \issue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  2193. The \term{stream} \term{object} to which the \param{stream} \term{variable}
  2194. is \term{bound} has \term{dynamic extent};
  2195. its \term{extent} ends when the \term{form} is exited.
  2196. \endissue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  2197. %% 23.2.0 39
  2198. \macref{with-open-file} evaluates the \param{forms} as an \term{implicit progn}
  2199. with \param{stream} bound to
  2200. \issue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2201. the value returned by \funref{open}.
  2202. \endissue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2203. %% 23.2.0 40
  2204. When control leaves the body, either normally or abnormally (such as by
  2205. use of \specref{throw}), the file is automatically closed. If a new
  2206. output file is being written, and control leaves abnormally, the file is
  2207. aborted and the file system is left, so far as possible, as if the file
  2208. had never been opened.
  2209. It is possible by the use of \f{:if-exists nil}
  2210. or \f{:if-does-not-exist nil} for
  2211. \param{stream} to be bound to \nil.
  2212. \issue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2213. Users of \f{:if-does-not-exist nil} should check for a valid \term{stream}.
  2214. \endissue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2215. %% 23.2.0 42
  2216. % %This looks suspect to me. -kmp 22-Apr-91
  2217. % %Moon: Yes, this is drivel.
  2218. %
  2219. % \macref{with-open-file} opens, modifies, and
  2220. % tries to close the \param{file stream}.
  2221. \issue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  2222. The consequences are undefined if an attempt is made to \term{assign} the
  2223. \param{stream} \term{variable}. The compiler may choose to issue a
  2224. warning if such an attempt is detected.
  2225. \endissue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  2226. \label Examples::
  2227. \code
  2228. (setq p (merge-pathnames "test"))
  2229. \EV #<PATHNAME :HOST NIL :DEVICE \i{device-name} :DIRECTORY \i{directory-name}
  2230. :NAME "test" :TYPE NIL :VERSION :NEWEST>
  2231. (with-open-file (s p :direction :output :if-exists :supersede)
  2232. (format s "Here are a couple~%of test data lines~%")) \EV NIL
  2233. (with-open-file (s p)
  2234. (do ((l (read-line s) (read-line s nil 'eof)))
  2235. ((eq l 'eof) "Reached end of file.")
  2236. (format t "~&*** ~A~%" l)))
  2237. \OUT *** Here are a couple
  2238. \OUT *** of test data lines
  2239. \EV "Reached end of file."
  2240. \endcode
  2241. %\code
  2242. % (with-open-file (ifile name :direction :input)
  2243. % (with-open-file (ofile (merge-pathname-defaults ifile
  2244. % nil
  2245. % "out")
  2246. % :direction :output
  2247. % :if-exists :supersede)
  2248. % (transduce-file ifile ofile)))
  2249. %\endcode
  2250. \issue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2251. %!!! This example is -way- too weird to be included without more commentary.
  2252. \code
  2253. ;; Normally one would not do this intentionally because it is
  2254. ;; not perspicuous, but beware when using :IF-DOES-NOT-EXIST NIL
  2255. ;; that this doesn't happen to you accidentally...
  2256. (with-open-file (foo "no-such-file" :if-does-not-exist nil)
  2257. (read foo))
  2258. \OUT \IN{hello?}
  2259. \EV HELLO? ;This value was read from the terminal, not a file!
  2260. ;; Here's another bug to avoid...
  2261. (with-open-file (foo "no-such-file" :direction :output :if-does-not-exist nil)
  2262. (format foo "Hello"))
  2263. \EV "Hello" ;FORMAT got an argument of NIL!
  2264. \endcode
  2265. \endissue{WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL}
  2266. \label Side Effects::
  2267. Creates a \term{stream} to the \term{file} named by \param{filename} (upon entry),
  2268. and closes the \term{stream} (upon exit).
  2269. In some \term{implementations},
  2270. the \term{file} might be locked in some way while it is open.
  2271. If the \term{stream} is an \term{output} \term{stream},
  2272. a \term{file} might be created.
  2273. \label Affected By::
  2274. The host computer's file system.
  2275. \label Exceptional Situations::
  2276. \issue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2277. %% This restriction (and more) is already manifest in OPEN, so just omit it here.
  2278. %
  2279. % \issue{PATHNAME-WILD:NEW-FUNCTIONS}
  2280. % % !!! Moon: I would have assumed type-error rather than file-error for this one.
  2281. % % I have no strong opinion, though.
  2282. % An error \oftype{file-error} is signaled if
  2283. % \f{(wild-pathname-p \param{filespec})} returns true.
  2284. % \endissue{PATHNAME-WILD:NEW-FUNCTIONS}
  2285. \Seefun{open}.
  2286. \endissue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2287. \label See Also::
  2288. \issue{PATHNAME-LOGICAL:ADD}
  2289. \funref{open},
  2290. \funref{close},
  2291. \typeref{pathname},
  2292. \typeref{logical-pathname},
  2293. \endissue{PATHNAME-LOGICAL:ADD}
  2294. \issue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2295. {\secref\PathnamesAsFilenames}
  2296. \endissue{FILE-OPEN-ERROR:SIGNAL-FILE-ERROR}
  2297. \label Notes:\None.
  2298. \issue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  2299. % \issue{PATHNAME-LOGICAL:ADD}
  2300. % Whether or not \macref{with-open-file} recognizes \term{logical pathname} \term{namestrings}
  2301. % is \term{implementation-defined}.
  2302. % \endissue{PATHNAME-LOGICAL:ADD}
  2303. \endissue{PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES}
  2304. \endissue{DECLS-AND-DOC}
  2305. \endcom
  2306. %-------------------- Stream Closing --------------------
  2307. %%% ========== CLOSE
  2308. \begincom{close}\ftype{Function}
  2309. \label Syntax::
  2310. \issue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  2311. \DefunWithValues close {stream {\key} abort} {result}
  2312. \endissue{RETURN-VALUES-UNSPECIFIED:SPECIFY}
  2313. \label Arguments and Values::
  2314. %% 21.3.0 7
  2315. \param{stream}---a \term{stream} (either \term{open} or \term{closed}).
  2316. \param{abort}---a \term{generalized boolean}.
  2317. \Default{\term{false}}
  2318. \issue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  2319. \param{result}---\t\ if the \param{stream} was \term{open} at the time it was
  2320. received as an \term{argument},
  2321. or \term{implementation-dependent} otherwise.
  2322. \endissue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  2323. \label Description::
  2324. %% 21.3.0 7
  2325. %% 23.2.0 1
  2326. \funref{close} closes \param{stream}.
  2327. Closing a \term{stream} means
  2328. that it may no longer be used in input or output operations.
  2329. The act of \term{closing} a \term{file stream}
  2330. ends the association between the \term{stream} and its associated \term{file};
  2331. the transaction with the \term{file system} is terminated,
  2332. and input/output may no longer be performed on the \term{stream}.
  2333. If \param{abort} is \term{true}, an attempt is made to clean up any side
  2334. effects of having created \param{stream}.
  2335. If \param{stream} performs output to a file
  2336. that was created when the \term{stream} was created, the
  2337. file is deleted and any previously existing file is not superseded.
  2338. It is permissible to close an already closed \term{stream},
  2339. but in that case the \param{result} is \term{implementation-dependent}.
  2340. After \param{stream} is closed, it is still possible to perform
  2341. the following query operations upon it:
  2342. \issue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  2343. \funref{streamp}, \funref{pathname}, \funref{truename},
  2344. \funref{merge-pathnames}, \funref{pathname-host}, \funref{pathname-device},
  2345. \funref{pathname-directory},\funref{pathname-name},
  2346. \funref{pathname-type}, \funref{pathname-version}, \funref{namestring},
  2347. \funref{file-namestring}, \funref{directory-namestring},
  2348. \funref{host-namestring}, \funref{enough-namestring}, \funref{open},
  2349. \funref{probe-file}, and \funref{directory}.
  2350. \endissue{CLOSED-STREAM-FUNCTIONS:ALLOW-INQUIRY}
  2351. \issue{CLOSE-CONSTRUCTED-STREAM:ARGUMENT-STREAM-ONLY}
  2352. The effect of \funref{close} on a \term{constructed stream} is
  2353. to close the argument \param{stream} only.
  2354. There is no effect on the \term{constituents} of \term{composite streams}.
  2355. For a \term{stream} created with \funref{make-string-output-stream},
  2356. the result of \funref{get-output-stream-string} is unspecified after \funref{close}.
  2357. %% Sandra: Redundant.
  2358. % For a \term{composite stream},
  2359. % the call to \funref{close} has no effect on any of its \term{constituents}.
  2360. \endissue{CLOSE-CONSTRUCTED-STREAM:ARGUMENT-STREAM-ONLY}
  2361. \label Examples::
  2362. %!!! Need to look at this! -kmp 23-Apr-91
  2363. \code
  2364. (setq s (make-broadcast-stream)) \EV #<BROADCAST-STREAM>
  2365. (close s) \EV T
  2366. (output-stream-p s) \EV \term{true}
  2367. \endcode
  2368. \label Side Effects::
  2369. The \param{stream} is \term{closed} (if necessary).
  2370. If \param{abort} is \term{true} and the \param{stream} is
  2371. an \term{output} \term{file stream}, its associated \term{file}
  2372. might be deleted.
  2373. \label Affected By:\None!
  2374. \label Exceptional Situations:\None.
  2375. \label See Also::
  2376. \funref{open}
  2377. \label Notes:\None.
  2378. \endcom
  2379. %%% ========== WITH-OPEN-STREAM
  2380. \begincom{with-open-stream}\ftype{Macro}
  2381. \issue{DECLS-AND-DOC}
  2382. \label Syntax::
  2383. \DefmacWithValuesNewline with-open-stream
  2384. {\paren{var stream}
  2385. \starparam{declaration}
  2386. \starparam{form}}
  2387. {\starparam{result}}
  2388. \label Arguments and Values::
  2389. \param{var}---a \term{variable} \term{name}.
  2390. \param{stream}---a \term{form}; evaluated to produce a \term{stream}.
  2391. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  2392. \param{forms}---an \term{implicit progn}.
  2393. \param{results}---the \term{values} returned by the \param{forms}.
  2394. \label Description::
  2395. \macref{with-open-stream} performs a series of operations on
  2396. \param{stream}, returns a value, and then closes the \param{stream}.
  2397. %% 21.2.0 11
  2398. \param{Var} is bound to the value of \param{stream},
  2399. and then \param{forms} are executed
  2400. as an \term{implicit progn}.
  2401. \param{stream}
  2402. is automatically closed on exit from \macref{with-open-stream},
  2403. no matter whether the exit is normal or abnormal.
  2404. \issue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  2405. %!!!
  2406. %Moon: I don't see how the following could possibly be true,
  2407. % since WITH-OPEN-STREAM does not create the stream.
  2408. % WITH-OPEN-FILE is different. On the other hand,
  2409. % this accurately reflects the cleanup and CLtL.
  2410. %KMP: I concur, but it will take a technical vote to fix it.
  2411. The \param{stream} has \term{dynamic extent};
  2412. its \term{extent} ends when the \term{form} is exited.
  2413. \endissue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  2414. \issue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  2415. The consequences are undefined if an attempt is made to \term{assign} the
  2416. the \term{variable} \param{var} with the \param{forms}.
  2417. %The compiler may choose to issue a warning if such an attempt is detected.
  2418. \endissue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  2419. \label Examples::
  2420. \code
  2421. (with-open-stream (s (make-string-input-stream "1 2 3 4"))
  2422. (+ (read s) (read s) (read s))) \EV 6
  2423. \endcode
  2424. \label Side Effects::
  2425. The \param{stream} is closed (upon exit).
  2426. \label Affected By:\None.
  2427. \label Exceptional Situations:\None.
  2428. \label See Also::
  2429. \funref{close}
  2430. \label Notes:\None.
  2431. \endissue{DECLS-AND-DOC}
  2432. \endcom
  2433. %-------------------- Stream Buffering --------------------
  2434. %%% ========== LISTEN
  2435. \begincom{listen}\ftype{Function}
  2436. \label Syntax::
  2437. \DefunWithValues {listen} {{\opt} input-stream} {generalized-boolean}
  2438. \label Arguments and Values::
  2439. \param{input-stream}---an \term{input} \term{stream designator}.
  2440. \Default{\term{standard input}}
  2441. \param{generalized-boolean}---a \term{generalized boolean}.
  2442. \label Description::
  2443. %% 22.2.1 36
  2444. Returns \term{true} if
  2445. there is a character immediately available from \param{input-stream};
  2446. otherwise, returns \term{false}.
  2447. On a non-interactive \param{input-stream},
  2448. \funref{listen} returns \term{true} except when at \term{end of file}\meaning{1}.
  2449. If an \term{end of file} is encountered, \funref{listen} returns \term{false}.
  2450. \funref{listen} is intended to be used
  2451. when \param{input-stream} obtains characters
  2452. from an interactive device such as a keyboard.
  2453. \label Examples::
  2454. \code
  2455. (progn (unread-char (read-char)) (list (listen) (read-char)))
  2456. \OUT \IN{1}
  2457. \EV (T #\\1)
  2458. (progn (clear-input) (listen))
  2459. \EV NIL ;Unless you're a very fast typist!
  2460. \endcode
  2461. \label Side Effects:\None.
  2462. \label Affected By::
  2463. \varref{*standard-input*}
  2464. \label Exceptional Situations:\None.
  2465. \label See Also::
  2466. \funref{interactive-stream-p},
  2467. \funref{read-char-no-hang}
  2468. \label Notes:\None.
  2469. \endcom
  2470. %%% ========== CLEAR-INPUT
  2471. \begincom{clear-input}\ftype{Function}
  2472. \label Syntax::
  2473. \DefunWithValues {clear-input} {{\opt} input-stream} {\nil}
  2474. \label Arguments and Values::
  2475. \param{input-stream}---an \term{input} \term{stream designator}.
  2476. \Default{\term{standard input}}
  2477. \label Description::
  2478. %% 22.2.1 38
  2479. Clears any available input from \param{input-stream}.
  2480. If \funref{clear-input} does not make sense for \param{input-stream},
  2481. then \funref{clear-input} does nothing.
  2482. \label Examples::
  2483. \code
  2484. ;; The exact I/O behavior of this example might vary from implementation
  2485. ;; to implementation depending on the kind of interactive buffering that
  2486. ;; occurs. (The call to SLEEP here is intended to help even out the
  2487. ;; differences in implementations which do not do line-at-a-time buffering.)
  2488. (defun read-sleepily (&optional (clear-p nil) (zzz 0))
  2489. (list (progn (print '>) (read))
  2490. ;; Note that input typed within the first ZZZ seconds
  2491. ;; will be discarded.
  2492. (progn (print '>)
  2493. (if zzz (sleep zzz))
  2494. (print '>>)
  2495. (if clear-p (clear-input))
  2496. (read))))
  2497. (read-sleepily)
  2498. \OUT > \IN{10}
  2499. \OUT >
  2500. \OUT >> \IN{20}
  2501. \EV (10 20)
  2502. (read-sleepily t)
  2503. \OUT > \IN{10}
  2504. \OUT >
  2505. \OUT >> \IN{20}
  2506. \EV (10 20)
  2507. (read-sleepily t 10)
  2508. \OUT > \IN{10}
  2509. \OUT > \IN{20} ; Some implementations won't echo typeahead here.
  2510. \OUT >> \IN{30}
  2511. \EV (10 30)
  2512. \endcode
  2513. \label Side Effects::
  2514. The \param{input-stream} is modified.
  2515. \label Affected By::
  2516. \varref{*standard-input*}
  2517. \label Exceptional Situations::
  2518. \Shouldchecktype{input-stream}{a \term{stream designator}}
  2519. \label See Also::
  2520. \funref{clear-output}
  2521. \label Notes:\None.
  2522. \endcom
  2523. %%% ========== FINISH-OUTPUT
  2524. %%% ========== FORCE-OUTPUT
  2525. %%% ========== CLEAR-OUTPUT
  2526. \begincom{finish-output, force-output, clear-output}\ftype{Function}
  2527. \label Syntax::
  2528. \DefunWithValues {finish-output} {{\opt} output-stream} {\nil}
  2529. \DefunWithValues {force-output} {{\opt} output-stream} {\nil}
  2530. \DefunWithValues {clear-output} {{\opt} output-stream} {\nil}
  2531. \label Arguments and Values::
  2532. \param{output-stream}---an \term{output} \term{stream designator}.
  2533. \Default{\term{standard output}}
  2534. \label Description::
  2535. \funref{finish-output}, \funref{force-output}, and \funref{clear-output}
  2536. exercise control over the internal handling of buffered stream output.
  2537. \funref{finish-output} attempts to ensure that any buffered output
  2538. sent to \param{output-stream} has reached its destination, and then returns.
  2539. \funref{force-output} initiates the emptying of any
  2540. internal buffers but does not wait for completion
  2541. or acknowledgment to return.
  2542. %% 22.3.1 19
  2543. \funref{clear-output} attempts to abort any
  2544. outstanding output operation in progress in order
  2545. to allow as little output as possible
  2546. to continue to the destination.
  2547. % This next sentence was added per Moon, since it was present in CLtL for CLEAR-INPUT
  2548. % and probably only accidentally omitted here. (I agree.) -kmp 11-Feb-92
  2549. If any of these operations does not make sense for \param{output-stream},
  2550. then it does nothing.
  2551. %% 22.3.1 20
  2552. The precise actions of these \term{functions} are \term{implementation-dependent}.
  2553. \label Examples::
  2554. \code
  2555. ;; Implementation A
  2556. (progn (princ "am i seen?") (clear-output))
  2557. \EV NIL
  2558. ;; Implementation B
  2559. (progn (princ "am i seen?") (clear-output))
  2560. \OUT am i seen?
  2561. \EV NIL
  2562. \endcode
  2563. \label Side Effects:\None.
  2564. \label Affected By::
  2565. \varref{*standard-output*}
  2566. \label Exceptional Situations::
  2567. \Shouldchecktype{output-stream}{a \term{stream designator}}
  2568. %!!! Barmar: Are conditions signaled if stream is closed?
  2569. \label See Also::
  2570. \funref{clear-input}
  2571. \label Notes:\None.
  2572. \endcom
  2573. %-------------------- Query Functions --------------------
  2574. %%% ========== Y-OR-N-P
  2575. %%% ========== YES-OR-NO-P
  2576. \begincom{y-or-n-p, yes-or-no-p}\ftype{Function}
  2577. \label Syntax::
  2578. \DefunWithValues {y-or-n-p} {{\opt} control {\rest} arguments} {generalized-boolean}
  2579. \DefunWithValues {yes-or-no-p} {{\opt} control {\rest} arguments} {generalized-boolean}
  2580. \label Arguments and Values::
  2581. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2582. \param{control}---a \term{format control}.
  2583. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2584. \param{arguments}---\term{format arguments} for \param{control}.
  2585. \param{generalized-boolean}---a \term{generalized boolean}.
  2586. \label Description::
  2587. These functions ask a question and parse a response from the user.
  2588. They return \term{true} if the answer is affirmative,
  2589. or \term{false} if the answer is negative.
  2590. %% 22.4.0 2
  2591. %% 22.4.0 9
  2592. \funref{y-or-n-p} is for asking the user a question whose answer is either
  2593. ``yes'' or ``no.''
  2594. It is intended that the reply require
  2595. the user to answer a yes-or-no question with a single
  2596. character.
  2597. %% 22.4.0 7
  2598. \funref{yes-or-no-p} is also for asking the user a question
  2599. whose answer is either ``Yes'' or ``No.''
  2600. It is intended that the reply require
  2601. the user to take more action than just a single keystroke, such as typing
  2602. the full word \f{yes} or \f{no} followed by a newline.
  2603. %% 22.4.0 6
  2604. %% this paragraph was left out
  2605. \funref{y-or-n-p} types out a message (if supplied), reads an answer
  2606. in some \term{implementation-dependent} manner (intended to be short and simple,
  2607. such as reading a single character such as \f{Y} or \f{N}).
  2608. \funref{yes-or-no-p} types out a message (if supplied),
  2609. attracts the user's attention (for example, by ringing
  2610. the terminal's bell),
  2611. and reads an answer
  2612. in some \term{implementation-dependent} manner (intended to be multiple characters,
  2613. such as \f{YES} or \f{NO}).
  2614. %% 22.4.0 3
  2615. %% 22.4.0 8
  2616. If \param{format-control} is supplied and not \nil,
  2617. then a \funref{fresh-line} operation is performed; then
  2618. a message is printed as if \param{format-control} and \param{arguments}
  2619. were given to \funref{format}.
  2620. In any case, \funref{yes-or-no-p} and \funref{y-or-n-p} will provide
  2621. a prompt such as ``\f{(Y or N)}'' or ``\f{(Yes or No)}'' if appropriate.
  2622. %% 22.4.0 4
  2623. %% 22.4.0 9
  2624. %% 22.4.0 1
  2625. All input and output are performed using \term{query I/O}.
  2626. \label Examples::
  2627. %% 22.4.0 5
  2628. \code
  2629. (y-or-n-p "(t or nil) given by")
  2630. \OUT (t or nil) given by (Y or N) \IN{Y}
  2631. \EV \term{true}
  2632. (yes-or-no-p "a ~S message" 'frightening)
  2633. \OUT a FRIGHTENING message (Yes or No) \IN{no}
  2634. \EV \term{false}
  2635. (y-or-n-p "Produce listing file?")
  2636. \OUT Produce listing file?
  2637. \OUT Please respond with Y or N. \IN{n}
  2638. \EV \term{false}
  2639. \endcode
  2640. \label Side Effects::
  2641. Output to and input from \term{query I/O} will occur.
  2642. \label Affected By::
  2643. \varref{*query-io*}.
  2644. \label Exceptional Situations:\None.
  2645. \label See Also::
  2646. \funref{format}
  2647. \label Notes::
  2648. \funref{yes-or-no-p} and \funref{yes-or-no-p} do not add question marks
  2649. to the end of the prompt string, so any desired question mark or other
  2650. punctuation should be explicitly included in the text query.
  2651. \endcom
  2652. %-------------------- File Streams --------------------
  2653. %-------------------- Synonym Streams --------------------
  2654. %%% ========== MAKE-SYNONYM-STREAM
  2655. \begincom{make-synonym-stream}\ftype{Function}
  2656. \label Syntax::
  2657. \DefunWithValues make-synonym-stream {symbol} {synonym-stream}
  2658. \label Arguments and Values::
  2659. \param{symbol}---a \term{symbol} that names a \term{dynamic variable}.
  2660. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2661. \param{synonym-stream}---a \term{synonym stream}.
  2662. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2663. \label Description::
  2664. %% 21.2.0 3
  2665. Returns a \term{synonym stream} whose \term{synonym stream symbol} is \param{symbol}.
  2666. \label Examples::
  2667. \code
  2668. (setq a-stream (make-string-input-stream "a-stream")
  2669. b-stream (make-string-input-stream "b-stream"))
  2670. \EV #<String Input Stream>
  2671. (setq s-stream (make-synonym-stream 'c-stream))
  2672. \EV #<SYNONYM-STREAM for C-STREAM>
  2673. (setq c-stream a-stream)
  2674. \EV #<String Input Stream>
  2675. (read s-stream) \EV A-STREAM
  2676. (setq c-stream b-stream)
  2677. \EV #<String Input Stream>
  2678. (read s-stream) \EV B-STREAM
  2679. \endcode
  2680. \label Side Effects:\None.
  2681. \label Affected By:\None.
  2682. \label Exceptional Situations::
  2683. Should signal \typeref{type-error} if its argument is not a \term{symbol}.
  2684. \label See Also::
  2685. {\secref\StreamConcepts}
  2686. \label Notes:\None.
  2687. \endcom
  2688. %%% ========== SYNONYM-STREAM-SYMBOL
  2689. \begincom{synonym-stream-symbol}\ftype{Function}
  2690. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2691. \label Syntax::
  2692. \DefunWithValues synonym-stream-symbol {synonym-stream} {symbol}
  2693. \label Arguments and Values::
  2694. \param{synonym-stream}---a \term{synonym stream}.
  2695. \param{symbol}---a \term{symbol}.
  2696. \label Description::
  2697. Returns the \term{symbol} whose \funref{symbol-value} the \param{synonym-stream} is using.
  2698. \label Examples:\None.
  2699. \label Side Effects:\None.
  2700. \label Affected By:\None.
  2701. \label Exceptional Situations:\None.
  2702. \label See Also::
  2703. \funref{make-synonym-stream}
  2704. \label Notes:\None.
  2705. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2706. \endcom
  2707. %-------------------- Broadcast Streams --------------------
  2708. %%% ========== BROADCAST-STREAM-STREAMS
  2709. \begincom{broadcast-stream-streams}\ftype{Function}
  2710. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2711. \label Syntax::
  2712. \DefunWithValues broadcast-stream-streams {broadcast-stream} {streams}
  2713. \label Arguments and Values::
  2714. \param{broadcast-stream}---a \term{broadcast stream}.
  2715. \param{streams}---a \term{list} of \term{streams}.
  2716. \label Description::
  2717. Returns a \term{list} of output \term{streams} that constitute
  2718. all the \term{streams} to which the \param{broadcast-stream} is broadcasting.
  2719. \label Examples:\None.
  2720. \label Affected By:\None.
  2721. \label Exceptional Situations:\None.
  2722. \label See Also:\None.
  2723. \label Notes:\None.
  2724. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2725. \endcom
  2726. %%% ========== MAKE-BROADCAST-STREAM
  2727. \begincom{make-broadcast-stream}\ftype{Function}
  2728. \label Syntax::
  2729. \DefunWithValues make-broadcast-stream {{\rest} streams} {broadcast-stream}
  2730. \label Arguments and Values::
  2731. \param{stream}---an \term{output} \term{stream}.
  2732. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2733. \param{broadcast-stream}---a \term{broadcast stream}.
  2734. \label Description::
  2735. %% 21.2.0 4
  2736. Returns a \term{broadcast stream}.
  2737. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2738. \label Examples::
  2739. \code
  2740. (setq a-stream (make-string-output-stream)
  2741. b-stream (make-string-output-stream)) \EV #<String Output Stream>
  2742. (format (make-broadcast-stream a-stream b-stream)
  2743. "this will go to both streams") \EV NIL
  2744. (get-output-stream-string a-stream) \EV "this will go to both streams"
  2745. (get-output-stream-string b-stream) \EV "this will go to both streams"
  2746. \endcode
  2747. \label Side Effects:\None.
  2748. %% Sandra thinks this is excessive.
  2749. %A \term{broadcast stream} is created.
  2750. \label Affected By:\None.
  2751. \label Exceptional Situations::
  2752. \Shouldcheckanytype{stream}{an \term{output} \term{stream}}
  2753. \label See Also::
  2754. \funref{broadcast-stream-streams}
  2755. \label Notes:\None.
  2756. \endcom
  2757. %-------------------- two-Way Streams --------------------
  2758. %%% ========== MAKE-TWO-WAY-STREAM
  2759. \begincom{make-two-way-stream}\ftype{Function}
  2760. \label Syntax::
  2761. \DefunWithValues make-two-way-stream {input-stream output-stream} {two-way-stream}
  2762. \label Arguments and Values::
  2763. \param{input-stream}---a \term{stream}.
  2764. \param{output-stream}---a \term{stream}.
  2765. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2766. \param{two-way-stream}---a \term{two-way stream}.
  2767. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2768. \label Description::
  2769. %% 21.2.0 6
  2770. Returns a \term{two-way stream}
  2771. that gets its input from \param{input-stream}
  2772. and sends its output to \param{output-stream}.
  2773. \label Examples::
  2774. \code
  2775. (with-output-to-string (out)
  2776. (with-input-from-string (in "input...")
  2777. (let ((two (make-two-way-stream in out)))
  2778. (format two "output...")
  2779. (setq what-is-read (read two))))) \EV "output..."
  2780. what-is-read \EV INPUT...
  2781. \endcode
  2782. \label Side Effects:\None.
  2783. \label Affected By:\None.
  2784. \label Exceptional Situations::
  2785. \Shouldchecktype{input-stream}{an \term{input} \term{stream}}
  2786. \Shouldchecktype{output-stream}{an \term{output} \term{stream}}
  2787. \label See Also:\None.
  2788. \label Notes:\None.
  2789. \endcom
  2790. %%% ========== TWO-WAY-STREAM-INPUT-STREAM
  2791. %%% ========== TWO-WAY-STREAM-OUTPUT-STREAM
  2792. \begincom{two-way-stream-input-stream, two-way-stream-output-stream}\ftype{Function}
  2793. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2794. \label Syntax::
  2795. \DefunWithValues two-way-stream-input-stream {two-way-stream} {input-stream}
  2796. \DefunWithValues two-way-stream-output-stream {two-way-stream} {output-stream}
  2797. \label Arguments and Values::
  2798. \param{two-way-stream}---a \term{two-way stream}.
  2799. \param{input-stream}---an \term{input} \term{stream}.
  2800. \param{output-stream}---an \term{output} \term{stream}.
  2801. \label Description::
  2802. \funref{two-way-stream-input-stream} returns the \term{stream}
  2803. from which \param{two-way-stream} receives input.
  2804. \funref{two-way-stream-output-stream} returns the \term{stream}
  2805. to which \param{two-way-stream} sends output.
  2806. \label Examples:\None.
  2807. \label Side Effects:\None.
  2808. \label Affected By:\None.
  2809. \label Exceptional Situations:\None.
  2810. \label See Also:\None.
  2811. \label Notes:\None.
  2812. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2813. \endcom
  2814. %-------------------- Echo Streams --------------------
  2815. %%% ========== ECHO-STREAM-INPUT-STREAM
  2816. %%% ========== ECHO-STREAM-OUTPUT-STREAM
  2817. \begincom{echo-stream-input-stream, echo-stream-output-stream}\ftype{Function}
  2818. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2819. \label Syntax::
  2820. \DefunWithValues echo-stream-input-stream {echo-stream} {input-stream}
  2821. \DefunWithValues echo-stream-output-stream {echo-stream} {output-stream}
  2822. \label Arguments and Values::
  2823. \param{echo-stream}---an \term{echo stream}.
  2824. \param{input-stream}---an \term{input} \term{stream}.
  2825. \funref{output-stream}---an \term{output} \term{stream}.
  2826. \label Description::
  2827. \funref{echo-stream-input-stream} returns the \term{input} \term{stream}
  2828. from which \param{echo-stream} receives input.
  2829. \funref{echo-stream-output-stream} returns the \term{output} \term{stream}
  2830. to which \param{echo-stream} sends output.
  2831. \label Examples:\None.
  2832. \label Side Effects:\None!
  2833. \label Affected By:\None.
  2834. \label Exceptional Situations:\None.
  2835. \label See Also:\None.
  2836. \label Notes:\None.
  2837. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2838. \endcom
  2839. %%% ========== MAKE-ECHO-STREAM
  2840. \begincom{make-echo-stream}\ftype{Function}
  2841. \label Syntax::
  2842. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2843. \DefunWithValues make-echo-stream {input-stream output-stream} {echo-stream}
  2844. \label Arguments and Values::
  2845. \param{input-stream}---an \term{input} \term{stream}.
  2846. \param{output-stream}---an \term{output} \term{stream}.
  2847. \param{echo-stream}---an \term{echo stream}.
  2848. \label Description::
  2849. %% 21.2.0 7
  2850. Creates and returns an \term{echo stream}
  2851. that takes input from \param{input-stream}
  2852. and sends output to \param{output-stream}.
  2853. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2854. \label Examples::
  2855. \code
  2856. (let ((out (make-string-output-stream)))
  2857. (with-open-stream
  2858. (s (make-echo-stream
  2859. (make-string-input-stream "this-is-read-and-echoed")
  2860. out))
  2861. (read s)
  2862. (format s " * this-is-direct-output")
  2863. (get-output-stream-string out)))
  2864. \EV "this-is-read-and-echoed * this-is-direct-output"
  2865. \endcode
  2866. \label Side Effects:\None.
  2867. \label Affected By:\None.
  2868. \label Exceptional Situations:\None.
  2869. \label See Also::
  2870. \funref{echo-stream-input-stream},
  2871. \funref{echo-stream-output-stream},
  2872. \funref{make-two-way-stream}
  2873. \label Notes:\None.
  2874. \endcom
  2875. %-------------------- Concatenated Streams --------------------
  2876. %%% ========== CONCATENATED-STREAM-STREAMS
  2877. \begincom{concatenated-stream-streams}\ftype{Function}
  2878. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2879. \label Syntax::
  2880. \DefunWithValues concatenated-stream-streams {concatenated-stream} {streams}
  2881. \label Arguments and Values::
  2882. \param{concatenated-stream} -- a \term{concatenated stream}.
  2883. \param{streams}---a \term{list} of \term{input} \term{streams}.
  2884. \label Description::
  2885. Returns a \term{list} of \term{input} \term{streams} that constitute the
  2886. ordered set of \term{streams} the \param{concatenated-stream} still
  2887. has to read from, starting with the current one it is reading from.
  2888. The list may be \term{empty} if no more \term{streams} remain to be read.
  2889. The consequences are undefined if the \term{list structure} of the \param{streams}
  2890. is ever modified.
  2891. \label Examples:\None.
  2892. \label Side Effects:\None.
  2893. \label Affected By:\None.
  2894. \label Exceptional Situations:\None.
  2895. \label See Also:\None.
  2896. \label Notes:\None.
  2897. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2898. \endcom
  2899. %%% ========== MAKE-CONCATENATED-STREAM
  2900. \begincom{make-concatenated-stream}\ftype{Function}
  2901. \label Syntax::
  2902. \DefunWithValues make-concatenated-stream {{\rest} input-streams} {concatenated-stream}
  2903. \label Arguments and Values::
  2904. \param{input-stream}---an \term{input} \term{stream}.
  2905. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2906. \param{concatenated-stream}---a \term{concatenated stream}.
  2907. \label Description::
  2908. %% 21.2.0 5
  2909. Returns a \term{concatenated stream} that has the indicated \param{input-streams}
  2910. initially associated with it.
  2911. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2912. \label Examples::
  2913. %% POSSIBLE CLEAN-UP ISSUE Symbolics returns 1.
  2914. \code
  2915. (read (make-concatenated-stream
  2916. (make-string-input-stream "1")
  2917. (make-string-input-stream "2"))) \EV 12
  2918. \endcode
  2919. \label Side Effects:\None.
  2920. \label Affected By:\None.
  2921. \label Exceptional Situations::
  2922. Should signal \typeref{type-error} if any argument is not an \term{input} \term{stream}.
  2923. \label See Also::
  2924. \funref{concatenated-stream-streams}
  2925. \label Notes:\None.
  2926. \endcom
  2927. %-------------------- String Streams --------------------
  2928. %%% ========== GET-OUTPUT-STREAM-STRING
  2929. \begincom{get-output-stream-string}\ftype{Function}
  2930. \label Syntax::
  2931. \DefunWithValues get-output-stream-string {string-output-stream} {string}
  2932. \label Arguments and Values::
  2933. \param{string-output-stream}---a \term{stream}.
  2934. \param{string}---a \term{string}.
  2935. \label Description::
  2936. %% 21.2.0 10
  2937. Returns a \term{string} containing, in order, all the \term{characters}
  2938. that have been output to \param{string-output-stream}.
  2939. This operation clears any \term{characters} on \param{string-output-stream},
  2940. so the \param{string} contains only those \term{characters} which have been output
  2941. since the last call to \funref{get-output-stream-string}
  2942. or since the creation of the \param{string-output-stream},
  2943. whichever occurred most recently.
  2944. \label Examples::
  2945. \code
  2946. (setq a-stream (make-string-output-stream)
  2947. a-string "abcdefghijklm") \EV "abcdefghijklm"
  2948. (write-string a-string a-stream) \EV "abcdefghijklm"
  2949. (get-output-stream-string a-stream) \EV "abcdefghijklm"
  2950. (get-output-stream-string a-stream) \EV ""
  2951. \endcode
  2952. \label Side Effects::
  2953. The \param{string-output-stream} is cleared.
  2954. \label Affected By:\None.
  2955. \label Exceptional Situations::
  2956. \issue{CLOSE-CONSTRUCTED-STREAM:ARGUMENT-STREAM-ONLY}
  2957. %The result of calling \funref{get-output-stream-string} on
  2958. % the \param{string-stream} returned by \funref{make-string-output-stream}
  2959. % is unspecified after \funref{close}.
  2960. %% Rewritten for Sandra:
  2961. The consequences are undefined if \param{stream-output-string} is \term{closed}.
  2962. \endissue{CLOSE-CONSTRUCTED-STREAM:ARGUMENT-STREAM-ONLY}
  2963. The consequences are undefined if \param{string-output-stream} is a \term{stream} that
  2964. was not produced by \funref{make-string-output-stream}.
  2965. \issue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  2966. The consequences are undefined if \param{string-output-stream} was
  2967. created implicitly by \macref{with-output-to-string} or \funref{format}.
  2968. %% Redundant -- Said already in WITH-OUTPUT-TO-STRING and FORMAT. -kmp 14-Feb-92
  2969. % In the cases where a \term{string} argument with a \term{fill pointer} is supplied
  2970. % as an \term{argument} to \macref{with-output-to-string} or \funref{format},
  2971. % the consequences are undefined if destructive modifications are performed
  2972. % directly on the \term{string} during the \term{dynamic extent} of the call.
  2973. \endissue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  2974. \label See Also::
  2975. \funref{make-string-output-stream}
  2976. \label Notes:\None.
  2977. \endcom
  2978. %%% ========== MAKE-STRING-INPUT-STREAM
  2979. \begincom{make-string-input-stream}\ftype{Function}
  2980. \label Syntax::
  2981. \DefunWithValues make-string-input-stream {string {\opt} start end} {string-stream}
  2982. \label Arguments and Values::
  2983. \param{string}---a \term{string}.
  2984. \issue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  2985. \param{start}, \param{end}---\term{bounding index designators} of \param{string}.
  2986. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  2987. \endissue{RANGE-OF-START-AND-END-PARAMETERS:INTEGER-AND-INTEGER-NIL}
  2988. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2989. \param{string-stream}---an \term{input} \term{string stream}.
  2990. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  2991. \label Description::
  2992. %% 21.2.0 8
  2993. Returns an \term{input} \term{string stream}.
  2994. This \term{stream} will supply, in order, the \term{characters} in the substring
  2995. of \param{string} \term{bounded} by \param{start} and \param{end}.
  2996. After the last \term{character} has been supplied,
  2997. the \term{string stream} will then be at \term{end of file}.
  2998. %% Implied by bounded. -kmp 14-Feb-92
  2999. % \param{Start} marks the beginning position of the substring.
  3000. % \param{End} marks the position following the last element of the substring.
  3001. \label Examples::
  3002. \code
  3003. (let ((string-stream (make-string-input-stream "1 one ")))
  3004. (list (read string-stream nil nil)
  3005. (read string-stream nil nil)
  3006. (read string-stream nil nil)))
  3007. \EV (1 ONE NIL)
  3008. (read (make-string-input-stream "prefixtargetsuffix" 6 12)) \EV TARGET
  3009. \endcode
  3010. \label Side Effects:\None.
  3011. \label Affected By:\None.
  3012. \label Exceptional Situations:\None.
  3013. \label See Also::
  3014. \macref{with-input-from-string}
  3015. \label Notes:\None.
  3016. \endcom
  3017. %%% ========== MAKE-STRING-OUTPUT-STREAM
  3018. \begincom{make-string-output-stream}\ftype{Function}
  3019. \label Syntax::
  3020. \DefunWithValues make-string-output-stream {{\key} element-type} {string-stream}
  3021. \label Arguments and Values::
  3022. \issue{CHARACTER-PROPOSAL:2-5-6}
  3023. \param{element-type}---a \term{type specifier}.
  3024. \Default{\typeref{character}}
  3025. \endissue{CHARACTER-PROPOSAL:2-5-6}
  3026. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3027. \param{string-stream}---an \term{output} \term{string stream}.
  3028. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3029. \label Description::
  3030. %% 21.2.0 9
  3031. Returns
  3032. \issue{CHARACTER-PROPOSAL:2-5-6}
  3033. an \term{output} \term{string stream} that accepts \term{characters}
  3034. and makes available (via \funref{get-output-stream-string})
  3035. a \term{string} that contains the \term{characters} that were actually output.
  3036. The \param{element-type} names the \term{type} of the \term{elements}
  3037. of the \term{string}; a \term{string} is constructed of the most specialized
  3038. \term{type} that can accommodate \term{elements} of that \term{element-type}.
  3039. \endissue{CHARACTER-PROPOSAL:2-5-6}
  3040. \label Examples::
  3041. \code
  3042. (let ((s (make-string-output-stream)))
  3043. (write-string "testing... " s)
  3044. (prin1 1234 s)
  3045. (get-output-stream-string s))
  3046. \EV "testing... 1234"
  3047. \endcode
  3048. \label Affected By:\None.
  3049. \label Exceptional Situations:\None.
  3050. \None.
  3051. \label See Also::
  3052. \funref{get-output-stream-string}, \macref{with-output-to-string}
  3053. \label Notes:\None.
  3054. \endcom
  3055. %%% ========== WITH-INPUT-FROM-STRING
  3056. \begincom{with-input-from-string}\ftype{Macro}
  3057. \issue{DECLS-AND-DOC}
  3058. \label Syntax::
  3059. \DefmacWithValuesNewline with-input-from-string
  3060. {\paren{var string {\key} index start end}
  3061. \starparam{declaration}
  3062. \starparam{form}}
  3063. {\starparam{result}}
  3064. \label Arguments and Values::
  3065. \param{var}---a \term{variable} \term{name}.
  3066. \param{string}---a \term{form}; evaluated to produce a \term{string}.
  3067. \param{index}---a \term{place}.
  3068. \issue{SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR}
  3069. \param{start}, \param{end}---\term{bounding index designators} of \param{string}.
  3070. \Defaults{\param{start} and \param{end}}{\f{0} and \nil}
  3071. \endissue{SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR}
  3072. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  3073. \param{forms}---an \term{implicit progn}.
  3074. \param{result}---the \term{values} returned by the \param{forms}.
  3075. \label Description::
  3076. Creates an
  3077. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3078. \term{input} \term{string stream},
  3079. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3080. provides an opportunity to perform operations on the \term{stream}
  3081. (returning zero or more \term{values}),
  3082. and then closes the \term{string stream}.
  3083. %% 21.2.0 12
  3084. \param{String} is evaluated first, and \param{var} is bound to
  3085. a character \term{input} \term{string stream} that supplies
  3086. \term{characters} from the subsequence of the resulting \term{string} \term{bounded} by
  3087. \param{start} and \param{end}.
  3088. The body is executed as an \term{implicit progn}.
  3089. %% 21.2.0 13
  3090. The \term{input} \term{string stream} is automatically closed on exit from
  3091. \macref{with-input-from-string}, no matter whether the exit is normal or abnormal.
  3092. \issue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  3093. The \term{input} \term{string stream} to which the \term{variable} \param{var}
  3094. is \term{bound} has \term{dynamic extent};
  3095. its \term{extent} ends when the \term{form} is exited.
  3096. \endissue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  3097. %% 21.2.0 14
  3098. %% 21.2.0 15
  3099. % \beginlist
  3100. % \itemitem{\kwd{index}}
  3101. The \param{index} is a pointer within the \param{string} to be advanced.
  3102. If \macref{with-input-from-string}
  3103. is exited normally, then \param{index} will have
  3104. % stored into it
  3105. as its \term{value}
  3106. the index into the \param{string} indicating the first character not read
  3107. which is {\tt (length \param{string})} if all characters were used.
  3108. The place specified by \param{index}
  3109. is not updated as reading progresses, but only at the
  3110. end of the operation.
  3111. %% This is redundant with "bounded".
  3112. % %% 21.2.0 16
  3113. % \itemitem{\kwd{start}}
  3114. %
  3115. % \kwd{start} indicates the beginning of a substring of \param{string} to be used.
  3116. % If \kwd{start} is not supplied or \nil, the beginning position is 0.
  3117. %
  3118. % %% 21.2.0 17
  3119. % \itemitem{\kwd{end}}
  3120. %
  3121. % \kwd{end} indicates the end of a substring of \param{string} to be used.
  3122. % If \kwd{end} is not supplied or \nil, the ending position is {\tt (length \param{string})}.
  3123. % \endlist
  3124. %% 21.2.0 19
  3125. \param{start} and \param{index} may both specify the same variable,
  3126. which is a pointer within the \param{string} to be advanced,
  3127. perhaps repeatedly by some containing loop.
  3128. \issue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  3129. The consequences are undefined if an attempt is made to \term{assign}
  3130. the \term{variable} \param{var}.
  3131. %% Sandra thinks this isn't needed.
  3132. % The compiler may choose to issue a
  3133. % warning if such an attempt is detected.
  3134. \endissue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  3135. \label Examples::
  3136. %% 21.2.0 18
  3137. \code
  3138. (with-input-from-string (s "XXX1 2 3 4xxx"
  3139. :index ind
  3140. :start 3 :end 10)
  3141. (+ (read s) (read s) (read s))) \EV 6
  3142. ind \EV 9
  3143. (with-input-from-string (s "Animal Crackers" :index j :start 6)
  3144. (read s)) \EV CRACKERS
  3145. \endcode
  3146. The variable \f{j} is set to \f{15}.
  3147. \label Side Effects::
  3148. The \term{value} of the \term{place} named by \param{index}, if any, is modified.
  3149. %% Sandra thinks this is excessive.
  3150. %A \term{string stream} is created (upon entry) and closed (upon exit).
  3151. \label Affected By:\None.
  3152. \label Exceptional Situations:\None.
  3153. \label See Also::
  3154. \funref{make-string-input-stream},
  3155. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3156. {\secref\TraversalRules}
  3157. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3158. \label Notes:\None.
  3159. \endissue{DECLS-AND-DOC}
  3160. \endcom
  3161. %%% ========== WITH-OUTPUT-TO-STRING
  3162. \begincom{with-output-to-string}\ftype{Macro}
  3163. \issue{DECLS-AND-DOC}
  3164. \label Syntax::
  3165. \DefmacWithValuesNewline with-output-to-string
  3166. {\paren{var {\opt} string-form {\key} element-type}
  3167. \starparam{declaration}
  3168. \starparam{form}}
  3169. {\starparam{result}}
  3170. \label Arguments and Values::
  3171. \param{var}---a \term{variable} \term{name}.
  3172. \param{string-form}---a \term{form} or \nil;
  3173. if \term{non-nil}, evaluated to produce \param{string}.
  3174. \param{string}---a \term{string} that has a \term{fill pointer}.
  3175. \issue{CHARACTER-PROPOSAL:2-5-6}
  3176. \param{element-type}---a \term{type specifier}; \eval.
  3177. \issue{CHARACTER-PROPOSAL:2-3-6}
  3178. \Default{\typeref{character}}
  3179. \endissue{CHARACTER-PROPOSAL:2-3-6}
  3180. \endissue{CHARACTER-PROPOSAL:2-5-6}
  3181. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  3182. \param{forms}---an \term{implicit progn}.
  3183. \param{results}---If a \param{string-form} is not supplied or \nil,
  3184. a \term{string}; otherwise,
  3185. the \term{values} returned by the \param{forms}.
  3186. \label Description::
  3187. \macref{with-output-to-string} creates a
  3188. \issue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3189. character \term{output} \term{stream}, performs a series of operations
  3190. that may send results to this \term{stream}, and then closes the \term{stream}.
  3191. \endissue{STREAM-ACCESS:ADD-TYPES-ACCESSORS}
  3192. \issue{CHARACTER-PROPOSAL:2-3-6}
  3193. The \param{element-type} names the \term{type} of the elements
  3194. of the \term{stream}; a \term{stream} is constructed of the most specialized
  3195. \term{type} that can accommodate elements of the given \term{type}.
  3196. \endissue{CHARACTER-PROPOSAL:2-3-6}
  3197. %% 21.2.0 20
  3198. The body is executed as an \term{implicit progn} with \param{var}
  3199. bound to an \term{output} \term{string stream}.
  3200. All output to that \term{string stream} is saved in a \term{string}.
  3201. %% 21.2.0 22
  3202. \issue{WITH-OUTPUT-TO-STRING-APPEND-STYLE:VECTOR-PUSH-EXTEND}
  3203. If \param{string} is supplied, \param{element-type} is ignored,
  3204. and the output is incrementally appended to \param{string} as
  3205. if by use of \funref{vector-push-extend}.
  3206. \endissue{WITH-OUTPUT-TO-STRING-APPEND-STYLE:VECTOR-PUSH-EXTEND}
  3207. %% 21.2.0 24
  3208. %% Sandra: Huh?
  3209. %In either case,
  3210. The \term{output} \term{stream}
  3211. is automatically closed on exit from \macref{with-output-from-string},
  3212. no matter whether the exit is normal or abnormal.
  3213. \issue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  3214. The \term{output} \term{string stream} to which the \term{variable} \param{var}
  3215. is \term{bound} has \term{dynamic extent};
  3216. its \term{extent} ends when the \term{form} is exited.
  3217. \endissue{WITH-OPEN-FILE-STREAM-EXTENT:DYNAMIC-EXTENT}
  3218. %% 21.2.0 21
  3219. If no \param{string} is provided, then \macref{with-output-from-string}
  3220. \issue{CHARACTER-PROPOSAL:2-5-6}
  3221. produces a \term{stream} that accepts characters and returns a \term{string}
  3222. of the indicated \param{element-type}.
  3223. \endissue{CHARACTER-PROPOSAL:2-5-6}
  3224. If \param{string} is provided,
  3225. \macref{with-output-to-string} returns the results of evaluating the last \param{form}.
  3226. \issue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  3227. The consequences are undefined if an attempt is made to \term{assign}
  3228. the \term{variable} \param{var}.
  3229. %% Sandra: unnecessary.
  3230. %The compiler may choose to issue a
  3231. %warning if such an attempt is detected.
  3232. \endissue{WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE}
  3233. \label Examples::
  3234. \code
  3235. (setq fstr (make-array '(0) :element-type 'base-char
  3236. :fill-pointer 0 :adjustable t)) \EV ""
  3237. (with-output-to-string (s fstr)
  3238. (format s "here's some output")
  3239. (input-stream-p s)) \EV \term{false}
  3240. fstr \EV "here's some output"
  3241. \endcode
  3242. \label Side Effects::
  3243. The \param{string} is modified.
  3244. \label Affected By:\None.
  3245. \label Exceptional Situations::
  3246. \issue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  3247. The consequences are undefined if destructive modifications are performed
  3248. directly on the \param{string} during the \term{dynamic extent} of the call.
  3249. \endissue{STRING-OUTPUT-STREAM-BASHING:UNDEFINED}
  3250. \label See Also::
  3251. \funref{make-string-output-stream},
  3252. \funref{vector-push-extend},
  3253. \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3254. {\secref\TraversalRules}
  3255. \endissue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}
  3256. \label Notes:\None.
  3257. \endissue{DECLS-AND-DOC}
  3258. \endcom
  3259. %-------------------- Stream Variables --------------------
  3260. % \def\iovarconstraint#1#2 #3{
  3261. % \issue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3262. % \term{implementation-dependent}, but it must be an \term{open},
  3263. % \term{#1} \term{stream} which is not a
  3264. % \term{generalized synonym stream} to any of the \term{symbols} #3, but
  3265. % which might be a \term{generalized synonym stream} to the
  3266. % \term{value} of one of those \term{symbols}. #2
  3267. % \endissue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3268. % }
  3269. %
  3270. % \def\TerminalIOsynOK{%
  3271. % The initial value might also be a \term{generalized synonym stream}
  3272. % to either the \term{symbol} \varref{*terminal-io*} or to the \term{stream}
  3273. % which is its \term{value}.}
  3274. %
  3275. % \def\iovarrationale#1{
  3276. % \issue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3277. % The intent of the constraints on the initial \term{value}
  3278. % is to ensure that it is always safe to bind \varref{*#1*}
  3279. % to one of the above-mentioned variables without
  3280. % unduly restricting implementation flexibility.
  3281. % \endissue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3282. % }
  3283. %
  3284. % %%% ========== *DEBUG-IO*
  3285. % \begincom{*debug-io*}\ftype{Variable}
  3286. %
  3287. % \label Value Type::
  3288. %
  3289. % a \term{bidirectional} \term{stream}.
  3290. %
  3291. % \label Initial Value::
  3292. %
  3293. % \iovarconstraint{bidirectional}{\TerminalIOsynOK}
  3294. % {\varref{*standard-input*},
  3295. % \varref{*standard-output*},
  3296. % \varref{*error-output*},
  3297. % \varref{*trace-output*}, or
  3298. % \varref{*query-io*}}
  3299. %
  3300. % \label Description::
  3301. %
  3302. % %% 21.1.0 7
  3303. % A \term{stream} to be used for interactive debugging purposes.
  3304. %
  3305. % \label Examples:\None.
  3306. %
  3307. % %% Moon: Not only is this example under *debug-io* disgusting, it is not correct Common
  3308. % %% Lisp because it violates dynamic extent:
  3309. % %% KMP: I concur! Commented out.
  3310. % %
  3311. % % \code
  3312. % % (with-output-to-string (out)
  3313. % % (with-input-from-string (in "enter > ")
  3314. % % (let ((two-way (make-two-way-stream in out)))
  3315. % % (setq *debug-io* two-way)))) \EV ""
  3316. % % *debug-io* \EV #<TWO-WAY-STREAM>
  3317. % % \endcode
  3318. %
  3319. % \label Affected By:\None.
  3320. %
  3321. % \label See Also::
  3322. %
  3323. % \varref{*query-io*},
  3324. % \funref{make-synonym-stream}
  3325. %
  3326. % \label Notes::
  3327. %
  3328. % \iovarrationale{debug-io}
  3329. %
  3330. % Frequently \varref{*debug-io*} is bound to the same \term{stream} as \varref{*query-io*}.
  3331. %
  3332. % \endcom
  3333. %
  3334. % %%% ========== *ERROR-OUTPUT*
  3335. % \begincom{*error-output*}\ftype{Variable}
  3336. %
  3337. % \label Value Type::
  3338. %
  3339. % an \term{output} \term{stream}.
  3340. %
  3341. % \label Initial Value::
  3342. %
  3343. % \iovarconstraint{output}{\TerminalIOsynOK}
  3344. % {\varref{*standard-input*},
  3345. % \varref{*standard-output*},
  3346. % \varref{*trace-output*},
  3347. % \varref{*query-io*}, or
  3348. % \varref{*debug-io*}}
  3349. %
  3350. % \label Description::
  3351. %
  3352. % %% 21.1.0 5
  3353. % \Thevalueof{*error-output*} is a \term{stream} to which error messages should be sent.
  3354. %
  3355. % \label Examples::
  3356. %
  3357. % \code
  3358. % (with-output-to-string (*error-output*)
  3359. % (warn "this string is sent to *error-output*"))
  3360. % \EV "Warning: this string is sent to *error-output*
  3361. % " ;The exact format of this string is \term{implementation-dependent}.
  3362. % \endcode
  3363. %
  3364. % \label Affected By:\None.
  3365. %
  3366. % %%Sandra: Gratuitous
  3367. % %The \term{implementation}.
  3368. %
  3369. % \label See Also::
  3370. %
  3371. % \varref{*standard-output*},
  3372. % \varref{*terminal-io*},
  3373. % \funref{make-synonym-stream},
  3374. % \funref{warn},
  3375. % \funref{error},
  3376. % \funref{cerror},
  3377. % \funref{break},
  3378. % \macref{check-type},
  3379. % \macref{assert},
  3380. % \macref{etypecase},
  3381. % \macref{ctypecase},
  3382. % \macref{ecase},
  3383. % \macref{ccase}
  3384. %
  3385. % \label Notes::
  3386. %
  3387. % \iovarrationale{error-output}
  3388. %
  3389. % Frequently \varref{*error-output*} is bound to the \term{same} \term{stream}
  3390. % as \varref{*standard-output*}.
  3391. %
  3392. % \endcom
  3393. %
  3394. % %%% ========== *QUERY-IO*
  3395. % \begincom{*query-io*}\ftype{Variable}
  3396. %
  3397. % \label Value Type::
  3398. %
  3399. % a \term{bidirectional} \term{stream}.
  3400. %
  3401. % \label Initial Value::
  3402. %
  3403. % \iovarconstraint{bidirectional}{\TerminalIOsynOK}
  3404. % {\varref{*standard-input*},
  3405. % \varref{*standard-output*},
  3406. % \varref{*error-output*},
  3407. % \varref{*trace-output*}, or
  3408. % \varref{*debug-io*}}
  3409. %
  3410. % \label Description::
  3411. %
  3412. % %% 21.1.0 6
  3413. % \Thevalueof{*query-io*}, \term{query I/O}, is a \term{bidirectional} \term{stream}
  3414. % to be used when asking questions of the user. The question should be output
  3415. % to this \term{stream}, and the answer read from it.
  3416. %
  3417. % \label Examples:\None.
  3418. %
  3419. % \label Affected By:\None.
  3420. %
  3421. % %%Sandra: Gratuitous
  3422. % %The \term{implementation}.
  3423. %
  3424. % \label See Also::
  3425. %
  3426. % \varref{*debug-io*},
  3427. % \varref{*terminal-io*},
  3428. % \funref{make-synonym-stream},
  3429. % \funref{y-or-n-p},
  3430. % \funref{yes-or-no-p}
  3431. %
  3432. % \label Notes::
  3433. %
  3434. % \iovarrationale{query-io}
  3435. %
  3436. % %\varref{*query-io*} is normally a \term{synonym stream} to \varref{*terminal-io*}.
  3437. %
  3438. % \varref{*query-io*} is used by such functions as \funref{y-or-n-p}
  3439. % and \funref{yes-or-no-p}.
  3440. % \endcom
  3441. %
  3442. % %%% ========== *STANDARD-INPUT*
  3443. % \begincom{*standard-input*}\ftype{Variable}
  3444. %
  3445. % \label Value Type::
  3446. %
  3447. % an \term{input} \term{stream}.
  3448. %
  3449. % \label Initial Value::
  3450. %
  3451. % \iovarconstraint{input}{\TerminalIOsynOK}
  3452. % {\varref{*standard-output*},
  3453. % \varref{*error-output*},
  3454. % \varref{*trace-output*},
  3455. % \varref{*query-io*}, or
  3456. % \varref{*debug-io*}}
  3457. %
  3458. % \label Description::
  3459. %
  3460. % \issue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3461. % \Thevalueof{*standard-input*}, \term{standard input}, is a \term{stream}
  3462. % that is used by many \term{operators} as a default source of input when
  3463. % no specific \term{input} \term{stream} is explicitly supplied.
  3464. % \endissue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3465. %
  3466. % \label Examples::
  3467. %
  3468. % \code
  3469. % (with-input-from-string (*standard-input* "1001")
  3470. % (+ 990 (read))) \EV 1991
  3471. % \endcode
  3472. %
  3473. % \label Affected By:\None.
  3474. %
  3475. % %%Sandra: Gratuitous
  3476. % %The \term{implementation}.
  3477. %
  3478. % \label See Also::
  3479. %
  3480. % \funref{make-synonym-stream}
  3481. %
  3482. % \label Notes::
  3483. %
  3484. % \iovarrationale{standard-input}
  3485. %
  3486. % %% 21.1.0 3
  3487. % %% 22.2.1 1
  3488. % In the normal \term{Lisp read-eval-print loop}, input is read from
  3489. % \term{standard input}. Many input functions, including \funref{read}
  3490. % and \funref{read-char}, take a \term{stream} argument that defaults
  3491. % to \term{standard input}.
  3492. %
  3493. % \endcom
  3494. %
  3495. %
  3496. % %%% ========== *STANDARD-OUTPUT*
  3497. % \begincom{*standard-output*}\ftype{Variable}
  3498. %
  3499. % \label Value Type::
  3500. %
  3501. % an \term{output} \term{stream}.
  3502. %
  3503. % \label Initial Value::
  3504. %
  3505. % \iovarconstraint{output}{\TerminalIOsynOK}
  3506. % {\varref{*standard-input*},
  3507. % \varref{*error-output*},
  3508. % \varref{*trace-output*},
  3509. % \varref{*query-io*}, or
  3510. % \varref{*debug-io*}}
  3511. %
  3512. % \label Description::
  3513. %
  3514. % \Thevalueof{*standard-output*}, \term{standard output}, is a \term{stream}
  3515. % that is used by many \term{operators} as a default destination for output
  3516. % when no specific \term{output} \term{stream} is explicitly supplied.
  3517. %
  3518. % \label Examples::
  3519. % \code
  3520. % (progn (setq out (with-output-to-string (*standard-output*)
  3521. % (print "print and format t send things to")
  3522. % (format t "*standard-output* now going to a string")))
  3523. % :done)
  3524. % \EV :DONE
  3525. % out
  3526. % \EV "
  3527. % \\"print and format t send things to\\" *standard-output* now going to a string"
  3528. % \endcode
  3529. %
  3530. % \label Affected By:\None.
  3531. %
  3532. % %%Sandra: Gratuitous
  3533. % %The \term{implementation}.
  3534. %
  3535. % \label See Also::
  3536. %
  3537. % \funref{make-synonym-stream}
  3538. %
  3539. % \label Notes::
  3540. %
  3541. % %% 21.1.0 4
  3542. % In the normal \term{Lisp read-eval-print loop}, output is sent to \term{standard output}.
  3543. % Many output functions, including \funref{print} and \funref{write-char},
  3544. % take a \term{stream} argument that defaults to \term{standard output}.
  3545. %
  3546. % %!!! This needs to be cross-checked against the new descriptions of these streams.
  3547. % %% 21.1.0 11
  3548. % A program that wants, for example, to divert output to a file should do so by
  3549. % \term{binding} \varref{*standard-output*}; that way error messages sent to
  3550. % \varref{*error-output*} can still get to the user by going through
  3551. % \varref{*terminal-io*} (if \varref{*error-output*} is bound to \varref{*terminal-io*}),
  3552. % which is usually what is desired.
  3553. %
  3554. % \endcom
  3555. %
  3556. %
  3557. % %%% ========== *TRACE-OUTPUT*
  3558. % \begincom{*trace-output*}\ftype{Variable}
  3559. %
  3560. % \label Value Type::
  3561. %
  3562. % an \term{output} \term{stream}.
  3563. %
  3564. % \label Initial Value::
  3565. %
  3566. % \iovarconstraint{output}{\TerminalIOsynOK}
  3567. % {\varref{*standard-input*},
  3568. % \varref{*standard-output*},
  3569. % \varref{*error-output*},
  3570. % \varref{*query-io*}, or
  3571. % \varref{*debug-io*}}
  3572. %
  3573. % \label Description::
  3574. %
  3575. % %% 21.1.0 9
  3576. % The \term{stream} on which traced functions (see \macref{trace})
  3577. % and \themacro{time} print their output.
  3578. %
  3579. % \label Examples::
  3580. %
  3581. % \code
  3582. % (defun fact (n) (if (< n 2) 1 (* n (fact (- n 1)))))
  3583. % \EV FACT
  3584. % (trace fact)
  3585. % \EV (FACT)
  3586. % ;; Of course, the format of traced output is implementation-dependent.
  3587. % (with-output-to-string (*trace-output*)
  3588. % (fact 3))
  3589. % \EV "
  3590. % 1 Enter FACT 3
  3591. % | 2 Enter FACT 2
  3592. % | 3 Enter FACT 1
  3593. % | 3 Exit FACT 1
  3594. % | 2 Exit FACT 2
  3595. % 1 Exit FACT 6"
  3596. % \endcode
  3597. %
  3598. % \label Affected By:\None.
  3599. %
  3600. % %%Sandra: Gratuitous
  3601. % %The \term{implementation}.
  3602. %
  3603. % \label See Also::
  3604. %
  3605. % \funref{make-synonym-stream},
  3606. % \macref{trace},
  3607. % \macref{time}.
  3608. %
  3609. % \label Notes::
  3610. %
  3611. % \iovarrationale{trace-output}
  3612. %
  3613. % \endcom
  3614. %
  3615. % %%% ========== *TERMINAL-IO*
  3616. % \begincom{*terminal-io*}\ftype{Variable}
  3617. %
  3618. % \label Value Type::
  3619. %
  3620. % a \term{bidirectional} \term{stream}.
  3621. %
  3622. % \label Initial Value::
  3623. %
  3624. % \editornote{KMP: Doesn't debug-io belong in this list?}
  3625. %
  3626. % \iovarconstraint{bidirectional}{}
  3627. % {\varref{*standard-input*},
  3628. % \varref{*standard-output*},
  3629. % \varref{*error-output*},
  3630. % \varref{*trace-output*}, or
  3631. % \varref{*query-io*}}
  3632. %
  3633. % \label Description::
  3634. %
  3635. % %% 21.1.0 8
  3636. % \Thevalueof{*terminal-io*}, \term{terminal I/O}, is ordinarily
  3637. % a \term{bidirectional} \term{stream} that connects to the user's console.
  3638. % Typically, writing to this \term{stream}
  3639. % would cause the output to appear
  3640. % on a display screen, for example, and reading from the \term{stream} would
  3641. % accept input from a keyboard. It is intended
  3642. % that standard input functions such as \funref{read} and \funref{read-char},
  3643. % when used with this \term{stream}, cause echoing of the input
  3644. % into the output side of the \term{stream}. The means by which this is
  3645. % accomplished are \term{implementation-dependent}.
  3646. %
  3647. % %% 21.1.0 11, clarified by KMP
  3648. % The effect of changing \thevalueof{*terminal-io*},
  3649. % either by \term{binding} or \term{assignment},
  3650. % is \term{implementation-defined}.
  3651. %
  3652. % \label Examples::
  3653. %
  3654. % \code
  3655. % (progn (prin1 'foo) (prin1 'bar *terminal-io*))
  3656. % \OUT FOOBAR
  3657. % \EV BAR
  3658. % (with-output-to-string (*standard-output*)
  3659. % (prin1 'foo)
  3660. % (prin1 'bar *terminal-io*))
  3661. % \OUT BAR
  3662. % \EV "FOO"
  3663. % \endcode
  3664. %
  3665. % \label Affected By:\None.
  3666. %
  3667. % %%Sandra: Gratuitous
  3668. % %The \term{implementation}.
  3669. %
  3670. % \label See Also:\None.
  3671. %
  3672. % \label Notes:\None.
  3673. %
  3674. % \endcom
  3675. %%% ========== *DEBUG-IO*
  3676. %%% ========== *ERROR-OUTPUT*
  3677. %%% ========== *QUERY-IO*
  3678. %%% ========== *STANDARD-INPUT*
  3679. %%% ========== *STANDARD-OUTPUT*
  3680. %%% ========== *TRACE-OUTPUT*
  3681. \begincom{*debug-io*, *error-output*, *query-io*,
  3682. *standard-input*, *standard-output*,
  3683. *trace-output*}\ftype{Variable}
  3684. \label Value Type::
  3685. For \varref{*standard-input*}:
  3686. an \term{input} \term{stream}
  3687. For \varref{*error-output*}, \varref{*standard-output*}, and \varref{*trace-output*}:
  3688. an \term{output} \term{stream}.
  3689. For \varref{*debug-io*}, \varref{*query-io*}:
  3690. a \term{bidirectional} \term{stream}.
  3691. \label Initial Value::
  3692. \term{implementation-dependent}, but
  3693. it must be an \term{open} \term{stream}
  3694. that is not a \term{generalized synonym stream}
  3695. to an \term{I/O customization variables}
  3696. but that might be a \term{generalized synonym stream} to
  3697. the value of some \term{I/O customization variable}.
  3698. The initial value might also be a \term{generalized synonym stream}
  3699. to either the \term{symbol} \varref{*terminal-io*} or to the \term{stream}
  3700. that is its \term{value}.
  3701. \label Description::
  3702. These \term{variables} are collectively called the
  3703. \term{standardized} \term{I/O customization variables}.
  3704. They can be \term{bound} or \term{assigned} in order to
  3705. change the default destinations for input and/or output
  3706. used by various \term{standardized} \term{operators} and facilities.
  3707. %% 21.1.0 7
  3708. \Thevalueof{*debug-io*}, called \term{debug I/O},
  3709. is a \term{stream} to be used for interactive debugging purposes.
  3710. %% 21.1.0 5
  3711. \Thevalueof{*error-output*}, called \term{error output},
  3712. is a \term{stream} to which warnings and non-interactive error messages should be sent.
  3713. %% 21.1.0 6
  3714. \Thevalueof{*query-io*}, called \term{query I/O},
  3715. is a \term{bidirectional} \term{stream}
  3716. to be used when asking questions of the user. The question should be output
  3717. to this \term{stream}, and the answer read from it.
  3718. \issue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3719. \Thevalueof{*standard-input*}, called \term{standard input},
  3720. is a \term{stream} that is used by many \term{operators}
  3721. as a default source of input when no specific \term{input} \term{stream}
  3722. is explicitly supplied.
  3723. \endissue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3724. \Thevalueof{*standard-output*}, called \term{standard output},
  3725. is a \term{stream} that is used by many \term{operators}
  3726. as a default destination for output when no specific \term{output} \term{stream}
  3727. is explicitly supplied.
  3728. %% 21.1.0 9
  3729. \Thevalueof{*trace-output*}, called \term{trace output},
  3730. is the \term{stream} on which traced functions (see \macref{trace})
  3731. and \themacro{time} print their output.
  3732. \label Examples::
  3733. \code
  3734. (with-output-to-string (*error-output*)
  3735. (warn "this string is sent to *error-output*"))
  3736. \EV "Warning: this string is sent to *error-output*
  3737. " ;The exact format of this string is \term{implementation-dependent}.
  3738. \medbreak
  3739. (with-input-from-string (*standard-input* "1001")
  3740. (+ 990 (read))) \EV 1991
  3741. \medbreak
  3742. (progn (setq out (with-output-to-string (*standard-output*)
  3743. (print "print and format t send things to")
  3744. (format t "*standard-output* now going to a string")))
  3745. :done)
  3746. \EV :DONE
  3747. out
  3748. \EV "
  3749. \\"print and format t send things to\\" *standard-output* now going to a string"
  3750. \medbreak
  3751. (defun fact (n) (if (< n 2) 1 (* n (fact (- n 1)))))
  3752. \EV FACT
  3753. (trace fact)
  3754. \EV (FACT)
  3755. ;; Of course, the format of traced output is implementation-dependent.
  3756. (with-output-to-string (*trace-output*)
  3757. (fact 3))
  3758. \EV "
  3759. 1 Enter FACT 3
  3760. | 2 Enter FACT 2
  3761. | 3 Enter FACT 1
  3762. | 3 Exit FACT 1
  3763. | 2 Exit FACT 2
  3764. 1 Exit FACT 6"
  3765. \endcode
  3766. \label See Also::
  3767. \varref{*terminal-io*},
  3768. \typeref{synonym-stream},
  3769. \macref{time},
  3770. \macref{trace},
  3771. {\chapref\Conditions},
  3772. {\chapref\Reader},
  3773. {\chapref\Printer}
  3774. \label Notes::
  3775. \issue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3776. The intent of the constraints on the initial \term{value}
  3777. of the \term{I/O customization variables} is to ensure that it
  3778. is always safe to \term{bind} or \term{assign} such a \term{variable} to
  3779. the \term{value} of another \term{I/O customization variable}, without
  3780. unduly restricting \term{implementation} flexibility.
  3781. \endissue{STANDARD-INPUT-INITIAL-BINDING:DEFINED-CONTRACTS}
  3782. It is common for an \term{implementation} to make
  3783. the initial \term{values} of \varref{*debug-io*} and \varref{*query-io*}
  3784. be the \term{same} \term{stream},
  3785. and to make
  3786. the initial \term{values} of \varref{*error-output*} and \varref{*standard-output*}
  3787. be the \term{same} \term{stream}.
  3788. The functions \funref{y-or-n-p} and \funref{yes-or-no-p} use \term{query I/O}
  3789. for their input and output.
  3790. %% 21.1.0 3
  3791. %% 22.2.1 1
  3792. In the normal \term{Lisp read-eval-print loop},
  3793. input is read from \term{standard input}.
  3794. Many input functions, including \funref{read} and \funref{read-char},
  3795. take a \term{stream} argument that defaults to \term{standard input}.
  3796. %% 21.1.0 4
  3797. In the normal \term{Lisp read-eval-print loop}, output is sent to \term{standard output}.
  3798. Many output functions, including \funref{print} and \funref{write-char},
  3799. take a \term{stream} argument that defaults to \term{standard output}.
  3800. %% 21.1.0 11
  3801. A program that wants, for example, to divert output to a file should do so by
  3802. \term{binding} \varref{*standard-output*}; that way error messages sent to
  3803. \varref{*error-output*} can still get to the user by going through
  3804. \varref{*terminal-io*} (if \varref{*error-output*} is bound to \varref{*terminal-io*}),
  3805. which is usually what is desired.
  3806. \endcom
  3807. %%% ========== *TERMINAL-IO*
  3808. \begincom{*terminal-io*}\ftype{Variable}
  3809. \label Value Type::
  3810. a \term{bidirectional} \term{stream}.
  3811. \label Initial Value::
  3812. \term{implementation-dependent}, but
  3813. it must be an \term{open} \term{stream}
  3814. that is not a \term{generalized synonym stream}
  3815. to an \term{I/O customization variables}
  3816. but that might be a \term{generalized synonym stream} to
  3817. the \term{value} of some \term{I/O customization variable}.
  3818. \label Description::
  3819. %% 21.1.0 8
  3820. \Thevalueof{*terminal-io*}, called \term{terminal I/O}, is ordinarily
  3821. a \term{bidirectional} \term{stream} that connects to the user's console.
  3822. Typically, writing to this \term{stream}
  3823. would cause the output to appear
  3824. on a display screen, for example, and reading from the \term{stream} would
  3825. accept input from a keyboard. It is intended
  3826. that standard input functions such as \funref{read} and \funref{read-char},
  3827. when used with this \term{stream}, cause echoing of the input
  3828. into the output side of the \term{stream}. The means by which this is
  3829. accomplished are \term{implementation-dependent}.
  3830. %% 21.1.0 11, clarified by KMP
  3831. The effect of changing \thevalueof{*terminal-io*},
  3832. either by \term{binding} or \term{assignment},
  3833. is \term{implementation-defined}.
  3834. \label Examples::
  3835. \code
  3836. (progn (prin1 'foo) (prin1 'bar *terminal-io*))
  3837. \OUT FOOBAR
  3838. \EV BAR
  3839. (with-output-to-string (*standard-output*)
  3840. (prin1 'foo)
  3841. (prin1 'bar *terminal-io*))
  3842. \OUT BAR
  3843. \EV "FOO"
  3844. \endcode
  3845. \label Affected By:\None.
  3846. \label See Also::
  3847. \varref{*debug-io*},
  3848. \varref{*error-output*},
  3849. \varref{*query-io*},
  3850. \varref{*standard-input*},
  3851. \varref{*standard-output*},
  3852. \varref{*trace-output*}
  3853. \label Notes:\None.
  3854. \endcom
  3855. %-------------------- Stream Errors --------------------
  3856. \begincom{stream-error}\ftype{Condition Type}
  3857. \label Class Precedence List::
  3858. \typeref{stream-error},
  3859. \typeref{error},
  3860. \typeref{serious-condition},
  3861. \typeref{condition},
  3862. \typeref{t}
  3863. \label Description::
  3864. \Thetype{stream-error}
  3865. consists of error conditions that are related to receiving input from
  3866. or sending output to a \term{stream}.
  3867. The ``offending stream'' is initialized by
  3868. \theinitkeyarg{stream} to \funref{make-condition},
  3869. and is \term{accessed} by \thefunction{stream-error-stream}.
  3870. \label See Also::
  3871. \funref{stream-error-stream}
  3872. \endcom%{stream-error}\ftype{Condition Type}
  3873. %%% ========== STREAM-ERROR-STREAM
  3874. \begincom{stream-error-stream}\ftype{Function}
  3875. \label Syntax::
  3876. \DefunWithValues stream-error-stream {condition} {stream}
  3877. \label Arguments and Values::
  3878. \param{condition}---a \term{condition} \oftype{stream-error}.
  3879. \param{stream}---a \term{stream}.
  3880. \label Description::
  3881. Returns the offending \term{stream} of a \term{condition} \oftype{stream-error}.
  3882. \label Examples::
  3883. \code
  3884. (with-input-from-string (s "(FOO")
  3885. (handler-case (read s)
  3886. (end-of-file (c)
  3887. (format nil "~&End of file on ~S." (stream-error-stream c)))))
  3888. "End of file on #<String Stream>."
  3889. \endcode
  3890. % )
  3891. \label Side Effects:\None.
  3892. \label Affected By:\None.
  3893. \label Exceptional Situations:\None.
  3894. \label See Also::
  3895. \typeref{stream-error},
  3896. {\secref\Conditions}
  3897. \label Notes:\None.
  3898. %% This shouldn't be needed.
  3899. %It is an error to use \macref{setf} with \funref{stream-error-stream}.
  3900. \endcom
  3901. \begincom{end-of-file}\ftype{Condition Type}
  3902. \label Class Precedence List::
  3903. \typeref{end-of-file},
  3904. \typeref{stream-error},
  3905. \typeref{error},
  3906. \typeref{serious-condition},
  3907. \typeref{condition},
  3908. \typeref{t}
  3909. \label Description::
  3910. \Thetype{end-of-file} consists of
  3911. error conditions related to read operations that are done on
  3912. \term{streams} that have no more data.
  3913. \label See Also::
  3914. \funref{stream-error-stream}
  3915. \endcom%{end-of-file}\ftype{Condition Type}