Home
Sections - MIT Computer Science and Artificial Intelligence Laboratory
Contents
1. 192 type predicate for pathname host 195 type predicate for port 159 type predicate for primitive procedure 148 type predicate for procedure 148 type predicate for promise 116 type predicate for record oo ooooo 115 type predicate for record type 115 type predicate for stream pair 118 type predicate for string oooooooo o o 73 type predicate for symbol TIL type predicate for VectOT ooooooooooooo 102 type predicate for weak pair 119 type conditioneren iia 226 type of condition 22 once enc 240 type Of procedure 2 25 2 ee red Enea 147 type pathname component 189 types latent defn 0 0 005 3 types manifest defn 0 000000 3 types Windows ded rre ete 274 U unassigned variable ooo oooooooooooo 14 unassigned variable defn 000 7 unassigned variable and assignment 24 unassigned variable and definition 23 unassigned variable and dynamic bindings 21 unassigned variable and named let 29 unbound variable cesses 14 unbound variable defn ooocooccccccccc 7 uninterned symbol defn 110 universal tie 2o le be ood e 205 unparser method defn 0 174 unspecified resul
2. 274 form special deli cesso REIR REPERI 14 formal parameter list of lambda defn i7 format directive defn 00 171 format entry ri eee RD RUE RE RAD 5 G generalization of condition types 226 227 240 241 generalization of condition types defn 225 generating external representation 169 gensym see uninterned symbol 112 geometry string X graphics 260 graphic character defn 69 graphiCSce sore a ae ae Ge E Hber Pos 251 graphics itMapS iis eee ee nbd 257 graphics buffering of output 256 graphics Circle usi emper EET 265 graphics clipping come 256 graphics coordinate systems 252 graphics cursor defn oooococccccccoc 253 graphics custom operations 257 graphics device coordinates defn 252 graphics drawing oooooooccccccccoooo o 253 graphics drawing arcs and circles 260 261 graphics drawing mode defn 254 graphics ellipse coco 90904 urb chee e 265 graphics images mocis e EU RR RR REA 257 graphics line style defn suus 255 graphics opening and closing devices 251 graphics output characteristics 254 graphics virtual coordinates defn 252 greatest common divisor of numbers 50 growing of vector iil en e ero pce e d
3. T environment initial defn sues 7 environment of procedure oooccoooccooooo Df environment procedure closing defn Ek environment procedure invocation defn 17 EOF object construction 179 EOF object predicate for 0 166 equivalence predicate defn us 37 equivalence predicate for bit strings 107 equivalence predicate for boolean objects 110 equivalence predicate for characters 65 equivalence predicate for fixnums 57 equivalence predicate for flonums 59 equivalence predicate for numbers 47 equivalence predicate for pathname host 195 equivalence predicate for pathnames 192 equivalence predicate for strings 13 equivalence predicate of hash table 126 equivalence predicates for characters 65 error messages CONVenti0QS ooo oooo 228 error in examplesS o ooooooooomoooo 4 error unassigned variable 0 o o 7 error unbound variable defn 7 error gt notational convention 4 errors notational conventions 4 escape character for string 71 escape procedure defn 0 149 escape procedure alternate invocation 150 evaluation order of arguments 15 evaluation call by ne
4. gt 6 1 3 5 2 do variable init step test expression command special form do is an iteration construct It specifies a set of variables to be bound how they are to be initialized at the start and how they are to be updated on each iteration When a termination condition is met the loop exits with a specified result value do expressions are evaluated as follows The init expressions are evaluated in some unspecified order the variables are bound to fresh locations the results of the init expressions are stored in the bindings of the variables and then the iteration phase begins Each iteration begins by evaluating test if the result is false then the command expressions are evaluated in order for effect the step expressions are evaluated in some unspecified order the variables are bound to fresh locations the results of the steps are stored in the bindings of the variables and the next iteration begins If test evaluates to a true value then the expressions are evaluated from left to right and the value of the last expression is returned as the value of the do expression If no expressions are present then the value of the do expression is unspecified in standard Scheme in MIT Scheme the value of test is returned The region of the binding of a variable consists of the entire do expression except for the inits It is an error for a variable to appear more than once in the list of do variables Cha
5. ge environment procedure Changes the current REP loop environment to environment Environment can be either an environment or a procedure object If it s a procedure the environment in which that procedure was closed is the new environment 13 4 Interpreter Environments The operations in this section return environments that are constructed by the inter preter These operations should only be used at the top level of a file they are not supported in any other place In particular they force the current environment to be represented in a form suitable for use by the interpreter This prevents the compiler from performing many useful optimizations on such environments and forces the use of the interpreter for variable references in them However because all top level environments such as user initial environment are already interpreter environments it does no harm to use such operations on them Warning A future release of MIT Scheme will support hygienic macros which are incompatible with non top level instances of make environment and the environment At that time other uses of these constructs will be disallowed make environment expression special form Produces a new environment that is a child of the environment in which it is executed evaluates the expressions sequentially in the new environment and returns the new environment Note that make environment expression is equivalent to let O expression t
6. lambda expression defn 044 lambda list defn 0 00 000 00005 lambda implicit in define lambda implicit in let latent types defn eie lazy evaluation defn 0000 eee least common multiple of numbers length of bit string 4 cse tems length of bit string defn length of list defM ooooooo ooomoo length of stream ooooooccocooccomoo length of string Lund pere length of string defn oooooocccoo length of vector defn ooooocooomo o o letrec implicit in define lexical binding expression lexical conventions I is lexical scoping defn 00020 00 ee library system pathname limitations x 14 tota arabe 313 line style graphics defn 0 255 linking hard of fille 0 0 198 linking soft of file ecce eres 199 List AGM urticaria 87 list index den ces tabs 92 list association defn sssuesus 121 list converting to StreaM ooooo oooooooo 118 list converting to string 72 list converting to vector oooooooooooooo 102 list external representation sss 87 list improper defn 000 eee eee 87 literal expression defn oooococccccccoo 14 literal and quasiquote 00 0
7. t f HN Overview 13 The backquote indicates almost constant data see Section 2 6 Quoting page 24 The comma is used in conjunction with the backquote see Section 2 6 Quoting page 24 A comma followed by an at sign is used in conjunction with the backquote see Section 2 6 Quoting page 24 The sharp or pound sign has different uses depending on the character that immediately follows it These character sequences denote the boolean constants see Section 10 1 Booleans page 109 This character sequence introduces a character constant see Chapter 5 Char acters page 63 This character sequence introduces a vector constant see Chapter 8 Vectors page 101 A close parenthesis terminates a vector constant e Hi Hb Ho Hd 1 Hs x Hx amp 0 Tt These character sequences are used in the notation for numbers see Chapter 4 Numbers page 43 This character sequence introduces an extended comment The comment is terminated by the sequence This notation is an MIT Scheme extension This character sequence is used to denote a small set of named constants Cur rently there are only two of these optional and rest both of which are used in the lambda special form to mark certain parameters as being optional or rest parameters This notation is an MIT Scheme extension This character sequence introduces a bit string see Chapter 9 Bit Stri
8. Chapter 13 Environments 155 13 Environments 13 1 Environment Operations Environments are first class objects in MIT Scheme An environment consists of some bindings and possibly a parent environment from which other bindings are inherited The operations in this section reveal the frame like structure of environments by permitting you to examine the bindings of a particular environment separately from those of its parent environment object procedure Returns t if object is an environment otherwise returns amp f environment has parent environment procedure Returns t if environment has a parent environment otherwise returns f environment parent environment procedure Returns the parent environment of environment It is an error if environment has no parent environment bound names environment procedure Returns a newly allocated list of the names symbols that are bound by environ ment This does not include the names that are bound by the parent environment of environment environment bindings environment procedure Returns a newly allocated list of the bindings of environment does not include the bindings of the parent environment Each element of this list takes one of two forms name indicates that name is bound but unassigned while name object indicates that name is bound and its value is object environment bound environment symbol procedure Returns stt if symbol is bound in environment or one of its
9. Chapter 4 Numbers 45 An implementation of Scheme must support exact integers throughout the range of numbers that may be used for indexes of lists vectors and strings or that may result from computing the length of a list vector or string The length vector length and string length procedures must return an exact integer and it is an error to use anything but an exact integer as an index Furthermore any integer constant within the index range if expressed by an exact integer syntax will indeed be read as an exact integer regardless of any implementation restrictions that may apply outside this range Finally the procedures listed below will always return an exact integer result provided all their arguments are exact integers and the mathematically expected result is representable as an exact integer within the implementation gcd modulo imag part numerator inexact gt exact quotient abs 1cm rationalize angle magnitude real part ceiling make polar remainder denominator make rectangular round expt max truncate floor min Implementations are encouraged but not required to support exact integers and exact rationals of practically unlimited size and precision and to implement the above procedures and the procedure in such a way that they always return exact results when given exact arguments If one of these procedures is unable to deliver an exact result when given exact arguments then it may either report a violation
10. These procedures return t if all the letters in the string substring are of the correct case otherwise they return f The string substring must contain at least one letter or the procedures return f map string upper case A art Art ART gt tf tt f f t string capitalize string procedure string capitalize string procedure substring capitalize string start end procedure string capitalize returns a newly allocated copy of string in which the first alpha betic character is uppercase and the remaining alphabetic characters are lowercase For example abcDEF becomes Abcdef string capitalize is the destructive version of string capitalize it alters string and returns an unspecified value substring capitalize destructively capitalizes the specified part of string string downcase string procedure string downcase string procedure substring downcase string start end procedure string downcase returns a newly allocated copy of string in which all uppercase letters are changed to lowercase string downcase is the destructive version of string downcase it alters string and returns an unspecified value substring downcase destructively changes the case of the specified part of string define str ABCDEFG gt unspecified substring downcase str 3 5 unspecified str ABCdeFG 76 MIT Scheme Reference string upcase string procedure string upcase string procedure substring upcase str
11. and 1 2 c f g gt f g and gt t Or expression special form The expressions are evaluated from left to right and the value of the first expression that evaluates to a true value is returned Any remaining expressions are not eval uated If all expressions evaluate to false values the value of the last expression is returned If there are no expressions then f is returned or 2 2 2 1 gt dit or 2 2 lt 2 1 gt dtt or 4f f f gt df or memq b ab c 3 0 gt bc 2 8 Sequencing The begin special form is used to evaluate expressions in a particular order Chapter 2 Special Forms 29 begin expression expression special form The expressions are evaluated sequentially from left to right and the value of the last expression is returned This expression type is used to sequence side effects such as input and output define x 0 begin set x 5 x 1 gt 6 begin display 4 plus 1 equals display 4 1 4 plus 1 equals 5 gt unspecified Often the use of begin is unnecessary because many special forms already support sequences of expressions that is they have an implicit begin Some of these special forms are case cond define procedure define only do fluid let lambda let let letrec named lambda The obsolete special form sequence is identical to begin It should not be used in new code 2 9 Iteration The iteration expressions are
12. rather than the actual procedures and even so if a garbage collection occurs during the execution of the callback procedure objects in Scheme s heap will have moved Thus in a foreign procedure that has a callback and a string after calling the callback the string value may no longer be valid Playing this game requires a profound knowledge of the implementation The interface to the FFI has two main components a language for declaring the types of values passed to and returned from the foreign procedures and a form for declaring foreign procedures 18 2 1 Windows Types Foreign types are designed to represent a correspondence between a Scheme data type that is used to represent an object within the Scheme world and a C data type that represents the data object in the C world Thus we cannot manipulate true C objects in Scheme nor can we manipulate Scheme objects in C Each foreign type has four aspects that together ensure that the correspondence between the Scheme and C objects is maintained These aspects are all encoded as procedures that either check for validity or convert between representations Thus a foreign type is not a declarative type so much as a procedural description of how to pass the type The underlying foreign procedure call mechanism can pass integers and vector like Scheme objects and returns integer values All other objects must be translated into integers or some other basic type and must be recovered from integer
13. 2c wer eo adum 103 Vector set talca 102 vector seventh 15ife2100R RESI Rb YS 103 vector sixth ehi oasian su peaa ana red 103 vector tarl ir 103 vector third scordar merae Eroe E E 103 VeGtbOET nsu ibd ya ai la wae DENE E 102 WA ia EEE EELEE 227 234 Weak Car rl 120 Weak cdr i22 ae a pep i nE RR AE ER 120 Weak CONS ciar 119 weak hash table constructor 126 weak pair car 0c eee 119 132 Heak Palt iii eee Pants 119 weak set cab icon 120 eak set ecards hers 120 PSP Eae URN estes 175 window frame size on os2 graphics device 268 window position on os2 graphics device 267 window size on os2 graphics device 268 windows procedure cc er 277 with current unparser state 175 with input from binary file 163 with input from f3l6 5 dee eked 163 with input from port ccc iit eme 160 with input from string 164 with interaction i o port 160 with notification output port 160 with output to binary file 163 with output to fil6 clem RR 163 with o tput to port iic2bee RR peres 160 with output to string ss 164 with output to truncated string 164 WITH TOS tiamina 226 231 233 235 with simple restart 291 232 235 with string outp t port o irre iesca iers 164 With timingS casi rea 214 Binding Index with trace output port se
14. An expression consisting of an identifier see Section 1 3 3 Identifiers page 11 is a variable reference the identifier is the name of the variable being referenced The value of the variable reference is the value stored in the location to which the variable is bound An error is signalled if the referenced variable is unbound or unassigned define x 28 x 1 4 3 Special Form Syntax keyword component A parenthesized expression that starts with a syntactic keyword is a special form Each special form has its own syntax which is described later in the manual The following list contains all of the syntactic keywords that are defined when MIT Scheme is initialized access define syntax macro and delay make environment begin do named lambda case fluid let or cond if quasiquote cons stream in package quote declare lambda Scode quote default object let Sequence define let set define integrable let syntax the environment define macro letrec unassigned define structure local declare 1 4 4 Procedure Call Syntax using syntax Chapter 1 Overview 15 operator operand A procedure call is written by simply enclosing in parentheses expressions for the proce dure to be called the operator and the arguments to be passed to it the operands The operator and operand expressions are evaluated and the resulting procedure is passed the resulting arguments See Section 2 1 Lambda Expressions page 17 f
15. The author s and publisher s of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version COMBINING DOCUMENTS GNU Free Documentation License 287 You may combine the Document with other documents released under this License under the terms defined in section 4 above for modified versions provided that you include in the combination all of the Invariant Sections of all of the original documents unmodified and list them all as Invariant Sections of your combined work in its license notice The combined work need only contain one copy of this License and multiple identical Invariant Sections may be replaced with a single copy If there are multiple Invariant Sections with the same name but different contents make the title of each such section unique by adding at the end of it in parentheses the name of the original author or publisher of that section if known or else a unique number Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work In the combination you must combine any sections entitled History in the various original documents forming one section entitled History likewise combine any sec tions entitled Acknowledgements and any sections entitled Dedications You must delete all sections entitled Endorsements 6 COLLECTIONS OF DOCUME
16. To continue call RESTART with an option number RESTART 3 gt Specify a value to use instead of foo RESTART 2 gt Set foo to a given value RESTART 1 gt Return to read eval print level 1 condition type arithmetic error operator operands condition type This is an abstract type It indicates that a numerical operation was unable to com plete because of an arithmetic error For example division by zero The operator field contains the procedure that implements the operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure condition type divide by zero operator operands condition type This type is generated when a program attempts to divide by zero The operator field contains the procedure that implements the failing operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure 1 0 Division by zero signalled by To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 error divide by zero operator operands procedure This procedure signals a condition of type condition type divide by zero The operator and operands fields of the condition are filled in from the corresponding arguments to the procedure condition type floating point overflow operator operands condition type This type is generated when a pr
17. procedure y x gt 100 MIT Scheme Reference If sequence is a list vector sort returns a newly allocated list vector whose ele ments are those of sequence except that they are rearranged to be sorted in the order defined by procedure So for example if the elements of sequence are numbers and procedure is lt then the resulting elements are sorted in monotonically nondecreasing order Likewise if procedure is gt the resulting elements are sorted in monotonically nonincreasing order To be precise if x and y are any two adjacent elements in the result where x precedes y it is the case that procedure y x gt Two sorting algorithms are implemented merge sort and quick sort The proce dure sort is an alias for merge sort See also the definition of sort Chapter 8 Vectors 101 8 Vectors Vectors are heterogenous structures whose elements are indexed by exact non negative integers A vector typically occupies less space than a list of the same length and the average time required to access a randomly chosen element is typically less for the vector than for the list The length of a vector is the number of elements that it contains This number is an exact non negative integer that is fixed when the vector is created The valid indexes of a vector are the exact non negative integers less than the length of the vector The first element in a vector is indexed by zero and the last element is indexed by one l
18. All characters for which the char bits procedure returns O or 1 i e no bucky bits or just Meta count as legal ASCII characters char gt ascii char procedure Returns the ASCH code for char An error condition type bad range argument is signalled if char doesn t have an ASCII representation ascii gt char code procedure Code must be the exact integer representation of an ASCII code This procedure returns the character corresponding to code 5 6 Character Sets MIT Scheme s character set abstraction is used to represent groups of characters such as the letters or digits Character sets may contain only ASCII characters in the future this may be changed to allow the full range of characters There is no meaningful external representation for character sets use char set members to examine their contents There is at present no specific equivalence predicate for char acter sets use equal for this purpose char set object procedure Returns t if object is a character set otherwise returns f Chapter 5 Characters 69 char set upper case variable char set lower case variable char set alphabetic variable char set numeric variable char set alphanumeric variable char set whitespace variable char set not whitespace variable char set graphic variable char set not graphic variable char set standard variable These variables contain predefined character sets To see the contents of one of these sets use char set
19. CONS Se shite eb Seah as 88 CONST Em 91 COnS SLrOam 2 0 bee nee ee cee tes 118 Console i 0 POE ui res dene es 159 161 di AAA 160 console output pOrt sse RIS nes 160 CODSLEUCLOE 2 lude ber ii E ned 33 contindatjon hesitated ia bw 150 Continue ssec pla Reged epo wir don gs 231 234 COP mein ri ia aia de 33 copy area on win32 graphics device 266 copy area on x graphics device 262 copy bitmap ec eec eee ugue 281 CODy fil6 io 198 COS ii odds bi A cre te dib ius a 281 create image on graphics device 257 rop DitMap cocida dei ete 281 current t le tiMO mueca ne Rs 202 c rrent input port miii er 160 163 current outp t port e 160 163 164 D day of week long string 212 day of week short string 212 deactivate window on os2 graphics device 269 sp n siria m 175 decoded time gt file time 210 decoded time string lesse 210 decoded time gt universal time 210 293 decoded time date string 212 decoded time day i eiiis er RE Heg 207 decoded time day of week 207 decoded time daylight savings time 207 decoded time hoUT o 207 decoded time minute 207 decoded time month 000000 207 decoded time second 207 decoded time time string 212 decoded time year 00 000 207 deco
20. The returned procedure accepts exactly one argument which must be a proper list and applies predicate to each of the elements of the argument deleting those for which it is true The procedure returned by list deletor deletes elements non destructively by re turning a newly allocated copy of the argument with the appropriate elements re moved The procedure returned by list deletor performs a destructive deletion 7 6 Searching Lists 96 MIT Scheme Reference list search positive list predicate procedure list search negative list predicate procedure Returns the first element in list for which predicate is respectively true or false re turns f if it doesn t find such an element This means that if predicate is true false for 4f it may be impossible to distinguish a successful result from an unsuccessful one Predicate must be a procedure of one argument memq object list procedure memv object list procedure member object list procedure These procedures return the first pair of list whose car is object the returned pair is always one from which list is composed If object does not occur in list f n b not the empty list is returned memq uses eq to compare object with the elements of list while memv uses eqv and member uses equal memq a a b c gt abc memq b a b c gt bc memqg a bc d gt H memq list a b a c gt f member list a b a c fa c memq 1
21. an end of file object is returned In MIT Scheme if input port is an interactive input port and no characters are immediately available read char will hang waiting for input even if the port is in non blocking mode peek char input port procedure Returns the next character available from input port without updating input port to point to the following character If no more characters are available an end of file object is returned In MIT Scheme if input port is an interactive input port and no characters are immediately available peek char will hang waiting for input even if the port is in non blocking mode The value returned by a call to peek char is the same as the value that would have been returned by a call to read char on the same port The only difference is that the very next call to read char or peek char on that input port will return the value returned by the preceding call to peek char In particular a call to peek char on an interactive port will hang waiting for input whenever a call to read char would have hung 166 MIT Scheme Reference char ready input port procedure Returns t if a character is ready on input port and returns f otherwise If char ready returns t then the next read char operation on input port is guaranteed not to hang If input port is a file port at end of file then char ready returns ttt read input port procedure Converts external representations of Scheme objects int
22. bar bar rtd gt t record type 19 conc name name structure option By default the prefix for naming accessors and modifiers is the name of the structure followed by a hyphen The conc name option can be used to specify an alternative If name is not given the prefix is the name of the structure followed by a hyphen the default If name is f the slot names are used directly without prefix Otherwise name must a symbol and that symbol is used as the prefix define structure foo conc name moby a b defines accessors moby a and moby b and modifiers set moby a and set moby b define structure foo conc name f a b defines accessors a and b and modifiers set a and set b type representation type structure option This option cannot be used with the type descriptor option By default structures are implemented as records The type option overrides this default allowing the programmer to specify that the structure be implemented using another data type The option value representation type specifies the alternate data type it is allowed to be one of the symbols vector or list and the data type used is the one corresponding to the symbol Chapter 2 Special Forms 35 If this option is given and the named option is not specified the representation will not be tagged and neither a predicate nor a type descriptor will be defined also the print procedure option may not be given define structure foo type list
23. but may alternately be lists or vectors The accessors and modifiers are marked with compiler declara tions so that calls to them are automatically transformed into appropriate references Often no options are required so a simple call to define structure looks like define structure foo a b c This defines a type descriptor foo a constructor make foo a predicate foo ac cessors foo a foo b and foo c and modifiers set foo a set foo b and set foo c In general if no options are specified define structure defines the following using the simple call above as an example type descriptor The name of the type descriptor is the same as the name of the structure e g foo The type descriptor satisfies the predicate record type 32 MIT Scheme Reference constructor The name of the constructor is make followed by the name of the structure e g make foo The number of arguments accepted by the constructor is the same as the number of slots the arguments are the initial values for the slots and the order of the arguments matches the order of the slot definitions predicate The name of the predicate is the name of the structure followed by e g foo The predicate is a procedure of one argument which re turns stt if its argument is a record of the type defined by this structure definition and f otherwise accessors For each slot an accessor is defined The name of the accessor is formed by
24. defn oooococccccccccc 101 vector length defn 0 0000 101 MIT Scheme Reference Vector Dybe x cadet prp re ee dani 84 vector converting to list 91 version pathname component 189 virtual coordinates graphics defn 252 W WANTING ic ue dede eie ad 274 weak pair defn ooooocccccccccccccco 119 weak pair and 1D table 123 weak types defd ooooooccoccccccccccc 3 weakly held keys of hash table 126 weight balanced binary trees 138 whitespace character defd 0 ooo 69 whitespace in programs defn 10 Win32 API names 2 cess te ee eae 278 Wins grap Mie dispar RS REF Ren 263 Windows types oven rra 274 working directory see current working directory id ita 197 X display graphicsS 00ooooooooccocooocoo 259 X geometry string graphics 260 X BIaphiCS ers ida 258 X resources graphicS oo oooooo oo 259 X window system 2 cece eee eee 258 Short Contents Acknowledgements e EDI AAA 1 o sso seseo xs REA OR ESS SEEK OH 3 2 pecial PORTS S soc ek ets ee ws IC AAA D e Se 17 9 Egquvalence Predicatess aus kh mad uox aatinaa RR Cd 2 ot 4 Number nio a ae Ee Re RE ee SS 43 5 Characters 144 400 a 9o 0 eS ewe eee de ROS OR RR Ye RS 63 O SNES unica ened ceeds acdc eines eee ue wee eS 71 DISEASE AAA 87 BR VeGLO
25. dit equal make vector 5 a make vector 5 a gt dtt equal lambda x x lambda y y gt unspecified 42 MIT Scheme Reference Chapter 4 Numbers 43 4 Numbers This section is largely taken from the Revised 4 Report on the Algorithmic Language Scheme Numerical computation has traditionally been neglected by the Lisp community Until Common Lisp there was no carefully thought out strategy for organizing numerical com putation and with the exception of the MacLisp system little effort was made to execute numerical code efficiently This report recognizes the excellent work of the Common Lisp committee and accepts many of their recommendations In some ways this report simplifies and generalizes their proposals in a manner consistent with the purposes of Scheme It is important to distinguish between the mathematical numbers the Scheme numbers that attempt to model them the machine representations used to implement the Scheme numbers and notations used to write numbers This report uses the types number complex real rational and integer to refer to both mathematical numbers and Scheme numbers Machine representations such as fixed point and floating point are referred to by names such as fiznum and flonum 4 1 Numerical types Mathematically numbers may be arranged into a tower of subtypes in which each level is a subset of the level above it number complex real rational integer For exa
26. epoch is the representation of midnight January 1 1970 UTC in universal time for mat epoch 2208988800 15 5 2 Decoded Time Objects representing standard time components such as seconds and minutes are re quired to be exact non negative integers Seconds and minutes must be inclusively between O and 59 hours between 0 and 23 days between 1 and 31 months between 1 and 12 years are represented in four digit form in which 1999 is represented as 1999 not 99 206 MIT Scheme Reference local decoded time procedure Return the current time in decoded format The decoded time is represented in the local time zone pp local decoded time decoded time 76 second 2 minute 12 hour 11 4 day 27 month 4 4 year 1999 day of week 1 daylight savings time 1 zone 5 global decoded time procedure Return the current time in decoded format The decoded time is represented in UTC pp global decoded time decoded time 77 second 8 minute 12 hour 15 4 day 27 month 4 4 year 1999 day of week 1 4 daylight savings time 0 4 zone 0 make decoded time second minute hour day month year zone procedure Return a new decoded time object representing the given time The arguments must be valid components according to the above rules and must form a valid date If zone is not supplied or is f the resulting decoded time will be represent
27. file type indirect filename file regular filename procedure Returns stt if the file named filename exists and is a regular file i e not a directory symbolic link device file etc Otherwise returns 4f In operating systems that support symbolic links if filename names a symbolic link this examines the file linked to not the link itself This is equivalent to eq regular file type indirect filename file symbolic link filename procedure In operating systems that support symbolic links if the file named filename exists and is a symbolic link this procedure returns the contents of the symbolic link as a newly allocated string The returned value is the name of the file that the symbolic link points to and must be interpreted relative to the directory of filename If filename either does not exist or is not a symbolic link or if the operating system does not support symbolic links this procedure returns f file type direct filename procedure file type indirect filename procedure If the file named filename exists file type direct returns a symbol specifying what type of file it is For example if filename refers to a directory the symbol directory is returned If filename doesn t refer to an existing file f is returned If filename refers to a symbolic link file type direct returns the type of the link itself while file type indirect returns the type of the file linked to At this time the symbols that can be
28. gt 1 f procedure arity lambda x optional y x gt 1 2 procedure environment procedure procedure Returns the closing environment of procedure Signals an error if procedure is a primitive procedure or if procedure is a compiled procedure for which the debugging information is unavailable Chapter 12 Procedures 149 12 2 Primitive Procedures make primitive procedure name arity procedure Name must be a symbol Arity must be an exact non negative integer 1 or stt if not supplied it defaults to Returns the primitive procedure called name May perform further actions depending on arity f If the primitive procedure is not implemented signals an error t If the primitive procedure is not implemented returns f integer If the primitive procedure is implemented signals an error if its arity is not equal to arity If the primitive procedure is not implemented returns an unimplemented primitive procedure object that accepts arity arguments An arity of 1 means it accepts any number of arguments primitive procedure name primitive procedure procedure Returns the name of primitive procedure a symbol primitive procedure name car gt car implemented primitive procedure primitive procedure procedure Returns t if primitive procedure is implemented otherwise returns f Useful be cause the code that implements a particular primitive procedure is not necessarily linked into the executable Scheme pr
29. gt Nyon string trim but x y is char set gt x y 6 6 Searching Strings The first few procedures in this section perform string search in which a given string the text is searched to see if it contains another given string the pattern as a proper substring At present these procedures are implemented using a hybrid strategy For short patterns of less than 4 characters the naive string search algorithm is used For longer patterns the Boyer Moore string search algorithm is used string search forward pattern string procedure substring search forward pattern string start end procedure Pattern must be a string Searches string for the leftmost occurrence of the substring pattern If successful the index of the first character of the matched substring is returned otherwise f is returned substring search forward limits its search to the specified substring of string string search forward searches all of string 78 MIT Scheme Reference string search forward rat pirate 8 P gt 2 string search forward rat pirate rating gt 2 substring search forward rat pirate rating 4 13 gt 7 substring search forward rat pirate rating 9 13 gt f string search backward pattern string procedure substring search backward pattern string start end procedure Pattern must be a string Searches string for the rightmost occurrence of the substring pattern If successful the index
30. hee ph ii pia eds 159 input operatios seser coco ee Rb a 165 input port operatie s erriei eier essit 179 input port console ooooooooooooo 161 input port current defn o o ooo o 159 input port file 2 222 solos x le t p 161 input port string soessose som mms 163 insensitivity to case in programs defn 11 installed as pathname component 191 instance of condition defn 237 integer divisionis sss dac me ye RR abia a 49 Concept Index integer converting to bit string interactive input ports defn internal definitioO 0o ooooooomooo internal definition defn su internal representation for character internal representation for inexact number interned symbol defn oooooooocoo o interning of symbolsS oo o ooooo o o o interpreted procedure type inverse additive of number inverse multiplicative of number inverse of bit String oooooooo inverse of boolean Object invocation environment of procedure defn iteration expression defn K key of association list element defn keyword constructor ooooooococcccccco oo keyword constructor defn isse keyword of special form defn L l as exponent marker in number
31. it defaults to string append char gt name char t name gt char string Converts a string that names a character into the character specified If string does not name any character name gt char signals an error name gt char name gt char name gt char name gt char Wal space c a control a V V V procedure Ha Space C a C a Chapter 5 Characters 65 5 2 Comparison of Characters char charl char2 procedure char lt charl char2 procedure char gt charl char2 procedure char lt charl char2 procedure char charl char2 procedure char ci charl char2 procedure char ci lt charl char2 procedure char ci gt charl char2 procedure char ci lt charl char2 procedure char ci gt charl char2 procedure Returns t if the specified characters are have the appropriate order relationship to one another otherwise returns f The ci procedures don t distinguish uppercase and lowercase letters Character ordering follows these rules e The digits are in order for example char lt 0 4X9 returns stt e The uppercase characters are in order for example char lt HA HB returns t e The lowercase characters are in order for example char a b returns t In addition MIT Scheme orders those characters that satisfy char standard the same way that ASCII does Specifically all the digits precede all the uppercase letters and all the upper
32. it is necessary to redefine the clip rectangle afterwards Chapter 17 Graphics 253 17 3 Drawing Graphics The procedures in this section provide the basic drawing capabilities of Scheme s graphics system graphics clear graphics device procedure Clears the display of graphics device Unaffected by the current drawing mode graphics draw point graphics device x y procedure Draws a single point on graphics device at the virtual coordinates given by x and y using the current drawing mode graphics erase point graphics device x y procedure Erases a single point on graphics device at the virtual coordinates given by x and y This procedure is unaffected by the current drawing mode This is equivalent to lambda device x y graphics bind drawing mode device 0 lambda graphics draw point device x y graphics draw line graphics device x start y start x end y end procedure X start y start x end and y end must be real numbers Draws a line on graphics device that connects the points x start y start and x end y end The line is drawn using the current drawing mode and line style graphics draw text graphics device x y string procedure Draws the characters of string at the point x y on graphics device using the current drawing mode The characteristics of the characters drawn are device dependent but all devices are initialized so that the characters are drawn upright from left to right with the leftmost edg
33. lesse 181 substring searching string for tb subtraction of numbers 0 00 48 subvector defn 2 20 002 eee 101 o 1s ne ep E RARI MPG DAR hee 80 sum of numbers crx ei Rue 48 super bucky bit prefix defn 63 symbol defn s scestttders the ERSA 110 Concept Index symbolic link predicate for 200 symbolic linking of file 199 synchronous subprocess ssss elles 215 syntactic keyword ooooooooooooommmo oo 15 syntactic keyword defn ssssssuss 14 syntactic keyword identifier aS 11 T table association defn 124 table one dimensional defn 123 tail recursion defn 0 2 0000 3 tail recursion vs iteration expression 29 taxonomical link of condition type defn 225 terminal mode of port 000 00 183 terminal screen clearing 170 Dj PER 213 time decoded ccce eser xe 205 time Bie uui a eb es meos repu 205 tune String a6 eb eee ecd Tonke P Yd reds 205 time universal 2 oec plz er Rd ye 205 token in programs defn iuuuee 10 top bucky bit prefix defn ooo ooo 63 top level definition oo ooooooomooo 28 top level definition defn ssuss 22 total ordering defn 2 0 0 99 tree COPYING es
34. object hash ica de la s 134 object hashed cian ici 134 object u nhash los ru EIE rd RES 135 OQ i hxc Pu eaae na eek d Ds op ect ied 48 open binary i o file ioo nee erm 162 open binary input file 162 open binary output file 162 Opeh dibus iia aan 280 open1 0 files sends coe dd 162 open input file6 2222 9 ee ae 162 open output flXle 5 2 DRE IRR 162 open tcp server socket ess 220 open tcp stream socket 220 o rc cT 28 109 0S hoBthames irradia 223 os2 file mode archived 201 os2 file mode directory 201 os2 file mode hidden 0 201 os2 file mode read only 201 os2 file mode system 00 201 Output sol 217 o tp t b ffer sizZe ia cd 218 output buffer size on output port 182 output line translation lt lt 218 output port type deme ci 178 299 output port discretionary flush output 181 output port flush output 181 output port fresh line 181 output port write char sss 181 output port write string 181 output port write substring 181 o tput port x size i e ene p nds 182 o tput port y size o or si RA 182 output port 2 9 REB RI SMARPF RE RR S 159 P pros eisai merenan Condesa ade EE Na 88 91 119 parse namestring iiiildde
35. only the console port defines discretionary flush output this is used to guarantee that output to the console appears immediately after it is written without requiring calls to flush output All optional arguments called output port if not supplied default to the current output port write char char output port procedure Writes char the character itself not a written representation of the character to output port performs discretionary output flushing and returns an unspecified value Chapter 14 Input Output 169 write string string output port procedure Writes string to output port performs discretionary output flushing and returns an unspecified value This is equivalent to writing the contents of string one character at a time using write char except that it is usually much faster write substring string start end output port procedure Writes the substring defined by string start and end to output port performs dis cretionary output flushing and returns an unspecified value This is equivalent to writing the contents of the substring one character at a time using write char except that it is usually much faster write object output port procedure Writes a written representation of object to output port and returns an unspecified value If object has a standard external representation then the written representa tion generated by write shall be parsable by read into an equivalent object Thus strings that a
36. tions page 31 make record type type name field names procedure Returns a record type descriptor a value representing a new data type disjoint from all others The type name argument must be a string but is only used for debugging purposes such as the printed representation of a record of the new type The field names argument is a list of symbols naming the fields of a record of the new type It is an error if the list contains any duplicates It is unspecified how record type descriptors are represented record constructor record type field names procedure Returns a procedure for constructing new members of the type represented by record type The returned procedure accepts exactly as many arguments as there are symbols in the given list field names these are used in order as the initial values of those fields in a new record which is returned by the constructor procedure The values of any fields not named in the list of field names are unspecified The field names argument defaults to the list of field names in the call to make record type that created the type represented by record type if the field names argument is provided it is an error if it contains any duplicates or any symbols not in the default list Chapter 10 Miscellaneous Datatypes 115 record predicate record type procedure Returns a procedure for testing membership in the type represented by record type The returned procedure accepts exactly one argument
37. write restart report restart port procedure Writes a description of restart to port This works by either displaying if it is a string or calling if it is a procedure the reporter that was supplied when the restart was created 16 5 Condition Instances A condition in addition to the information associated with its type usually contains other information that is not shared with other conditions of the same type For example the condition type associated with unbound variable errors does not specify the name of the variable that was unbound The additional information is captured in a condition object also called a condition instance In addition to information that is specific to a given type of condition such as the variable name for unbound variable conditions every condition instance also contains a continuation that encapsulates the state of the computation in which the condition occurred This continuation is used for analyzing the computation to learn more about the context in which the condition occurred It is not intended to provide a mechanism for continuing the computation that mechanism is provided by restarts 16 5 1 Generating Operations on Conditions Scheme provides four procedures that take a condition type as input and produce oper ations on the corresponding condition object These are reminiscent of the operations on record types that produce record operators see Section 10 4 Records page 114 Given a
38. 1 Jan month short string 10 Oct time zone gt string procedure Returns a string corresponding to the given time zone This string is the same string that is used to generate RFC 822 time strings time zone gt string 5 0500 time zone gt string 4 gt 0400 time zone gt string 11 2 gt 0530 15 6 Machine Time The previous section dealt with procedures that manipulate clock time This section describes procedures that deal with computer time elapsed CPU time elapsed real time and so forth These procedures are useful for measuring the amount of time it takes to execute code Some of the procedures in this section manipulate a time representation called ticks A tick is a unit of time that is unspecified here but can be converted to and from seconds by supplied procedures A count in ticks is represented as an exact integer At present each tick is one millisecond but this may change in the future process time clock procedure Returns the amount of process time in ticks that has elapsed since Scheme was started Process time is measured by the operating system and is time during which the Scheme process is computing It does not include time in system calls but depending on the operating system it may include time used by subprocesses process time clock gt 21290 real time clock procedure Returns the amount of real time in ticks that has elapsed since Scheme was started Real time is the time
39. 147 l St paiE Sorte ee Lip RATES 94 Y nl ood ru bua geh ta pes bae dd band dee ne hes 50 A godess Bede dE du bei dd 44 92 let bee bene anaes 1 19 21 22 23 29 Letras T 19 22 25 20 l trec ine x en tarttisi rit 1 20 22 23 29 298 A EE 6 90 91 99 101 list 8tr68m O bepPLepeePPLST EU 118 list 2StrXng 2 2 feet PEAS RU 12 91 list V6CbOr 4 ido Bae trae nu 91 102 lx t CODysaccleledeigociCUwereeceieib be 91 123 list deletor o uc Rims 95 123 list deletor sites mom 95 123 A PUPPI Ri aS 98 LIS Tin 92 list search negatiVe iipcinnrcosiriri esos 96 li t search positive ID REDE IER 95 Jist tallo Li1nkR su4 eb A CERES PODES 92 93 list transform negative 94 list transform positive vase seek nes eee cee 94 Eq UTE 91 122 124 load bitmap on win32 graphics device 265 l sd Oopti h i o sees 125 135 139 171 local decoded time 2 p ee es 206 localhost da Ro RR LR 195 IGE Ll snp eins tee dui a care ated etatis 52 MONG oe m eg RR erereP bde vee ee See dns 276 lower window on os2 graphics device 268 M A ee ERES 53 mnake 1d table 2 26 9409 bv PERRA 124 make pply hook c4 ies 152 make bit StriBg si c awe pae Pea 105 MAKES COM 9s cmb ak os per 114 make char i2 2 ra eee ie er aes 66 make circular l3St ii 99 make condition 226 227 239 make condition type o dam as 240 make decoded time esses 2
40. 9 required parameter defn ususuuu alg resizing of hash table 129 resources X graphicS ooooooooooomo o 259 rest parameter defn 0ooooococcccccccc 17 restart dein ibid 291 restart effector defn oooocoocccccccoo 231 restart protocol cios dh ra pta 291 restarts bound sb Rei 238 239 result of evaluation in examples 4 result unspecified defn sssuusue 5 316 reversal of Vist cig cor ias 99 ringing the console bell 170 root as pathname component 190 run time loadable option 125 135 139 171 runtime system 2 22 rerai ur odeti dew en 3 S s as exponent marker in number 46 SHOXPPOSSION cio sc de vd d eR 156 scheme concepts 0 cee e cence eee eee 6 Scheme standard 0 22 cess eee ians 3 scope see region 0 00s eee eee ee 3 scoping lexical defn 00 0000 8 SCOPING StatiG is eee ve hee eed ENS 8 Screen Clearing AA as idee meas eels 170 searching for regular expression 81 searching of alist i eror be 122 searching of bit string ooooooo o oooo 106 searching Of USE vet RUDI E SERERE 95 searching of StTiD8 0oooooooooooomoo A searching of vector 0ooooooooocoo momo 103 selecting of stream component 119 selection components of pathname 194
41. Binding Index hash table make 00 eee eee eee oo 135 hash table make entry 133 hash table put lacio posa ios da 127 hash table rehash size 130 hash table rehash threshold 131 hash table remove sess oo 128 hash table set entry datum 133 hash table size ss esses esses 130 hash table ii cic ted bee tine du 127 hbitmap e e dde pt e te 276 lahon oke E cid 276 HCUrSOM Si idiota see aa 276 nn PET 276 Bi CON sie a eles pare mE aedes Pe e Res 276 hide window on os2 graphics device 268 hinstance i 3 eskao cep p dox E oh hn 276 Linenu lc ed aid Hee aad a A dH be 276 host address any ricino ad 223 host address loopback o o 223 host namesStrihE o ccioiciiatioardcia 194 HOST eiii ri ridad 195 kolci ii ERE AERA doa does 195 hpalette nuroa griego ee hua ey ide 276 POr ro ri de 276 O eie noA baden eds hale 276 AWN EE 276 i o0 port type oacceneb dabei 178 l 0 DOPUT 25 ere RT ue LER 159 D PER 26 109 ipnor efrOr co ee ii due e ee E Racers 230 Jgnor errOIrS ica jede rie 230 imag dee ei REOR Re peche ati duci 53 imape destroy e ope E errer uprise troy 258 image fill from byte vector 258 image height 2 00 i eb RE P ES 258 inage widthu ucl vented eee E EFLFE 258 IMA ls Rhe eka es eran etree dus 258 implemented primitive procedure 149 inexact 8exa ct de oi ETE 44 53 o A
42. DLL need not necessarily be linked at or immediately after this call DLL modules are linked on need and unlinked before Scheme exits and when there are no remaining references to entry points after a garbage collection This behavior ensures that the Scheme system can run when a DLL is absent provided the DLL is not actually used i e no attempt is made to call a procedure in the DLL gdi32 dll variable This variable is bound to the module describing the GDI32 DLL library which con tains the Win32 API graphics calls e g LineTo kernel32 dll variable This variable is bound to the module describing the KERNEL32 DLL library user32 dll variable This variable is bound to the module describing the USER32 DLL library This mod ule contains many useful Win32 API procedures like MessageBox and SetWindowText windows procedure name parameter type return type special form module entry name options This form creates a procedure and could be thought of as foreign named lambda The form creates a Scheme procedure that calls the C procedure identified by the exported entry point entry name in the module identified by the value of module Both entry name and module are evaluated at procedure creation time so either may be expression Entry name must evaluate to a string and module must evaluate to a module as returned by find module These are the only parts of the form that are evaluated at procedure creation
43. E i eben bee 81 re string search backward 81 re string search forward 81 re substring match c e BR Hee eee IIS 81 re substring search backward 81 re substring search forward 81 TEA fees al ira 4 9 64 88 110 111 159 166 read button on os2 graphics device 269 read char tia ebbe TEES 159 165 166 read char on input port 179 tead char no hang ol ia 166 r ad line ee rra 167 Binding Index read only mien ce id DRESS 32 read String a ieee sede ea a eee 166 read string on input port 179 read string si e ad nini eetas 167 read substring on input port 180 read substringl iio idis nb o eretia n 167 read user event on os2 graphics device 270 real part iii iaa ban 53 real time Cclock ii ra RE 213 real iiiresawees ra v Einer 46 record accessSor ii eco rd ss 115 record conStr ctOr Zs lo toss sos 114 record modifier i edu er b EROR S 115 record predicate ici ordei cf X elvis 115 record type descriptor 115 record type field names 115 record type nale lssei s ed ERES 115 record type esere iarna berries 115 A wi PPCCSCESPPr Ta aus 115 redispla y ho0E cs ada 218 r d cG ic cbe Re berb EX a per piece oF reduce right 2 oaks la 98 r gexp grolp e 9g takes e tpp RE PE Eee i 82 remainder iaa ay 49 50 renaimn file8 l 10 oe red 198 re
44. IA ecd 104 QqUOtG8 oca add 24 88 MIT Scheme Reference R raise window on os2 graphics device 268 Taide 60 r ndom state coo doe ege oes 61 rational viii eae Pees atl be 46 rationaliz6 si cig 0 e esses nen Epe ares 51 rationalize gt exach soriana 51 rb tree alist orrei b e HERR 136 Ib tr ee GCO0py esses ied ea ur repe dee gang a i 137 rb tree datum list esse eee 136 rb tree delete 0 0 0 eee eee eee 136 rb tree delete max 0 0 eee eee 138 rb tree delete max datum 138 rb tree delete max pair 138 rb tree delete min lusus 138 rb tree delete min datum 138 rb tree delete min pair 138 rfb tree emptyTf eve RENE UE ERES 137 fb tree equal 2 a aaa 137 tb tree height ss ri evkee EREeeRPEPP RY 137 rb tree insert 22 tra DRE a 136 rb tree key lisSt dace Rees 136 rb tree loOk poisi wl RAE RENE ASPERA 136 rb tree max ockinasgukkeReegpet d NES RES 138 rb tree max datum cess eee eee 138 Tb tree max Pai iaa ce news 138 ED CHEC MID ocean b Oe ORCI 138 rb tree min datum esses esses 138 rb tree min pair dac e eres 138 rb tree 8126 4 cd 20 580 0 nd DPA nde 137 tfb tree mia m EE REO ede oki 136 re match end index ss esee eee 82 TOMATE iii nro rea 82 re match start index sess ena 82 rte string matcl iv i hene
45. Substring Sligte rer as ds 91 substring capitalizel 2 2 e nm 75 substring capitalized 75 S bStrihRg Ci 7 22 des 13 s bstring Ci4 1 5205 daros 74 substring downcase i lm endnote 75 Substring filli ii o iia 83 substring find next char news s 19 substring find next char Cci sss 9 substring find next char in set 19 substring find previous char 19 substring find previous char ci 79 substring find previous char in set 19 s bstring lower case muii iia ri i mnis 75 substring match backward 80 substring match backward ci 80 su bstring match forward ius 80 substring match forward ci 80 s bstring move left 22 2 2 2009 45 83 substring move right 83 substring prefix ci 5 kettles 80 s bstring prefix 22 2 aaa 80 303 substring replace o 000 esses e Rn 82 substring replace ziiisersieiiveaieereyd 82 substring search all eiis 78 substring search backward 78 substring search forward 77 substring suffix l 022s scaee cena niga iis 80 substring suffix ned sea a 80 substring upcasel ra lle eae ee 76 substring upper case sese 75 s bstfing 7 ii Rer REPE 73 Substring it 78 substring idad NES 74 S bveCtor side eibhir ni ti ae 103 S bvector liSt d
46. The integer 28 also has representations e28 000 and x1c and the list in the previous paragraph also has the representations 08 13 and 8 13 DY Many objects have standard external representations but some such as procedures and circular data structures do not have standard representations although particular implementations may define representations for them An external representation may be written in a program to obtain the corresponding object see Section 2 6 Quoting page 24 External representations can also be used for input and output The procedure read parses external representations and the procedure write generates them Together they provide an elegant and powerful input output facility Note that the sequence of characters 2 6 is not an external representation of the integer 8 even though it is an expression that evaluates to the integer 8 rather it is an external representation of a three element list the elements of which are the symbol and the integers 2 and 6 Scheme s syntax has the property that any sequence of characters that is an expression is also the external representation of some object This can lead to confusion since it may not be obvious out of context whether a given sequence of characters is intended to denote data or program but it is also a source of power since it facilitates writing programs such as interpreters and compilers that treat programs as d
47. The result may be compared to other file times using ordinary integer arithmetic If filename names a file that does not exist file access time returns f In operating systems that support symbolic links if filename names a symbolic link file access time returns the access time of the file linked to An alternate pro cedure file access time direct returns the access time of the link itself in all other respects it is identical to file access time For symmetry file access time indirect is a synonym of file access time set file times filename access time modification time procedure Filename must name an existing file while access time and modification time must be valid file times that might have been returned by file access time and file modification time respectively set file times alters the access and modifi cation times of the file specified by filename to the values given by access time and modification time respectively For convenience either of the time arguments may be specified as f in this case the corresponding time is not changed set file times returns an unspecified value current file time procedure Returns the current time as an exact non negative integer in the same format used by the above file time procedures This number can be compared to other file times using ordinary arithmetic operations Chapter 15 Operating System Interface 203 file touch filename procedure Touches the file named filenam
48. a b make foo 1 2 2 named expression structure option This is valid only in conjunction with the type option and specifies that the structure instances be tagged to make them identifiable as instances of this structure type This option cannot be used with the type descriptor option In the usual case where expression is not given the named option causes a type descriptor and predicate to be defined for the structure recall that the type option without named suppresses their definition and also defines a default unparser method for the structure instances which can be overridden by the print procedure option If the default unparser method is not wanted then the print procedure option should be specified as F This causes the structure to be printed in its native representation as a list or vector which includes the type descriptor The type descriptor is a unique object not a record type that describes the structure instances and is additionally stored in the structure instances to identify them if the representation type is vector the type descriptor is stored in the zero th slot of the vector and if the representation type is list it is stored as the first element of the list define structure foo type vector named a b c vector ref make foo 1 2 3 0 structure type 52 If expression is specified it is an expression that is evaluated to yield a tag object The expression is evaluated once when the structure def
49. a signalling procedure with parameters field names When the signalling procedure is called it creates and signals a condition of type condition type If the condition isn t handled i e if no handler is invoked that causes an escape from the current continuation the signalling procedure reduces to a call to default handler with the condition as its argument There are several standard procedures that are conventionally used for default handler If condition type is a specialization of condition type error default handler should be the procedure standard error handler If condition type is a specialization of condition type warning default handler should be the procedure standard warning handler Chapter 16 Error System 239 If condition type is a specialization of condition type breakpoint default handler should be the procedure standard breakpoint handler 16 5 2 Condition Abstraction The condition data type is abstracted through a predicate condition and a set of accessor procedures condition object procedure Returns f if and only if object is not a condition condition type condition procedure Returns the condition type of which condition is an instance condition error condition procedure Returns t if the condition is an instance of condition type condition type error or a specialization of it otherwise condition restarts condition procedure Returns the list of restarts specified when condition was crea
50. and returns stt if the argument is a member of the indicated record type it returns f otherwise record accessor record type field name procedure Returns a procedure for reading the value of a particular field of a member of the type represented by record type The returned procedure accepts exactly one argument which must be a record of the appropriate type it returns the current value of the field named by the symbol field name in that record The symbol field name must be a member of the list of field names in the call to make record type that created the type represented by record type record modifier record type field name procedure Returns a procedure for writing the value of a particular field of a member of the type represented by record type The returned procedure accepts exactly two arguments first a record of the appropriate type and second an arbitrary Scheme value it modifies the field named by the symbol field name in that record to contain the given value The returned value of the modifier procedure is unspecified The symbol field name must be a member of the list of field names in the call to make record type that created the type represented by record type record object procedure Returns t if object is a record of any type and f otherwise Note that record may be true of any Scheme value of course if it returns t for some particular value then record type descriptor is applicable to that value and returns a
51. and y are in the range of char gt integer then lt char gt integer a char gt integer b gt dit char lt integer gt char x integer gt char y gt dit Note If the argument to char gt integer or integer gt char is a constant the com piler will constant fold the call replacing it with the corresponding result This is a very useful way to denote unusual character constants or ASCII codes char integer limit variable The range of char gt integer is defined to be the exact non negative integers that are less than the value of this variable exclusive 68 MIT Scheme Reference 5 5 ASCII Characters MIT Scheme internally uses ASCII codes for 1 0 and stores character objects in a fashion that makes it convenient to convert between ASCII codes and characters Also character strings are implemented as byte vectors whose elements are ASCII codes these codes are converted to character objects when accessed For these reasons it is sometimes desirable to be able to convert between ASCII codes and characters Not all characters can be represented as ASCII codes character that has an equivalent ASCII representation is called an ASCII character char ascii char procedure Returns the ASCII code for char if char has an ASCII representation otherwise returns Hf In the current implementation the characters that satisfy this predicate are those in which the Control Super Hyper and Top bucky bits are turned off
52. appending the name of the structure a hyphen and the name of the slot e g foo a The accessor is a procedure of one argument which must be a record of the type defined by this structure definition The accessor extracts the contents of the corresponding slot in that record and returns it modifiers For each slot a modifier is defined The name of the modifier is formed by appending set the name of the accessor and e g set foo a The modifier is a procedure of two arguments the first of which must be a record of the type defined by this structure definition and the sec ond of which may be any object The modifier modifies the contents of the corresponding slot in that record to be that object and returns an unspecified value When options are not supplied name may be abbreviated to name This convention holds equally for structure options and slot options Hence these are equivalent define structure foo a b c define structure foo a b c as are define structure foo keyword constructor a b c define structure foo keyword constructor a b c When specified as option values false and nil are equivalent to f and true and t are equivalent to stt Possible slot options are read only value slot option When given a value other than f this specifies that no modifier should be created for the slot type type descriptor slot option This is accepted but not presently used Possible s
53. are not defined At a minimum the following operations must be defined for input ports read char and peek char for output ports either write char or write substring I O ports must supply the minimum operations for both input and output If an operation in operations is defined to be f then the corresponding operation in port type is not inherited If read char is defined in operations then any standard input operations defined in port type are ignored Likewise if write char or write substring is defined in operations then any standard output operations defined in port type are ignored 178 MIT Scheme Reference This feature allows overriding the standard operations without having to enumerate them port type object procedure input port type object procedure output port type object procedure i o port type object procedure These predicates return t if object is a port type input port type output port type or I O port type respectively Otherwise they return f port type operations port type procedure Returns a newly allocated list containing all of the operations implemented by port type Each element of the list is a list of two elements the name and its associated operation port type operation names port type procedure Returns a newly allocated list whose elements are the names of the operations imple mented by port type port type operation port type symbol procedure Returns the operation named sy
54. as the results of other procedures and so on Other languages with such procedure objects include Common Lisp and ML 4 MIT Scheme Reference Continuations are explicit In most other languages continuations operate behind the scenes In Scheme continuations are objects you can use continuations for implementing a variety of advanced control constructs including non local exits backtracking and coroutines Arguments are passed by value Arguments to Scheme procedures are passed by value which means that Scheme evaluates the argument expressions before the procedure gains control whether or not the procedure needs the result of the evaluations ML C and APL are three other languages that pass arguments by value In languages such as SASL and Algol 60 argument expressions are not evaluated unless the values are needed by the procedure Scheme uses a parenthesized list Polish notation to describe programs and other data The syntax of Scheme like that of most Lisp dialects provides for great expressive power largely due to its simplicity An important consequence of this simplicity is the susceptibility of Scheme programs and data to uniform treatment by other Scheme programs As with other Lisp dialects the read primitive parses its input that is it performs syntactic as well as lexical decomposition of what it reads 1 1 Notational Conventions This section details the notational conventions used throughout the rest of this d
55. atan 1 1 3141 6 fluid let flonum unparser cutoff relative 5 scientific number gt string 4000 atan 1 1 gt 3 1416e3 fluid let flonum unparser cutoff relative 5 scientific number string 40000 atan 1 1 gt 3 1416e4 fluid let flonum unparser cutoff relative 5 engineering number gt string 40000 atan 1 1 gt 31 416e3 fluid let flonum unparser cutoff absolute 5 56 MIT Scheme Reference number gt string 4 atan 1 1 gt 3 14159 fluid let flonum unparser cutoff absolute 5 number gt string 4000 atan 1 1 gt 3141 59265 fluid let flonum unparser cutoff absolute 4 number gt string 4e10 atan 1 1 31415930000 fluid let flonum unparser cutoff absolute 4 scientific number gt string 4e10 atan 1 1 gt 3 141593e10 fluid let flonum unparser cutoff absolute 4 engineering number gt string 4e10 atan 1 1 gt 31 41593e9 fluid let flonum unparser cutoff absolute 5 number gt string 4e10 atan 1 1 31415900000 string gt number string radix procedure Returns a number of the maximally precise representation expressed by the given string Radix must be an exact integer either 2 8 10 or 16 If supplied radix is a default radix that may be overridden by an explicit radix prefix in string e g 0177 If radix is not supplied then the default
56. behavior of this procedure is to print a fresh line a newline and the prompt string flush the output buffer then read an object and return it Under Edwin and Emacs before the object is read the interaction buffer is put into a mode that allows expressions to be edited and submitted for input using specific editor commands The first expression that is submitted is returned as the value of this procedure prompt for command char prompt port procedure Prompts the user for a single character that is to be executed as a command the returned character is guaranteed to satisfy char graphic If at all possible the character is read from the user interface using a mode that reads the character as a single keystroke in other words it should not be necessary for the user to follow the character with a carriage return or something similar This is the procedure called by debug and where to read the user s commands 176 MIT Scheme Reference If prompt is a string it is used verbatim as the prompt string Otherwise it must be a pair whose car is standard and whose cdr is a string in this case the prompt string is formed by prepending to the string the current REP loop level number and a space Also a space is appended to the string unless it already ends in a space or is an empty string The default behavior of this procedure is to print a fresh line a newline and the prompt string flush the output buffer read a character in raw mo
57. calls are the source of values of this type and the values are meaningless except as arguments to other Win32 API calls Currently these values are represented as integers but we expect that Win32 handles will in future be represented by allocated Scheme objects e g records that will allow predicates e g hmenu and sensible interlocking with the garbage collector to free the programmer of the current tedious allocation and deallocation of handles A Windows resource identifier is either a small integer or a string In C this distinc tion is possible because pointers look like larger integers so a machine word repre senting a small integer can be distinguished from a machine word that is a pointer to the text of the name of the resource windows type Chapter 18 Win32 Package Reference 277 18 2 2 Windows Foreign Procedures Foreign procedures are declared as callable entry points in a module usually a dynami cally linked library DLL find module name procedure Returns a module suitable for use in creating procedures with windows procedure Name is a string which is the name of a DLL file Internally find module uses the LoadLibrary Win32 API so name should conform to the specifications for this call Name should be either a full path name of a DLL or the name of a DLL that resides in the same directory as the Scheme binary SCHEME EXE or in the system directory The module returned is a description for the DLL and the
58. char returns f digit gt char 8 gt 8 digit gt char 14 16 gt E 5 4 Internal Representation of Characters An MIT Scheme character consists of a code part and a bucky bits part The MIT Scheme set of characters can represent more characters than ASCII can it includes characters with Super Hyper and Top bucky bits as well as Control and Meta Every ASCII character corresponds to some MIT Scheme character but not vice versa MIT Scheme uses a 16 bit character code with 5 bucky bits Normally Scheme uses the least significant 7 bits of the character code to contain the ASCII representation for the character The representation is expanded in order to allow for future accomodation of international character sets make char code bucky bits procedure Builds a character from code and bucky bits Both code and bucky bits must be exact non negative integers in the appropriate range Use char code and char bits to extract the code and bucky bits from the character If O is specified for bucky bits make char produces an ordinary character otherwise the appropriate bits are turned on as follows 1 Meta 2 Control 4 Super 8 Hyper 16 Top For example Note that the Control bucky bit is different from the ASCII control key This means that SOH ASCII ctrl A is different from C A In fact the Control bucky bit is completely orthogonal to the ASCII control key making possible such characters as C SOH Chapt
59. character numeric defn oocoooccccccoo 69 character output to POTb o o o oo 168 181 character searching string for 77 character standard eeeeee 65 character standard defn 0 69 character whitespace defn 69 characters special in programs 12 child of environment defn i circle graphbies usus ase oe ELEME EG 265 circles drawing 0ooooooooooooo 260 261 circular lists rones poda 91 99 circular structure 4c2 226 65 cade dde eR 41 clause of case expression lesse esses 27 clause of cond expression ooooococoooo o o 26 clearing the console screen 170 chent 8ocket si s ata 219 clip rectangle graphics defn 256 clipping of graphics 000 256 closing environment of procedure defn E7 closing of file p rbe cier RR ge 162 closing Of pOtticc 2 26 pedee tegur di 161 code of character defn 000 66 COLOR tonsg 26 2 9 EE E eos 264 266 combination defn cesse ee ees 15 comma as external representation 26 comment extended in programs defn 12 comment in programs defn 12 comparison for equivalence 4 37 comparison Of bit strings 107 comparison of boolean objects 110 comparison of charactelS
60. compare a b cheer lambda ignore boo Hooray gt unspecified string hash string procedure string hash mod string k procedure string hash returns an exact non negative integer that can be used for storing the specified string in a hash table Equal strings in the sense of string return equal hash codes and non equal but similar strings are usually mapped to distinct hash codes string hash mod is like string hash except that it limits the result to a particular range based on the exact non negative integer k The following are equivalent Chapter 6 Strings 75 string hash mod string k modulo string hash string k 6 4 Alphabetic Case in Strings string capitalized string procedure substring capitalized string start end procedure These procedures return t if the first word in the string substring is capitalized and any subsequent words are either lower case or capitalized Otherwise they return 4f A word is defined as a non null contiguous sequence of alphabetic characters delimited by non alphabetic characters or the limits of the string substring A word is capitalized if its first letter is upper case and all its remaining letters are lower case map string capitalized A art Art ART gt tf tt f t Hf string upper case string procedure substring upper case string start end procedure string lower case string procedure substring lower case string start end procedure
61. copy and distribute verbatim copies of this license document but changing it is not allowed 0 PREAMBLE The purpose of this License is to make a manual textbook or other written document free in the sense of freedom to assure everyone the effective freedom to copy and redistribute it with or without modifying it either commercially or noncommercially Secondarily this License preserves for the author and publisher a way to get credit for their work while not being considered responsible for modifications made by others This License is a kind of copyleft which means that derivative works of the document must themselves be free in the same sense It complements the GNU General Public License which is a copyleft license designed for free software We have designed this License in order to use it for manuals for free software because free software needs free documentation a free program should come with manuals providing the same freedoms that the software does But this License is not limited to software manuals it can be used for any textual work regardless of subject matter or whether it is published as a printed book We recommend this License principally for works whose purpose is instruction or reference 1 APPLICABILITY AND DEFINITIONS This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License The Documen
62. copy of list that omits the last pair except last pair destructively removes the last pair from list and returns list If the cdr of list is not a pair the empty list is returned by either procedure 7 5 Filtering Lists list transform positive list predicate procedure list transform negative list predicate procedure These procedures return a newly allocated copy of list containing only the elements for which predicate is respectively true or false Predicate must be a procedure of one argument list transform positive 12 3 4 5 odd gt 1 3 5 list transform negative 1 2 3 4 5 odd gt 2 4 delq element list procedure delv element list procedure delete element list procedure Returns a newly allocated copy of list with all entries equal to element removed delq uses eq to compare element with the entries in list delv uses eqv and delete uses equal delq element list procedure delv element list procedure delete element list procedure Returns a list consisting of the top level elements of list with all entries equal to element removed These procedures are like delq delv and delete except that they destructively modify list delq uses eq to compare element with the entries in list delv uses eqv and delete uses equal Because the result may not be eq to list it is desirable to do something like set x delete x Chapter 7 Lists 95 define x a b c b delete b x gt ac x
63. define binds variable to a new location in the current environment before performing the assignment it is an error to perform a set on an unbound variable If you omit expression the variable becomes unassigned an attempt to reference such a variable is an error define add3 lambda x x 3 unspecified add3 3 6 define first car unspecified first 1 2 1 define bar unspecified bar Unassigned variable 2 4 2 Internal Definitions An internal definition is a definition that occurs at the beginning of a body that is the body of a lambda let let letrec fluid let or procedure define expression rather than at the top level of a program The variable defined by an internal definition is local to the body That is variable is bound rather than assigned and the region of the binding is the entire body For example let x 5 define foo lambda y bar x y define bar lambda a b a b a foo x 3 gt 45 A body containing internal definitions can always be converted into a completely equiva lent letrec expression For example the let expression in the above example is equivalent to 24 MIT Scheme Reference let x 5 letrec foo lambda y bar x y bar lambda a b a b a foo x 3 2 5 Assignments set variable expression special form If expression is specified evaluates expression and stores the resulting value in the location to wh
64. depth limit 170 nparser radixt i 2 12 o dr 170 unparser string length limit Dr A tdo ee 26 88 Oi ado eau cR EUN 26 88 Saioa terah ine biag aie d E ERE E she 48 namestring coccion 188 pathname cio ci 188 197 SAA peas er REEF E APER 199 ES pd pP pP qu Au wea in dcs 48 t 8T aria a TL eO 45 48 Suo chiede da dos APER ES 37 47 74 O A AAA AA 27 6 e E E EET EEE E eae beh nates S ET 26 88 ucc EET 11 290 Da a dut 15 44 48 gt Praia 47 PP 47 Vi ai 71 Monetarios aa PDA ds 71 Mirar aires 71 di eal eats wees E teats 71 lt da ore aid dots 47 KE ai tbc nate es caren deci a dard 47 67 1 das deas Sube aldo bie ang Wind elses snp eens 48 id table alist i ed leaders bee towed oe 124 Td table Sebi is rai 124 1d table lookup 0c eee ee eae 124 id table put deorienn ienten raio kE 124 1d table remove esses esses 124 did tablet 22 zs a 124 2 ZAS E is 125 2d get alistan Dai a 125 2d get alisSt Yesica in ie 125 e A dg bee ERR E eee bead 125 2d removel sse ep ac e ERE tos 125 APOT HU PEE E casts 231 234 cp eO 49 ACCESS adidas Pep baee 24 access condition esses 238 240 ACUSA eR p dee ES isse 52 MIT Scheme Reference alist 2rb tre6 ies reenmebke ee hr pne 137 alist wt tre ii RE ELA RR 140 alist CODyoclosieelede bee de N 123 aliSt seed bei oa 122 allocate host address 2cs
65. dynamic wind which guarantees that the input blocking mode is restored if thunk escapes from its continuation port output blocking mode port procedure Returns the output blocking mode of port port set output blocking mode port mode procedure Changes the output blocking mode of port to be mode Returns an unspecified value port with output blocking mode port mode thunk procedure Thunk must be a procedure of no arguments port with output blocking mode binds the output blocking mode of port to be mode executes thunk restores the output blocking mode of port to what it was when port with output blocking mode was called and returns the value that was yielded by thunk This binding is performed by dynamic wind which guarantees that the output blocking mode is restored if thunk escapes from its continuation 14 9 6 Terminal Mode A port that reads from or writes to a terminal has a terminal mode this is either cooked or raw This mode is independent of the blocking mode each can be changed independent of the other Furthermore a terminal 1 0 port has independent terminal modes both for input and for output 184 MIT Scheme Reference A terminal port in cooked mode provides some standard processing to make the terminal easy to communicate with For example under unix cooked mode on input reads from the terminal a line at a time and provides rubout processing within the line while cooked mode on output might translate linefeeds
66. empty temporary file and returns a pathname referring to it The temporary file is created with Scheme s default permissions so barring unusual cir cumstances it can be opened for input and or output without error The temporary file will remain in existence until explicitly deleted If the file still exists when the Scheme process terminates 1t will be deleted If directory is specified the temporary file will be stored there If it is not specified or if it is the temporary file will be stored in the directory returned by temporary directory pathname temporary directory pathname procedure Returns the pathname of an existing directory that can be used to store temporary files These directory names are tried in order until a writeable directory is found e The directories specified by the environment variables TMPDIR TEMP or TMP e Under unix the directories var tmp usr tmp or tmp 200 MIT Scheme Reference e Under OS 2 or Windows the following directories on the system drive temp tmp or V e Under OS 2 or Windows the current directory as specified by default pathname defaults file directory filename procedure Returns stt if the file named filename exists and is a directory Otherwise returns f In operating systems that support symbolic links if filename names a symbolic link this examines the file linked to not the link itself This is equivalent to eq directory
67. ems 162 call with outp t file sers poets iers 162 call with temporary file pathname 199 call with valu s Lace ede eked deals 151 canonical host name ss suse 222 capture image on os2 graphics device 272 CBE aed den pe e e eos Re wee tee 10 88 118 CASE Lo e in 2 29 Cdi ot ice ct hie cid BVPRSU STAT NM DIT ERES 197 CA iuis eee eee ERN elt 89 Cdad 4 euin bidder boarded era anes 89 refs rn rp 89 Cad at se ei id iva 89 Cdad ii ita a a 89 Cdad A m 89 A Ese oL be ee Ege ee cuts 89 sero PME 89 CddadEs unu er D neri A RUIIq eR Ee RE 89 LA yere bi EISE RI IE Ene 89 cddd t s io vci de ue ed nd et dos dve s 89 CODD ai 22 ze des eo brote abiens 89 dddo cii cer etr bi thi LE eh 89 fes on Er 89 o EEEPREPET 6 88 118 Ceiling so niai eg ada Es 51 ceiling 6 xact iliele e be 46e biel ete 51 cell contents s aen RR es 114 Cell heeere EE PERS M 114 Chat j22 decease eedet eee E EA 275 ei Em 276 Char 2asGli ciceeebz 9g ie ERXgoeePEPREPTU sG 67 68 char digit 200529 020 tie 66 char inteBe i mde PERI RE qs 67 char mname uere o ERG eL 64 char alphabetiC ici deal ar 69 char alphanumeriC as 69 CHarSascii eiii al tia 67 68 71 char bits iii ii 67 68 char b1t8 Limit coli pa ERE 67 Char Ci a orina lr ns 65 char 6i5974 iip a iaa 65 CharqCi gt cs ic ae ala 65 CHA s Ada 65 AA uot babet dran 65 char eod 4i li bee ieee Re EYE 67 Char Code Ji mit 2 2 2 scie be e es 67
68. encoded as an exact integer between 0 Monday and 6 Sunday inclusive decoded time day of week local decoded time 4 decoded time daylight savings time decoded time Return t if decoded time is represented using daylight savings time return f decoded time daylight savings time local decoded time df procedure Otherwise 208 MIT Scheme Reference decoded time zone decoded time procedure Return the time zone in which decoded time is represented This is an exact rational number between 24 and 24 inclusive that when multiplied by 3600 is an integer The value is the number of hours west of UTC decoded time zone local decoded time gt 5 time zone object procedure Returns stt if object is an exact number between 24 and 24 inclusive that when multiplied by 3600 is an integer time zone 5 gt t time zone 11 2 gt ttt time zone 11 7 gt ttf month max days month procedure Returns the maximum number of days possible in month Month must be an exact integer between 1 and 12 inclusive month max days 2 29 month max days 3 gt 31 month max days 4 gt 30 15 5 3 File Time As stated above file time is operating system dependent As of this writing two formats are used For unix and Windows systems file time is the number of seconds since midnight January 1 1970 UTC the standard unix time convention OS 2 represents file time as a 32 bit unsigned integ
69. enod s sd dest ea niensis 47 init file pathname s n d n 195 initijal offS6et e ld ge DD Re RES EAE 35 297 INput buffer S1ZO ati ii ia iesi 217 input buffer size on input port 180 input Iine trenslation 2 b xg 217 INPpuUt POTt LND decicion pem 178 input port char ready 180 input port discard char 180 input port discard chars 180 input port peek char 000 180 input port read char suus 180 input port read string 180 input port read substring 180 Input port 2 a m ed 159 Ti te acti ean rers 216 Integer Cha cir LP ees 67 AA 03 0 22 UE 49 integer divide ci 50 58 integer divide quotient 50 58 integer divide remainder 50 58 integer flOoOFE 4 dog xe Ree baee d 49 integer round oergie tere ie EEG Re pre hdd 49 integer truncate oisucui se Dae mee as 49 e ogg gh RE A tsian EN INE ES 46 interaction i port bbs 160 175 INGETD ira ida pA bia Rd D nae 111 inte rn soft liie bis bises eric ebbe gud 112 internal time seconds gt ticks 213 internal time ticks gt seconds 213 interpreter environment 157 invoke restart 231 233 235 236 237 invoke restart interactively 231 235 236 237 K kernel32 dll encuen 277 keyword CODStTUCHO cc a 34 L lambda 5 8 13 15 17 20 22 23 29
70. exact non negative integer file attributes change time attributes procedure The last change time of the file an exact non negative integer file attributes length attributes procedure The length of the file in bytes file attributes mode string attributes procedure The mode string of the file a newly allocated string showing the file s mode bits Under unix this string is in unix format Under OS 2 and Windows this string shows the standard DOS attributes in their usual format file attributes n links attributes procedure The number of links to the file an exact positive integer Under Windows and OS 2 this is always 1 204 MIT Scheme Reference The following additional accessors are defined under unix file attributes uid attributes procedure The user id of the file s owner an exact non negative integer file attributes gid attributes procedure The group id of the file s group an exact non negative integer file attributes inode number attributes procedure The inode number of the file an exact non negative integer The following additional accessor is defined under OS 2 and Windows file attributes modes attributes procedure The attribute bits of the file This is an exact non negative integer containing the file s attribute bits exactly as specified by the operating system s API The following additional accessor is defined under OS 2 file attributes allocated length attributes procedure The allo
71. existence of the file pointed to by the link copy file source filename target filename procedure Makes a copy of the file named by source filename The copy is performed by creating a new file called target filename and filling it with the same data as source filename rename file source filename target filename procedure Changes the name of source filename to be target filename In the unix implementa tion this will not rename across file systems delete file filename procedure Deletes the file named filename delete file no errors filename procedure Like delete file but returns a boolean value indicating whether an error occurred during the deletion If no errors occurred t is returned If an error of type condition type file error or condition type port error is signalled f is re turned hard link file source filename target filename procedure Makes a hard link from source filename to target filename This operation gives the file specified by source filename a new name in addition to the old name This currently works only on unix systems It is further restricted to work only when source filename and target filename refer to names in the same file system Chapter 15 Operating System Interface 199 soft link file source filename target filename procedure Creates a new soft link called target filename that points at the file source filename Soft links are also sometimes called symbolic links Note that source file
72. from left to right If predicate returns f for any element of list f is immediately returned as the value of for a117 predicate will not be applied to the remaining elements of list If predicate is true for all of the elements of list then t is returned 7 9 Miscellaneous List Operations circular list object procedure make circular list k element procedure These procedures are like list and make list respectively except that the returned lists are circular circular list could have been defined like this define circular list objects append objects objects reverse list procedure Returns a newly allocated list consisting of the top level elements of list in reverse order reverse a b c gt cba reverse a b c d e f gt Ce d bo a reverse list procedure Returns a list consisting of the top level elements of list in reverse order reverse is like reverse except that it destructively modifies list Because the result may not be equ to list it is desirable to do something like set x reverse x sort sequence procedure procedure merge sort sequence procedure procedure quick sort sequence procedure procedure Sequence must be either a list or a vector Procedure must be a procedure of two arguments that defines a total ordering on the elements of sequence In other words if x and y are two distinct elements of sequence then it must be the case that and procedure x y
73. graphics type available graphics device type procedure This predicate returns t if the graphics system named by the symbol graphics device type is implemented by the Scheme system Otherwise it returns f in which case it is an error to attempt to make a graphics device using graphics device type enumerate graphics types procedure This procedure returns a list of symbols which are the names of all the graphics device types that are supported by the Scheme system The result is useful in deciding what additional arguments to supply to make graphics device as each device type typically has a unique way of specifying the initial size shape and other attributes make graphics device graphics device type object procedure This operation creates and returns a graphics device object Graphics device type is a symbol naming a graphics device type and both the number and the meaning of the remaining arguments is determined by that type see the description of each de vice type for details graphics device type must satisfy graphics type available Graphics device type may also be f in which case the graphics device type is cho sen by the system from what is available This allows completely portable graphics programs to be written provided no custom graphics operations are used When graphics device type is tf no further arguments may be given each graphics device type will use some sensible defaults If more control is required then the
74. gt a car 1 2 gt 1 car error Illegal datum cdr pair procedure Returns the contents of the cdr field of pair Note that it is an error to take the cdr of the empty list cdr a b c 3D gt bc d cdr 1 2 gt 9 cdr Illegal datum Chapter 7 Lists 89 set car pair object procedure Stores object in the car field of pair The value returned by set car is unspecified define f list not a constant list define g constant list set car f 3 unspecified set car g 3 Illegal datum set cdr pair object procedure Stores object in the cdr field of pair The value returned by set cdr is unspecified caar pair procedure cadr pair procedure cdar pair procedure cddr pair procedure caaar pair procedure caadr pair procedure cadar pair procedure caddr pair procedure cdaar pair procedure cdadr pair procedure cddar pair procedure cdddr pair procedure caaaar pair procedure caaadr pair procedure caadar pair procedure caaddr pair procedure cadaar pair procedure cadadr pair procedure caddar pair procedure cadddr pair procedure cdaaar pair procedure cdaadr pair procedure cdadar pair procedure cdaddr pair procedure cddaar pair procedure cddadr pair procedure cdddar pair procedure cddddr pair procedure These procedures are compositions of car and cdr for example caddr could be defined by define caddr lambda x car cdr cdr x general car cdr object path procedu
75. gt abc b define x a b c b delete b x gt ac x gt ac Returns correct result delete a x gt c Didn t modify what x points to x gt ac delete member procedure deletor predicate procedure Returns a deletion procedure similar to delv or delete Deletor should be one of the procedures list deletor or list deletor Predicate must be an equivalence predicate The returned procedure accepts exactly two arguments first an object to be deleted and second a list of objects from which it is to be deleted If deletor is list deletor the procedure returns a newly allocated copy of the given list in which all entries equal to the given object have been removed If deletor is list deletor the procedure returns a list consisting of the top level elements of the given list with all entries equal to the given object removed the given list is destructively modified to produce the result In either case predicate is used to compare the given object to the elements of the given list Here are some examples that demonstrate how delete member procedure could have been used to implement delv and delete define delv delete member procedure list deletor eqv define delete delete member procedure list deletor equal list deletor predicate procedure list deletor predicate procedure These procedures each return a procedure that deletes elements from lists Predicate must be a procedure of one argument
76. hash table procedure hash table set entry datum hash table procedure Each procedure returns the value of the corresponding argument that was used to construct hash table The following procedures return the contents of a hash table as a collection of entries While the data structure holding the entries is newly allocated the entries themselves are not copied Since hash table operations can modify these entries the entries should be copied if it is desired to keep them while continuing to modify the table hash table entries list hash table procedure Returns a newly allocated list of the entries in hash table hash table entries vector hash table procedure Returns a newly allocated vector of the entries in hash table Equivalent to list gt vector hash table entries list hash table 11 5 Object Hashing The MIT Scheme object hashing facility provides a mechanism for generating a unique hash number for an arbitrary object This hash number unlike an object s address is unchanged by garbage collection The object hashing facility is useful in conjunction with hash tables but it may be used for other things as well In particular it is used in the generation of the written representation for many objects see Section 14 7 Custom Output page 173 134 MIT Scheme Reference All of these procedures accept an optional argument called table this table contains the object integer associations If given this argument must be
77. have been defined by define string tail string start substring string start string length string string tail uncommon 2 gt common Chapter 6 Strings 77 string pad left string k char procedure string pad right string k char procedure These procedures return a newly allocated string created by padding string out to length k using char If char is not given it defaults to space If k is less than the length of string the resulting string is a truncated form of string string pad left adds padding characters or truncates from the beginning of the string lowest indices while string pad right does so at the end of the string highest indices string pad left hello 4 gt ello string pad left hello 8 gt hello string pad left hello 8 gt hello string pad right hello 4 gt hell string pad right hello 8 gt hello string trim string char set procedure string trim left string char set procedure string trim right string char set procedure Returns a newly allocated string created by removing all characters that are not in char set from string trim both ends of string string trim left the be ginning of string or string trim right the end of string Char set defaults to char set not whitespace string trim in the end gt in the end string trim 1 puM string trim 100th char set numeric 100 string trim left char set
78. in some way exactly how this situation is indicated is separately specified for each procedure or operation Chapter 14 Input Output 183 An output port in blocking mode will block if the output device is not ready to accept output In non blocking mode it will return immediately after performing as much output as the device will allow again each procedure or operation reports this situation in its own way Interactive ports are initially in blocking mode this can be changed at any time with the procedures defined in this section These procedures represent blocking mode by the symbol blocking and non blocking mode by the symbol nonblocking An argument called mode must be one of these symbols A port argument to any of these procedures may be any port even if that port does not support blocking mode in that case the port is not modified in any way port input blocking mode port procedure Returns the input blocking mode of port port set input blocking mode port mode procedure Changes the input blocking mode of port to be mode Returns an unspecified value port with input blocking mode port mode thunk procedure Thunk must be a procedure of no arguments port with input blocking mode binds the input blocking mode of port to be mode executes thunk restores the input blocking mode of port to what it was when port with input blocking mode was called and returns the value that was yielded by thunk This binding is performed by
79. in the external representation of the procedure making it useful for debugging In MIT Scheme lambda is implemented as named lambda with a special name that means unnamed named lambda f x x x compound procedure 53 f named lambda f x x x 4 gt 8 2 2 Lexical Binding The three binding constructs let let and letrec give Scheme block structure The syntax of the three constructs is identical but they differ in the regions they establish for their variable bindings In a let expression the initial values are computed before any of the variables become bound In a let expression the evaluations and bindings are sequentially interleaved And in a letrec expression all the bindings are in effect while the initial values are being computed thus allowing mutually recursive definitions let variable init expression expression special form The inits are evaluated in the current environment in some unspecified order the variables are bound to fresh locations holding the results the expressions are evalu ated sequentially in the extended environment and the value of the last expression is returned Each binding of a variable has the expressions as its region MIT Scheme allows any of the inits to be omitted in which case the corresponding variables are unassigned Note that the following are equivalent let variable init expression expression lambda variable expression expr
80. instead of Front Cover Texts being list likewise for Back Cover Texts If your document contains nontrivial examples of program code we recommend releasing these examples in parallel under your choice of free software license such as the GNU General Public License to permit their use in free software Binding Index Binding Index A dea 46 dloptQonal di rara 13 18 A Ed a eer EP ad 13 18 jp PE 101 j 63 d Naltmode E E debits da elder eae 64 dNbacknektooi esennprbokeb ee nE ESE r e d s 64 INDACESPACE siii epn idrara EErEE da 64 cl ire 64 A AA p orinni iE ered 64 69 newline sonoridad Enn 63 64 69 71 Xpage ccobs se een E LerUDP RW PERI UE 64 69 71 dNreturn 22s en eet LESE REPE 64 69 dNrubout 22160 9 26i e SG inde 64 dSNSpacec osi Uo AES 63 64 69 77 Di Lm 64 69 71 Dire 46 A E ETE addins aed obue eae de albania 46 HO TEE 46 E na Wiad ane ean hae bn tte ste 8 26 109 Ma aida aia 46 RR RR 46 dE cose si ie da 8 26 109 po ET 46 76 J delete dibz 2zgui Ie RR de REG 281 OCCHI 24 88 EEEE EE EAN seas EE wa eae onc eho 87 Du D atten cs era ate deat E ety ag nes 87 289 PT 15 48 default pathname defaults 194 parser canonicalize symbols 168 parser radilX ec sp exes ip 168 random Staterw ssc i sauces dad ana POSS i 61 unparse with maximum readability i71 unparser list breadth limit 170 unparser list
81. invoking inside continuation At this point 3 is written indicating that the side effect that previously occurred within the body has been preserved Finally we exit body normally and write 4 demonstrating that the side effect that occurred outside of the body was also preserved 2 4 Definitions define variable expression special form define formals expression expression special form Definitions are valid in some but all contexts where expressions are allowed Definitions may only occur at the top level of a program and at the beginning of a lambda body that is the body of a lambda let let letrec fluid let or procedure define expression A definition that occurs at the top level of a program is called a top level definition and a definition that occurs at the beginning of a body is called an internal definition Chapter 2 Special Forms 23 In the second form of define called procedure define the component formals is identical to the component of the same name in a named lambda expression In fact these two expressions are equivalent define namel name2 expression expression define namel named lambda namel name2 expression expression 2 4 1 Top Level Definitions A top level definition define variable expression has essentially the same effect as this assignment expression if variable is bound set variable expression If variable is not bound however
82. irritants contains a list of objects The reporter for this type uses format error message to generate its output from message and irritants condition type breakpoint environment message prompt condition type A condition of this type is generated by the breakpoint mechanism The contents of its fields are beyond the scope of this document 250 MIT Scheme Reference Chapter 17 Graphics 251 17 Graphics MIT Scheme has a simple two dimensional line graphics interface that is suitable for many graphics applications In particular it is often used for plotting data points from experiments The interface is generic in that it can support different types of graphics devices in a uniform manner At the present time only one type of graphics device is implemented on each operating system Procedures are available for drawing points lines and text defining the coordinate system clipping graphics output controlling some of the drawing characteristics and con trolling the output buffer for devices that perform buffering Additionally devices may support custom operations such as control of colors There are some constraints on the arguments to the procedures described in this chapter Any argument named graphics device must be a graphics device object that was returned from a call to make graphics device Any argument that is a coordinate must be either an exact integer or an inexact real 17 1 Opening and Closing of Graphics Devices
83. its creation The image may be used freely with other graphics devices created with the same attributes but the effects of using an image with a graphics device with different attributes for example different colors is undefined Under X the image is display dependent draw image x y image operation on graphics device The image is copied into the graphics device at the specified position 258 MIT Scheme Reference draw subimage x y image im x im y w h operation on graphics device Part of the image is copied into the graphics device at the specified x y position The part of the image that is copied is the rectangular region at im x and im y and of width w and height h These four numbers are given in device coordinates pixels image object procedure Returns stt if object is an image otherwise returns ttf image destroy image procedure This procedure destroys image returning storage to the system Programs should destroy images after they have been used because even modest images may use large amounts of memory Images are reclaimed by the garbage collector but they may be implemented using memory outside of Scheme s heap If an image is reclaimed before being destroyed the implementation might not deallocate that non heap memory which can cause a subsequent call to create image to fail because it is unable to allocate enough memory image height image procedure Returns the height of the image in device coordinates ima
84. iul sds e eddie rb 75 string match backward 80 string match backward ci 80 stringomatch forWard oooooooocmoooo 80 string match forward ci 80 string maximum length 84 String Dull jii R342204 4 ihe ues 73 string pa d left sc rca ia te 76 String pad Tier en tods TT String prefik Ci nevar criar 80 String pref i ioo RM assinei 80 String ref oi lu vB ad 10 73 84 String replace 224 3 ge quta eR dace 82 Binding Index string replacel 23e breed ere hay xe 82 string search all si44 tect WERT vane as 78 string search backward 78 string search forward ru String set loni ITA 10 73 111 string suffix Ci ioio sec lr 3 Rr pas 80 String Suffix Varonil Db Eds 80 String tall oa bcne feebgGd gebe did medidor 76 String trim 0 Mie ed pd Te ERAI Rd er TE String trim left irrita ssh riada E Sstring trim right iade eee is rp String upcaSe i 22e ad Ru S Rep IRE unde 76 string upcase socia kiip iin a 76 StriNg UPpeT cas enrii c d p dada misa 75 SLring wt type sc sus Jacke ee ihre ete 140 SLIDES miis 37 73 74 110 111 126 127 SEPANG ii a rodadas 73 SUTIN GFE il clos io du ea died 74 SECADO a dei 74 String4s oc caeecdad rr ate edd 74 SETE ST sod ces bard dove hihi ume di Seen 74 strong hash table constructor 126 S DIYSU ae 93 S bSUtErlBg xe rd decrees ETE 76
85. key hash argument is a procedure that computes a hash number Specifically key hash accepts two arguments a key and an exact positive integer the modulus and returns an exact non negative integer that is less than the modulus The optional argument rehash after gc if true says that the values returned by key hash might change after a garbage collection If so the hash table implementation Chapter 11 Associations 127 arranges for the table to be rehashed when necessary See Section 11 4 4 Address Hashing page 131 for information about hash procedures that have this property Otherwise it is assumed that key hash always returns the same value for the same arguments The default value of this argument is f The constructors returned by strong hash table constructor make hash ta bles that hold their keys strongly The constructors returned by weak hash table constructor make hash tables that hold their keys weakly Some examples showing how some standard hash table constructors could have been defined define make eq hash table weak hash table constructor eq hash mod eq t define make equal hash table strong hash table constructor equal hash mod equal t define make string hash table strong hash table constructor string hash mod string f The following procedure is sometimes useful in conjunction with weak hash tables Nor mally it is not needed because such hash tables clean themselves automatically
86. limit 4 write to string a b c d bed unparser string length limit variable This variable specifies a limit on the length of the printed representation of strings If a string s length exceeds this limit the part of the printed representation for the characters exceeding the limit is replaced by ellipses The value of this variable must be an exact non negative integer or f meaning no limit the default is fluid let unparser string length limit 4 write to string abcd gt abcd fluid let unparser string length limit 4 write to string abcde gt abcd unparse with maximum readability variable This variable which takes a boolean value tells the printer to use a special printed representation for objects that normally print in a form that cannot be recognized by read These objects are printed using the representation n where n is the result of calling hash on the object to be printed The reader recognizes this syntax calling unhash on n to get back the original object Note that this printed representation can only be recognized by the Scheme program in which it was generated because these hash numbers are different for each invocation of Scheme 14 6 Format The procedure format is very useful for producing nicely formatted text producing good looking messages and so on MIT Scheme s implementation of format is similar to that of Common Lisp exc
87. names in the Win32 support are part of the win32 package The names are bound in the win32 environment and do not appear as bindings in the user or root environments An effect of this is that it is far easier to develop Win32 software in the win32 package environment or a child environment 18 2 Foreign Function Interface The Win32 foreign function interface FFI is a primitive and fairly simple system for calling procedures written in C in a dynamically linked library DLL Both user s proce dures from a custom DLL and system procedures e g MessageBox are called using the same mechanism Warning The FFI as it stands has several flaws which make it difficult to use reliably It is expected that both the interface to and the mechanisms used by the FFI will be changed in the future We provide it and this documentation only to give people an early start in accessing some of the features of Win32 from Scheme Should you use it in an experiment we welcome any feedback The FFI is designed for calling C procedures that use C data types rather than Scheme data objects Thus it is not possible to write and call a C procedure that returns for 274 MIT Scheme Reference example a Scheme list The object returned will always be an integer which may represent the address of a C data structure Warning It is extremely dangerous to try to pass Scheme callback procedures to C procedures It is only possible by passing integer handles
88. null i e zero indicating that there is no block of memory describing the DIB The null value is usually returned by C functions that are supposed to create a DIB but failed for some reason like the memory could not be allocated or a file could not be opened In the Scheme world a DIB is a structure containing information about the bitmap specifically the integer that represents the handle We also include f in the dib windows type to mirror the null handle error value 280 MIT Scheme Reference define dib result lambda handle if handle 0 f make dib handle define dib arg lambda dib if dib cell contents dib handle dib 0 define windows type dib lambda thing or dib thing eq thing f dib arg dib result 18 3 1 DIB procedures The following procedures have typed parameters using the same convention as windows procedure open dib filename string procedure Return type dib Calls the OpenDIB entry of DIBUTILS DLL If the return value is not f then the file filename was found successfully opened and the contents were suitable for loading into memory as a device independent bitmap write dib filename string dib dib procedure Return type bool Calls the WriteDIB entry of DIBUTILS DLL Returns stt if the file filename could be opened and written to After this operation the file contains the bitmap data in a standard format that is understood by open dib and various
89. numerical value of the result cannot be represented as an inexact number without loss of accuracy then the procedure may report a violation of an implementation restriction zl procedure uP PM procedure These procedures return the sum or product of their arguments 3 4 gt 7 3 gt 3 gt 0 4 gt 4 C gt 1 zlz2 procedure ziz2 procedure With two or more arguments these procedures return the difference or quotient of their arguments associating to the left With one argument however they return the additive or multiplicative inverse of their argument 34 gt 1 3 4 5 gt 6 3 gt 3 3 4 5 gt 3 20 3 gt 1 3 1 z procedure 1 z procedure 1 z is equivalent to z 1 1 z is equivalent to z 1 MIT Scheme signals an error of type condition type bad range argument in this case Chapter 4 Numbers 49 abs x procedure abs returns the magnitude of its argument abs 7 gt 7 quotient ni n2 procedure remainder nl n2 procedure modulo n1 n2 procedure These procedures implement number theoretic integer division for positive integers nl and n2 if n3 and n4 are integers such that Ny nona Na 0 n4 lt na then quotient nl n2 gt n8 remainder nl n2 gt n4 modulo n1 n2 gt n4 For integers nl and n2 with n2 not equal to 0 nl n2 quotient nl n2 remainder nl n2 gt dit provided all numbers in
90. object condition type wrong type datum datum type condition type This type indicates the class of errors in which a program discovers an object that is of the wrong type The type field contains a string describing the type that was expected and the datum field contains the object that is of the wrong type error wrong type datum 3 4 integer error The object 3 4 is not an integer To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 error wrong type datum datum type procedure This procedure signals a condition of type condition type wrong type datum The datum and type fields of the condition are filled in from the corresponding arguments to the procedure condition type wrong type argument datum type operator condition type operand This type indicates that a procedure was passed an argument of the wrong type The operator field contains the procedure or a symbol naming the procedure the operand field indicates the argument position that was involved this field contains either a symbol a non negative integer or amp the type field contains a string describ ing the type that was expected and the datum field contains the offending argument a 3 error The object a passed as the first argument to integer add is not the correct type To continue call RESTART with an option number RESTART 2 gt Specify an argument to use in its plac
91. objects without protecting them from garbage collection The car of a weak pair holds its pointer weakly while the cdr holds its pointer in the normal way If the object in the car of a weak pair is not held normally by any other data structure it will be garbage collected Note weak pairs are not pairs that is they do not satisfy the predicate pair weak pair object procedure Returns t if object is a weak pair otherwise returns f weak cons car cdr procedure Allocates and returns a new weak pair with components car and cdr The car component is held weakly weak pair car weak pair procedure This predicate returns f if the car of weak pair has been garbage collected otherwise returns t In other words it is true if weak pair has a valid car component 120 MIT Scheme Reference weak car weak pair procedure Returns the car component of weak pair If the car component has been garbage collected this operation returns f but it can also return f if that is the value that was stored in the car Normally weak pair car is used to determine if weak car would return a valid value An obvious way of doing this would be if weak pair car x weak car x K However since a garbage collection could occur between the call to weak pair car and weak car this would not always work correctly Instead the following should be used which always works or weak car x and not weak pair car x fa The reason that th
92. of the Document and satisfy these conditions can be treated as verbatim copying in other respects If the required texts for either cover are too voluminous to fit legibly you should put the first ones listed as many as fit reasonably on the actual cover and continue the rest onto adjacent pages If you publish or distribute Opaque copies of the Document numbering more than 100 you must either include a machine readable Transparent copy along with each Opaque copy or state in or with each Opaque copy a publicly accessible computer network location containing a complete Transparent copy of the Document free of added ma terial which the general network using public has access to download anonymously at no charge using public standard network protocols If you use the latter option you must take reasonably prudent steps when you begin distribution of Opaque copies in quantity to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy directly or through your agents or retailers of that edition to the public It is requested but not required that you contact the authors of the Document well before redistributing any large number of copies to give them a chance to provide you with an updated version of the Document 4 MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 an
93. on Bit strings are encoded very densely in memory Each bit occupies exactly one bit of storage and the overhead for the entire bit string is bounded by a small constant However accessing a bit in a bit string is slow compared to accessing an element of a vector or character string If performance is of overriding concern it is better to use character strings to store sets of boolean values even though they occupy more space The length of a bit string is the number of bits that it contains This number is an exact non negative integer that is fixed when the bit string is created The valid indexes of a bit string are the exact non negative integers less than the length of the bit string Bit strings may contain zero or more bits They are not limited by the length of a machine word In the printed representation of a bit string the contents of the bit string are preceded by The contents are printed starting with the most significant bit highest index Note that the external representation of bit strings uses a bit ordering that is the reverse of the representation for bit strings in Common Lisp It is likely that MIT Scheme s repre sentation will be changed in the future to be compatible with Common Lisp For the time being this representation should be considered a convenience for viewing bit strings rather than a means of entering them as data 11111 1010 00000000 Hx All of the bit string procedures are MIT Scheme ex
94. only the handle value and not needing the dib record The importance of this is that if the dib record is GC ed then a GC hook can reclaim the storage knowing only the handle delete dib dib dib procedure Return type bool This procedure calls 4delete dib to reclaim the storage occupied by a DIB After being deleted the DIB should not be used This procedure allows the programmer to reclaim external heap storage rather than risking it running out before the next garbage collection dib height dib dib procedure Return type int Calls the DibHeight expand entry of DIBUTILS DLL which returns the height of the bitmap in pixels dib width dib dib procedure Return type int Calls the DibWidth entry of DIBUTILS DLL which returns the width of the bitmap in pixels copy bitmap bm hbitmap procedure Return type hbitmap Calls the CopyBitmap of DIBUTILS DLL which creates a new bitmap with the same size and contents as the original create dib width int height int style int depth int palette procedure hpalette Return type dib Calls the CreateDIB entry of DIBUTILS DLL Creates a DIB of width by height pixels and depth bits of colour information The style parameter determines how the bitmap is stored I have only ever used BI RGB If depth lt 8 then the palette determines the DIB s colour table crop bitmap bm hbitmap left int top int right int bottom int procedure Return type hbitmap C
95. output port For exam ple the following are equivalent output port write char output port char Coutput port operation output port write char output port char output port write string output port string procedure Writes string to output port Equivalent to output port write substring output port string 0 string length string The following custom operations are generally useful 182 MIT Scheme Reference buffered output chars output port operation on output port Returns the number of unwritten characters that are stored in output port s buffer This will always be less than or equal to the buffer s size output buffer size output port operation on output port Returns the maximum number of characters that output port s buffer can hold set output buffer size output port size operation on output port Resizes output port s buffer so that it can hold at most size characters Characters in the buffer are discarded Size must be an exact non negative integer x size output port operation on output port Returns an exact positive integer that is the width of output port in characters If output port has no natural width e g if it is a file port f is returned y size output port operation on output port Returns an exact positive integer that is the height of output port in characters If output port has no natural height e g if it is a file port is returned output port x size output port procedure This proced
96. pels pixels relative to the lower left hand corner of the client area and the graphics device that the mouse pointer was over at the time the button was pressed Note that this operation only works when button events are selected which is the default 270 MIT Scheme Reference select user events mask operation on os2 graphics device This operation sets the event selection mask for the graphics device to mask The event selection mask is an exact non negative integer that specifies which types of incoming events are to be saved in the user event queue for later retrieval by the read user event operation The mask is specified by setting the bits corresponding to the event types that you are interested in as follows Number Mask Description 0 x001 Button press release 1 x002 Close close the window WM_CLOSE 2 x004 Focus change WM_SETFOCUS 3 x008 Key press release WM_CHAR 4 x010 Paint WM_PAINT 5 x020 Size change WM_SIZE 6 x040 Visibility change WM_SHOW 7 x080 Command WM_COMMAND 8 x100 Help WM_HELP o ES N o o Mouse move WM MOUSEMOVE Note that this operation does not affect any events that are already in the user event queue Changing the mask only affects what events will be added to the queue in the future read user event operation on os2 graphics device This operation returns the next user event available from the user event queue If there are no events in the queue the operation
97. primitive procedure otherwise returns f The following two procedures test the arity of a procedure that is the number of arguments that the procedure accepts The results of the test may be less restrictive than the effect of calling the procedure In other words these procedures may indicate that the procedure will accept a given number of arguments but if you call the procedure it may signal a condition type wrong number of arguments error This is because these procedures examine the apparent arity of a procedure For example here is a procedure that appears to accept any number of arguments but when called will signal an error if the number of arguments is not one lambda arguments apply car arguments procedure arity valid procedure k procedure Returns t if procedure accepts k arguments otherwise returns f procedure arity procedure procedure Returns a description of the number of arguments that procedure accepts The result is a newly allocated pair whose car field is the minimum number of arguments and whose cdr field is the maximum number of arguments The minimum is an exact non negative integer The maximum is either an exact non negative integer or f meaning that the procedure has no maximum number of arguments procedure arity lambda 3 gt 0 0 procedure arity lambda x x gt 1 41 procedure arity car gt 1 1 procedure arity lambda x x gt 0 sf procedure arity lambda x y x
98. procedures MIT Scheme allows any of the inits to be omitted in which case the corresponding variables are unassigned letrec even lambda n if zero n t odd n 1 odd lambda n if zero n f even n 1 even 88 gt dt One restriction on letrec is very important it shall be possible to evaluated each init without assigning or referring to the value of any variable If this restriction is violated then it is an error The restriction is necessary because Scheme passes arguments by value rather than by name In the most common uses of letrec all the inits are lambda or delay expressions and the restriction is satisfied automatically 2 3 Dynamic Binding Chapter 2 Special Forms 21 fluid let variable init expression expression special form The inits are evaluated in the current environment in some unspecified order the current values of the variables are saved the results are assigned to the variables the expressions are evaluated sequentially in the current environment the variables are restored to their original values and the value of the last expression is returned The syntax of this special form is similar to that of let but fluid let temporarily rebinds existing variables Unlike let fluid let creates no new bindings instead it assigns the value of each init to the binding determined by the rules of lexical scoping of its corresponding variable MIT Scheme allows
99. procedures performs the corresponding bitwise logical operation on its arguments places the result into target bit string and returns an unspecified result 108 MIT Scheme Reference 9 5 Modification of Bit Strings bit string fill bit string initialization procedure Fills bit string with zeroes if initialization is otherwise fills bit string with ones Returns an unspecified value bit string move target bit string bit string procedure Moves the contents of bit string into target bit string Both arguments must be bit strings of the same length The results of the operation are undefined if the arguments are the same bit string bit substring move right bit string 1 start1 end1 bit string 2 procedure start2 Destructively copies the bits of bit string 1 starting at index startl inclusive and ending at end1 exclusive into bit string 2 starting at index start2 inclusive Startl and endi must be valid substring indices for bit string 1 and start2 must be a valid index for bit string 2 The length of the source substring must not exceed the length of bit string 2 minus the index start2 The bits are copied starting from the MSB and working towards the LSB the direction of copying only matters when bit string 1 and bit string 2 are eqv 9 6 Integer Conversions of Bit Strings unsigned integer gt bit string length integer procedure Both length and integer must be exact non negative integers Converts integer into a new
100. radix is 10 If string is not a syntactically valid notation for a number then string gt number returns f string gt number 100 gt 100 string number 100 16 gt 256 string gt number 1e2 gt 100 0 string gt number 15 1500 0 Note that a numeric representation using a decimal point or an exponent marker is not recognized unless radix is 10 4 7 Fixnum and Flonum Operations This section describes numerical operations that are restricted forms of the operations described above These operations are useful because they compile very efficiently However care should be exercised if used improperly these operations can return incorrect answers or even malformed objects that confuse the garbage collector 4 7 1 Fixnum Operations A fixnum is an exact integer that is small enough to fit in a machine word In MIT Scheme fixnums are typically 24 or 26 bits depending on the machine it is reasonable to assume that fixnums are at least 24 bits Fixnums are signed they are encoded using 2 s complement Chapter 4 Numbers 57 All exact integers that are small enough to be encoded as fixnums are always encoded as fixnums in other words any exact integer that is not a fixnum is too big to be encoded as such For this reason small constants such as 0 or 1 are guaranteed to be fixnums fix fixnum object Returns stt if object is a fixnum otherwise returns ttf Here is an expression that determines t
101. required defn 0 17 parameter rest defn 0 00 17 parent of directory 0 eee ee ioti 190 parent of environment defn 7 parenthesis as external representation 87 101 parsing of external representation 166 pasting of bit strings ooooo o ooooo o 106 pasting of lisboa ins 93 pasting of strings 00 76 pasting of symbols 04 113 path directory defn 2 005 190 DGG MATS cerdas ia lod EIS 187 pathname defn 0 0 0000 0 0200s 187 pathname components ss lesse 189 pathname absolute defn 197 pathname relative defn 197 period as external representation 87 physical size of hash table defn 129 plus sign in entries oo ooooooocoroo o 5 DOE dit alas 159 Concept Index port dell 4i ce rb pedra 159 port number TOP 3 6564 ecc Re erg 220 port primitivos seses n orisa impres 176 port type sies heebRe A d sean Reese rand port console4 c 2 epe pata 161 port current cene rer tp RR doro ups 159 port le cronica ride 161 port Sai 163 positive NUMBER mico i iaa is 48 precision of inexact number 46 predicate defn eiers inriere eres nriens is 11 97 predicate equivalence defh o o 37 prefix OSA ss ber rA ERRORS 80 pretty printer 22
102. returned are the following The names are in tended to be self explanatory Most of these names can only be returned on particular operating systems and so the operating system name is prefixed to the name regular directory unix symbolic link unix character device unix block device unix named pipe unix socket os2 named pipe win32 named pipe Chapter 15 Operating System Interface 201 file readable filename procedure Returns t if filename names a file that can be opened for input i e a readable file Otherwise returns f file writeable filename procedure Returns t if filename names a file that can be opened for output i e a writeable file Otherwise returns f file executable filename procedure Returns stt if filename names a file that can be executed Otherwise returns Under unix an executable file is identified by its mode bits Under OS 2 an executable file 13 has one of the file extensions exe com cmd or bat Under Windows an executable file has one of the file extensions exe com or bat file access filename mode procedure Mode must be an exact integer between O and 7 inclusive it is a bitwise encoded predicate selector with 1 meaning executable 2 meaning writeable and 4 mean ing readable file access returns t if filename exists and satisfies the predicates selected by mode For example if mode is 5 then file
103. server socket it continues to listen for additional client connections You can have multiple client connections to the same server socket open si multaneously open tcp server socket service address procedure This procedure opens a server socket that listens for connections to service the socket will continue to listen until you close it The returned value is a server socket object Chapter 15 Operating System Interface 221 An error is signalled if another process is already listening on the service Additionally ports whose number is less than 1024 are privileged on many operating systems and cannot be used by non privileged processes if service specifies such a port and you do not have administrative privileges an error may be signalled The optional argument address specifies the IP address on which the socket will listen If this argument is not supplied or is given as f then the socket listens on all IP addresses for this machine This is equivalent to passing the result of calling host address any tcp server connection accept server socket block peer address procedure Checks to see if a client has connected to server socket If so an 1 O port is returned The returned port can be read and written using ordinary Scheme 1 O procedures such as read char and write char The argument block says what to do if no client has connected at the time of the call If f it says to return immediately with two values of Oth
104. simultaneously is much faster than computing them separately For example the following are equivalent lambda n d cons quotient n d remainder n d lambda n d let qr integer divide n d cons integer divide quotient qr integer divide remainder qr gcd nl procedure lcm nl procedure These procedures return the greatest common divisor or least common multiple of their arguments The result is always non negative gcd 32 36 gt 4 gcd gt 0 1cm 32 36 gt 288 lem 32 0 36 gt 288 0 inexact 1cm gt 1 numerator q procedure denominator q procedure These procedures return the numerator or denominator of their argument the result is computed as if the argument was represented as a fraction in lowest terms The denominator is always positive The denominator of 0 is defined to be 1 numerator 6 4 gt 3 denominator 6 4 gt 2 denominator exact gt inexact 6 4 gt 2 0 Chapter 4 Numbers 51 floor x procedure ceiling x procedure truncate x procedure round x procedure These procedures return integers floor returns the largest integer not larger than x ceiling returns the smallest integer not smaller than x truncate returns the integer closest to x whose absolute value is not larger than the absolute value of x round returns the closest integer to x rounding to even when x is halfway between two integers Rationale round rounds to even for consi
105. string2 procedure substring match backward stringl start end string2 start end procedure string match backward ci stringl string2 procedure substring match backward ci stringl start end string2 start end procedure Compares the two strings substrings starting from the end and matching toward the front returning the number of characters that are the same If the two strings sub strings end differently returns 0 The ci procedures don t distinguish uppercase and lowercase letters string match backward ci BULBOUS fractious gt 3 matches ous string prefix stringl string2 procedure substring prefix stringl start1 end1 string2 start2 end2 procedure string prefix ci stringl string2 procedure substring prefix ci string start1 end1 string2 start2 end2 procedure These procedures return t if the first string substring forms the prefix of the second otherwise returns amp f The ci procedures don t distinguish uppercase and lowercase letters string prefix abc abcdef gt dit string prefix any string gt dit string suffix stringl string2 procedure substring suffix stringl startl end1 string2 start2 end2 procedure string suffix ci stringl string2 procedure substring suffix ci string start1 end1 string2 start2 end2 procedure These procedures return stt if the first string substring forms the suffix of the second otherwise returns f The ci procedures don t distinguish uppercase and l
106. system utilities like the bitmap editor Any problems resulting in failure are signalled by a f return value bitmap from dib dib dib palette hpalette procedure Return type hbitmap Calls the BitmapFromDib entry of DIBUTILS DLL The returned value is a device dependent bitmap The colours from the DIB are matched against colors in palette dib from bitmap bitmap hbitmap style dword bits word procedure palette hpalette Return type dib Returns a DIB containing the same image as the device dependent bitmap bitmap Style determines the kind of DIB e g compression style Calls the DibFromBitmap entry of DIBUTILS DLL Chapter 18 Win32 Package Reference 281 dib blt dest hdc x int y int w int h int src dib src x int procedure src y int raster op long Return type bool Calls the DibB1t entry of DIBUTILS DLL Similar to the Win32 API BitBlt call but draws a DIB rather than a piece of another device context Draws the dib on device context hdc at position x y A rectangle of width w and height h is copied from position src x src y of dib Raster op is supposed to allow the source and destination to be combined but I don t think I got this right so stick to SRCCOPY delete dib dib handle handle procedure Return type bool Calls the DeleteDIB entry of DIBUTILS DLL Note that the parameter is a handle and not a dib This allows us to destroy a DIB and reclaim its memory by knowing
107. t want to consider any previous input 17 11 5 Miscellaneous Operations for OS 2 Graphics These operations allow you to change the font used for drawing text in a graphics device window take a snapshot of a graphics device window and return it as an image object and draw multiple lines efficiently set font font name operation on os2 graphics device This operation sets the font used for drawing text in the graphics device win dow Font name is a string describing the font this string is in the form point size gt lt family name gt for example 10 Courier You may specify any fixed pitch 272 MIT Scheme Reference font family in any point size that is supported for that font family This includes both image fonts and outline fonts capture image x left y bottom x right y top operation on os2 graphics device This operation creates and returns an image that contains part of the client area of the graphics device window The portion of the client area that is selected is specified by the four coordinate arguments which are given in the current virtual coordinates for the device See Section 17 8 Images page 257 for more information about manipulating images draw lines xv yv operation on os2 graphics device This operation draws multiple disjoint lines it is like multiple calls to graphics draw line but much faster The arguments xv and yv are vectors of coordinates these vectors must be the same length and the length mus
108. terminating character as a newly allocated string This procedure ignores the blocking mode of the port blocking unconditionally until it sees either a delimiter or eof of file If end of file is encountered before any characters are read an end of file object is returned On many input ports this operation is significantly faster than the following equiva lent code using peek char and read char 3 char ready exists to make it possible for a program to accept characters from in teractive ports without getting stuck waiting for input Any input editors associated with such ports must make sure that characters whose existence has been asserted by char ready cannot be rubbed out If char ready were to return f at end of file a port at end of file would be indistinguishable from an interactive port that has no ready characters Chapter 14 Input Output 167 define read string char set input port let char peek char input port if eof object char char list gt string let loop char char if or eof object char char set member char set char E begin read char input port cons char loop peek char input port read line input port procedure read line reads a single line of text from input port and returns that line as a newly allocated string The newline terminating the line if any is discarded and does not appear in the returned string This procedure ignores the blocking mode of
109. the lambda expression is evaluated is remembered as part of the procedure it is called the closing environment When the procedure is later called with some arguments the closing environment is extended by binding the variables in the formal parameter list to fresh locations and the locations are filled with the arguments according to rules about to be given The new environment created by this process is referred to as the invocation environment Once the invocation environment has been constructed the expressions in the body of the lambda expression are evaluated sequentially in it This means that the region of the variables bound by the lambda expression is all of the expressions in the body The result of evaluating the last expression in the body is returned as the result of the procedure call Formals the formal parameter list is often referred to as a lambda list The process of matching up formal parameters with arguments is somewhat involved There are three types of parameters and the matching treats each in sequence Required All of the required parameters are matched against the arguments first If there are fewer arguments than required parameters an error of type condition type wrong number of arguments is signalled this error is also signalled if there are more arguments than required parameters and there are no further parameters Optional Once the required parameters have all been matched the optional param eters ar
110. the port blocking unconditionally until it has read an entire line If end of file is encountered before any characters are read an end of file object is returned read string string input port procedure read substring string start end input port procedure read string and read substring fill the specified region of string with characters read from input port until the region is full or else there are no more characters available from the port For read string the region is all of string and for read substring the region is that part of string specified by start and end The returned value is the number of characters filled into the region However there are several interesting cases to consider e Ifread string read substring is called when input port is at end of file then the returned value is 0 Note that end of file can mean a file port that is at the file s end a string port that is at the string s end or any other port that will never produce more characters e If input port is an interactive port e g a terminal and one or more characters are immediately available the region is filled using the available characters The procedure then returns immediately without waiting for further characters even if the number of available characters is less than the size of the region The returned value is the number of characters actually filled in e If input port is an interactive port and no characters are immedia
111. time Name is the name of the procedure and is for documentation purposes only This form does not define a procedure called name It is more like lambda The name might be used for debugging and pretty printing A windows procedure has a fixed number of parameters i e no rest parameters or varargs each of which is named and associated with a windows type type Both the name parameter and the windows type type must be symbols and are not evaluated The procedure returns a value of the windows type return type 278 MIT Scheme Reference The following example creates a procedure that takes a window handle hwnd and a string and returns a boolean boo1 result The procedure does this by calling the SetWindowText entry in the module that is the value of the variable user32 d11 The variable set window title is defined to have this procedure as it s value define set window title windows procedure set window text window hwnd text string bool user32 dll SetWindowText set window title my win Hi gt dit 5 Changes window s title text set window title gt compiled procedure set window text Unbound variable When there are no options the created procedure will a check its arguments against the types b convert the arguments c call the C procedure and d convert the returned value No reversion is performed even if one of the types has a reversion defined Reverted types are rare I have never u
112. to the name of the procedure console i o port variable console i o port is an I O port that communicates with the console Under unix the console is the controlling terminal of the Scheme process Under Windows and OS 2 the console is the window that is created when Scheme starts up This variable is rarely used instead programs should use one of the standard ports defined above This variable should not be modified close port port procedure Closes port and returns an unspecified value If port is a file port the file is closed close input port port procedure Closes port and returns an unspecified value Port must be an input port or an 1 0 port if it is an I O port then only the input side of the port is closed close output port port procedure Closes port and returns an unspecified value Port must be an output port or an 1 O port if it is an I O port then only the output side of the port is closed 14 2 File Ports Before Scheme can access a file for reading or writing it is necessary to open a port to the file This section describes procedures used to open ports to files Such ports are closed like any other port by close port File ports are automatically closed if and when they are reclaimed by the garbage collector Before opening a file for input or output by whatever method the filename argument is converted to canonical form by calling the procedure merge pathnames with filename as its sole argument Th
113. to the right of the last character of the matched substring is returned otherwise f is returned substring search backward limits its search to the specified substring of string string search backward searches all of string string search backward rat pirate gt 5 string search backward rat pirate rating 10 substring search backward rat pirate rating 1 8 gt 5 substring search backward rat pirate rating 9 13 gt df string search all pattern string procedure substring search all pattern string start end procedure Pattern must be a string Searches string to find all occurrences of the substring pattern Returns a list of the occurrences each element of the list is an index pointing to the first character of an occurrence substring search all limits its search to the specified substring of string string search all searches all of string string search all rat pirate gt 2 string search all rat pirate rating gt 2 T7 substring search all rat pirate rating 4 13 7 substring search all rat pirate rating 9 13 0 substring pattern string procedure Pattern must be a string Searches string to see if it contains the substring pattern Returns t if pattern is a substring of string otherwise returns f Chapter 6 Strings 79 substring rat pirate gt t substring rat outrage gt f substring any string gt dit if substring mo
114. tree type of wt tree The average and worst case times required by this operation are proportional to the logarithm of the size of wt tree wt tree union wt tree 1 wt tree 2 procedure Returns a new tree containing all the associations from both trees This operation is asymmetric when both trees have an association for the same key the returned tree associates the datum from wt tree 2 with the key Thus if the trees are viewed as discrete maps then wt tree union computes the map override of wt tree 1 by wt tree 2 If the trees are viewed as sets the result is the set union of the arguments The worst case time required by this operation is proportional to the sum of the sizes of both trees If the minimum key of one tree is greater than the maximum key of the other tree then the worst case time required is proportional to the logarithm of the size of the larger tree wt tree intersection wt tree 1 wt tree 2 procedure Returns a new tree containing all and only those associations from wt tree 1 that have keys appearing as the key of an association in wt tree 2 Thus the associated data in the result are those from wt tree 1 If the trees are being used as sets the result is the set intersection of the arguments As a discrete map operation wt tree intersection computes the domain restriction of wt tree 1 to the domain of wt tree 2 The worst case time required by this operation is proportional to the sum of the sizes of the trees Chapter
115. treel tree2 wt tree union merge treel tree2 lambda key vali val2 val2 The merge procedure takes the key as a parameter in case the data are not independent of the key 11 7 4 Indexing Operations on Weight Balanced Trees Weight balanced trees support operations that view the tree as sorted sequence of as sociations Elements of the sequence can be accessed by position and the position of an element in the sequence can be determined both in logarthmic time Chapter 11 Associations 145 wt tree index wt tree index procedure wt tree index datum wt tree index procedure wt tree index pair wt tree index procedure Returns the 0 based indexth association of wt tree in the sorted sequence under the tree s ordering relation on the keys wt tree index returns the indexth key wt tree index datum returns the datum associated with the indexth key and wt tree index pair returns a new pair key datum which is the cons of the indexth key and its datum The average and worst case times required by this operation are proportional to the logarithm of the number of associations in the tree These operations signal a condition of type condition type bad range argument if index lt 0 or if index is greater than or equal to the number of associations in the tree If the tree is empty they signal an anonymous error Indexing can be used to find the median and maximum keys in the tree as follows median wt tree index wt tree quotient wt
116. useful however for collecting the list of restarts for inclusion in newly generated condition objects or for inspecting the current state of the system find restart name restarts procedure Returns the first restart object named name in the list of restarts permissible values for restarts are described above in Section 16 4 Restarts page 231 When used in a condition handler find restart is usually passed the name of a particular restart and the condition object that has been signalled In this way the handler finds only restarts that were available when the condition was created usually the same as when it was signalled If restarts is omitted the currently active restarts would be used and these often include restarts added after the condition ocurred invoke restart restart argument procedure Calls the restart effector encapsulated in restart passing the specified arguments to it invoke restart is intended for use by condition handling code that understands the protocol implemented by restart and can therefore calculate and pass an appropriate set of arguments If a condition handler needs to interact with a user to gather the arguments for an effector e g if it does not understand the protocol implemented by restart invoke restart interactively should be used instead of invoke restart invoke restart interactively restart procedure First calls the interactor encapsulated in restart to interactively gather the argume
117. 0 25 literal and quote oeste b ER REESE 24 literal identifier aS oo oooooooo 11 loading DUDS 2 ir De RR ed ee TERR 217 A esrb WADE eiae tate a 10 location of variable 0ooo ocooooooooo m o 6 logical operations on fixnums 58 long precision of inexact number 46 loopback interface oooococococcoooo m o 223 looping see iteration expressions 29 ld Wer caserio aia 11 lowercase character conversion 65 lowercase m s ring ellc Rr eR 75 M magnitude of real number 49 manifest types defn 00 000 3 mapping ot listens pisan 96 mapping Of Str its cai sass naadeee 119 mapping of vector 0 0 eee eee eee 102 matching of Strings rcs tse 80 maximum length of string defn 84 maximum of numbers 0 05 48 memoization of promise 116 merging of pathnames ssssssssss 193 meta bucky bit prefix defn 63 method unparser defn 205 174 minimum of numbers 000005 48 modification time of file 202 modification of bit string 108 modification of string esses 82 modification of vector sses esses eee 104 modulus of hashing procedure 126 314 modulus of integerS oooooomoooooo 49 moving of bit string elemen
118. 00000000 100000000 gt dit eqv cons 1 2 cons 1 2 gt df eqv lambda 1 lambda 2 gt df equ f nil gt f let p lambda x x eqv p p gt dit The following examples illustrate cases in which the above rules do not fully specify the behavior of eqv All that can be said about such cases is that the value returned by eqv must be a boolean eqv gt unspecified equ O 10 gt unspecified eqv lambda x x lambda x x unspecified eqv lambda x x lambda y y unspecified The next set of examples shows the use of eqv with procedures that have local state gen counter must return a distinct procedure every time since each procedure has its own internal counter gen loser however returns equivalent procedures each time since the local state does not affect the value or side effects of the procedures define gen counter lambda let n 0 lambda set n n 1 n let g gen counter eqv g g dt eqv gen counter gen counter gt df define gen loser lambda let n 0 lambda set n n 10 27 let g gen loser eqv g g gt dt eqv gen loser gen loser gt unspecified Chapter 3 Equivalence Predicates 39 letrec f lambda if equ f g both f g lambda if eqv f g both g eqv f g unspecified letrec f lambda O if eqv f g f bo
119. 01 100 101 102 unspecified memv 101 100 101 102 gt 101 102 member procedure predicate procedure Returns a procedure similar to memq except that predicate which must be an equiv alence predicate is used instead of eq This could be used to define memv as follows define memv member procedure eqv 7 7 Mapping of Lists map procedure list list procedure Procedure must be a procedure taking as many arguments as there are lists If more than one list is given then they must all be the same length map applies procedure element wise to the elements of the lists and returns a list of the results in order from left to right The dynamic order in which procedure is applied to the elements of the lists is unspecified use for each to sequence side effects map cadr a b d e g h gt beh map lambda n expt n n 1 2 34 1 4 27 256 map 1 2 3 4 5 6 gt 57 9 let count 0 map lambda ignored set count count 1 count a b c unspecified 3 Although they are often used as predicates memq memv and member do not have question marks in their names because they return useful values rather than just t or f Chapter 7 Lists 97 map initial value procedure list1 list2 procedure Similar to map except that the resulting list is terminated by initial value rather than the empty list The following are equivalent map procedure list list map p
120. 06 make directory c e RERO ERE 199 make enti3ty 222 ordre Exe sehe 152 make environment eee 157 make eof obje6t viv c v le EIE UG e veg 19 make eq hash tabl cli RERO 126 make equal hash table 126 make eqv hash table o 126 make graphics device suu 251 make initialized vector 102 Dnake liSt i esas a GP 90 99 make pathn me 22 22 0 dex Biens 191 MIT Scheme Reference make polaf sepp dd Rie rh ps 53 make port rio ra 178 make port Lbype ii su pad 177 make primitive procedure 149 make random State cinco dia 61 make rb tr e mai v e aaa 135 make record type esee 114 make rectangular iio 52 53 make string 22 eR REX ES E T ERRARE VES 72 make string hash table 126 MAke VECLOL Mii ee peii EEE EE 101 j ke ELIO a 140 make wt tree type conosca rones 140 MAP nes 96 MAP id e RSS 97 map window on x graphics device 261 Mira a ipi 48 maximize window on os2 graphics device 269 measure interval ss sess see eee 214 MOMDO Vic ci osseckkeiecenolvip DU gi Godan iron RD 96 membe r procedure i cvecveerpe e e eee ERR 96 MOMG ME 96 MOMV cores we RE HU gn E e EE pide ted ird 96 merge pathnames esse 161 193 N rg SOrEt sigh ak deo Ud teda be ada 99 merge sort ie dee es T pP Edu 104 microcode id operating system 221 mic
121. 0oooooooooo oo 65 comparison of numbers 00ooocccoccc 47 comparison of StTINBS 0oooocoooocooooo T3 compiled procedure type liue 147 component selection of bit string 106 component selection of cell 114 component selection of character 67 component selection of liSt 91 component selection of pair o oo o oo 88 component selection of stream 119 component selection of string 18 component selection of vector 102 component selection of weak pair 120 components of pathname 189 compound procedure ssseeeess esses 147 309 CONG CLAUSE seo oo cuta tnter ais 26 condition defui rcr ch gene deans 237 condition handler defn 0 229 condition instance defn 237 condition signalling defn iussu 226 condition type secl RR Re 226 240 conditional expression defn 26 console clearing oiv diri 170 console port comino ra 161 console ringing the bell 170 Joining 10 constant expression defn 0000 14 constant and quasiquote lesse 25 constant and quote sseeeeee enses 24 construction of bit string 105 construction of cell ooooooccoooccooooo 114 construction of characteT oooooooo oooo
122. 11 Associations 143 wt tree difference wt tree 1 wt tree 2 procedure Returns a new tree containing all and only those associations from wt tree 1 that have keys that do not appear as the key of an association in wt tree 2 If the trees are viewed as sets the result is the asymmetric set difference of the arguments As a discrete map operation it computes the domain restriction of wt tree 1 to the com plement of the domain of wt tree 2 The worst case time required by this operation is proportional to the sum of the sizes of the trees wt tree subset wt tree 1 wt tree 2 procedure Returns t iff the key of each association in wt tree 1 is the key of some association in wt tree 2 otherwise returns f Viewed as a set operation wt tree subset is the improper subset predicate A proper subset predicate can be constructed define proper subset s1 s2 and wt tree subset s1 s2 lt wt tree size s1 wt tree size s2 As a discrete map operation wt tree subset is the subset test on the domain s of the map s In the worst case the time required by this operation is proportional to the size of wt tree 1 wt tree set equal wt tree 1 wt tree 2 procedure Returns stt iff for every association in wt tree 1 there is an association in wt tree 2 that has the same key and vice versa Viewing the arguments as sets wt tree set equal is the set equality predicate As a map operation it determines if two maps are defined on the same doma
123. 2 definition top level o ooo oooooo o oo o 23 definition top level defn 0 ooooo o 22 deletion of alist element 122 deletion of file 22 2 esie tmn be nihai 198 deletion of list element o o ooooooo ooo 94 delimiter in programs defn 10 device coordinates graphics defn 252 device pathname component 189 difference of numbers 00005 48 directive format defn 00 Tr MIT Scheme Reference directory path def oooooooocccoomo 190 directory converting pathname to 195 directory current working defn 197 directory pathname component 189 directory predicate for ooocoooooooooo 200 directory reading 195 204 discrete maps using binary trees 139 discretionary flushing of buffered output 168 disembodied property list 110 display clearing viii s 170 display X graphicsS 0ooooooooocooooocoo 259 division of integers ooooooooo 49 division of numbers sssesseesseeseess 48 DLL DIBUTILS DLL ert cerros 279 DLL EXPOS o rr rhe er RED 282 DLL GDIS2DEL cima e 271 DLL KERNEL32 DLL 277 DLE loading oo cof e Rv eme 217 DLL USER32 DLL eMe 277 dot as external representation 87 dotted notation for pa
124. 2 0 b Rbe raivaa very r4 57 PDK O A eni au eue p 58 fi Zero os amine cedere and dup Rebus Gun que 57 EUG A a 59 daros 59 rg A O See eee 59 OS A A e zu 59 flOSb2liliblbeec etc beeen a hee eto Te 59 ng P 59 LOPS lese spRenevbspPe esp v E eDPOipeipixads 59 TO adria 59 dT M a ia 60 o A tees minii doe Sane rE D EDE 60 PL OF aC AM es sped ia See eaves aie gre oro Boe dM I RE 60 flosatan2 atari rs Managed 60 Elo ceiling so citar ir leads den mile asd 60 flo ceiling exact i e mp RE ps 60 flO5COB L0b iy Ee O4e rH RIA quete beri es 60 pd lo p q o COCO dod tese NO 60 O O 60 flo flonume e eater eer eae a 59 flOoiflOOEP 2222 229b ade 60 flo floof 5ex ct dde ep das 60 1 Eo 79 o 1 PARES OO TO IE Ae Ip enbeg Re ag 60 flornegate ves 2 estoy aos te hae ee Re IUE 59 296 floinegative js nessa OO Elo positive 22 Medias bg DH gare RE PRESS 59 flo r ndom nit 22222 ga Seas egos 61 fl rf undu 2 aaae a EE DER 60 floiround exa ct i i v a er e eua 60 flOiSin sagsc x o Re e ER a RF ERERSE 60 floisqrt ce kp pb PR uana ber 60 5 eel lo ia 6 ee bea eee mtb 60 a a s 002538 eho weee eee beheld 60 flo truncate gt exact 2 cece eee eee 60 ELIOT OG a a Seed 59 flo m p rser fast tem iii res 54 flonum unparser cutoff s tessei 54 flOO0Pf5 2 05 ebeweiBeeRe o sspIV I Pera in geben 50 floor exa ct o 4 e poe RR RP ML UR PEERS 51 fluid l t 5 2406x Sid S aie 21 22 23 29 flush OHtp t ce bel
125. 2326 pIEPR eI E ta debes 170 primitive procedure defn uuuu 147 primitive procedure type 147 print name of symbol ooo o oo Ti printed output in examples suus 5 printing graphics output 265 procedures e rra di EG 147 procedure call defn 0 00 000 15 procedure define defd ooooocccococoo o 22 procedure closing environment defn 17 procedure compiled 0oo oooooo ooo 147 procedure compound ssesess esses 147 procedure construction s lesse eese E procedure entry format ssssss esses 6 procedure escape defn 044 149 procedure interpreted o ooooooocooooc o 147 procedure invocation environment defn nm procedure of application hook 152 procedure primitive ooo oooomccooomo 147 procedure type sseeeeeeeee ee eee eee 147 product of numbers ee ee ee ee wee 48 promise defn 2k bee eg ER LEER E 116 promise construction sse eese 116 promise foreground Pann 116 promplinhg i128 ar paa ers 175 proper tail recursion defn 3 property list ias ba es 121 123 124 property list of symbol 110 protocol restart defn o0ooooo ooo 231 pseudo random number uuusssse 60 315 Q quote as external representation 24 quotie
126. 27 238 239 240 specialization of condition types defn 225 specified result in examples 4 standard character o ooooooccooorcoommoo 65 standard character defn 0 69 standard operations on port 177 standard ports 2 22 rrer tenemos 160 standard Scheme defn ssueuusuuu 3 start of substring defn 0 71 start of subvector defn 00 101 static SCOPING ironico rd a daa 8 static scoping defn 2 00000 3 static types defn 0 0 000005 3 stream defn cesse ceded estr 118 stream converting to list 118 string index defn 2 0 00005 71 string length defn 0 00 0 T string character defn sssuuuu 71 string converting to input port 163 string converting to list 91 string input and output portS 163 string input from port 166 179 string interning as symbol 112 string of bits defn ooooooooooo o 105 String output to port 2 zo2soses eco e 169 strong types defn 0 0000000 3 strongly held keys of hash table 126 SUDPTOCES enes ects heed veceasendsnd ered 215 Substring defn 12 eese rtp ph ea ehe Ti substring of bit string eerte 107 substring output to port
127. 292 ch r downcase 2 ic e cr o ed aes 65 char graphiCT isss ssec d ved ia 69 175 char integer limit 2 29 0 Lp npiS 67 Char Lower Case muii e es bene ER 69 char nu meric i022 e 9 REIR E PEES 69 char ready 2 10 94 4 bIRebeeew ee ri ES 166 char ready on input port sss 179 cliar s0t bee e ia pP are Ras 69 clar set differ nce c e see ee eas 70 char set intersection sess 70 Char Set inver diaria ais 70 char set member oer e ic 69 char set members e n eee hs 69 char set union eii re ios bg 88s 70 char set alphab6etiC i2e l4 c REA 69 char set alphanumeriC e b rers 69 char seUvigraphic6 42 oia 69 char set lower case sese ess 69 char set not graphiC 4 ed ces te ded rk Ree 69 char set not whitespace 4 69 ch r set num riC sien e be er a 69 char setistandard oe e hse eed cin ees 69 char set iupper case isis v pe ERIS 68 char set whitespace o oo oo o o 69 77 char set O 68 clar standard cos lelel6ct DRE ies 65 69 char pcase 2224 e eR Lit RO ea 65 char u pper case o 2 bad Pie tbe ide 69 char whitespace o oic rm li 69 charte idk eee bk E ii 37 65 CHAT ni ee teat ate tweed dala da 65 CHAT ir riada 65 CHAPS a ad E ia 65 Char a a aii 65 67 A neque 3 eee oe nae hn 65 Chars gt Char set 2 c e is sks na epo tesa ds 69 chars remaining on input port 180 circular LIS
128. 45 90 stt draw circle x y radius operation on x graphics device fill circle x y radius operation on x graphics device These operations draw a circle outline or a filled circle solid at on the graph ics device at the virtual coordinates given by x and y These operations could be implemented trivially interms of the draw arc operation set border width width operation on x graphics device set internal border width width operation on x graphics device These operations change the external and internal border widths of a window Width must be an exact non negative integer specified in pixels The change takes place im mediately Note that changing the internal border width can cause displayed graphics to be garbled we recommend calling graphics clear on the window s device after doing so set font font name operation on x graphics device Changes the font used when drawing text in a window Font name must be a string that is a font name known to the X server This operation does not affect text drawn prior to its invocation set mouse shape shape number operation on x graphics device Changes the shape of the mouse cursor Shape number is an exact non negative integer that is used as an index into the mouse shape font when multiplied by 2 this number corresponds to an index in the file asr include X11 cursorfont h map window operation on x graphics device withdraw window operation on x graphics device These operations control t
129. 5 15 2 Working Directory 00 0 serait ii eee ee 197 15 3 File Manipulation eb pee eer idee Reb 198 15 4 Directory Reader 0 0 cece cece eese 204 15 5 Date and Time idee re E aos 205 15 5 1 Universal Time s comi cig anid DX A 205 15 5 2 Decoded Time 0 00 cece ene eens 205 15 5 3 Files TIME censor tert eR RR RES 208 15 5 4 Time Format ConversioN oo ooo oooo 209 15 5 5 External Representation of Time 22 15 6 Machine Time 0 ccc ccc ce nen 213 15 7 SUDPrOCESS6S idad pone doe ee ER debi a 215 15 7 1 Subprocess Procedures oooooooooooo 215 15 7 2 Subprocess Conditions 0o o ooocoooo o 216 15 7 3 Subprocess Opti0OS 00oococooocccooco eee 216 15 8 TOPSocketS orina e 219 15 9 Miscellaneous OS FacilitieS o0oooooooooooo m o 221 A os A 225 16 1 Condition Signaling sess eses aansneed ee oc 226 16 2 Error Messages sesiis rie pian sce e eee erence Eaa 228 16 3 Condition Handling 0 00 eee ee eee 229 10 4 JR SUaPUS enne laci n Re eee RR Ro uet ee SR des 231 16 4 1 Establishing Restart Code 232 16 4 2 Invoking Standard Restart Code 234 16 4 3 Finding and Invoking General Restart Code 235 16 4 4 The Named Restart Abstraction 236 16 5 Condition Instances ssseeseeeeeeeee sees 237 16 5 1 Generating Operations on Conditions 291 16 5 2 Condition Abstra
130. 86 MIT Scheme Reference Chapter 15 Operating System Interface 187 15 Operating System Interface The Scheme standard provides a simple mechanism for reading and writing files file ports MIT Scheme provides additional tools for dealing with other aspects of the operating system e Pathnames are a reasonably operating system independent tool for manipulating the component parts of file names This can be useful for implementing defaulting of file name components e Control over the current working directory the place in the file system from which relative file names are interpreted e Procedures that rename copy delete and test for the existence of files Also proce dures that return detailed information about a particular file such as its type directory link etc or length e Procedures for reading the contents of a directory e Procedures for obtaining times in various formats converting between the formats and generating human readable time strings e Procedures to run other programs as subprocesses of Scheme to read their output and write input to them e means to determine the operating system Scheme is running under 15 1 Pathnames MIT Scheme programs need to use names to designate files The main difficulty in dealing with names of files is that different file systems have different naming formats for files For example here is a table of several file systems actually operating systems that provide file sy
131. Ei ee e ERR aum E 99 Cle8T b UP Ie RO Hare DERE b eis 170 close all open fijl g 22 6 3 1335 162 elose input port i olore RRIARUO Ri 161 close outp t port o v pre E PREX 161 CloSe pO ELb id hidaneses ecd etna os 161 close tcp server socket 221 COLORS i epi E e OPERI ea 266 MIT Scheme Reference compiled procedure eese 148 COMPLEX esis cern achat aii boxes 46 compound procedure sess ro 148 CONCA ME i neo eios oa dao talc edens 34 COM e iris uhm end bbe 5 26 29 109 condition accessor 237 238 240 condition constructor 231 238 condition predicate 237 238 condition signaller 2 0 237 238 condition type error sss 240 condition type field names 240 condition type generalizations 241 condition type arithmetic error 247 condition type bad range argument 48 53 68 108 134 244 condition type breakpoint 226 249 condition type control error 248 condition type datum out of range 244 condition type derived file error 246 condition type derived port error 246 condition type divide by zero 247 condition type error 230 239 240 242 condition type file error 245 condition type file operation error 162 196 198 199 245 condition type floating point overflow 247
132. Error System 231 be changed to a procedure of one argument and will then be invoked with standard error hook rebound to f by standard error handler just prior to starting the error REPL It is passed one argument the condition being signalled standard warning handler condition procedure This is the procedure called internally by warn after it calls signal condition The normal behavior of standard warning handler is to print a message but see standard warning hook More precisely the message is printed to the port returned by notification output port The message is formed by first printing the string Warning to this port and then calling write condition report on condition and the port In order to simulate the effect of calling warn code may call signal condition di rectly and then call standard warning handler if signal condition returns This is not sufficient to implement the muffle warning protocol however For that pur pose an explicit restart must be provided standard warning hook variable This variable controls the behavior of the procedure standard warning handler and hence warn It is intended to be bound with fluid let and is normally f It may be changed to a procedure of one argument and will then be invoked with standard warning hook rebound to f by standard warning handler in lieu of writing the warning message It is passed one argument the condition being signalled 16 4 Restarts The Scheme erro
133. If input port has no more characters but will eventually have some more e g a terminal where nothing has been typed recently and it is in non blocking mode f is returned otherwise the operation hangs until input is available peek char input port operation on input port Reads the next character available from input port and returns it The character is not removed from input port and a subsequent attempt to read from the port will get that character again In other respects this operation behaves like read char discard char input port operation on input port Discards the next character available from input port and returns an unspecified value In other respects this operation behaves like read char char ready input port k operation on input port char ready returns t if at least one character is available to be read from input port If no characters are available the operation waits up to k milliseconds before returning f returning immediately if any characters become available while it is waiting read string input port char set operation on input port discard chars input port char set operation on input port These operations are like read char and discard char except that they read or discard multiple characters at once This can have a marked performance improve ment on buffered input ports All characters up to but excluding the first character in char set or end of file are read from input port read string returns th
134. MIT Scheme Reference Manual Edition 1 94 for Scheme Release 7 5 16 July 2001 by Chris Hanson the MIT Scheme Team and a cast of thousands Copyright c 1988 2001 Massachusetts Institute of Technology Permission is granted to copy distribute and or modify this document under the terms of the GNU Free Documentation License Version 1 1 or any later version published by the Free Software Foundation with no Invariant Sections with no Front Cover Texts and with no Back Cover Texts A copy of the license is included in the section entitled GNU Free Documentation License Acknowledgements 1 Acknowledgements While a cast of thousands may be an overstatement it is certainly the case that this document represents the work of many people First and foremost thanks go to the authors of the Revised 4 Report on the Algorithmic Language Scheme from which much of this document is derived Thanks also to BBN Advanced Computers Inc for the use of parts of their Butterfly Scheme Reference and to Margaret O Connell for translating it from BBN s text formatting language to ours Special thanks to Richard Stallman Bob Chassell and Brian Fox all of the Free Software Foundation for creating and maintaining the Texinfo formatting language in which this document is written This report describes research done at the Artificial Intelligence Laboratory and the Laboratory for Computer Science both of the Massachusetts Institute of Technology
135. MesS 0ooooocooocoooomoo 11 in entries reo EM MERI ERU Hber RE EA 5 Bron 2285 sed aradin E eeaede ede iraan 5 1 as external representation 26 as external representation pa FAN entries cie aos tira 5 as escape character in String TE 1D table dell rrr RR ken 123 308 A absolute pathname defn suse 197 absolute value of number 49 access time of file coii eee ee 202 access used with Setl ooooooccccccocoo 24 addition of numbers esros sisseroiiodeiss isu 48 address hashing 5421 ria 131 alist dein ecce eri ares renee ERES 121 alphabetic case of interned symbol 110 alphabetic case of StIIO8 oooooooooooo 75 alphabetic case insensitivity of programs defn o lia ide 11 alphabetic character defn oooooo o 69 alphanumeric character defn 69 apostrophe as external representation 24 appending of bit strings 106 appending of lists ooooooooooooo 93 appending of strings 00 000 76 appending of symbols 0 113 appending to output file 162 application hook defn Az 152 application of procedure issues 147 apply hook defn ssseeeseeeuess 152 argument evaluation order Lue 15 ASCOM character idee scite
136. NTS You may make a collection consisting of the Document and other documents released under this License and replace the individual copies of this License in the various documents with a single copy that is included in the collection provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects You may extract a single document from such a collection and distribute it individu ally under this License provided you insert a copy of this License into the extracted document and follow this License in all other respects regarding verbatim copying of that document 7 AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works in or on a volume of a storage or distribution medium does not as a whole count as a Modified Version of the Document provided no compilation copyright is claimed for the compilation Such a compilation is called an aggregate and this License does not apply to the other self contained works thus compiled with the Document on account of their being thus compiled if they are not themselves derivative works of the Document If the Cover Text requirement of section 3 is applicable to these copies of the Document then if the Document is less than one quarter of the entire aggregate the Document s Cover Texts may be placed on covers that surround only the Document within the aggre
137. Pathnames for other operating systems have different external representations 15 1 1 Filenames and Pathnames Pathname objects are usually created by parsing filenames character strings into com ponent parts MIT Scheme provides operations that convert filenames into pathnames and vice versa gt pathname object procedure Returns a pathname that is the equivalent of object Object must be a pathname or a string If object is a pathname it is returned If object is a string this procedure returns the pathname that corresponds to the string in this case it is equivalent to parse namestring object tf f gt pathname foo pathname 65 foo gt pathname usr morris pathname 66 usr morris parse namestring thing host defaults procedure This turns thing into a pathname Thing must be a pathname or a string If thing is a pathname it is returned If thing is a string this procedure returns the pathname that corresponds to the string parsed according to the syntax of the file system specified by host This procedure does not do defaulting of pathname components The optional arguments are used to determine what syntax should be used for parsing the string In general this is only really useful if your implementation of MIT Scheme supports more than one file system otherwise you would use pathname If given host must be a host object or f and defaults must be a pathname Host specifies the syntax used to
138. RS de AAA AAA AAA AA 101 D Bit lS esses kx e AAA AAA 105 10 Miscellaneous Datatypes sa aco cann hee ier nw RR 109 TI Associations sso be shew s eee ASSESS oS dw TT 121 12 Procedures 6 2956 69 xa 4249S 45445954594 147 lo Environments aL 155 I4 Inpub Cbpill sca Pid oot wee eee nee see oe esse eo 159 15 Operating System Interfaces 54 92092 rs 187 16 Error SEM uas bat pad eek e RC QE OR RC eS 225 TT Graphis awake ies ex m dw Rez A 251 18 Win32 Package Reference 242922229 oo 213 GNU Free Documentation License oooooooooo o 283 Binding Index 2222442 aed PE RISE RAE AG REG d iu see de oe 289 Concept IHE uuu ewes donde ta Gam ub d EE aie ib aod 307 MIT Scheme Reference Table of Contents Acknowledgements 222522229 ad a 1 a x ps 3 1 1 Notational Conventions lesse esses 4 MES m 4 1 1 2 Examples dre rias 4 l3 Entry Format crean ten RD TC reg 9 1 2 Scheme ConceptS ooooccocccccccccoccc e 6 1 2 1 Variable Bindings 00 0 0000 ee eee 6 1 2 2 Environment Concepts ss esses 7 1 2 8 Initial and Current Environments 7 1 2 4 Static Scoping 0 eee eee eee 8 1 2 5 True and False 2 2 eR her 8 1 2 6 External Representations ssess esses 9 1 2 7 Disjointness of Types 0 0c cece eee eee 9 1 2 8 Storage Model 0 c cece ee eee eee 9 1 8 Lexieal Conventions 32 244 da 10 1 3 4 Whitespace ess
139. Reb eee es 169 flush output on output port 181 fold left 2 2 22 di Ed 98 fold right 2299 46 9e ta e a pads 98 font structure on x graphics device 262 O sd pee ed 99 fOr each 2153 9 PIE e Ad ep 97 IO FCO bit sawn uks eos aid iaa 116 118 FOTMAE bos Sse A fe ee Sa 171 format error Message 562s v res 229 Torti ee eet aa a sl bewidednet ties 46 92 fresh lin meros capi aa nE 169 fresh line on output pOrtb o oo oo 181 G Ae E EE 50 gdi32 dll sa aceto ia daa 217 Eder e 7 157 general car 6dE iio la a 89 generate uninterned symbol 112 get default on x graphics device 262 get host by addresS oooocooocccocoooc oo 222 get host by name we ies cet dr be s 222 get host nom essor a ieee sees 222 get uniyersal time car la 205 global decoded time soos as 206 graphics bind drawing mode 255 graphics bind line style 255 Graphics chear omic 253 260 261 MIT Scheme Reference graphics Cl088 2 2 2 iba ii 252 graphics coordinate limits 252 graphics device coordinate limits 252 graphics disable buffering 256 graphics dragHCcursor ices gal et dis 254 graphics draw line isis cua na pas 253 graphics draw polnt s e 253 graphics draw text idisse es p ade 253 graphics enable buffering 256 graphics erase point see sees 253 graphics flush ocoeld
140. StEIng se 48e c ge ieee range eee les 72 276 String char Set ass e o tp rg pe edd 70 MIT Scheme Reference string gt decoded time oooo oooocooooo 211 string file time eder ae se 212 string inp t port i20 RR REPRE QUEDS 163 String lIisSt s is E uva 12 91 Stringp number i bep noe aaa E YR RR aun 56 String SIDO Ll median E SES cete 112 string gt uninterned symbol 112 string gt universal time 211 string append o s e P 4 eA RIYS 16 sString capitalize iesoaguge re adus 75 string capitalize issus eene rs 75 string capitalized isse esso e ees 75 String CiS pepin rn e alae b aee de dU Rd 73 Siring Clo 7 cel ra 74 String CiS ites sal o d e E eee PREEN 74 SUMING Cla ii eee ng e 74 String cl4T sto coca pr ERON Ea den 74 string compar ccoo ci 74 SLIDE COMPALO Cisco ni Res T4 String Copy da ska mane depa padded 72 String downcaS esso ciar T5 string downcase i lera beh ew 75 String filll aia acaba s 83 string find next char mcr cua die gies 19 string find next char ci es 79 string find next char in set 79 string find previous char 19 string find previous char ci 79 string find previous char in set 79 String h sh i224 a vee nee 74 113 String ASA MO vocoder 74 127 String CA ii 76 string length liliis esae e 44 13 84 String lower casef i
141. Sup port for this research is provided in part by the Advanced Research Projects Agency of the Department of Defense and by the National Science Foundation MIT Scheme Reference Chapter 1 Overview 3 1 Overview This manual is a detailed description of the MIT Scheme runtime system It is intended to be a reference document for programmers It does not describe how to run Scheme or how to interact with it that is the subject of the MIT Scheme User s Manual This chapter summarizes the semantics of Scheme briefly describes the MIT Scheme pro gramming environment and explains the syntactic and lexical conventions of the language Subsequent chapters describe special forms numerous data abstractions and facilities for input and output Throughout this manual we will make frequent references to standard Scheme which is the language defined by the document Revised 4 Report on the Algorithmic Language Scheme by William Clinger Jonathan Rees et al or by IEEE Std 1178 1990 IEEE Stan dard for the Scheme Programming Language in fact several parts of this document are copied from the Revised Report MIT Scheme is an extension of standard Scheme These are the significant semantic characteristics of the Scheme language Variables are statically scoped Scheme is a statically scoped programming language which means that each use of a variable is associated with a lexically apparent binding of that variable Algol is another static
142. To continue call RESTART with an option number RESTART 2 gt Specify an argument to use in its place RESTART 1 gt Return to read eval print level 1 error bad range argument datum operator procedure This procedure signals a condition of type condition type bad range argument The datum and operator fields of the condition are filled in from the corresponding arguments to the procedure the operand field of the condition is set to f Chapter 16 Error System 245 condition type inapplicable object datum operands condition type This type indicates an error in which a program attempted to apply an object that is not a procedure The object being applied is saved in the datum field and the arguments being passed to the object are saved as a list in the operands field 3 4 error The object 3 is not applicable To continue call RESTART with an option number RESTART 2 gt Specify a procedure to use in its place RESTART 1 gt Return to read eval print level 1 condition type file error filename condition type This is an abstract type It indicates that an error associated with a file has occurred For example attempting to delete a nonexistent file will signal an error The filename field contains a filename or pathname associated with the operation that failed condition type file operation error filename verb noun condition type reason operator operands This is the most common co
143. a ner ME darius 149 12 4 Application Hooks o ooooooooooronrranrnamo o 152 13 Environments sources 155 13 1 Environment Operations seseeeee eene 155 13 2 Environment Variables o oooooooocoooomooo 156 133 REPL Environment seseee seh 156 13 4 Interpreter Environments 0000 e eee eee eee 157 14 Input OU pte soe eecee neces ette 159 El SP ODS scheint don dn hr RR Ru hele ae d Melee ad 159 O Ned ahd ah tona eee ae a 161 143 String POPRUS 4d ge ERROR RO RERO EORR 163 14 4 Input Procedures lsluueessseeeeesee eese 165 14 5 Output Procedures ooooccccocccccocccccr ro 168 TACO Tonale escerai EITHER ar ari d 14 7 Custom Output 0 nn 173 14 8 Prompting ts cc et bRere RR pe ERR IE E 175 149 Port Primitives iii ed pt o el eed aad ees 176 149 1 Port LypesSi b RR Ree ds 177 14 9 2 Constructors and Accessors for Ports 178 14 9 3 Input Port Operations lisse else 179 14 9 4 Output Port Operations 181 14 9 5 Blocking Mode 00 eee eee eee 182 14 9 6 Terminal Mode 0 00 c cece eee eee 183 15 Operating System Interface 187 19 1 Pathnames n omtia taria dcir iras heeds 187 15 1 1 Filenames and Pathnames o oooo o o 188 15 1 2 Components of Pathnames oo ooo 189 15 1 3 Operations on Pathnames 192 15 1 4 Miscellaneous Pathname Procedures 19
144. a pathname that has no name type or version components just host device and directory components pwd is an alias for working directory pathname the long name is intended for programs and the short name for interactive use set working directory pathname filename procedure cd filename procedure Makes filename the current working directory and returns the new current working directory as a pathname Filename is coerced to a pathname using pathname as directory cd is an alias for set working directory pathname the long name is intended for programs and the short name for interactive use Additionally set working directory pathname modifies the value of default pathname defaults by merging the new working directory into it When this procedure is executed in the top level REP loop it changes the working directory of the running Scheme executable set working directory pathname usr morris blisp gt pathname usr morris blisp set working directory pathname gt ttlpathname usr morris This procedure signals an error if filename does not refer to an existing directory If filename describes a relative rather than absolute pathname this procedure in terprets it as relative to the current working directory before changing the working directory working directory pathname pathname usr morris set working directory pathname foo pathname usr morris foo with working directory pathnam
145. abetic case before generating the symbol This is the preferred way to create interned symbols as it guarantees the following independent of which case the imple mentation uses for symbols names eq bitBlt intern bitBlt gt itt The user should take care that string obeys the rules for identifiers see Section 1 3 3 Identifiers page 11 otherwise the resulting symbol cannot be read as itself MIT Scheme reserves a specific set of interned symbols for its own use If you use these reserved symbols it is possible that you could break specific pieces of software that depend on them The reserved symbols all have names beginning with the characters T and ending with the character thus none of these symbols can be read by the procedure read and hence are not likely to be used by accident For example intern 3t unnamed procedure produces a reserved symbol 112 MIT Scheme Reference intern soft string procedure Returns the interned symbol whose name is string Converts string to the standard alphabetic case before generating the symbol If no such interned symbol exists returns sf This is exactly like intern except that it will not create an interned symbol but only returns symbols that already exist string gt symbol string procedure Returns the interned symbol whose name is string Although you can use this proce dure to create symbols with names containing special characters or lowercase letters i
146. ad any characters written to the file are appended to the end of the existing contents If the file does not exist append mode creates the file and writes to it in the normal way open i o file filename procedure Takes a filename referring to an existing file and returns an 1 O port capable of both reading and writing the file If the file cannot be opened an error of type condition type file operation error is signalled This procedure is often used to open special files For example under unix this procedure can be used to open terminal device files PTY device files and named pipes open binary input file filename procedure open binary output file filename append procedure open binary i o file filename procedure These procedures open files in binary mode In all other respects they are identical to open input file open output file and open i o file respectively close all open files procedure This procedure closes all file ports that are open at the time that it is called and returns an unspecified value call with input file filename procedure procedure call with output file filename procedure procedure These procedures call procedure with one argument the port obtained by opening the named file for input or output respectively If the file cannot be opened an error of type condition type file operation error is signalled If procedure returns Chapter 14 Input Output 163 then the port is closed automatically an
147. ad their input from given strings and output ports that accumulate their output and return it as a string It also describes truncating output ports which can limit the length of the resulting string to a given value string gt input port string start end procedure Returns a new string port that delivers characters from string The optional argu ments start and end may be used to specify that the string port delivers charac ters from a substring of string if not given start defaults to O and end defaults to string length string 1 Because Scheme s escape procedures have unlimited extent it is possible to escape from the current continuation but later to escape back in If implementations were permitted to close the port on any escape from the current continuation then it would be impossible to write portable code using both call with current continuation and call with input file or call with output file 164 MIT Scheme Reference with input from string string thunk procedure Thunk must be a procedure of no arguments with input from string creates a new input port that reads from string makes that port the current input port and calls thunk When thunk returns with input from string restores the previous current input port and returns the result yielded by thunk with input from string a b c d e f read gt abc Note this procedure is equivalent to with input from port string gt input port string thun
148. ah didah gt dah dah didah string gt list string procedure substring gt list string start end procedure string gt list returns a newly allocated list of the character elements of string substring gt list returns a newly allocated list of the character elements of the given substring The inverse of string gt list is list gt string string gt list abcd gt Ma Hb c Hd substring gt list abcdef 1 3 gt b c 7 3 Selecting List Components list object procedure Returns t if object is a list otherwise returns f By definition all lists have finite length and are terminated by the empty list This procedure returns an answer even for circular structures Any object satisfying this predicate will also satisfy exactly one of pair or nu117 92 list a list O list l a b c b let x list a set cdr list x length list x x 3 Returns the length of list length a b c length a b c d e length null object Returns t if object is the empty list otherwise returns True and False page 8 null a null a b b c null list ref list k y tidy V 4 tt t f f w f f f tt MIT Scheme Reference procedure procedure but see Section 1 2 5 procedure Returns the kth element of list using zero origin indexing The valid indexes of a list are the exact non negative
149. al decoded time 209 universal time gt local time string 210 unparser set tagged pair method 173 unparser set tagged vector method 173 unquote c lm e br m ERE nROPCRERY 26 88 unquote sSplicing 2 de d in tni 26 88 unsigned integer bit string 108 uSe pty ji kg b ee ur a ER 219 use value i iiiizeees in an oe 291 235 user homedir pathname 196 user initial environment 7 156 157 MIS SRD ia eii wheres ee 2T USO m E EEE EEE EE ita 276 y valid hash number urtie 0d 433 134 Values techie E ROAD RIOSRePegebPRRPIT 152 ps upper REDE ee pnus 101 vector li iria EM 91 102 vector 8b t1l Mica ica teclado ted 85 vector 8b find next char 85 vector 8b find next char ci 85 vector 8b find previous char 85 vector 8b find previous char ci 85 V ctor Bb cEef i ildleseerR ia 84 vector Ob setl 2 2 pc uo bd nahe RI SIG 84 vector binary search esses 103 NectOr CODy 22e ti a epis ut Pare a 101 vector eighth ias a 103 vector fifth notan niu ne LIS 103 Vector fill 2 Lseiezage6he Mee adu ids 104 VectOE fiFSU 2oxascd enn xr eaa e 103 MIT Scheme Reference vector fourth 2 Sinepes nea niina 103 VeCtOF BIOW serai Ditto 102 VOCLOLTACAd cir a rr bI ME ad 103 vector length tado io ds 44 102 vector Map erca eih a iu Eds 102 VECCOr LOF ciar a ipinia 10 102 vector secomnd
150. alls the CropBitmap entry of DIBUTILS DLL Returns a new bitmap containing the image from a region of the original 282 MIT Scheme Reference dib set pixels unaligned dib pixels string procedure Return type bool Calls the DIBSetPixelsUnaligned entry of DIBUTILS DLL Stuffs bytes from pixels into the bitmap There are no alignment constraints on pixels the usual way of doing this is to use the SetDIBits function which requires that every scan line of the bitmap is 32 bit word aligned even if the scan lines are not a multiple of 4 bytes long doing this 18 3 2 Other parts of the DIB Utilities implementation The DIBUTILS DLL library is an ordinary DLL See the standard Microsoft Windows documentation on how to create DLLs Look at the code in the WIN32 DIBUTILS directory of the Scheme source Please note e For the foreign function interface to find the procedures they must be declared as exports in the DEF definition file e Toload the DLL file use the find module Scheme function Look at WIN32 DIB SCM to see how this is done e The current system works with C procedures with the stdcall and __cdecl calling conventions but not the __fastcall calling convention GNU Free Documentation License 283 GNU Free Documentation License Version 1 1 March 2000 Copyright c 2000 Free Software Foundation Inc 59 Temple Place Suite 330 Boston MA 02111 1307 USA Everyone is permitted to
151. ally scoped language Types are latent Scheme has latent types as opposed to manifest types which means that Scheme associates types with values or objects rather than with variables Other languages with latent types also referred to as weakly typed or dynamically typed languages include APL Snobol and other dialects of Lisp Languages with manifest types sometimes referred to as strongly typed or statically typed languages include Algol 60 Pascal and C Objects have unlimited extent All objects created during a Scheme computation including procedures and continuations have unlimited extent no Scheme object is ever destroyed The system doesn t run out of memory because the garbage collector reclaims the storage occupied by an object when the object cannot possibly be needed by a future computation Other languages in which most objects have unlimited extent include APL and other Lisp dialects Proper tail recursion Scheme is properly tail recursive which means that iterative computation can occur in constant space even if the iterative computation is described by a syn tactically recursive procedure With a tail recursive implementation you can express iteration using the ordinary procedure call mechanics special iteration expressions are provided only for syntactic convenience Procedures are objects Scheme procedures are objects which means that you can create them dy namically store them in data structures return them
152. ambda x x compound procedure 57 define foo x x foo compound procedure 58 foo car primitive procedure car call with current continuation lambda x x continuation 59 Note that interpreted procedures are called compound procedures strictly speaking com piled procedures are also compound procedures The written representation makes this distinction for historical reasons and may eventually change 12 1 Procedure Operations apply procedure object object procedure Calls procedure with the elements of the following list as arguments cons object object The initial objects may be any objects but the last object there must be at least one object must be a list apply list 3 4 5 6 gt 18 apply 3 4 5 6 gt 18 define compose lambda f g lambda args f apply g args compose sqrt 12 75 gt 30 148 MIT Scheme Reference procedure object procedure Returns stt if object is a procedure otherwise returns 4f If t is returned exactly one of the following predicates is satisfied by object compiled procedure compound procedure or primitive procedure compiled procedure object procedure Returns t if object is a compiled procedure otherwise returns f compound procedure object procedure Returns stt if object is a compound i e interpreted procedure otherwise returns f primitive procedure object procedure Returns t if object is a
153. ame 75 usr morris merge pathnames pathi path2 pathname 76 usr scheme foo scm merge pathnames path2 path1 gt ttlpathname 77 usr morris scm The merging rules for the version are more complex and depend on whether pathname specifies a name If pathname does not specify a name then the version if not provided will come from defaults However if pathname does specify a name then the version is not affected by defaults l he reason is that the version belongs to some other file name and is unlikely to have anything to do with the new one Finally if this process leaves the version missing then default version is used 194 MIT Scheme Reference The net effect is that if the user supplies just a name then the host device directory and type will come from defaults but the version will come from default version If the user supplies nothing or just a directory the name type and version will come over from defaults together default pathname defaults variable This is the default pathname defaults pathname if any pathname primitive that needs a set of defaults is not given one it uses this one set working directory pathname sets this variable to a new value computed by merging the new working directory with the variable s old value pathname default pathname device directory name type version procedure This procedure defaults all of the components of pathname simultaneously It could have been defined
154. ames specified in the rrggbb no tation draw arc x y radius x radius y angle start operation on x graphics device angle sweep fill Operation draw arc draws or fills an arc An arc is a segment of a circle which may have been stretched along the x or y axis to form an ellipse The parameters x y radius x and radius y describe the circle and angle start and angle sweep choose which part of the circle is drawn The arc is drawn on the graphics Chapter 17 Graphics 261 device with the center of the circle at the virtual coordinates given by x and y radius x and radius y determine the size of the circle in virtual coordinate units The parameter angle start determines where the arc starts It is measured in degrees in an anti clockwise direction starting at 3 o clock angle sweep determines how much of the circle is drawn It too is measured anti clockwise in degrees A negative value means the measurement is in a clockwise direction Note that the angles are determined on a unit circle before it is stretched into an ellipse so the actual angles that you will see on the computer screen depends on all of radius x and radius y the window size and the virtual coordinates If fill is f then just the segment of the circle is drawn otherwise the arc is filled in a pie slice fashion This draws a quarter circle pie slice standing on its point with point at virtual coordinates 3 5 graphics opereration g draw arc 3 5 5 5
155. amically bound to change the behavior of the write and display procedures unparser radix variable This variable specifies the default radix used to print numbers Its value must be one of the exact integers 2 8 10 or 16 the default is 10 If unparser radix is not 10 numbers are prefixed to indicate their radix unparser list breadth limit variable This variable specifies a limit on the length of the printed representation of a list or vector for example if the limit is 4 only the first four elements of any list are printed followed by ellipses to indicate any additional elements The value of this variable must be an exact non negative integer or f meaning no limit the default is fluid let unparser list breadth limit 4 write to string a b c d gt a b c d fluid let unparser list breadth limit 4 write to string a b c d e gt abcd unparser list depth limit variable This variable specifies a limit on the nesting of lists and vectors in the printed repre sentation If lists or vectors are more deeply nested than the limit the part of the representation that exceeds the limit is replaced by ellipses The value of this variable must be an exact non negative integer or f meaning no limit the default is Chapter 14 Input Output 171 fluid let unparser list depth limit 4 write to string a b c d a b c d fluid let unparser list depth
156. an object hash table as constructed by hash table make see below If not given a default table is used hash object table procedure hash associates an exact non negative integer with object and returns that integer If hash was previously called with object as its argument the integer returned is the same as was returned by the previous call hash guarantees that distinct objects in the sense of eq are associated with distinct integers unhash k table procedure unhash takes an exact non negative integer k and returns the object associated with that integer If there is no object associated with k or if the object previously associ ated with k has been reclaimed by the garbage collector an error of type condition type bad range argument is signalled In other words if hash previously returned k for some object and that object has not been reclaimed it is the value of the call to unhash An object that is passed to hash as an argument is not protected from being reclaimed by the garbage collector If all other references to that object are eliminated the object will be reclaimed Subsequently calling unhash with the hash number of the now reclaimed object will signal an error define x cons O 0 gt unspecified hash x gt TT eqv hash x hash x gt dit define x 0 unspecified gc flip force a garbage collection unhash 77 object hashed object table procedure This predicate is true if object has a
157. ancestor environments otherwise returns sf environment lookup environment symbol procedure Symbol must be bound in environment or one of its ancestor environments Returns the value to which it is bound environment assignable environment symbol procedure Symbol must be bound in environment or one of its ancestor environments Returns t if the binding may be modified by side effect 156 MIT Scheme Reference environment assign environment symbol object procedure Symbol must be bound in environment or one of its ancestor environments and must be assignable Modifies the binding to have object as its value and returns an unspecified result eval expression environment procedure Evaluates expression a list structure representation sometimes called s expression representation of a Scheme expression in environment You rarely need eval in ordinary programs it is useful mostly for evaluating expressions that have been cre ated on the fly by a program eval is relatively expensive because it must convert expression to an internal form before it is executed define foo list 1 2 eval foo the environment gt ug 13 2 Environment Variables The user initial environment is where the top level read eval print REP loop eval uates expressions and stores definitions It is a child of the system global environment which is where all of the Scheme system definitions are stored All of the bindings in system global e
158. andlers established by bind default condition handler are checked again most recent first Finally if no handlers apply or all return in a normal manner signal condition returns an unspecified value Note unlike many other systems the MIT Scheme runtime library does not estab lish handlers of any kind However the Edwin text editor uses condition handlers extensively Thus calls to signal condition will return to the caller unless there are user supplied condition handlers as the following example shows signal condition make condition condition type error call with current continuation lambda x x 20 no restarts 02 no fields gt unspecified 16 2 Error Messages By convention error messages and in general the reports generated by write condition report should consist of one or more complete sentences The usual rules for sentences should be followed the first word of the sentence should be capitalized and the sentence should be terminated by a period The message should not contain extraneous whitespace such as line breaks or indentation The error system provides a simple formatting language that allows the programmer to have some control over the printing of error messages This formatting language will probably be redesigned in a future release Error messages typically consist of a string describing the error followed by some irritant objects The string is printed using display and the irritants are p
159. any of the inits to be omitted in which case the corresponding variables are temporarily unassigned An error of type condition type unbound variable is signalled if any of the vari ables are unbound However because fluid let operates by means of side effects it is valid for any variable to be unassigned when the form is entered Here is an example showing the difference between fluid let and let First see how let affects the binding of a variable define variable t define access variable variable variable gt dit let variable f access variable gt dtt variable gt dit access variable returns t in this case because it is defined in an environment with variable bound to stt fluid let on the other hand temporarily reuses an existing variable variable gt dit fluid let variable f reuses old binding access variable gt df variable gt dit The extent of a dynamic binding is defined to be the time period during which the variable contains the new value Normally this time period begins when the body is entered and ends when it is exited on a sequential machine it is normally a contiguous time period However because Scheme has first class continuations it is possible to leave the body and then reenter it as many times as desired In this situation the extent becomes non contiguous When the body is exited by invoking a continuation the new value is saved and the variable is set to the old va
160. aphics device This operation restores the graphics device window to its normal state If the window is hidden or minimized it is shown again at its former position on the desktop If the window is maximized it is returned to its normal size activate window operation on os2 graphics device This operation makes the graphics device window be the active window This causes the window to be put in front of all other windows on the desktop highlights its frame and gives it the keyboard focus deactivate window operation on os2 graphics device This operation deactivates the graphics device window if it was active otherwise it has no effect This causes some other window to be chosen to be active in its place set window title title operation on os2 graphics device This operation changes the text that appears in the graphics device window s title bar The new text is given by title which must be a string 17 11 4 Event Operations for OS 2 Graphics These operations allow you to read some of the events that are generated by the Pre sentation Manager and put in the message queue of a graphics device window read button operation on os2 graphics device This operation waits for the user to push a mouse button inside the client area of the graphics device window It then returns four values see Section 12 3 Continuations page 149 which are the button number the x and y coordinates of the mouse pointer at the time the button was pressed in
161. are some of the possible values 222 MIT Scheme Reference GNU Linux FreeBSD HP UX Sun0s OS 2 2 1 OS 2 4 0 Microsoft Windows NT 4 0 Build 1381 Service Pack 3 Microsoft Windows 98 Build 410 For Windows systems it is recommended that you match on the prefix of this string and ignore the Build suffix This is because the suffix may contain information about service packs or fixes while the prefix will be constant for a particular version of Windows The next few procedures provide access to the domain name service DNS which main tains associations between internet host names such as www swiss ai mit edu and IP addresses such as 18 23 0 16 In MIT Scheme we represent an internet host name as a string and an IP address as a byte vector of length 4 byte vectors are just character strings that are accessed using vector 8b ref rather than string ref The bytes in an IP address read in the same order as they do when written out get host by name www swiss 022 027 000 020 get host by name host name procedure Looks up the internet host name host name using the DNS returning a vector of IP addresses for the corresponding host or f if there is no such host Usually the returned vector has only one element but if a host has more than one network interface the vector might have more than one element get host by name www swiss gt 022 027 000 020 get host by address ip address pr
162. ariable A new environment can be created by extending an existing environment with a set of new bindings Note that extending an environment does not modify the environment rather it creates a new environment that contains the new bindings and the old ones The new bindings shadow the old ones that is if an environment that contains a binding for x is extended with a new binding for x then only the new binding is seen when x is looked up in the extended environment Sometimes we say that the original environment is the parent of the new one or that the new environment is a child of the old one or that the new environment inherits the bindings in the old one Procedure calls extend an environment as do let let letrec and do expressions Internal definitions see Section 2 4 2 Internal Definitions page 23 also extend an envi ronment Actually all the constructs that extend environments can be expressed in terms of procedure calls so there is really just one fundamental mechanism for environment ex tension A top level definition see Section 2 4 1 Top Level Definitions page 23 may add a binding to an existing environment 1 2 3 Initial and Current Environments MIT Scheme provides an initial environment that contains all of the variable bindings described in this manual Most environments are ultimately extensions of this initial envi ronment In Scheme the environment in which your programs execute is actually a child e
163. art end char procedure string find previous char ci string char procedure substring find previous char ci string start end char procedure Returns the index of the last occurrence of char in the string substring returns f if char doesn t appear in the string For the substring procedures the index returned is relative to the entire string not just the substring The ci procedures don t distinguish uppercase and lowercase letters string find previous char in set string char set procedure substring find previous char in set string start end char set procedure Returns the index of the last character in the string substring that is also in char set For the substring procedure the index returned is relative to the entire string not just the substring 80 MIT Scheme Reference 6 7 Matching Strings string match forward stringl string2 procedure substring match forward stringl start end string2 start end procedure string match forward ci stringl string2 procedure substring match forward ci stringl start end string2 start end procedure Compares the two strings substrings starting from the beginning and returns the number of characters that are the same If the two strings substrings start dif ferently returns 0 The ci procedures don t distinguish uppercase and lowercase letters string match forward mirror micro gt 2 matches mi string match forward a b gt 0 no match string match backward stringl
164. as they are used hash table clean hash table procedure If hash table is a type of hash table that holds its keys weakly this procedure recovers any space that was being used to record associations for objects that have been reclaimed by the garbage collector Otherwise this procedure does nothing In either case it returns an unspecified result 11 4 2 Basic Hash Table Operations The procedures described in this section are the basic operations on hash tables They provide the functionality most often needed by programmers Subsequent sections describe other operations that provide additional functionality needed by some applications hash table object procedure Returns stt if object is a hash table otherwise returns f hash table put hash table key datum procedure Associates datum with key in hash table and returns an unspecified result The average time required by this operation is bounded by a constant hash table get hash table key default procedure Returns the datum associated with key in hash table If there is no association for key default is returned The average time required by this operation is bounded by a constant 128 MIT Scheme Reference hash table remove hash table key procedure If hash table has an association for key removes it Returns an unspecified result The average time required by this operation is bounded by a constant hash table clear hash table procedure Removes all associations in ha
165. at the standard Scheme procedure list takes zero or more arguments each of which may be any Scheme object write char char output port procedure indicates that the standard Scheme procedure write char must be called with a character char and may also be called with a character and an output port 1 2 Scheme Concepts 1 2 1 Variable Bindings Any identifier that is not a syntactic keyword may be used as a variable see Section 1 3 3 Identifiers page 11 A variable may name a location where a value can be stored A variable that does so is said to be bound to the location The value stored in the location Chapter 1 Overview 7 to which a variable is bound is called the variable s value The variable is sometimes said to name the value or to be bound to the value A variable may be bound but still not have a value such a variable is said to be unas signed Referencing an unassigned variable is an error When this error is signalled it is a condition of type condition type unassigned variable sometimes the compiler does not generate code to signal the error Unassigned variables are useful only in combination with side effects see Section 2 5 Assignments page 24 1 2 2 Environment Concepts An environment is a set of variable bindings If an environment has no binding for a variable that variable is said to be unbound in that environment Referencing an unbound variable signals a condition of type condition type unbound v
166. ata or data as programs 1 2 7 Disjointness of Types Every object satisfies at most one of the following predicates but see Section 1 2 5 True and False page 8 for an exception bit string environment port symbol boolean null procedure vector cell number promise weak pair char pair string condition 1 2 8 Storage Model 10 MIT Scheme Reference This section describes a model that can be used to understand Scheme s use of storage Variables and objects such as pairs vectors and strings implicitly denote locations or sequences of locations A string for example denotes as many locations as there are characters in the string These locations need not correspond to a full machine word A new value may be stored into one of these locations using the string set procedure but the string continues to denote the same locations as before An object fetched from a location by a variable reference or by a procedure such as car vector ref or string ref is equivalent in the sense of eqv to the object last stored in the location before the fetch Every location is marked to show whether it is in use No variable or object ever refers to a location that is not in use Whenever this document speaks of storage being allocated for a variable or object what is meant is that an appropriate number of locations are chosen from the set of locations that are not in use and the chosen locations are marked to indicate that t
167. ay port input terminal mode port procedure Returns the input terminal mode of port port set input terminal mode port mode procedure Changes the input terminal mode of port to be mode Returns an unspecified value port with input terminal mode port mode thunk procedure Thunk must be a procedure of no arguments port with input terminal mode binds the input terminal mode of port to be mode executes thunk restores the input terminal mode of port to what it was when port with input terminal mode was called and returns the value that was yielded by thunk This binding is performed by dynamic wind which guarantees that the input terminal mode is restored if thunk escapes from its continuation port output terminal mode port procedure Returns the output terminal mode of port port set output terminal mode port mode procedure Changes the output terminal mode of port to be mode Returns an unspecified value port with output terminal mode port mode thunk procedure Thunk must be a procedure of no arguments port with output terminal mode binds the output terminal mode of port to be mode executes thunk restores the Chapter 14 Input Output 185 output terminal mode of port to what it was when port with output terminal mode was called and returns the value that was yielded by thunk This binding is performed by dynamic wind which guarantees that the output terminal mode is restored if thunk escapes from its continuation 1
168. bed above in Section 16 4 Restarts page 231 abort restarts procedure Abort the computation using the restart named abort The corresponding effector takes no arguments and abandons the current line of computation This is the restart provided by Scheme s REPL If there is no restart named abort this procedure signals an error of type condition type no such restart continue restarts procedure Continue the current computation using the restart named continue The cor responding effector takes no arguments and continues the computation beyond the point at which the condition was signalled muffle warning restarts procedure Continue the current computation using the restart named muffle warning The corresponding effector takes no arguments and continues the computation beyond the point at which any warning message resulting from the condition would be pre sented to the user The procedure warn establishes a muffle warning restart for this purpose If there is no restart named muffle warning this procedure signals an error of type condition type no such restart Chapter 16 Error System 235 retry restarts procedure Retry the current computation using the restart named retry The corresponding effector takes no arguments and simply retries the same computation that triggered the condition The condition may reoccur of course if the root cause has not been eliminated The code that signals a file does not exist
169. bject encapsulating the ordering relation Creating a tree is a two stage process First a tree type must be created from the predicate that gives the ordering The tree type is then used for making trees either empty or singleton trees or trees from other aggregate structures like association lists Once created a tree knows its type and the type is used to test 140 MIT Scheme Reference compatibility between trees in operations taking two trees Usually a small number of tree types are created at the beginning of a program and used many times throughout the program s execution make wt tree type key lt procedure This procedure creates and returns a new tree type based on the ordering predicate key lt Key lt must be a total ordering having the property that for all key values a band c key lt a a gt f and key lt a b key lt b a gt df if and key lt a b key lt b c key lt a c Ht gt dit Two key values are assumed to be equal if neither is less than the other by key lt Each call to make wt tree type returns a distinct value and trees are only compat ible if their tree types are eq A consequence is that trees that are intended to be used in binary tree operations must all be created with a tree type originating from the same call to mnake wt tree type number wt type variable A standard tree type for trees with numeric keys Number wt type could have been defined by define numbe
170. bject procedure Returns t if object is a vector otherwise returns f vector length vector procedure Returns the number of elements in vector vector ref vector k procedure Returns the contents of element k of vector K must be a valid index of vector vector ref 1 1235 8 13 21 5 gt 8 vector set vector k object procedure Stores object in element k of vector and returns an unspecified value K must be a valid index of vector let vec vector 0 2 2 2 2 Anna vector set vec 1 Sue Sue vec gt 0 Sue Sue Anna Chapter 8 Vectors 103 vector first vector procedure vector second vector procedure vector third vector procedure vector fourth vector procedure vector fifth vector procedure vector sixth vector procedure vector seventh vector procedure vector eighth vector procedure These procedures access the first several elements of vector in the obvious way It is an error if the implicit index of one of these procedurs is not a valid index of vector vector binary search vector key lt unwrap key key procedure Searches vector for an element with a key matching key returning the element if one is found or f if none The search operation takes time proportional to the logarithm of the length of vector Unwrap key must be a procedure that maps each element of vector to a key Key must be a procedure that implements a total ordering on the keys of the elements define translat
171. ble to set this variable to anything other than the default The default value of this variable is 10 parser canonicalize symbols variable This variable controls how the parser handles case sensitivity of symbols If it is bound to its default value of stt symbols read by the parser are converted to lower case before being interned Otherwise symbols are interned without case conversion In general it is a bad idea to use this feature as it doesn t really make Scheme case sensitive and therefore can break features of the Scheme runtime that depend on case insensitive symbols 14 5 Output Procedures Output ports may or may not support buffering of output in which output characters are collected together in a buffer and then sent to the output device all at once Most of the output ports implemented by the runtime system support buffering Sending all of the characters in the buffer to the output device is called flushing the buffer In general output procedures do not flush the buffer of an output port unless the buffer is full However the standard output procedures described in this section perform what is called discretionary flushing of the buffer Discretionary output flushing works as follows After a procedure performs its output writing characters to the output buffer it checks to see if the port implements an operation called discretionary flush output If so then that operation is invoked to flush the buffer At present
172. by define pathname default pathname device directory name type version make pathname pathname host pathname or pathname device pathname device or pathname directory pathname directory or pathname name pathname name or pathname type pathname type or pathname version pathname version file namestring pathname procedure directory namestring pathname procedure host namestring pathname procedure enough namestring pathname defaults procedure These procedures return a string corresponding to a subset of the pathname informa tion file namestring returns a string representing just the name type and version components of pathname the result of directory namestring represents just the host device and directory components and host namestring returns a string for just the host portion enough namestring takes another argument defaults It returns an abbreviated namestring that is just sufficient to identify the file named by pathname when con sidered relative to the defaults which defaults to default pathname defaults file namestring usr morris minor van gt minor van directory namestring usr morris minor van gt usr morris enough namestring usr morris men gt men perhaps file pathname pathname procedure directory pathname pathname procedure enough pathname pathname defaults procedure These procedures return a pathname corresponding to a subset of the pathname i
173. call error error derived port port condition procedure This procedure signals a condition of type condition type derived port error The port and condition fields of the condition are filled in from the corresponding arguments to the procedure condition type variable error location environment condition type This is an abstract type It indicates that an error associated with a variable has occurred The location field contains the name of the variable and the environment field contains the environment in which the variable was referenced condition type unbound variable location environment condition type This type is generated when a program attempts to access or modify a variable that is not bound The location field contains the name of the variable and the environment field contains the environment in which the reference occurred foo Unbound variable foo To continue call RESTART with an option number RESTART 3 gt Specify a value to use instead of foo RESTART 2 gt Define foo to a given value RESTART 1 gt Return to read eval print level 1 Chapter 16 Error System 247 condition type unassigned variable location environment condition type This type is generated when a program attempts to access a variable that is not assigned The location field contains the name of the variable and the environment field contains the environment in which the reference occurred foo Unassigned variable foo
174. case letters precede all the lowercase letters Characters are ordered by first comparing their bucky bits part and then their code part In particular characters without bucky bits come before characters with bucky bits 5 3 Miscellaneous Character Operations char object procedure Returns t if object is a character otherwise returns f char upcase char procedure char downcase char procedure Returns the uppercase or lowercase equivalent of char if char is a letter otherwise returns char These procedures return a character char2 such that char ci char char2 66 MIT Scheme Reference char gt digit char radix procedure If char is a character representing a digit in the given radix returns the corresponding integer value If you specify radix which must be an exact integer between 2 and 36 inclusive the conversion is done in that base otherwise it is done in base 10 If char doesn t represent a digit in base radix char gt digit returns f Note that this procedure is insensitive to the alphabetic case of char char gt digit 8 gt 8 char gt digit He 16 gt 14 char gt digit tHe gt H digit gt char digit radix procedure Returns a character that represents digit in the radix given by radix Radix must be an exact integer between 2 and 36 inclusive and defaults to 10 Digit which must be an exact non negative integer should be less than radix if digit is greater than or equal to radix digit gt
175. cated length of the file which can be larger than the length of the file due to fixed length allocation units 15 4 Directory Reader directory read directory sort procedure Directory must be an object that can be converted into a pathname by pathname The directory specified by directory is read and the contents of the directory is returned as a newly allocated list of absolute pathnames The result is sorted according to the usual sorting conventions for directories unless sort is specified as 4f If directory has name type or version components the returned list contains only those pathnames whose name type and version components match those of directory wild or f as one of these components means match anything The OS 2 and Windows implementations support globbing in which the charac ters and are interpreted to mean match anything and match any character respectively This globbing is supported only in the file part of directory Chapter 15 Operating System Interface 205 15 5 Date and Time MIT Scheme provides a simple set of procedures for manipulating date and time infor mation There are four time representations each of which serves a different purpose Each representation may be converted to any of the others The primary time representation universal time is an exact non negative integer count ing the number of seconds that have elapsed since midnight January 1 1900 UTC UTC
176. ccept any of the following values e A list of restart objects e A condition The procedure condition restarts is called on the condition and the resulting list of restarts is used in place of the condition e The symbol bound restarts The procedure bound restarts is called with no ar guments and the resulting list of restarts is used in place of the symbol e If the restarts parameter is optional and is not supplied it is equivalent to having specified the symbol bound restarts 16 4 1 Establishing Restart Code with simple restart name reporter thunk procedure Invokes thunk in a dynamic environment created by adding a restart named name to the existing named restarts Reporter may be used during the execution of thunk to produce a description of the newly created restart it must either be a procedure of one argument a port or a string By convention the description generated by reporter should be a short complete sentence with first word capitalized and terminated by a period The sentence should fit on one line with a little room to spare see the examples below usually this means that the sentence should be 70 characters or less in length If the restart created by with simple restart is invoked it simply aborts the com putation in progress by returning an unspecified value from the call to with simple restart Otherwise with simple restart returns the value computed by thunk Chapter 16 Error System 233 with sim
177. cedure Returns the first tail of stream Equivalent to force cdr stream stream rest is a synonym for stream cdr Chapter 10 Miscellaneous Datatypes 119 stream null stream procedure Returns t if stream is the end ofstream marker otherwise returns f This is equivalent to nu117 but should be used whenever testing for the end of a stream stream length stream procedure Returns the number of elements in stream If stream has an infinite number of elements this procedure will not terminate Note that this procedure forces all of the promises that comprise stream stream ref stream k procedure Returns the element of stream that is indexed by k that is the kth element K must be an exact non negative integer strictly less than the length of stream stream head stream k procedure Returns the first k elements of stream as a list K must be an exact non negative integer strictly less than the length of stream stream tail stream k procedure Returns the tail of stream that is indexed by k that is the kth tail This is equivalent to performing stream cdr k times K must be an exact non negative integer strictly less than the length of stream stream map procedure stream stream procedure Returns a newly allocated stream each element being the result of invoking procedure with the corresponding elements of the streams as its arguments 10 7 Weak Pairs Weak pairs are a mechanism for building data structures that point at
178. cedure Returns stt if string has zero length otherwise returns amp f string null gt dit string null Hi gt f string ref string k procedure Returns character k of string K must be a valid index of string string ref Hello 1 gt He string ref Hello 5 error 5 not in correct range string set string k char procedure Stores char in element k of string and returns an unspecified value K must be a valid index of string and char must satisfy the predicate char ascii define str Dog unspecified string set str O HAL unspecified str gt Log string set str 3 t 3 not in correct range 6 3 Comparison of Strings string stringl string2 procedure substring stringl start end string2 start end procedure string ci stringl string2 procedure substring ci stringl start end string2 start end procedure Returns stt if the two strings substrings are the same length and contain the same characters in the same relative positions otherwise returns 4f string ci and substring ci don t distinguish uppercase and lowercase letters but string and substring do 74 MIT Scheme Reference string PIE PIE gt dit string PIE pie gt H string ci PIE pie gt dit substring Alamo 1 3 cola 2 4 gt t compares la string stringl string2 procedure substring lt string start1 endl string2 start2 end2 procedure string stringl string2 procedure string l
179. cedure make simple warning constructs a condition of type condition type simple warning given a continuation where the condition occurred a description of the restarts to be made available a warning message and a list of irritants that caused the warning define make simple warning condition constructor condition type simple warning gt message irritants condition accessor condition type field name procedure Returns a procedure that takes as input a condition object of type condition type and extracts the contents of the specified field name condition accessor sig nals error bad range argument if the field name isn t one of the named fields of condition type the returned procedure will signal error wrong type argument if passed an object other than a condition of type condition type or one of its special izations If it is known in advance that a particular field of a condition will be accessed re peatedly it is worth constructing an accessor for the field using condition accessor rather than using the possibly more convenient but slower access condition pro cedure condition predicate condition type procedure Returns a predicate procedure for testing whether an object is a condition of type condition type or one of its specializations there is no predefined way to test for a condition of a given type but not a specialization of that type condition signaller condition type field names default handler procedure Returns
180. condition type floating point underflow AN repe buds db ritos 247 condition type illegal datum 242 condition type inapplicable object 245 condition type no such restart 234 248 condition type not loading 248 condition type port error 246 condition type primitive procedure error ER 248 condition type serious condition 226 242 condition type simple condition 226 249 condition type simple error 227 242 condition type simple warning 227 249 condition type subprocess abnormal terminatiolh 2 12 29 19 ioii YR 216 condition type subprocess signalled 216 condition type subprocess stopped 216 condition type system call error 248 condition type unassigned variable 7 247 condition type unbound variable 7 21 246 Binding Index condition type variable error 246 condition type warning 226 249 condition type wrong number of arguments di 17 148 243 condition type wrong type argument 6 160 243 condition type wrong type datum 243 conditi n typ ors hesa 2 ar 241 condition continuation 239 condition efros 4 paved v RE TS 239 condition report string 240 condition restarts 238 239 cotdition typ6s core ep ieee e ep 239 Condition sti ve p E hee epee ke HE 239 conjugate ues ede d E npa ee ean 53
181. condition type it is possible to generate a constructor for instances of the type using condition constructor an accessor to extract the contents of a field in instances of the type using condition accessor a predicate to test for instances of the type using condition predicate and a procedure to create and signal an instance of the type using condition signaller Notice that the creation of a condition object is distinct from signalling an occurrence of the condition Condition objects are first class they may be created and never signalled or they may be signalled more than once Further notice that there are no procedures for modifying conditions once created a condition cannot be altered 238 MIT Scheme Reference condition constructor condition type field names procedure Returns a constructor procedure that takes as arguments values for the fields specified in field names and creates a condition of type condition type Field names must be a list of symbols that is a subset of the field names in condition type The constructor procedure returned by condition constructor has signature lambda continuation restarts field values where the field names correspond to the field values The constructor argument restarts is described in Section 16 4 Restarts page 231 Conditions created by the constructor procedure have f for the values of all fields other than those specified by field names For example the following pro
182. considered a generalization of itself condition type object procedure Returns f if and only if object is not a condition type 16 7 Condition Type Taxonomy The MIT Scheme error system provides a rich set of predefined condition types These are organized into a forest through taxonomic links providing the relationships for specializes and generalizes The chart appearing below shows these relationships by indenting all the specializations of a given type relative to the type Note that the variables that are bound to these condition types are prefixed by condition type for example the type appearing in the following table as simple error is stored in the variable condition type simple error Users are encouraged to add new condition types by creating specializations of existing ones Following the chart are detailed descriptions of the predefined condition types Some of these types are marked as abstract types Abstract types are not intended to be used directly as the type of a condition they are to be used as generalizations of other types and for binding condition handlers Types that are not marked as abstract are concrete they are intended to be explicitly used as a condition s type 242 MIT Scheme Reference serious condition error simple error illegal datum wrong type datum wrong type argument wrong number of arguments datum out of range bad range argument inapplicable object file error file op
183. cooked mode of terminal port 183 coordinates graphics oooooooocmcoooo 252 copying of alist 24 du conned hartge REEF 123 copying of bit String o eer vs 105 copying of fte enki ipee cheek peed 198 copyilig of SLEIBE i iaa ai 72 COPYING Of thee ra ie tirna E ri 90 copying Of vetot ent kiediusteh e pex yes 101 current environment defn 7 current input port defn suus 159 current input port rebinding 163 164 current output port defn 159 current output port rebinding 163 164 current working directory 187 current working directory defn 197 cursor graphics defn ooocooccccccccc o 253 custom operations on graphics device 257 custom operations on port 177 cutting of bit string nia 106 cut ng of list 4 0 9 2 RISDRRARPRSE ROSAS 93 cutting of String isse relie rA RS 76 cutting 0f Vector cer secede peas ees 103 D d as exponent marker in number 46 decoded time use sseimi pa 205 default object defn oooooccoccccccoo ij defaulting of pathname 193 194 define procedure defn 0000008 22 defining foreign procedures 206 defining foreign types 274 275 Ae rra 22 definition internal ier ter ege 23 definition internal defn 000 2
184. copy list list fold right cons list define append list1 list2 fold right cons list2 list1 define map p list fold right lambda x r cons p x r O list define reverse items fold right lambda x r append r list x O items fold left procedure initial list procedure Combines all the elements of list using the binary operation procedure Elements are combined starting with initial and then the elements of list from left to right Whereas fold right is recursive in nature capturing the essence of cdr ing down a list and then computing a result fold left is iterative in nature combining the elements as the list is traversed fold left list 1 2 3 4 0012 3 4 define length list fold left lambda sum element sum 1 O list define reverse items fold left lambda x y cons y x O items Chapter 7 Lists 99 there exists list predicate procedure Predicate must be a procedure of one argument Applies predicate to each element of list in order from left to right If predicate is true for any element of list the value yielded by predicate is immediately returned as the value of there exists predicate will not be applied to the remaining elements of list If predicate returns f for all of the elements of list then f is returned for all list predicate procedure Predicate must be a procedure of one argument Applies predicate to each element of list in order
185. cs device The graphics device contents are saved as a bitmap to the file specified by pathname If no file type is supplied then a BMP extension is added The saved bitmap may be incorporated into documents or printed move window x y operation on win32 graphics device The graphics device window is moved to the screen position specified by x and y resize window width height operation on win32 graphics device The graphics device window is resized to the specified width and height in device coordinates pixels If a clip rectangle is in effect when this procedure is called it is necessary to redefine the clip rectangle afterwards set line width width operation on win32 graphics device This operation sets the line width for future drawing of lines points and ellipses It does not affect existing lines and has no effect on filled polygons The line width is specified in device units T he default and initial value of this parameter is 1 pixel set window name name operation on win32 graphics device This sets the window title to the string name The window is given the name Scheme Graphics at creation 266 MIT Scheme Reference set font handle operation on win32 graphics device Sets the font for drawing text Currently not well supported If you can get a Win32 font handle it can be used here copy area source x left source y top width operation on win32 graphics device height destination x left destination y top This operation copie
186. ct hash tables hash table make procedure This procedure creates and returns a new empty object hash table that is suitable for use as the optional table argument to the above procedures The returned table contains no associations 11 6 Red Black Trees Balanced binary trees are a useful data structure for maintaining large sets of associations whose keys are ordered While most applications involving large association sets should use hash tables some applications can benefit from the use of binary trees Binary trees have two advantages over hash tables e The contents of a binary tree can be converted to an alist sorted by key in time proportional to the number of associations in the tree A hash table can be converted into an unsorted alist in linear time sorting it requires additional time e Two binary trees can be compared for equality in linear time Hash tables on the other hand cannot be compared at all they must be converted to alists before comparison can be done and alist comparison is quadratic unless the alists are sorted MIT Scheme provides an implementation of red black trees The red black tree balancing algorithm provides generally good performance because it doesn t try to keep the tree very closely balanced At any given node in the tree one side of the node can be twice as high as the other in the worst case With typical data the tree will remain fairly well balanced anyway A red black tree takes space tha
187. ct68SS ose tpe dont eg od aa n hrs Ek ede es 44 4 3 Implementation restrictions llis esses eese 44 4 4 Syntax of numerical constants ss esee eee eee 46 4 5 Numerical operations sssseeeesse seh 46 4 6 Numerical input and output 0000 eee ee eee ee 54 4 7 Fixnum and Flonum Operations 00000 56 4 7 1 Fixnum Operations 0 000 e eee eese 56 4 7 2 Flonum Operations 00 0c eee eee 59 4 8 Random Numbers 000 cece ii eee eee eens 60 D Characters orton ri 63 5 1 External Representation of Characters 63 5 2 Comparison of Characters o ooooooooooorrorrooo 65 5 3 Miscellaneous Character Operations 0ooooooooooooo 65 5 4 Internal Representation of CharacterS 66 5 5 ASCII Characters sro ssesioa nsaan daaa a aa a 68 5 6 Character Sets 0 cece cece eee eee eee neces 68 O TEMPS aa AAA ws 71 6 1 Construction of Strings ssseleeseseeees eese T2 6 2 Selecting String Components uslleissesssssssss 73 6 3 Comparison of Strings ssllseeesseseee esee 73 6 4 Alphabetic Case in Strings 0 0000 esses 75 6 5 Cutting and Pasting Strings 0 0 eee eee 76 6 6 Searching Strings 0 cece eee eee eee m 6 7 Matching Strings seuuseeeelseesle hne 80 6 8 Regular Expressions sessssee essen 81 6 9 Modification of Strin
188. cter is 4 Ny Y or space the procedure returns stt If the character is n AN or rubout the procedure returns 4f Otherwise the prompt is repeated Under Edwin or Emacs the confirmation is read in the minibuffer 14 9 Port Primitives This section describes the low level operations that can be used to build and manipulate 1 O ports The purpose of these operations is twofold to allow programmers to construct new kinds of I O ports and to provide faster I O operations than those supplied by the standard high level procedures The latter is useful because the standard 1 0 operations provide defaulting and error checking and sometimes other features which are often unnecessary This interface provides the means to bypass such features thus improving performance Chapter 14 Input Output 177 The abstract model of an 1 0 port as implemented here is a combination of a set of named operations and a state The state is an arbitrary object the meaning of which is determined by the operations The operations are defined by a mapping from names to procedures The set of named operations is represented by an object called a port type A port type is constructed from a set of named operations and is subsequently used to construct a port The port type completely specifies the behavior of the port Port types also support a simple form of inheritance allowing you to create new ports that are similar to existing ports The port opera
189. ction o ooooooooooooo 239 16 5 3 Simple Operations on Condition Instances 239 16 6 Condition Types 0 cece ee eee eee 240 16 7 Condition Type Taxonomy 0 eee eee eee 241 17 StApniGs acc ase tarios 251 17 1 Opening and Closing of Graphics Devices 251 17 2 Coordinates for Graphics slsioeee cece eee eee 252 17 3 Drawing Graphics mda Lue eer ER e ER 253 17 4 Characteristics of Graphics Output 254 17 5 Buffering of Graphics Output 000 256 17 6 Clipping of Graphics Output 0 0 00020 256 17 7 Custom Graphics Operati0OS 0oooocooococooccco oo 257 17 8 MALES eiria di a a da 257 11 9 X Graphi Seea epes ee es tee ade 258 17 9 1 X Graphics Type issessseseslleeeh 258 17 9 2 Utilities for X GraphicS 00oooooooooo o 259 17 9 3 Custom Operations on X Graphics Devices 260 17 10 Wind Graphics erue ett I eoe nt e ern 263 17 10 1 Win32 Graphics Type 2 04 263 17 10 2 Custom Operations for Win32 Graphics 264 aa GraphicSe A 266 17 11 1 05 2 Graphics Type ono ne he di 266 17 11 2 Color Operations for OS 2 Graphics 266 17 11 3 Window Operations for OS 2 Graphics 267 17 11 4 Event Operations for OS 2 Graphics 269 17 11 5 Miscellaneous Operations for OS 2 Graphics 271 vii viii MIT Scheme Reference 18 Win32 Package Reference 273 ISI OV
190. ctory pathname as file 195 directory pathname esses 193 directory redd ic s ria 204 discard char on input port 179 discard chars on input port 179 discard events on os2 graphics device 241 discretionary flush output 168 discretionary flush output on output port ERR 181 display siio cow Sh steko WR 159 169 228 dO ati cools rb e fuite gott ER REA 1 29 30 draw arC ite ek e Ee E EE E 260 draw arc on x graphics device 260 draw Circle i gu Ren RR a RA ern 261 draw circle on x graphics device 261 draw ellipse on win32 graphics device 265 draw image on graphics device 257 draw lines on os2 graphics device 242 draw subimage on graphics device 258 dynamic wind iileseRca n e eere E hie 150 E GXghtb tdci heli ae hee eee tee te 92 else cob Ec ele oa 5 27 enough namestring s 4o er nn 194 eno gh patbhname ie rie ecw nes 3 194 entity ozta o ter Seiad aes Goede tees 153 entity procedure o eens seed mies 153 CNGICY sci tac E E tans teeta ea depevatatie dus 153 enumerate graphics types 251 environment cicer deste Sates 218 environment assign 005 156 environment assignable 155 environment bindings esses 155 environment bound names 55 environment bound sess 155
191. d Substitutions are made only for unquoted compo nents appearing at the same nesting level as the outermost backquote The nesting level increases by one inside each successive quasiquotation and decreases by one inside each unquotation 26 MIT Scheme Reference Ca b 1 2 foo 1 3 d e f gt a b 1 2 foo 4d e f let namel x name2 y a b namel name2 d e gt a b x y d e The notations template and quasiquote template are identical in all respects expression is identical to unquote expression and Cexpression is identical to unquote splicing expression quasiquote list unquote 1 2 4 gt list 3 4 gt quasiquote list unquote 1 2 4 gt ist 1 2 4 i e quasiquote list unquote 1 2 4 Unpredictable behavior can result if any of the symbols quasiquote unquote or unquote splicing appear in a template in ways otherwise than as described above 2 7 Conditionals The behavior of the conditional expressions is determined by whether objects are true or false The conditional expressions count only f as false They count everything else including stt pairs symbols numbers strings vectors and procedures as true but see Section 1 2 5 True and False page 8 In the descriptions that follow we say that an object has a true value or is true when the conditional expressions treat it as true and we sa
192. d The average and worst case times required by this operation are proportional to the logarithm of the number of assocations in rb tree rb tree delete rb tree key procedure If rb tree contains an association for key removes it Returns an unspecified value The average and worst case times required by this operation are proportional to the logarithm of the number of assocations in rb tree rb tree gt alist rb tree procedure Returns the contents of rb tree as a newly allocated alist Each element of the alist is a pair key datum where key is one of the keys of rb tree and datum is its associated datum The alist is sorted by key according to the key lt argument used to construct rb tree The time required by this operation is proportional to the number of associations in the tree rb tree key list rb tree procedure Returns a newly allocated list of the keys in rb tree The list is sorted by key according to the key argument used to construct rb tree The time required by this operation is proportional to the number of associations in the tree rb tree datum list rb tree procedure Returns a newly allocated list of the datums in rb tree Each element of the list corresponds to one of the associations in rb tree so if the tree contains multiple associations with the same datum so will this list The list is sorted by the keys of the associations even though they do not appear in the result T he time required by this operation
193. d 108 Binding Index bit string mOweC i rebos et a 107 bit string not bee dee we i eren EE ER 107 Dit sString OP4 1 122 90i BICIS 107 bit string Orlii ie m acie RE epi 107 bit string ref 239 ni es 106 bit String Set 2 eee ie es Lt 106 bit string XOF iic x m eb RR dieses 107 bit String xor 62c 08 b bee dne 107 bit strinp zero i el1i9 4 oe 107 bit String T i tide hig du RA E teradi it 107 bit string ii 4ic4 ble gg e bd 106 bit substring lz4ex keg ea nep 107 bit substring find next set bit 106 bit substring move right 108 bitmap from dib e M ra 280 DO miii ii 20g ede URP IEEE 275 boolean and sirio iia Mad PEN 110 boolean for miii ar ide 110 booleana a dba 110 AA bep Rue meee 109 bound restart c 4o B RES EID B xv 235 bo nd reSta fts idn h ERU e RE 236 break on signals 5 6p Ls 227 229 230 buffered input chars on input port 180 buffered output chars on output port 182 byte ode er eei i imde aa 276 CA es AES 89 Cad rare laa 89 Caaa AN 89 CAMA e ida ls 89 cad arica a 89 aadi il bs cla Pi aleron 89 CHAT ii o a de dd 89 E cv eund igi ebRdd 89 Cadadf coaie niin ianea ER adhe Same 89 CAA CH 89 Cad te ora 89 A RS e a e TRE ER 89 Caddr da dada 89 A Pm 89 call with binary input file 163 call with binary output file 163 call with current continuation 149 291 call with input fi116 2 9
194. d 3 above provided that you release the Modified Version under precisely this License with the Modified Version filling the role of the Document thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it In addition you must do these things in the Modified Version A Use in the Title Page and on the covers if any a title distinct from that of the Document and from those of previous versions which should if there were any be listed in the History section of the Document You may use the same title as a previous version if the original publisher of that version gives permission B List on the Title Page as authors one or more persons or entities responsible for authorship of the modifications in the Modified Version together with at least five of the principal authors of the Document all of its principal authors if it has less than five C State on the Title page the name of the publisher of the Modified Version as the publisher D Preserve all the copyright notices of the Document E Add an appropriate copyright notice for your modifications adjacent to the other copyright notices F Include immediately after the copyright notices a license notice giving the public permission to use the Modified Version under the terms of this License in the form shown in the Addendum below G Preserve in that license notice the full lists of Invariant Sections and required Cover Texts giv
195. d baa nah 188 pathname absolute ooooomoocmoomoom 193 pathname as directory 195 197 pathname default i 2d hebes 194 pathname default device 192 pathname default directory 192 pathname default name 192 pathname default type 0 4 192 pathname default version 192 pathname device e evene ia 191 pathname directory cc ese rota e 191 pathname hoSt 2e 3 ataa ads p eddie 191 pathname name 2 ieeveei bate ib dai 191 pathname new device s esses 192 pathname new directory s 192 pathname new name ebbe i 192 pathname new type esee 192 pathname new version eee eee 192 pathname simplify 0 425 od 189 pathr ame type iR eb de ade ie 191 Pathname VET OM ici pe id ae 191 pathname wild ios 193 pathname eei kornere o XE RP 192 pathname tonal eS 192 peek chaf aii ie 165 peek char on input port 179 port type operation sess 178 port type operation names 178 port type operations cesses 178 port type veces alin oul eee E Tus 178 port input blocking mode 183 port input terminal mode 184 port operationogs itia be ERR RES 178 300 port operation nameS oooooccccocooooooooo 179 port output blocking mode 183 port output t
196. d the value yielded by procedure is returned If procedure does not return then the port will not be closed automatically unless it is reclaimed by the garbage collector call with binary input file filename procedure procedure call with binary output file filename procedure procedure These procedures open files in binary mode In all other respects they are identical to call with input file and call with output file respectively with input from file filename thunk procedure with output to file filename thunk procedure Thunk must be a procedure of no arguments The file is opened for input or output an input or output port connected to it is made the default value returned by current input port or current output port and the thunk is called with no arguments When the thunk returns the port is closed and the previous default is restored with input from file and with output to file return the value yielded by thunk If an escape procedure is used to escape from the continuation of these procedures their behavior is implementation dependent in that situation MIT Scheme leaves the files open with input from binary file filename thunk procedure with output to binary file filename thunk procedure These procedures open files in binary mode In all other respects they are identical to with input from file and with output to file respectively 14 3 String Ports This section describes the simplest kinds of ports input ports that re
197. dard arithmetic operations on flonums When compiled they do not check the types of their arguments flo negate flonum procedure This procedure returns the negation of its argument When compiled it does not check the type of its argument Equivalent to flo 0 flonum 60 MIT Scheme Reference flo abs flonum procedure flo exp flonum procedure flo log flonum procedure flo sin flonum procedure flo cos flonum procedure flo tan flonum procedure flo asin flonum procedure flo acos flonum procedure flo atan flonum procedure flo sqrt fonum procedure flo expt flonum1 flonum2 procedure flo floor flonum procedure flo ceiling flonum procedure flo truncate flonum procedure flo round flonum procedure flo floor gt exact flonum procedure flo ceiling gt exact flonum procedure flo truncate gt exact flonum procedure flo round gt exact flonum procedure These procedures are flonum versions of the corresponding procedures When com piled they do not check the types of their arguments flo atan2 flonuml flonum2 procedure This is the flonum version of atan with two arguments When compiled it does not check the types of its arguments 4 8 Random Numbers MIT Scheme provides a facility for generating pseudo random numbers The current im plementation is a subtract with carry random number generator based on the algorithm from A New Class of Random Number Generators George Marsaglia and Arif Zaman The Annals of Ap
198. de echo that character and return it Under Edwin and Emacs instead of reading a character the interaction buffer is put into a mode in which graphic characters submit themselves as input After this mode change the first such character submitted is returned as the value of this procedure prompt for expression prompt port procedure Prompts the user for an expression The prompt string is formed by appending a colon and a space to prompt unless prompt already ends in a space or is the null string The default behavior of this procedure is to print a fresh line a newline and the prompt string flush the output buffer then read an object and return it Under Edwin and Emacs the expression is read in the minibuffer prompt for evaluated expression prompt environment port procedure Prompts the user for an evaluated expression Calls prompt for expression to read an expression then evaluates the expression using environment if environment is not given the REP loop environment is used prompt for confirmation prompt port procedure Prompts the user for confirmation The result yielded by this procedure is a boolean The prompt string is formed by appending the string y or n to prompt unless prompt already ends in a space or is the null string The default behavior of this procedure is to print a fresh line a newline and the prompt string flush the output buffer then read a character in raw mode If the chara
199. ded time zone 00000 207 defa lt object c ies RP REP AREEY Ed I7 define be RIO xS 1 22 23 29 156 define color on os2 graphics device 267 define color on win32 graphics device 264 define similar windows type 275 define structure sn oc b ek 31 114 define windoWS typ6e c e ei ders 275 del assoC x closeenesselrfewutedesss i 122 A O pelts 2 oaks 123 d l assi itch niuni ne ap bn 122 del assq icon hee ieee See ES 123 del asSW ss passes iene fib e MRIDI SUE 122 d l asSv ninas nia dica 123 delirante cid dat 20 116 delia 94 deletel inmi xe Lee ARRAY ER 94 95 delete association procedure 123 delete dib iii Ioteifbee e be roo daras 281 delete dire CO Vii id ta 199 del te fi16 2 26 id 198 delet file no errorsS 4 09s 198 delete member procedure s 95 delq faa meer Pe EERE DPU RD ES 94 delat ii sd dt ina 94 delval sesse ex X deter pe a 94 95 dl esis cd arios re er er eder e rud nbus 94 denominator o pivelwe niii E EEKi nE 50 desktop size on os2 graphics device 268 AiD ienes pepadaan P Lis 279 dub Dit l2 gels a 281 dib from Ditmapo M EDIpPPSRSROPXR ER 280 dib height cese nnne 281 dib set pixels unaligned 282 dib width ii eese e IR RD IDEROEEES 281 digit char ng d e pRRERRRLRGpR RU Ne d 66 294 directory namestring sss 194 directory Path viii eds 194 dire
200. dering relation An error is signalled if 146 MIT Scheme Reference the tree is empty The average and worst case times required by this operation are proportional to the logarithm of the number of associations in the tree This operation is equivalent to wt tree delete wt tree wt tree min wt tree wt tree delete min wt tree procedure Removes the association with the least key under the wt tree s ordering relation An error is signalled if the tree is empty The average and worst case times required by this operation are proportional to the logarithm of the number of associations in the tree This operation is equivalent to wt tree delete wt tree wt tree min wt tree Chapter 12 Procedures 147 12 Procedures Procedures are created by evaluating lambda expressions see Section 2 1 Lambda Ex pressions page 17 the lambda may either be explicit or may be implicit as in a procedure define see Section 2 4 Definitions page 22 Also there are special built in procedures called primitive procedures such as car these procedures are not written in Scheme but in the language used to implement the Scheme system MIT Scheme also provides application hooks which support the construction of data structures that act like procedures In MIT Scheme the written representation of a procedure tells you the type of the procedure compiled interpreted or primitive PP gt compiled procedure 56 pp 4x2 x10 x307578 l
201. dition objects contain information about the nature of the condition information that describes the state of the computation from which the condition arose and information about the ways the computation can be restarted Classification of conditions Each condition has a type represented by a condition type object Each con dition type may be a specialization of some other condition types A group of types that share a common generalization can be handled uniformly by speci fying a handler for the generalization 16 1 Condition Signalling Once a condition instance has been created using make condition or any condition constructor it can be signalled The act of signalling a condition is separated from the act of creating the condition to allow more flexibility in how conditions are handled For Chapter 16 Error System 227 example a condition instance could be returned as the value of a procedure indicating that something unusual has happened to allow the caller to clean up some state The caller could then signal the condition once it is ready A more important reason for having a separate condition signalling mechanism is that it allows resignalling When a signalled condition has been caught by a particular handler and the handler decides that it doesn t want to process that particular condition it can signal the condition again This is one way to allow other handlers to get a chance to see the condition error reason argume
202. dler procedure Installs handler as a permanent condition handler for the conditions specified by condition types Condition types must be a list of condition types signalling a con dition whose type is a specialization of any of these types will cause the handler to be invoked See signal condition for a description of the mechanism used to invoke handlers By special extension if condition types is the empty list then the handler is called for all conditions break on signals condition types procedure Arranges for signal condition to create an interactive REPL before it signals a condition that is a specialization of any of the types in the list of condition types This can be extremely helpful when trying to debug code that uses custom condition handlers In order to create a REPL when any condition type is signalled it is best to actually put a breakpoint on entry to signal condition standard error handler condition procedure Called internally by error after it calls signal condition Normally creates creates a new REPL with the prompt error gt but see standard error hook In order to simulate the effect of calling error code may call signal condition directly and then call standard error handler if signal condition returns standard error hook variable This variable controls the behavior of the procedure standard error handler and hence error It is intended to be bound with fluid let and is normally f It may Chapter 16
203. dse gg p ku d tri 256 graphics move cursor sees 254 graphics operation ieec c t ERR Res 257 graphics reset clip rectangle 257 graphics set clip rectangle 256 graphics set coordinate limits 252 graphics set drawing mode 255 graphics set line style 256 graphics type available 251 guarantee i o port sese 160 guaranitee input pOrt o cor rr da 160 guarantee output pOrt zig eee sea 160 guarantee pol diia e ird bd ku EEEE 160 H Handles toi ri dyes rada 276 hard iink frle 1 22 21 2 2 Eis Ret 198 hash eR ums EE EREB in 134 174 hash table gt alist 00 0 0 00s 128 hash table clean 0c eee eee 127 hash table clear s esses 128 hash table constructor s ss 132 hash tabie count ui un eR e adna 128 hash table datum list 128 hash table entries list 133 hash table entries vector 133 hash table entry datum 133 hash table entry key 00 133 hash table entry valid 133 hash table for each 0 cece ee 128 ha sh tabl get eee ds pov eters 127 hash table key hash 133 hash table key list s esses 128 hash table key 000000 133 hash table lookup 00005 128
204. dure lt xl x2 x3 procedure gt xlx2x3 procedure These procedures return stt if their arguments are respectively equal monotonically increasing monotonically decreasing monotonically nondecreasing or monotonically nonincreasing These predicates are transitive Note that the traditional implementations of these predicates in Lisp like languages are not transitive Note While it is not an error to compare inexact numbers using these predicates the results may be unreliable because a small inaccuracy may affect the result this is especially true of and zero When in doubt consult a numerical analyst In MIT Scheme the rational procedure is the same as real and the complex procedure is the same as number 48 MIT Scheme Reference zero z procedure positive x procedure negative x procedure odd x procedure even x procedure These numerical predicates test a number for a particular property returning t or See note above regarding inexact numbers max xl x2 procedure min xl x2 procedure These procedures return the maximum or minimum of their arguments max 3 4 gt 4 exact max 3 9 4 gt 4 0 inexact Note If any argument is inexact then the result will also be inexact unless the procedure can prove that the inaccuracy is not large enough to affect the result which is possible only in unusual implementations If min or max is used to compare numbers of mixed exactness and the
205. e RESTART 1 gt Return to read eval print level 1 list copy 3 The object 3 passed as an argument to list copy is not a list To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 error wrong type argument datum type operator procedure This procedure signals a condition of type condition type wrong type argument The datum type and operator fields of the condition are filled in from the corre sponding arguments to the procedure the operand field of the condition is set to f condition type wrong number of arguments datum type condition type operands This type indicates that a procedure was called with the wrong number of arguments The datum field contains the procedure being called the type field contains the number of arguments that the procedure accepts and the operands field contains a list of the arguments that were passed to the procedure 244 MIT Scheme Reference car 3 4 The procedure car has been called with 2 arguments it requires exactly 1 argument To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 error wrong number of arguments datum type operands procedure This procedure signals a condition of type condition type wrong number of arguments The datum type and operands fields of the condition are filled in from the corresponding arguments to the procedure condition type dat
206. e If the file already exists its modification time is set to the current file time and f is returned Otherwise the file is created and t is returned This is an atomic test and set operation so it is useful as a synchronization mechanism file length filename procedure Returns the length in bytes of the file named filename as an exact non negative integer file attributes filename procedure This procedure determines if the file named filename exists and returns information about it if so if the file does not exist it returns f In operating systems that support symbolic links if filename names a symbolic link file attributes returns the attributes of the link itself An alternate proce dure file attributes indirect returns the attributes of the file linked to in all other respects it is identical to file attributes For symmetry file attributes direct is a synonym of file attributes The information returned by file attributes is decoded by accessor procedures The following accessors are defined in all operating systems file attributes type attributes procedure The file type stt if the file is a directory a character string the name linked to if a symbolic link or f for all other types of file file attributes access time attributes procedure The last access time of the file an exact non negative integer file attributes modification time attributes procedure The last modification time of the file an
207. e binary operation procedure For example using one can add up all the elements reduce O list of numbers The argument initial is used only if list is empty in this case initial is the result of the call to reduce If list has a single argument it is returned Otherwise the arguments are reduced in a left associative fashion For example 98 MIT Scheme Reference reduce 0 1 2 3 4 gt 10 reduce O 1 2 gt 3 reduce 0 1 gt 1 reduce 0 gt 0 reduce O foo gt foo reduce list O 1 2 3 4 gt U1 2 3 4 reduce right procedure initial list procedure Like reduce except that it is right associative reduce right list O 1 2 3 4 gt 1 2 3 4 fold right procedure initial list procedure Combines all of the elements of list using the binary operation procedure Unlike reduce and reduce right initial is always used fold right 0 1 2 3 4 gt 10 fold right 0 foo Illegal datum fold right list 1 2 3 4 gt 1 G 4 0 Fold right has interesting properties because it establishes a homomorphism be tween cons O and procedure initial It can be thought of as replacing the pairs in the spine of the list with procedure and replacing the at the end with initial Many of the classical list processing procedures can be expressed in terms of fold right at least for the simple versions that take a fixed number of arguments define
208. e entry s datum set entry datum A procedure that accepts an entry and an object as arguments modifies the entry s datum to be the object and returns an unspecified result rehash after gc An optional argument that if true says the values returned by key hash might change after a garbage collection If so the hash table imple mentation arranges for the table to be rehashed when necessary See Section 11 4 4 Address Hashing page 131 for information about hash procedures that have this property Otherwise it is assumed that key hash always returns the same value for the same arguments The default value of this argument is f Chapter 11 Associations 133 For example here is how the constructors for ordinary hash tables could be defined define strong hash table constructor key hash key optional rehash after gc hash table constructor key hash key cons t car cdr set cdr if default object rehash after gc f rehash after gc define weak hash table constructor key hash key optional rehash after gc hash table constructor key hash key weak cons weak pair car weak car weak cdr weak set cdr if default object rehash after gc f rehash after gc hash table key hash hash table procedure hash table key hash table procedure hash table make entry hash table procedure hash table entry valid hash table procedure hash table entry key hash table procedure hash table entry datum
209. e filename thunk procedure This procedure temporarily rebinds the current working directory to filename in vokes thunk a procedure of no arguments then restores the previous working di rectory and returns the value yielded by thunk Filename is coerced to a path name using pathname as directory In addition to binding the working directory 198 MIT Scheme Reference with working directory pathname also binds the variable default pathname defaults merging the old value of that variable with the new working directory pathname Both bindings are performed in exactly the same way as dynamic binding of a variable see Section 2 3 Dynamic Binding page 21 15 3 File Manipulation This section describes procedures that manipulate files and directories Any of these procedures can signal a number of errors for many reasons The specifics of these errors are much too operating system dependent to document here However if such an error is signalled by one of these procedures it will be of type condition type file operation error file exists filename procedure file exists direct filename procedure file exists indirect filename procedure These procedures return stt if filename is an existing file or directory otherwise they return 4f In operating systems that support symbolic links if the file is a symbolic link file exists direct tests for the existence of the link while file exists indirect and file exists test for the
210. e for presentation to human readers decoded time date string decoded time procedure decoded time time string decoded time procedure These procedures return strings containing external representations of the date and time respectively represented by decoded time The results are implicitly in local time decoded time date string local decoded time Tuesday March 30 1999 decoded time time string local decoded time gt 11 22 38 AM day of week long string day of week procedure day of week short string day of week procedure Returns a string representing the given day of week The argument must be an exact non negative integer between O and 6 inclusive day of week long string returns a long string that fully spells out the name of the day day of week short string returns a shortened string that abbreviates the day to three letters day of week long string 0 Monday day of week short string 0 gt Mon day of week short string 3 Thu month long string month procedure month short string month procedure Returns a string representing the given month The argument must be an exact non negative integer between 1 and 12 inclusive month long string returns a long Chapter 15 Operating System Interface 213 string that fully spells out the name of the month month short string returns a shortened string that abbreviates the month to three letters month long string 1 gt January month short string
211. e frame size is useful in conjunction with the window position and the desktop size to determine relative placement of the window or to guarantee that the entire window is visible on the desktop desktop size operation on os2 graphics device This operation returns the size of the OS 2 desktop The size is returned as two values see Section 12 3 Continuations page 149 which are the width and height of the frame in units of pels pixels raise window operation on os2 graphics device This operation raises the graphics device window so that it is on top of any other windows on the desktop lower window operation on os2 graphics device This operation lowers the graphics device window so that it is below all other windows on the desktop hide window operation on os2 graphics device This operation hides the graphics device window The window disappears from the desktop but still appears in the window list Chapter 17 Graphics 269 minimize window operation on os2 graphics device This operation minimizes the graphics device window The window disappears from the desktop but still appears in the window list Depending on how you have con figured your desktop the window may appear as an icon either on the desktop or in the minimized window viewer maximize window operation on os2 graphics device This operation maximizes the graphics device window This causes the window to fill the entire desktop restore window operation on os2 gr
212. e latter expression works is that weak car returns f in just two instances when the car component is f and when the car component has been garbage collected In the former case if a garbage collection happens between the two calls it won t matter because f will never be garbage collected And in the latter case it also won t matter because the car component no longer exists and cannot be affected by the garbage collector weak set car weak pair object procedure Sets the car component of weak pair to object and returns an unspecified result weak cdr weak pair procedure Returns the cdr component of weak cdr weak set cdr weak pair object procedure Sets the cdr component of weak pair to object and returns an unspecified result Chapter 11 Associations 121 11 Associations MIT Scheme provides several mechanisms for associating objects with one another Each of these mechanisms creates a link between one or more objects called keys and some other object called a datum Beyond this common idea however each of the mechanisms has various different properties that make it appropriate in different situations e Association lists are one of Lisp s oldest association mechanisms Because they are made from ordinary pairs they are easy to build and manipulate and very flexible in use However the average lookup time for an association list is linear in the number of associations e 1D tables have a very simple interface maki
213. e letters vector 8b find previous char string start end ascii procedure vector 8b find previous char ci string start end ascii procedure Returns the index of the last occurrence of ascii in the given substring returns f if ascii does not appear The index returned is relative to the entire string not just the substring Ascii must be a valid ASCII code vector 8b find previous char ci doesn t distinguish uppercase and lowercase let ters 86 MIT Scheme Reference Chapter 7 Lists 87 7 Lists A pair sometimes called a dotted pair is a data structure with two fields called the car and cdr fields for historical reasons Pairs are created by the procedure cons The car and cdr fields are accessed by the procedures car and cdr The car and cdr fields are assigned by the procedures set car and set cdr Pairs are used primarily to represent lists A list can be defined recursively as either the empty list or a pair whose cdr is a list More precisely the set of lists is defined as the smallest set X such that e The empty list is in X e If list is in X then any pair whose cdr field contains list is also in X The objects in the car fields of successive pairs of a list are the elements of the list For example a two element list is a pair whose car is the first element and whose cdr is a pair whose car is the second element and whose cdr is the empty list T he length of a list is the number of elements which is the same a
214. e matched against the remaining arguments If there are fewer ar guments than optional parameters the unmatched parameters are bound to special objects called default objects If there are more arguments than optional parameters and there are no further parameters an error of type condition type wrong number of arguments is signalled The predicate default object which is true only of default objects can be used to determine which optional parameters were supplied and which were defaulted Rest Finally if there is a rest parameter there can only be one any remaining arguments are made into a list and the list is bound to the rest parameter If there are no remaining arguments the rest parameter is bound to the empty list 18 MIT Scheme Reference In Scheme unlike some other Lisp implementations the list to which a rest parameter is bound is always freshly allocated It has infinite extent and may be modified without affecting the procedure s caller Specially recognized keywords divide the formals parameters into these three classes The keywords used here are optional and rest Note that only is defined by standard Scheme the other keywords are MIT Scheme extensions rest has the same meaning as in formals The use of these keywords is best explained by means of examples The following are typical lambda lists followed by descriptions of which parameters are required opt
215. e number vector binary search 1 i 2 ii 3 iii 6 vi lt car number translate 2 gt 2 ii translate 4 gt HF 8 3 Cutting Vectors subvector vector start end procedure Returns a newly allocated vector that contains the elements of vector between index start inclusive and end exclusive vector head vector end procedure Equivalent to subvector vector O end vector tail vector start procedure Equivalent to subvector vector start vector length vector 104 MIT Scheme Reference 8 4 Modifying Vectors vector fill vector object procedure subvector fill vector start end object procedure Stores object in every element of the vector subvector and returns an unspecified value subvector move left vectorl startl endl vector2 start2 procedure subvector move right vectorl start1 end1 vector2 start2 procedure Destructively copies the elements of vectorl starting with index start1 inclusive and ending with endl exclusive into vector2 starting at index start2 inclusive Vectorl start1 and end1 must specify a valid subvector and start2 must be a valid index for vector2 The length of the source subvector must not exceed the length of vector2 minus the index start2 The elements are copied as follows note that this is only important when vectorl and vector2 are eqv subvector move left The copy starts at the left end and moves toward the right from smaller indices
216. e object flo random unit returns a pseudo random number between zero inclusive and one exclusive the returned number is always a flonum and therefore an inexact real number flo random unit is equivalent to random with a modulus of 1 0 except that it is faster The next three definitions concern random state objects In addition to these definitions 1t is important to know that random state objects are specifically designed so that they can be saved to disk using the fasdump procedure and later restored using the fasload procedure This allows a particular random state object to be saved in order to replay a particular pseudo random sequence random state variable This variable holds a data structure a random state object that encodes the internal state of the random number generator that random uses by default A call to random will perform a side effect on this data structure This variable may be changed using set or fluid let to hold a new random state object make random state state procedure This procedure returns a new random state object suitable for use as the value of the variable random state or as the state argument to random If state is not given or 4f make random state returns a copy of the current random number state object the value of the variable random state If state is a random state object a copy of that object is returned If state is stt then a new random state object is returned that has been ra
217. e of the leftmost character at x and the baseline of the characters at y The following two procedures provide an alternate mechanism for drawing lines which is more akin to using a plotter They maintain a cursor which can be positioned to a particular point and then dragged to another point producing a line Sequences of connected line segments can be drawn by dragging the cursor from point to point Many graphics operations have an unspecified effect on the cursor The following excep tions are guaranteed to leave the cursor unaffected 254 MIT Scheme Reference graphics device coordinate limits graphics coordinate limits graphics enable buffering graphics disable buffering graphics flush graphics bind drawing mode graphics set drawing mode graphics bind line style graphics set line style The initial state of the cursor is unspecified graphics move cursor graphics device x y procedure Moves the cursor for graphics device to the point x y The contents of the device s display are unchanged graphics drag cursor graphics device x y procedure Draws a line from graphics device s cursor to the point x y simultaneously moving the cursor to that point The line is drawn using the current drawing mode and line style 17 4 Characteristics of Graphics Output Two characteristics of graphics output are so useful that they are supported uniformly by all graphics devices drawing mode and line style A third characteristic col
218. e rados 223 and xao ier ees ies hiesbesv one e eaae 28 109 angle cee ned adele ence RP uii bir 52 53 append eic enr ocn 95 97 append ieele e Rp ir 953 97 append map i ie e Die Er EE VERRE UE 97 append mapi encia ele 97 append maps ello eet bine e pa 97 append map oca ciar es ea 4 97 APPLY wale iii 15 147 apply hook extra i0 ERO titirin 152 apply hook procedure eese 152 APPLY hook isn heathens tenes ue e Ee 152 ascii gt char ei hig thinset RP RET UR eae EEA 68 ascii range gt char set 0 0 70 ASTM diria 52 ASSOC Lolo EO NEU hup ee bet ph Se 122 association procedure suus 122 A s Pi I debi dag date a e 122 Aia a PISIS DU e bei sete 122 abane resad enr ER bikai iraa aa eai 52 60 Drm 170 begin 2 2 MERE RP aoe ME ee perte 29 bind cell contents s t ign 114 bind condition handler 226 227 229 230 bind default condition handler 227 229 230 bit string gt signed integer 108 bit string gt unsigned integer 108 bit string allocate cocida de eres 105 bit string and uiii ue raras na 107 bit string and ics ied bs Lr nds 107 bit string andC ii ds4 ita be EXE dos 107 bit string and6 iooictee bbs Enn 107 bat string append e Rr re 106 bit string clear oli 106 bat string CODy mice RRRERI 105 bit string fill duos dori 108 bit string length esse pd 106 bit string movell 0 0228 a eee be L
219. e symbols names contain special characters or letters in the non standard 2 case The external representation for uninterned symbols is special to distinguish them from interned symbols and prevent them from being recognized by the read procedure string gt uninterned symbol foo tluninterned symbol 30 foo In this section the procedures that return symbols as values will either always return interned symbols or always return uninterned symbols The procedures that accept sym bols as arguments will always accept either interned or uninterned symbols and do not distinguish the two symbol object procedure Returns stt if object is a symbol otherwise returns ttf symbol foo gt t symbol car a b gt dit symbol bar gt df symbol string symbol procedure Returns the name of symbol as a string If symbol was returned by string gt symbol the value of this procedure will be identical in the sense of string to the string that was passed to string gt symbol It is an error to apply mutation procedures such as string set to strings returned by this procedure symbol gt string flying fish gt flying fish symbol gt string Martin gt martin symbol gt string string gt symbol Malvina gt Malvina Note that two distinct uninterned symbols can have the same name intern string procedure Returns the interned symbol whose name is string Converts string to the standard alph
220. e that path is restricted to a machine dependent range usually the size of a machine word On many machines this means that the maximum length of path will be 30 operations 32 bits less the sign bit and the end of sequence bit Chapter 7 Lists 91 cons object object procedure cons is similar to list except that cons conses together the last two arguments rather than consing the last argument with the empty list If the last argument is not a list the result is an improper list If the last argument is a list the result is a list consisting of the initial arguments and all of the items in the final argument If there is only one argument the result is the argument cons a b c gt ab c cons a b c d gt abc d cons a a These expressions are equivalent cons objl obj2 objN 1 objN cons objl cons obj2 cons objN 1 objN list copy list procedure Returns a newly allocated copy of list This copies each of the pairs comprising list This could have been defined by define list copy list if null list O cons car list list copy cdr list vector gt list vector procedure subvector gt list vector start end procedure vector list returns a newly allocated list of the elements of vector subvector gt list returns a newly allocated list of the elements of the given subvector The inverse of vector gt list is list gt vector vector list dah d
221. e types of its arguments fix xor x40 3 gt x43 fix xor x41 3 gt x42 fix lsh fixnuml fixnum2 procedure This procedure returns the result of logically shifting fixnum1 by fixnum2 bits If fixnum2 is positive fixnuml is shifted left if negative it is shifted right When compiled it does not check the types of its arguments nor the validity of its result fix lsh 1 10 gt x400 fix lsh x432 10 gt 1 fix lsh 1 3 gt 8 fix 1sh 128 4 gt Hx3FFFF8 Chapter 4 Numbers 59 4 7 2 Flonum Operations A flonum is an inexact real number that is implemented as a floating point number In MIT Scheme all inexact real numbers are flonums For this reason constants such as 0 and 2 3 are guaranteed to be flonums flo flonum object procedure Returns t if object is a flonum otherwise returns sf flo flonum1 flonum2 procedure flo lt fonum1l flonum2 procedure flo gt flonuml flonum2 procedure These procedures are the standard order and equality predicates on flonums When compiled they do not check the types of their arguments flo zero flonum procedure flo positive flonum procedure flo negative flonum procedure Each of these procedures compares its argument to zero When compiled they do not check the type of their argument flo flonuml flonum2 procedure flo flonum1 flonum2 procedure flo flonuml flonum2 procedure flo flonum1 flonum2 procedure These procedures are the stan
222. ead the effector should call a continuation created before the condition signalling process began and with restart will therefore not return in the normal manner define by george thunk This code handles conditions that arise while executing thunk by invoking the GEORGE restart passing 1 and 2 to the restart s effector code bind condition handler All conditions lambda condition invoke restart find restart george 1 2 thunk 234 MIT Scheme Reference define can george thunk This code provides a way of handling errors the GEORGE restart In order to GEORGE you must supply two values lambda call with current continuation lambda kappa with restart george Name This restart is named george Reporter lambda a b Effector kappa list george a b values Interactor thunk Thunk by george can george lambda 3 gt 3 by george can george lambda car x george 1 2 16 4 2 Invoking Standard Restart Code Scheme supports six standard protocols for restarting from a condition each encapsu lated using a named restart for use by condition signalling code and a simple procedure for use by condition handling code Unless otherwise specified if one of these procedures is unable to find its corresponding restart it returns immediately with an unspecified value Each of these procedures accepts an optional argument restarts which is descri
223. ed defn 116 evaluation in examples 000005 4 evaluation lazy defn issues 116 evaluation of s expression ooooo ooooo 156 even numbeE smc 48 deni m 44 examples ce eds eae ede RERERIS EE 4 existence testing of file 198 exit non local 22er RR oia 150 exponent marker defn issues 46 expression d fn oa osse et emet 13 311 expression binding defn suuuuueu 8 expression conditional defn 26 expression constant defn 14 expression input from port 166 expression iteration defn suuueu 29 expression literal defn 00 14 expression output to pOlt oooo oooo oo 169 expression procedure call defn 15 expression special form defn 14 extended comment in programs defn 12 extension of environment defn 7 extent of dynamic binding defn 21 extent Of objects sesso ese rerom eere 3 external representation defn 9 external representation and quasiquote 25 external representation and quote 24 external representation for bit string 105 external representation for character 63 external representation for empty list 87 external representation for list 87 external r
224. ed returning immediately to the caller of ignore errors More demanding applications require more powerful facilities To give a concrete exam ple suppose you want floating point division to return a very large number whenever the denominator is zero This behavior can be implemented using the error system The Scheme arithmetic system can signal many different kinds of errors including floating point divide by zero In our example we would like to handle this particular condition specially allowing the system to handle other arithmetic errors in its usual way The error system supports this kind of application by providing mechanisms for dis tinguishing different types of error conditions and for specifying where control should be transferred should a given condition arise In this example there is a specific object that represents the floating point divide by zero condition type and it is possible to dynami cally specify an arbitrary Scheme procedure to be executed when a condition of that type is signalled This procedure then finds the stack frame containing the call to the division operator and returns the appropriate value from that frame Another useful kind of behavior is the ability to specify uniform handling for related classes of conditions For example it might be desirable when opening a file for input to gracefully handle a variety of different conditions associated with the file system One such condition might be t
225. ed in the local time zone Otherwise zone must be a valid time zone and the result will be represented in that zone Warning because this procedure depends on the operating system s runtime library it is not capable of representing all dates In particular on most unix systems it is not possible to encode dates that occur prior to midnight January 1 1970 UTC Attempting to do this will signal an error Chapter 15 Operating System Interface pp make decoded time O 9 11 26 3 1999 decoded time 19 second 0 minute 9 hour 11 4 day 26 month 3 4 year 1999 day of week 4 daylight savings time 0 zone 5 pp make decoded time O 9 11 26 3 1999 3 decoded time 80 second 0 minute 9 hour 11 4 day 26 month 3 4 year 1999 day of week 4 daylight savings time 0 4 zone 3 os decoded time second decoded time decoded time minute decoded time decoded time hour decoded time decoded time day decoded time decoded time month decoded time decoded time year decoded time Return the corresponding component of decoded time decoded time second local decoded time 17 decoded time year local decoded time 1999 decoded time day local decoded time 26 decoded time day of week decoded time 207 procedure procedure procedure procedure procedure procedure procedure Return the day of the week on which decoded time falls
226. ed value define s make string 10 space gt unspecified substring fill s 2 8 gt unspecified s So substring move left stringl start1 end1 string2 start2 procedure substring move right stringl start1 end1 string2 start2 procedure Copies the characters from startl to endl of stringl into string2 at the start2 th position The characters are copied as follows note that this is only important when stringl and string2 are eqv substring move left The copy starts at the left end and moves toward the right from smaller indices to larger Thus if string and string2 are the same this procedure moves the characters toward the left inside the string substring move right The copy starts at the right end and moves toward the left from larger indices to smaller Thus if string and string2 are the same this proce dure moves the characters toward the right inside the string The following example shows how these procedures can be used to build up a string it would have been easier to use string append define answer make string 9 gt unspecified answer SEK substring move left start 0 5 answer 0 unspecified answer gt starter substring move left end 0 4 answer 5 unspecified answer gt start end reverse string string procedure reverse substring string start end procedure reverse string string procedure reverse substring string start end procedure Reverses the orde
227. edures for key hashing it is necessary to tell the hash table implementation by means of the rehash after gc argument to the constructor constructor procedure that the hash numbers computed by your key hashing procedure must be recomputed after a garbage collection eq hash object procedure eqv hash object procedure equal hash object procedure These procedures return a hash number for object The result is always a non negative integer and in the case of eq hash a non negative fixnum Two objects that are equivalent according to eq eqv or equal respectively will produce the same hash number when passed as arguments to these procedures provided that the garbage collector does not run during or between the two calls The following procedures are the key hashing procedures used by the standard address hash based hash tables eq hash mod object modulus procedure This procedure is the key hashing procedure used by make eq hash table eqv hash mod object modulus procedure This procedure is the key hashing procedure used by make eqv hash table equal hash mod object modulus procedure This procedure is the key hashing procedure used by make equal hash table 132 MIT Scheme Reference 11 4 5 Low Level Hash Table Operations The procedures in this section allow the programmer to control some of the internal structure of a hash table Normally hash tables maintain associations between keys and datums using pairs or wea
228. ee aes da 90 trees balanced binary 135 138 trimming Of String is 77 true boolean object oooooooo o o o 8 true boolean object defn 109 true in conditional expression defn 26 truename of input file 199 type predicate for 1D table 124 type predicate for alist 122 type predicate for apply hook 152 type predicate for bit String 106 type predicate for boolean lusus 109 type predicate for cell 0 o o ooooo 114 type predicate for character ooo o o ooo 65 type predicate for character Set 68 type predicate for compiled procedure 148 type predicate for compound procedure 148 type predicate for continuation 150 type predicate for empty list 92 type predicate for entity ooooooo ooooo 153 317 type predicate for environment 155 type predicate for EOF object 166 type predicate for fixmum 57 type predicate for flonum 59 type predicate for hash table 127 type predicate for interpreter environment 157 type predicate for list 91 type predicate for number 46 type predicate for pair lees esses 88 type predicate for pathname
229. een removed Note that while the returned copy is a newly allocated list the association pairs that are the elements of the list are shared with This introduction is taken from Common Lisp The Language second edition p 431 2 Although they are often used as predicates assq assv and assoc do not have question marks in their names because they return useful values rather than just t or f Chapter 11 Associations 123 alist not copied del assq uses eq to compare object with the keys while del assv uses eqv and del assoc uses equal define a butcher 231 e22nd St baker 515 w23rd St hardware 988 Lexington Ave del assq baker a gt Cbutcher 231 e22nd St hardware 988 Lexington Ave del assq object alist procedure del assv object alist procedure del assoc object alist procedure These procedures remove from alist all associations with keys equal to object They return the resulting list del assq uses eq to compare object with the keys while del assv uses eqv and del assoc uses equal These procedures are like del assq del assv and del assoc respectively except that they destructively modify alist delete association procedure deletor predicate selector procedure This returns a deletion procedure similar to del assv or del assq The predicate and selector arguments are the same as those for association procedure while the deletor argument should be either t
230. effect on anything drawn prior to their invocation Because changing the background color affects the entire window we recommend calling graphics clear on the window s device afterwards The foreground color affects the drawing of text points lines ellipses and filled polygons Colors are specified in one of three ways An integer This is the Win32 internal RGB value By name A limited number of names are understood by the system Names are strings e g red blue black More names can be registered with the define color operation RGB Red Green Blue triples A triple is either a vector or list of three integers in the range 0 255 inclusive which specify the intensity of the red green and blue components of the color Thus 0 0 0 is black 0 0 128 is dark blue and 255 255 255 is white If the color is not available in the graphics device then the nearest available color is used instead define color name spec operation on win32 graphics device Define the string name to be the color specified by spec Spec may be any acceptable color specification Note that the color names defined this way are available to any Win32 graphics device and the names do not have to be defined for each device Color names defined by this interface may also be used when setting the colors of the Scheme console window or the colors of Edwin editor windows Chapter 17 Graphics 265 find color name operation on win32 graphics device Lo
231. egisters are a set of index registers that record indexes into the matched string Each index register corresponds to an instance of the regular expression grouping operator AC and records the start index inclusive and end index exclusive of the matched group These registers are numbered from 1 to 9 corresponding left to right to the grouping operators in the expression Additionally register O corresponds to the entire substring matching the regular expression re match start index n registers procedure re match end index n registers procedure N must be an exact integer between 0 and 9 inclusive Registers must be a match registers object as returned by one of the regular expression match or search proce dures above re match start index returns the start index of the corresponding regular expression register and re match end index returns the corresponding end index re match extract string registers n procedure Registers must be a match registers object as returned by one of the regular expression match or search procedures above String must be the string that was passed as an argument to the procedure that returned registers N must be an exact integer between O and 9 inclusive If the matched regular expression contained m grouping operators then the value of this procedure is undefined for n strictly greater than m This procedure extracts the substring corresponding to the match register specified by registers and n This is equ
232. em global environment Chapter 18 Win32 Package Reference 279 declare usual integrations access error system global environment Complain The set of procedures is incomplete because procedures have been added on a by need basis for the implementation of other parts of the system e g Scheme Graphics Look in the implementation for further details Win32 API procedure names have been uniformly converted into Scheme identifiers as follows e leading uppercase letter is translated into a lowercase letter e Subsequent sequences of uppercase letters are translated into lowercase letters pre ceeded by a hyphen minus symbol i e hyphens are inserted at a lowercase to upper case transition e Predicates beginning with Is finally have a question mark appended Example applying these rules to IsWindow yields is window and GetDC is translated into get dc 18 3 Device Independent Bitmap Utilities The Device Independent Bitmap DIB utilities library DIBUTILS DLL and the associ ated procedures in dib scm in the Win32 system source is an example of how to use the foreign function interface to access and manipulate non Scheme objects dib windows type In the C world a DIB is a handle to a piece of memory containing the bits that represent information about the image and the pixels of the image The handle is a machine word sized piece of data which may be thought of as a 32 bit integer The handle may be
233. eme Reference access condition condition field name procedure Returns the value stored in the field field name within condition Field name must be one of the names returned by condition type field names condition type condition access condition looks up the field name at runtime so it is more efficient to use condition accessor to create an access function if the same field is to be extracted from several instances of the same condition type condition report string condition procedure Returns a string containing a report of the condition This is generated by calling write condition report on condition and a string output port and returning the output collected by the port as a string 16 6 Condition Types Each condition has a condition type object associated with it These objects are used as a means of focusing on related classes of conditions first by concentrating all of the information about a specific class of condition in a single place and second by specifying an inheritance relationship between types This inheritance relationship forms the taxonomic structure of the condition hierarchy see Section 16 7 Taxonomy page 241 The following procedures consititute the abstraction for condition types make condition type name generalization field names reporter procedure Creates and returns a new condition type that is a specialization of generalization if it is a condition type or is the root of a new tree of conditio
234. empts to locate and invoke a condition handler that is prepared to deal with the type of condition that has occurred A condition handler is a procedure of one parameter the condition that is being signalled A procedure is installed as a condition handler by calling bind condition handler to establish a handler that is in effect only while a particu lar thunk is executing or bind default condition handler to establish a handler that is in effect permanently As implied by the name handlers created by bind default condition handler are invoked only after all other applicable handlers have been invoked A handler may process a signal in any way it deems appropriate but the common patterns are Ignore the condition By returning from the handler in the usual manner Handle the condition By doing some processing and then invoking a restart or less preferably a continuation that was established at some point prior to the call to signal condition Resignal a condition By doing some processing and calling signal condition with either the same condition or a newly created one In order to support this signal condition runs handler in such a way that a subsequent call to signal condition sees only the handlers that were established prior to this one As an aid to debugging condition handlers Scheme maintains a set of condition types that will cause an interactive breakpoint to occur prior to normal condition signalling That is signa
235. en in the Document s license notice H Include an unaltered copy of this License 286 5 MIT Scheme Reference I Preserve the section entitled History and its title and add to it an item stating at least the title year new authors and publisher of the Modified Version as given on the Title Page If there is no section entitled History in the Document create one stating the title year authors and publisher of the Document as given on its Title Page then add an item describing the Modified Version as stated in the previous sentence J Preserve the network location if any given in the Document for public access to a Transparent copy of the Document and likewise the network locations given in the Document for previous versions it was based on These may be placed in the History section You may omit a network location for a work that was published at least four years before the Document itself or if the original publisher of the version it refers to gives permission K In any section entitled Acknowledgements or Dedications preserve the sec tion s title and preserve in the section all the substance and tone of each of the contributor acknowledgements and or dedications given therein L Preserve all the Invariant Sections of the Document unaltered in their text and in their titles Section numbers or the equivalent are not considered part of the section titles M Delete any section entitled Endo
236. ence predicate 110 bound variable defn 0 0 020005 6 bound restartsz iss rh tada 238 239 bracket in entriesS ooooooooococoocccro 5 bucky bit of character defn 66 bucky bit prefix defh oooooocccccccccc o 63 buffering of graphics output 256 buffering of OU pUb ocoooocccooooc rssi 168 built in procedure 2 ee eeee 147 Byta vector trat adi 84 C call by need evaluation defn 116 capitalization of string 04 75 car field of pair defn 000 87 case clause drid ti 27 case conversion of character lusus 65 case sensitivity of string operations 4 case of interned symbol 110 case Of SUITING isset rt LAN 75 case insensitivity of programs defn 11 cdr field of pair defn oooococcooccccc 87 celi defm 23st erp En oe kc edieels 115 character defn meiosis iris 63 character bits defn ooooooccocccocccoc 66 character code defn 00 2000 66 character S60 spes tada po YS 68 character alphabetic defn 69 character alphanumeric defn 69 character ASCII defn 68 character graphic defn 0 00 69 character input from port 165 179 Concept Index character named defn 205 63
237. entation of an exact non negative integer unique to the object being printed specifically it is the result of calling hash on the object Subsequently the expression hash is notation for the object If procedure is supplied the returned method generates a slightly different external representation name hash output Here name and hash are as above and output is the output generated by procedure The representation is constructed in three stages 1 The first part of the format up to output is written to the output port specified by the unparser state This is name and hash 2 Procedure is invoked on two arguments the object and an output port 3 The closing bracket is written to the output port The following procedure is useful for writing more general kinds of unparser methods Except that if the argument name is a string its external representation is generated by write string Chapter 14 Input Output 175 with current unparser state unparser state procedure procedure This procedure calls procedure with one argument the output port from unparser state Additionally it arranges for the remaining components of unparser state to be given to the printer when they are needed The procedure generates some output by writing to the output port using the usual output operations and the value yielded by procedure is returned from with current unparser state The port passed to procedure should
238. entifier see Section 1 3 3 Identifiers page 11 Any interned symbol that has been returned as part of a literal expression or read using the read procedure and subsequently written out using the write procedure will read back in as the identical symbol in the sense of eq Usually it is also true that reading in an interned symbol that was previously written out produces the same symbol An exception are symbols created by the procedures string gt symbol and intern they can create symbols for which this write read invariance may not Tn older dialects of Lisp uninterned symbols were fairly important This was true be cause symbols were complicated data structures in addition to having value cells and sometimes function cells these structures contained property lists Because of this uninterned symbols were often used merely for their property lists sometimes an uninterned symbol used this way was referred to as a disembodied property list In MIT Scheme symbols do not have property lists or any other components besides their names There is a different data structure similar to disembodied property lists one dimensional tables see Section 11 2 1D Tables page 123 For these reasons un interned symbols are not very useful in MIT Scheme In fact their primary purpose is to simplify the generation of unique variable names in programs that generate Scheme code Chapter 10 Miscellaneous Datatypes 111 hold because th
239. environment has parent 155 environment lookup esses 155 environment parent ce eee eens 155 environment ir ds 155 A II RO Re 166 179 eof on mpul port dr Le PES 180 MIT Scheme Reference eq hbash mod seco d ae Lowest Pedes 127 131 eq 37 40 94 96 110 112 122 123 124 126 127 134 236 equal Lahaina 131 equal hash m0d recita aida te 127 131 equal 20 91 41 94 96 122 123 126 127 egy hashi seco dr 131 eqv hash mod s 2 029 24 viver 131 eqv 10 28 37 83 88 94 96 122 123 126 ETOT 6 04 cw guae dts 4 225 227 230 error irritant noise 229 error bad range argument 244 error datum out of range 244 erroriderived fil6 cnr nd 246 error derived port o sess teres 246 error divide by zero so docu b B Vs 247 error file operation error 245 error no such restart s ess 248 error wrong number of arguments 244 error wrong type argument 243 error wrong type datum 243 OMAN ss tin Sods ores E ainicttaue Dee SES des E Run 156 event l i 2isec bee RE ip EPIO TRES ERU EE 48 a A 53 exact integer icoele ria dde P Rei RR 47 exact nonnegative integer 4T exact rational 2 pie RR np hs AT ORACLE Da cue pO XN EE bedient 47 except llast Pallicoiiiaros sorda ads 94 except las
240. eous Datatypes 113 generate uninterned symbol uninterned symbol 31 GO generate uninterned symbol tluninterned symbol 32 G1 generate uninterned symbol this tluninterned symbol 33 this2 generate uninterned symbol tluninterned symbol 34 G3 generate uninterned symbol 100 uninterned symbol 35 G100 generate uninterned symbol uninterned symbol 36 G101 symbol append symbol procedure Returns the interned symbol whose name is formed by concatenating the names of the given symbols This procedure preserves the case of the names of its arguments so if one or more of the arguments names has non standard case the result will also have non standard case symbol append foo bar gt foo bar the arguments may be uninterned symbol append foo string gt uninterned symbol baz gt foo baz the result has the same case as the arguments symbol append foo string gt symbol BAZ foo BAZ symbol hash symbol procedure Returns a hash number for symbol which is computed by calling string hash on symbol s name The hash number is an exact non negative integer symbol hash mod symbol modulus procedure Modulus must be an exact positive integer Equivalent to modulo symbol hash symbol modulus This procedure is provided for convenience in constructing hash tables However it is normally preferable to use make eq hash table to build hash tables keyed by symbols beca
241. eparated by commas optional colon and at sign 0 modifiers and a single character indicating what kind of directive this is The alphabetic case of the directive character is ignored The prefix parameters are generally integers notated as optionally signed decimal numbers If both the colon and at sign modifiers are given they may appear in either order In place of a prefix parameter to a directive you can put the letter V or v which takes an argument for use as a parameter to the directive Normally this should be an exact integer This feature allows variable width fields and the like You can also use the character in place of a parameter it represents the number of arguments remaining to be processed It is an error to give a format directive more parameters than it is described here as accepting It is also an error to give colon or at sign modifiers to a directive in a combination not specifically described here as being meaningful A The next argument which may be any object is printed as if by display mincolA inserts spaces on the right if necessary to make the width at least mincol columns The modifier causes the spaces to be inserted on the left rather than the right 7S The next argument which may be any object is printed as if by write mincolS inserts spaces on the right if necessary to make the width at least mincol columns The modifier causes the spaces to be inserted on
242. epresentation for number 46 external representation for pair 87 external representation for procedure 147 external representation for string 71 external representation for symbol 110 external representation for vector 101 external representation generating 169 external representation parsing 166 extra object of application hook 152 F f as exponent marker in number 46 false boolean object cto rd 8 false boolean object defn 109 false in conditional expression defn 26 false predicate forssa enpi sisse ar pe 109 file regular predicate for 0 200 file name inni pie Re RR EXER I be es 187 fle time name prior Sb 205 file type procedure for 200 file converting pathname directory to 195 file end of file marker see EOF object 166 file input and output ports 161 filename defi redondo te p eos 187 filling of bit SUING i e be e deis 108 312 filling of strihg ii i kem a pean as 82 filling of vector esmero 104 filtering of list c 2nd ra 94 fixnum del estos cepi e sieeve idee RR 56 Honum defun iiie PvP Ue RI RR 59 fluid binding ree Rep 21 230 231 flushing of buffered output 168 forcing of promises ox exe rereebr ere ped 116 foreign type declarations
243. ept that Common Lisp defines many more directives format is a run time loadable option To use it execute load option format once before calling it format destination control string argument procedure Writes the characters of control string to destination except that a tilde intro duces a format directive The character after the tilde possibly preceded by prefix parameters and modifiers specifies what kind of formatting is desired Most direc tives use one or more arguments to create their output the typical directive puts the 5 This description of format is adapted from Common Lisp The Language second edition section 22 3 3 172 MIT Scheme Reference next argument into the output formatted in some special way It is an error if no argument remains for a directive requiring an argument but it is not an error if one or more arguments remain unprocessed by a directive The output is sent to destination If destination is t a string is created that contains the output this string is returned as the value of the call to format In all other cases format returns an unspecified value If destination is t the output is sent to the current output port Otherwise destination must be an output port and the output is sent there This procedure performs discretionary output flushing see Section 14 5 Output Pro cedures page 168 A format directive consists of a tilde 7 optional prefix parameters s
244. er in which the time components are broken down into unsigned bit fields The components are always stated in local time The fields from MSB to LSB are e 7 bits representing the year relative to 1900 e 4 bits representing the month numbered 1 to 12 e 5 bits representing the day of the month numbered 1 to 31 e 5 bits representing the hour of the day numbered 0 to 23 e 6 bits representing the minute numbered 0 to 59 e 5 bits representing the second This field is unusual in that it counts units of two seconds so it is a number between 0 and 29 representing second counts corresponding to 0 through 58 The following procedures generate their results in file time format Chapter 15 Operating System Interface 209 file access time file access time direct file access time indirect file modification time file modification time direct file modification time indirect file attributes access time file attributes modification time file attributes change time Additionally set file times accepts its time arguments in file time format 15 5 4 Time Format Conversion The procedures described in this section convert times from one format to another universal time gt local decoded time universal time procedure universal time gt global decoded time universal time procedure Converts an argument in universal time format to decoded time format The result is in the local time zone or UTC respectively pp universal time g
245. er 5 Characters 67 make char 97 0 gt Ha make char 97 1 gt M a make char 97 2 gt C a make char 97 3 gt C M a char bits char procedure Returns the exact integer representation of char s bucky bits For example char bits Ha gt 0 char bits m a gt 4d char bits c a gt 2 char bits c m a gt 3 char code char procedure Returns the character code of char an exact integer For example char code Ha gt 97 char code Hic a gt 97 char code limit variable char bits limit variable These variables define the exclusive upper limits for the character code and bucky bits respectively The character code and bucky bits are always exact non negative integers and are strictly less than the value of their respective limit variable char gt integer char procedure integer gt char k procedure char gt integer returns the character code representation for char integer gt char returns the character whose character code representation is k In MIT Scheme if char ascii char is true then equ char gt ascii char char gt integer char However this behavior is not required by the Scheme standard and code that depends on it is not portable to other implementations These procedures implement order isomorphisms between the set of characters under the char lt ordering and some subset of the integers under the lt ordering That is if char lt a b gt t and lt xy gt t and x
246. er s home directory is specified by the HOME environment variable If this variable is undefined the user name is computed using the getlogin system call or if that fails the getuid system call The resulting user name is passed to the getpwnam system call to obtain the home directory Under OS 2 several heuristics are tried to find the user s home directory First if the environment variable HOME is defined that is the home directory If HOME is undefined but the USERDIR and USER environment variables are defined and the directory 4USERDIRANAUSER exists then it is used Failing that if the directory USER exists on the OS 2 system drive then it is used As a last resort the OS 2 system drive is the home directory Like OS 2 the Windows implementation uses heuristics based on environment vari ables The user s home directory is computed by examining several environment variables in the following order e HOMEDRIVE and HOMEPATH are both defined and 4HOMEDRIVE HOMEPATH is an existing directory These variables are automatically defined by Windows NT e HOME is defined and HOMEY is an existing directory e USERDIR and USERNAME are defined and AJUSERDIRANAUSERNAMEA is an existing directory e USERDIR and USER are defined and 4USERDIRANAUSERA is an existing directory e USERNAME is defined and USERNAMEY is an existing directory on the Windows system drive e USER is defined and AUSER is an existing director
247. er width on x graphics device 261 Set carl sicco gea hb bres a rr Pu bred 89 Set cdrl ii eve need a 87 89 s t cell contents osea e 114 set current input port eges 161 set current output port 161 set entity Oxtral mirarte ia 153 set entity procedure s esse 153 set file modes l0 bod dees ee EX 201 set file times ses RE ERR 202 set font on os2 graphics device 271 set font on win32 graphics device 266 set font on x graphics device 261 set foreground color 264 266 set foreground color on os2 graphics device idas 266 set foreground color on win32 graphics device A Ai 264 set foreground color on x graphics device 260 set hash table rehash size 130 set hash table rehash threshold 131 set input buffer size on input port 180 set interaction i o port 161 set internal border width on x graphics device EM 261 set line width on win32 graphics device 265 set mouse color on x graphics device 260 set mouse shape on x graphics device 261 302 set output buffer size on output port 182 set port statel ciar dt REESE aes 178 set record type unparser method 33 173 set string length sies ne ansdae aban 84 set trace o tp t port 2 942 debes 161 set window name on win32 graphics device 265 set window position on o
248. eraction i o port returns the value of console i o port with input from port input port thunk procedure with output to port output port thunk procedure with notification output port output port thunk procedure with trace output port output port thunk procedure with interaction i o port i o port thunk procedure Thunk must be a procedure of no arguments Each of these procedures binds one of the standard ports to its first argument calls thunk with no arguments restores the port to its original value and returns the result that was yielded by thunk This Chapter 14 Input Output 161 temporary binding is performed the same way as dynamic binding of a variable including the behavior in the presence of continuations see Section 2 3 Dynamic Binding page 21 with input from port binds the current input port with output to port binds the current output port with notification output port binds the notification output port with trace output port binds the trace output port and with interaction i o port binds the interaction 1 0 port set current input port input port procedure set current output port output port procedure set notification output port output port procedure set trace output port output port procedure set interaction i o port i o port procedure Each of these procedures alters the binding of one of the standard ports and returns an unspecified value The binding that is modified corresponds
249. eration error derived file error port error derived port error variable error unbound variable unassigned variable arithmetic error divide by zero floating point overflow floating point underflow control error no such restart not loading primitive procedure error system call error warning simple warning simple condition breakpoint condition type serious condition condition type This is an abstract type All serious conditions that require some form of intervention should inherit from this type In particular all errors inherit from this type condition type error condition type This is an abstract type All errors should inherit from this type condition type simple error message irritants condition type This is the condition generated by the error procedure when its first argument is not a condition or condition type The fields message and irritants are taken directly from the arguments to error message contains an object usually a string and irritants contains a list of objects The reporter for this type uses format error message to generate its output from message and irritants condition type illegal datum datum condition type This is an abstract type This type indicates the class of errors in which a program discovers an object that lacks specific required properties Most commonly the object Chapter 16 Error System 243 is of the wrong type or is outside a specific range The datum field contains the offending
250. ere outlined above make pathname f Hf absolute usr morris Foot scm 8f pathname 67 usr morris foo scm procedure pathname host pathname procedure pathname device pathname procedure pathname directory pathname procedure pathname name pathname procedure pathname type pathname procedure pathname version pathname procedure Returns a particular component of pathname 192 MIT Scheme Reference define x gt pathname usr morris foo scm pathname host x gt host 1 pathname device x gt unspecific pathname directory x absolute usr morris pathname name x gt foo pathname type x gt scm pathname version x unspecific pathname new device pathname device procedure pathname new directory pathname directory procedure pathname new name pathname name procedure pathname new type pathname type procedure pathname new version pathname version procedure Returns a new copy of pathname with the respective component replaced by the second argument Pathname is unchanged Portable programs should not explicitly replace a component with unspecific because this might not be permitted in some situations define p gt pathname usr blisp rel15 gt pathname 71 usr blisp rel15 pathname new name p rel100 gt ttlpathname 72 usr blisp rel100 pathname new directory p relative test morris pathname 73 test morris reli5 pathname 71
251. erical operations sees eese 46 numerical types 42i io dite ERA ER S TE Rees 43 O object hashing is iov Lir a ed 133 odd n mber 24de RII RIDERE 48 oldest as pathname component 191 one dimensional table defn 123 operand of procedure call defn 15 MIT Scheme Reference Operating System Interface ooooooooo o 187 operator of procedure call defn 15 option run time loadable 125 135 139 171 optional component in entries 5 optional parameter defn ssuusuue 17 order of argument evaluation 15 ordering of characters 004 65 ordering of n mb ers iio ot eee deeds V es AT ordering ofsbrIngs 2 o3 ee RD RR e 4 RC RIS T3 05 2 Braphi68 oce e e Re ee ana 266 OU CDUL iv eR eae RES eR C PIGunR wd des 159 output port operations ls eese eee 181 output port console ooooooo ooooo 161 output port current defn 159 output port file este occ b RR RIDERE mee 161 output port string Rb rrt 163 output procedures i620 sec eee ek Deere 168 P padding of string voe is T pait defn 2 recepere o died NI dad Diss 8T pair external representation 87 pair weak defn s cerriscipciscereepirioves 119 parameter list of lambda defn 17 parameter optional defn lusus 17 parameter
252. eries of expressions usually these expressions are evaluated sequentially un der conditions that are specified in the description of the special form This sequence of expressions is commonly referred to as the body of the special form 6 MIT Scheme Reference Procedure Template starts with the name of the variable to which the procedure is bound followed by a description of the procedure s arguments The arguments are described using lambda list notation see Section 2 1 Lambda Expressions page 17 except that brackets are used to denote optional arguments and ellipses are used to denote rest arguments The names of the procedure s arguments are italicized in the printed manual and uppercase in the Info file When an argument names a Scheme data type it indicates that the argument must be that type of data object For example cdr pair procedure indicates that the standard Scheme procedure cdr takes one argument which must be a pair Many procedures signal an error when an argument is of the wrong type usually this error is a condition of type condition type wrong type argument In addition to the standard data type names pair list boolean string etc the following names as arguments also imply type restrictions e object any object e thunk a procedure of no arguments e x y real numbers e q n integers e k an exact non negative integer Some examples list object procedure indicates th
253. erminal mode 184 port set input blocking mode 183 port set input terminal mode 184 port set output blocking mode 183 port set output terminal mode 184 port state erp Ebr RE E DEBERS 178 POPE TY Peis seis ceased omi eg Reto pcs 178 port with input blocking mode 183 port with input terminal mode 184 port with output blocking mode 183 port with output terminal mode 184 POE Le ira 159 positie evi oan ended oa 48 pp re 170 predicate cr Embed ERR 33 predicate char set lesse esses 70 primitive procedure name 149 Primitive procedure voice cesses bese koors 148 PPINt procedure 5 eid gies n P b Rep TER 33 Procedure Necro diicrgededbigedieress 148 procedure arity valid 148 procedure environment o o oo 148 procedure 2 I nace t RP eg dieses 147 process time clocK e I EE IRE ES 213 promise forced c p et nets 116 promis value 2v e b dos tes droir iare 116 promise e igo n p RP a dees 116 prompt for command char 175 prompt for command expression 175 prompt for confirmation 2 2 0c e 176 prompt for evaluated expression 176 prompt for expression s 176 A eGo G adh bk Me dates oad eee re babe Eur 197 QUASI QUOT Csi da ee bi 25 88 quick SOrt Jo edere O 99 qurckcsOrt iii kem
254. error can be expected to supply a retry restart The restart would be invoked after first creating the missing file since the computation is then likely to succeed if it is simply retried store value new value restarts procedure Retry the current computation using the restart named store value after first storing new value The corresponding effector takes one argument new value and stores it away in a restart dependent location then retries the same computation that triggered the condition The condition may reoccur of course if the root cause has not been eliminated The code that signals an unassigned variable error can be expected to supply a store value restart this would store the value in the variable and continue the computation use value new value restarts procedure Retry the current computation using the restart named use value but substituting new value for a value that previously caused a failure The corresponding effector takes one argument new value and retries the same computation that triggered the condition with the new value substituted for the failing value The condition may reoccur of course if the new value also induces the condition The code that signals an unassigned variable error can be expected to supply a use value restart this would simply continue the computation with new value instead of the value of the variable Contrast this with the retry and store value restarts If the retry r
255. ervieW uasa sese RR eR rt d d eie a aei Uc Re 219 18 2 Foreign Function Interface 0ooooooococoooccocooo 213 18 2 1 Windows Types consen 274 18 2 2 Windows Foreign Procedures 2f 18 2 3 Win32 API names and procedures 278 18 3 Device Independent Bitmap Utilities 279 18 3 1 DIB procedures sseesseee esie 280 18 3 2 Other parts of the DIB Utilities implementation p ios ds datada 282 GNU Free Documentation License 283 ADDENDUM How to use this License for your documents 288 Binding Index aso xx Rape ea us 289 Concept lideran 307
256. erwise the call waits until a client connects The argument peer address is either or an IP address as allocated by allocate host address If it is an IP address the address is modified to be the address of the client making the connection Note that closing the port returned by this procedure does not affect server socket it just closes the particular client connection that was opened by the call To close server socket use close tcp server socket close tcp server socket server socket procedure Closes the server socket server socket The operating system will cease listening for network connections to that service Client connections to server socket that have already been accepted will not be affected 15 9 Miscellaneous OS Facilities This section contains assorted operating system facilities that don t fit into other cate gories microcode id operating system variable microcode id operating system name variable microcode id operating system is bound to a symbol that specifies the type of operating system that Scheme is running under There are three possible values unix os 2 or nt microcode id operating system name is a string containing the same name as microcode id operating system the latter is created by interning the former as a symbol microcode id operating system variant variable This variable is a string that identifies the particular variant of the operating system that Scheme is running under Here
257. ery time the file is modified This component is currently unused for all file systems Note that a pathname is not necessarily the name of a specific file Rather it is a specification possibly only a partial specification of how to access a file A pathname need not correspond to any file that actually exists and more than one pathname can refer to the same file For example the pathname with a version of newest may refer to the same file as a pathname with the same components except a certain number as the version Indeed a pathname with version newest may refer to different files as time passes because the meaning of such a pathname depends on the state of the file system In file systems with 190 MIT Scheme Reference such facilities as links multiple file names logical devices and so on two pathnames that look quite different may turn out to address the same file To access a file given a pathname one must do a file system operation such as open input file Two important operations involving pathnames are parsing and merging Parsing is the conversion of a filename which might be something supplied interactively by the users when asked to supply the name of a file into a pathname object This operation is implementation dependent because the format of filenames is implementation dependent Merging takes a pathname with missing components and supplies values for those compo nents from a source of default values Not all o
258. es 160 with working directory pathname 197 withdraw window on x graphics device 261 within continuation s e e e nn 150 WO d 50e Gee e reds eda rtr dun bed aun eee 276 working directOry oigo da a oa A s 219 working directory pathname 197 o sace date epe teas 9 110 169 174 228 WIIte Cchaf ciosd6sbR eke ad bebe eI 6 159 168 write char on output port sss 181 write condition report 231 239 240 WIC OTOL momia EE nde re li ra ed 280 A y hb dese Reo es bb eee EEG 169 write restart repoft er Reps 237 VILO STO ici pedes 169 171 174 write substrinhg oei enteri treri id ene ts 169 write substring on output port 181 WIlte to SUtrIinEg e ni ind 165 WE tr ee AA venena 141 WE tree add na cris rr 141 Wh tree delete conosco dirt 142 wt tree delete 0 cece 142 wt tree delete min ss lesse 145 wt tree delete min eessssss 146 wt tree difference ss esses 143 wt tree empty 2 22 c 32 EIER RE 141 wt tree fold imbre deal ida 143 wt tree for each eee eee eee 144 Wwt tres imdeXx iia add aa 145 wt tree index datum esses 145 wt tree index pair 0000 145 wt tree intersection lesse sss 142 wt tree loOk p e orkdeewe eetexR PER 141 wt tree member lesse eee 141 WE tree MiN cir 145 wWt tree min datuUM oo oooooccooocc oo 145 Wt tree m
259. ese char acters as a newly allocated string while discard chars discards them and returns an unspecified value These operations hang until sufficient input is available even if input port is in non blocking mode If end of file is encountered before any input characters read string returns an end of file object 180 MIT Scheme Reference read substring input port string start end operation on input port Reads characters from input port into the substring defined by string start and end until either the substring has been filled or there are no more characters available Returns the number of characters written to the substring If input port is an interactive port and at least one character is immediately avail able the available characters are written to the substring and this operation returns immediately If no characters are available and input port is in blocking mode the operation blocks until at least one character is available Otherwise the operation returns f immediately This is an extremely fast way to read characters from a port input port read char input port procedure input port peek char input port procedure input port discard char input port procedure input port char ready input port k procedure input port read string input port char set procedure input port discard chars input port char set procedure input port read substring input port string start end procedure Each of these procedures invokes the r
260. espective operation on input port For example the following are equivalent input port read char input port input port operation input port read char input port The following custom operations are implemented for input ports to files and will also work with some other kinds of input ports eof input port operation on input port Returns stt if input port is known to be at end of file otherwise it returns f chars remaining input port operation on input port Returns an estimate of the number of characters remaining to be read from input port This is useful only when input port is a file port in binary mode in other cases it returns f buffered input chars input port operation on input port Returns the number of unread characters that are stored in input port s buffer This will always be less than or equal to the buffer s size input buffer size input port operation on input port Returns the maximum number of characters that input port s buffer can hold set input buffer size input port size operation on input port Resizes input port s buffer so that it can hold at most size characters Characters in the buffer are discarded Size must be an exact non negative integer Chapter 14 Input Output 181 14 9 4 Output Port Operations This section describes the standard operations on output ports Following that some useful custom operations are described write char output port char operation on output port Writes char
261. ess argument than its procedure make apply hook procedure object procedure Returns a newly allocated apply hook with a procedure component of procedure and an extra component of object apply hook object procedure Returns t if object is an apply hook otherwise returns amp tf apply hook procedure apply hook procedure Returns the procedure component of apply hook set apply hook procedure apply hook procedure procedure Changes the procedure component of apply hook to be procedure Returns an un specified value apply hook extra apply hook procedure Returns the extra component of apply hook set apply hook extra apply hook object procedure Changes the extra component of apply hook to be object Returns an unspecified value make entity procedure object procedure Returns a newly allocated entity with a procedure component of procedure and an extra component of object Chapter 12 Procedures 153 entity object procedure Returns t if object is an entity otherwise returns f entity procedure entity procedure Returns the procedure component of entity set entity procedure entity procedure procedure Changes the procedure component of entity to be procedure Returns an unspecified value entity extra entity procedure Returns the extra component of entity set entity extra entity object procedure Changes the extra component of entity to be object Returns an unspecified value 154 MIT Scheme Reference
262. ess than the length of the vector Vectors are written using the notation object For example a vector of length 3 containing the number zero in element 0 the list 2 2 2 2 in element 1 and the string Anna in element 2 can be written as 0 2 2 2 2 Anna Note that this is the external representation of a vector not an expression evaluating to a vector Like list constants vector constants must be quoted 0 2 2 2 2 Anna gt 0 2 2 2 2 Anna A number of the vector procedures operate on subvectors A subvector is a segment of a vector that is specified by two exact non negative integers start and end Start is the index of the first element that is included in the subvector and end is one greater than the index of the last element that is included in the subvector Thus if start and end are the same they refer to a null subvector and if start is zero and end is the length of the vector they refer to the entire vector The valid indexes of a subvector are the exact integers between start inclusive and end exclusive 8 1 Construction of Vectors make vector k object procedure Returns a newly allocated vector of k elements If object is specified make vector initializes each element of the vector to object Otherwise the initial elements of the result are unspecified vector object procedure Returns a newly allocated vector whose elements are the given arguments vector is analogous to list vecto
263. ession init Some examples let x 2 y 3 x y gt 6 let x 2 y 3 let foo lambda z x y z x 7 foo 4 gt 9 See Section 2 9 Iteration page 29 for information on named let let variable init expression expression special form let is similar to let but the bindings are performed sequentially from left to right and the region of a binding is that part of the let expression to the right of the binding Thus the second binding is done in an environment in which the first binding is visible and so on Note that the following are equivalent 20 MIT Scheme Reference let variablel initl variable2 init2 variableN initN expression expression let Cvariablel initl let Cvariable2 init2 let CvariableN initN expression expression 433 An example let x 2 y 3 let x 7 z x y z x gt 70 letrec variable init expression expression special form The variables are bound to fresh locations holding unassigned values the inits are evaluated in the extended environment in some unspecified order each variable is assigned to the result of the corresponding init the expressions are evaluated sequen tially in the extended environment and the value of the last expression is returned Each binding of a variable has the entire letrec expression as its region making it possible to define mutually recursive
264. ession does the following 1 Evaluates key and compares the result with each object 2 If the result of evaluating key is equivalent in the sense of eqv see Chapter 3 Equivalence Predicates page 37 to an object case evaluates the expressions 28 MIT Scheme Reference in the corresponding clause from left to right and returns the result of evaluating the last expression in the clause as the result of the case expression 3 If the result of evaluating key is different from every object and if there s an else clause case evaluates its expressions and returns the result of the last one as the result of the case expression If there s no else clause case returns an unspecified result Programs should not depend on the value of a case expression that has no else clause For example case 2 3 2 3 5 7 prime 14 6 8 9 composite gt composite case car c d Ga a b b gt unspecified case car c d a e i o ou vowel w y semivowel else consonant gt consonant and expression special form The expressions are evaluated from left to right and the value of the first expression that evaluates to a false value is returned Any remaining expressions are not evalu ated If all the expressions evaluate to true values the value of the last expression is returned If there are no expressions then t is returned and 2 2 gt 2 1 gt dit and 2 2 lt 2 19 gt
265. estart is used it will fail because the variable still has no value The store value restart could be used but it would alter the value of the variable so that future references to the variable would not be detected 16 4 3 Finding and Invoking General Restart Code Restarts are a general mechanism for establishing a protocol between condition signalling and condition handling code The Scheme error system provides packaging for a number of common protocols It also provides lower level hooks that are intended for implementing customized protocols The mechanism used by signalling code with restart and with simple restart is used for both purposes Four additional operations are provided for the use of condition handling code T wo operations bound restarts and find restart allow condition handling code to lo cate active restarts The other two operations invoke restart and invoke restart interactively allow restart effectors to be invoked once the restart object has been located In addition there is a data abstraction that provides access to the information encapsu lated in restart objects 236 MIT Scheme Reference bound restarts procedure Returns a list of all currently active restart objects most recently installed first bound restarts should be used with caution by condition handling code since it reveals all restarts that are active at the time it is called rather than at the time the condition was signalled It is
266. f the components of a pathname need to be specified If a component of a pathname is missing its value is f Before the file system interface can do anything interesting with a file such as opening the file all the missing components of a pathname must be filled in Pathnames with missing components are used internally for various purposes in particular parsing a namestring that does not specify certain components will result in a pathname with missing components Any component of a pathname may be the symbol unspecific meaning that the com ponent simply does not exist for file systems in which such a value makes no sense For example unix Windows and OS 2 file systems usually do not support version numbers so the version component for such a host might be unspecific In addition to f and unspecific the components of a pathname may take on the following meaningful values host An implementation defined type which may be tested for using the host pred icate device On systems that support this component Windows and OS 2 it may be specified as a string containing a single alphabetic character for which the alphabetic case is ignored directory A non empty list which represents a directory path a sequence of directories each of which has a name in the previous directory the last of which is the directory specified by the entire path Each element in such a path specifies the name of the directory relative to the directory s
267. fications Chapter 11 Associations 139 e An element in a tree may be indexed by its position under the ordering of the keys and the ordinal position of an element may be determined both with reasonable efficiency e Operations to find and remove minimum element make weight balanced trees simple to use for priority queues e The implementation is functional rather than imperative This means that operations like inserting an association in a tree do not destroy the old tree in much the same way that 1 x modifies neither the constant 1 nor the value bound to x The trees are referentially transparent thus the programmer need not worry about copying the trees Referential transparency allows space efficiency to be achieved by sharing subtrees These features make weight balanced trees suitable for a wide range of applications especially those that require large numbers of sets or discrete maps Applications that have a few global databases and or concentrate on element level operations like insertion and lookup are probably better off using hash tables or red black trees The size of a tree is the number of associations that it contains Weight balanced binary trees are balanced to keep the sizes of the subtrees of each node within a constant factor of each other This ensures logarithmic times for single path operations like lookup and insertion A weight balanced tree takes space that is proportional to the number of associations
268. following character names are supported shown here with their ASCII equivalents Some of the details in this section depend on the fact that the underlying operating system uses the ASCII character set This may change when someone ports MIT Scheme to non ASCII operating system 64 Character Name altmode backnext backspace call linefeed page return rubout space tab ASCII Name ESC US BS SUB LF FF CR DEL HT MIT Scheme Reference In addition newline is the same as linefeed but this may change in the future so you should not depend on it All of the standard ASCII names for non printing characters are supported NUL BS DLE CAN DEL SOH STX HT LF DC1 DC2 EM SUB char gt name char slashify Returns a string corresponding to the printed representation of char ETX EOT VT FF DC3 DC4 ESC FS ENQ CR NAK GS ACK BEL SO SI SYN ETB RS US procedure This is the character or character name component of the external representation combined with the appropriate bucky bit prefixes char gt name char gt name char gt name char gt name Ha iH space c a control a todd tan Space C a C a Slashify if specified and true says to insert the necessary backslash characters in the result so that read will parse it correctly In other words the following generates the external representation of char If slashify is not specified
269. for each hash table procedure procedure Procedure must be a procedure of two arguments Invokes procedure once for each association in hash table passing the association s key and datum as arguments in that order Returns an unspecified result Procedure must not modify hash table with one exception it is permitted to call hash table remove to remove the association being processed The following procedure is an alternate form of hash table get that is useful in some situations Usually hash table get is preferable because it is faster hash table lookup hash table key if found if not found procedure If found must be a procedure of one argument and if not found must be a procedure of no arguments If hash table contains an association for key if found is invoked on the datum of the association Otherwise if not found is invoked with no arguments In either case the result yielded by the invoked procedure is returned as the result of hash table lookup hash table lookup reduces into the invoked procedure i e calls it tail recursively The average time required by this operation is bounded by a constant Chapter 11 Associations 129 11 4 3 Resizing of Hash Tables Normally hash tables automatically resize themselves according to need Because of this the programmer need not be concerned with management of the table s size However some limited control over the table s size is provided which will be discussed below This discuss
270. force p P count force p count Here is a possible implementation of delay and force delay expression to have the same meaning as the procedure call make promise lambda expression where make promise is defined as follows define make promise lambda proc let already run ttf result f lambda cond not already run set result proc set already run t result V V V VV 117 0 tt promise 54 15 tt promise 54 1 15 1 We define the expression Promises are implemented here as procedures of no arguments and force simply calls its argument define force lambda promise promise Various extensions to this semantics of delay and force are supported in some imple mentations none of these are currently supported in MIT Scheme e Calling force on an object that is not a promise may simply return the object e It may be the case that there is no means by which a promise can be operationally distinguished from its forced value That is expressions like the following may evaluate to either t or f depending on the implementation eqv delay 1 1 unspecified pair delay cons 1 2 unspecified e Some implementations will implement implicit forcing where the value of a promise is forced by primitive procedures like car and delay 3 7 13 gt 34 118 MIT Scheme Reference 10 6 Streams In addition to promises MIT Scheme support
271. g length string k procedure Alters the length of string to be k and returns an unspecified value K must be less than or equal to the maximum length of string set string length does not change the maximum length of string 6 11 Byte Vectors MIT Scheme implements strings as packed vectors of 8 bit ASC bytes Most of the string operations such as string ref coerce these 8 bit codes into character objects However some lower level operations are made available for use vector 8b ref string k procedure Returns character k of string as an ASCII code K must be a valid index of string vector 8b ref abcde 2 gt 99 ascii for c vector 8b set string k ascii procedure Stores ascii in element k of string and returns an unspecified value K must be a valid index of string and ascii must be a valid ASCII code Chapter 6 Strings 85 vector 8b fill string start end ascii procedure Stores ascii in elements start inclusive to end exclusive of string and returns an unspecified value Ascii must be a valid ASCII code vector 8b find next char string start end ascii procedure vector 8b find next char ci string start end ascii procedure Returns the index of the first occurrence of ascii in the given substring returns f if ascii does not appear The index returned is relative to the entire string not just the substring Ascii must be a valid ASCII code vector 8b find next char ci doesn t distinguish uppercase and lowercas
272. gate Otherwise they must appear on covers around the whole aggregate 8 TRANSLATION Iranslation is considered a kind of modification so you may distribute translations of the Document under the terms of section 4 Replacing Invariant Sections with translations requires special permission from their copyright holders but you may 288 MIT Scheme Reference include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections You may include a translation of this License provided that you also include the original English version of this License In case of a disagreement between the translation and the original English version of this License the original English version will prevail 9 TERMINATION You may not copy modify sublicense or distribute the Document except as expressly provided for under this License Any other attempt to copy modify sublicense or distribute the Document is void and will automatically terminate your rights under this License However parties who have received copies or rights from you under this License will not have their licenses terminated so long as such parties remain in full compliance 10 FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new revised versions of the GNU Free Documentation License from time to time Such new versions will be similar in spirit to the present version but may differ in detail to address ne
273. ge width image procedure Returns the width of the image in device coordinates image fill from byte vector image bytes procedure The contents of image are set in a device dependent way using one byte per pixel from bytes a string Pixels are filled row by row from the top of the image to the bottom with each row being filled from left to right There must be at least image height image image width image bytes in bytes 17 9 X Graphics MIT Scheme supports graphics in the X window system version 11 Arbitrary numbers of displays may be opened and arbitrary numbers of graphics windows may be created for each display A variety of operations is available to manipulate various aspects of the windows to control their size position colors and mapping The X graphics device type supports images which are implemented as Xlib XImage objects X display window and image objects are automatically closed if they are reclaimed by the garbage collector 17 9 1 X Graphics Type A graphics device for X windows is created by passing the symbol x as the graphics device type name to make graphics device Chapter 17 Graphics 259 make graphics device x optional display geometry suppress map where display is either a display object or a string geometry is either f or a string and suppress map is a boolean or a vector see below A new window is created on the appropriate display and a graphics device representing that wind
274. gs ssseseseseeleee eee eee 82 6 10 Variable Length Strings 00 0 00 cece eee eee 84 0 11 Byte VectO S cu sts od soe dada Ree eek ae ox ete 84 T LISUS 65 65 54 9 885595054 65545556856 XY 87 Tal PITS carpa hate eae Gee see eR e aaa eat 88 7 2 Construction of Lists cies due taba eser seen ghee es 90 7 3 Selecting List Components 0 000 eee eee eee 91 7 4 Cutting and Pasting Lists 0 00 c eee ee eee 93 To Filtering Lists rada dad bbw ed bed ete nae ee Pe a 94 1 6 Searching Dist aa a Pea a O a t e Rn bas 95 7 7 Mapping of Lists 0 0 eee eee eee 96 7 8 Reduction of Lists 3 as4 024 eeu hed er rae aaa 97 7 9 Miscellaneous List Operations 000 eee eee 99 B VeClOre der o ductum NS wetessonuecaceuns 101 8 1 Construction of Vectors ssssseessseeelse esee 101 8 2 Selecting Vector Components suseslssssssesn 102 8 Cutting VecholS veranda sc dpt ebbe ER RR RS 103 8 4 Modifying Vectors 0 00 cee ee seh 104 9 Bit SWines cs adan ori 105 9 1 Construction of Bit Strings 0 00 22 eee 105 9 2 Selecting Bit String Components 2 04 106 9 3 Cutting and Pasting Bit Strings 106 9 4 Bitwise Operations on Bit Strings 107 9 5 Modification of Bit Strings 00 0 0 eee 108 9 6 Integer Conversions of Bit Strings 108 10 Miscellaneous Dataty
275. han error As with error warn first calls signal condition the condition that is signalled is chosen exactly as in error except that a condition of type condition type simple warning is signalled if reason is neither a condition nor a condition type If the condition is not handled warn calls the procedure standard warning handler which normally prints a warning message and continues the computation by returning from warn warn establishes a restart named muffle warning before calling signal condition This allows a signal handler to prevent the generation of the warning message by calling muffle warning The value of a call to warn is unspecified signal condition condition procedure This is the fundamental operation for signalling a condition The precise operation of signal condition depends on the condition type of which condition is an instance the condition types set by break on signals and the handlers established by bind condition handler and bind default condition handler 228 MIT Scheme Reference If the condition is an instance of a type that is a specialization of any of the types specified by break on signals then a breakpoint REPL is initiated Otherwise or when that REPL returns the handlers established by bind condition handler are checked most recent first Each applicable handler is invoked and the search for a handler continues if the handler returns normally If all applicable handlers return then the applicable h
276. hat the file does not exist in which case the program will try some other action perhaps opening a different file instead Another related condition is that the file exists but is read protected so it cannot be opened for input If these or any other related conditions occur the program would like to skip this operation and move on to something else At the same time errors unrelated to the file system should be treated in their usual way For example calling car on the argument 3 should signal an error Or perhaps the name given for the file is syntactically incorrect a condition that probably wants to be handled differently from the case of the file not existing To facilitate the handling of classes of conditions the error system taxonomically orga nizes all condition types The types are related to one another by taxonomical links which 226 MIT Scheme Reference specify that one type is a kind of another type If two types are linked this way one is considered to be a specialization of the other or vice versa the second is a generalization of the first In our example all of the errors associated with opening an input file would be specializations of the condition type cannot open input file The taxonomy of condition types permits any condition type to have no more than one immediate generalization Thus the condition types form a forest set of trees While users can create new trees the standard taxonomy see Sec
277. he average and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree 142 MIT Scheme Reference wt tree delete wt tree key procedure Returns a new tree containing all the associations in wt tree except that if wt tree contains an association for key it is removed from the result The average and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree wt tree delete wt tree key procedure If wt tree contains an association for key the association is removed Returns an unspecified value The average and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree 11 7 3 Advanced Operations on Weight Balanced Trees In the following the size of a tree is the number of associations that the tree contains and a smaller tree contains fewer associations wt tree split wt tree bound procedure Returns a new tree containing all and only the associations in wt tree that have a key that is less than bound in the ordering relation of the tree type of wt tree The average and worst case times required by this operation are proportional to the logarithm of the size of wt tree wt tree split gt wt tree bound procedure Returns a new tree containing all and only the associations in wt tree that have a key that is greater than bound in the ordering relation of the
278. he environment the environment special form Returns the current environment interpreter environment object procedure Returns t if object is an interpreter environment otherwise returns f 158 MIT Scheme Reference Chapter 14 Input Output 159 14 Input Output This chapter describes the procedures that are used for input and output 1 0 The chapter first describes ports and how they are manipulated then describes the 1 0 opera tions Finally some low level procedures are described that permit the implementation of custom ports and high performance 1 0 14 1 Ports Scheme uses ports for 1 0 A port which can be treated like any other Scheme object serves as a source or sink for data A port must be open before it can be read from or written to The standard 1 0 port console i o port is opened automatically when you start Scheme When you use a file for input or output you need to explicitly open and close a port to the file with procedures described in this chapter Additional procedures let you open ports to strings Many input procedures such as read char and read read data from the current input port by default or from a port that you specify The current input port is initially console i o port but Scheme provides procedures that let you change the current input port to be a file or string Similarly many output procedures such as write char and display write data to the current output port by default or t
279. he largest fixnum let loop n 1 if fix fixnum n loop n 2 n 1 A similar expression determines the smallest fixnum fix fixnum fixnum fix fixnum fixnum fix gt fixnum fixnum fix fixnum fixnum fix fixnum fixnum procedure procedure procedure procedure procedure procedure These are the standard order and equality predicates on fixnums When compiled they do not check the types of their arguments fix zero fixnum fix positive fixnum fix negative fixnum These procedures compare their argument to zero procedure procedure procedure When compiled they do not check the type of their argument The code produced by the following expressions is identical fix zero fixnum fix fixnum 0 Similarly fix positive and fix negative produce code identical to equivalent expressions using fix gt and fix lt fix fixnum fixnum fix fixnum fixnum fix fixnum fixnum fix quotient fixnum fixnum fix remainder fixnum fixnum fix gcd fixnum fixnum fix 1 fixnum fix 1 fixnum procedure procedure procedure procedure procedure procedure procedure procedure These procedures are the standard arithmetic operations on fixnums When compiled they do not check the types of their arguments Furthermore they do not check to see if the result can be encoded as a fixnum If the result is too large to be encoded as a fixnum a malformed object is retu
280. he latter fashion are referred to as synchronous because they are started and stopped in synchrony with a Scheme procedure call This chapter documents Scheme s high level synchronous subprocess support The low level support is not documented but is available for those who are willing to read the source code Synchronous subprocess support is a run time loadable option To use it execute load option synchronous subprocess once before calling it 15 7 1 Subprocess Procedures There are two commands for running synchronous subprocesses under Scheme run shell command is very simple to use provides access to all shell features and is to be preferred in most situations run synchronous subprocess allows direct execution of a program and precise control of the command line arguments passed to the program but does not provide file globbing I O redirection or other shell features run shell command command option procedure Runs command which must be a string Command is passed to a command shell for interpretation how the shell is chosen is detailed below The options are a sequence of keyword value pairs that specify optional behavior See below for more information about options run shell command waits until the subprocess completes its execution and returns the exit code from the subprocess If the subprocess is killed or stopped an error is signalled and the procedure does not return run synchronous subprocess
281. he mapping of windows They correspond directly to Xlib s XMapWindow and XWithdrawWindow 262 MIT Scheme Reference resize window width height operation on x graphics device Changes the size of a window Width and height must be exact non negative integers The operation corresponds directly to Xlib s XResizeWindow This operation resets the virtual coordinate system and the clip rectangle move window x y operation on x graphics device Changes the position of a window on the display X and y must be exact integers The operation corresponds directly to Xlib s XMoveWindow Note that the coordinates x and y do not take the external border into account and therefore will not position the window as you might like The only reliable way to position a window is to ask a window manager to do it for you get default resource property operation on x graphics device This operation corresponds directly to Xlib s XGetDefault Resource and property must be strings The operation returns the character string corresponding to the association of resource and property if no such association exists f is returned copy area source x left source y top width height operation on x graphics device destination x left destination y top This operation copies the contents of the rectangle specified by source x left source y top width and height to the rectangle of the same dimensions at destination x left and destination y top font structure font name o
282. he procedure list deletor for non destructive deletions or the procedure list deletor for destructive deletions For example here is a possible implementation of del assv define del assv delete association procedure list deletor eqv car alist copy alist procedure Returns a newly allocated copy of alist This is similar to list copy except that the association pairs ie the elements of the list alist are also copied alist copy could have been implemented like this define alist copy alist if null alist O cons cons car car alist cdr car alist alist copy cdr alist 11 2 1D Tables 1D tables one dimensional tables are similar to association lists In a 1D table unlike an association list the keys of the table are held weakly if a key is garbage collected its associated value in the table is removed 1D tables compare their keys for equality using eq 124 MIT Scheme Reference 1D tables can often be used as a higher performance alternative to the two dimensional association table see Section 11 3 The Association Table page 124 If one of the keys being associated is a compound object such as a vector a 1D table can be stored in one of the vector s slots Under these circumstances accessing items in a 1D table will be comparable in performance to using a property list in a conventional Lisp make 1d table procedure Returns a newly allocated empty 1D table 1d table object pr
283. hese two invocations of dynamic wind are both to be called then the after associated with the second inner call to dynamic wind is called first If a second call to dynamic wind occurs within the dynamic extent of the call to thunk and then a continuation is invoked in such a way that the befores from these two invocations of dynamic wind are both to be called then the before associated with the first outer call to dynamic wind is called first If invoking a continuation requires calling the before from one call to dynamic wind and the after from another then the after is called first The effect of using a captured continuation to enter or exit the dynamic extent of a call to before or after is undefined let path c let add lambda s set path cons s path dynamic wind lambda add connect lambda add call with current continuation lambda cO set c cO talki lambda add disconnect if length path 4 c talk2 reverse path gt connect talk1 disconnect connect talk2 disconnect The following two procedures support multiple values call with values thunk procedure procedure Thunk must be a procedure of no arguments and procedure must be a procedure Thunk is invoked with a continuation that expects to receive multiple values specif ically the continuation expects to receive the same number of values that procedure accepts as arguments Thunk must ret
284. hey are now in use before the variable or object is made to denote them In many systems it is desirable for constants i e the values of literal expressions to reside in read only memory To express this it is convenient to imagine that every object that denotes locations is associated with a flag telling whether that object is mutable or immutable The constants and the strings returned by symbol gt string are then the im mutable objects while all objects created by other procedures are mutable It is an error to attempt to store a new value into a location that is denoted by an immutable object Note that the MIT Scheme compiler takes advantage of this property to share constants but that these constants are not immutable Instead two constants that are equal may be eq in compiled code 1 3 Lexical Conventions This section describes Scheme s lexical conventions 1 3 1 Whitespace Whitespace characters are spaces newlines tabs and page breaks Whitespace is used to improve the readability of your programs and to separate tokens from each other when necessary A token is an indivisible lexical unit such as an identifier or number White space is otherwise insignificant Whitespace may occur between any two tokens but not within a token Whitespace may also occur inside a string where it is significant 1 3 2 Delimiters All whitespace characters are delimiters In addition the following characters act as delimiters Chap
285. hics window i e excluding the frame Palette determines the colors available for drawing in the window When a color is specified for drawing the nearest color available in the palette is used Permitted values for palette are grayscale The window allocates colors from a grayscale palette of approximately 236 shades of gray gt grayscale 128 The window allocates colors from a grayscale palette of 128 shades of gray standard The standard palette has good selection of colors and grays 264 MIT Scheme Reference f or system The colors available are those in the system palette There are usually 16 to 20 colors in the system palette and these are usually sufficent for simple applications like line drawings and x vs y graphs of mathematical functions Drawing with the system palette can be more efficient If palette is not specified then the standard palette is used 17 10 2 Custom Operations for Win32 Graphics Custom operations are invoked using the procedure graphics operation For example graphics operation device set foreground color blue set background color color name operation on win32 graphics device set foreground color color name operation on win32 graphics device These operations change the colors associated with a window Color name must be of one of the valid color specification forms listed below set background color and set foreground color change the colors to be used when drawing but have no
286. hics device whose name is the symbol name passing it the remaining arguments This procedure can be used to invoke the stan dard operations as well as custom operations that are specific to a particular graphics device type The names of the standard graphics operations are formed by removing the graphics prefix from the corresponding procedure For example the following are equivalent graphics draw point device x y graphics operation device draw point x y For information on the custom operations for a particular device see the documen tation for its type 17 8 Images Some graphics device types support images which are rectangular pieces of picture that may be drawn into a graphics device Images are often called something else in the host graphics system such as bitmaps or pixmaps The operations supported vary between devices so look under the different device types to see what operations are available AII devices that support images support the following operations create image width height operation on graphics device Images are created using the create image graphics operation specifying the width and height of the image in device coordinates pixels graphics operation device create image 200 100 The initial contents of an image are unspecified create image is a graphics operation rather than a procedure because the kind of image returned depends on the kind of graphics device used and the options specified in
287. icates the character s position in the string The index of the first leftmost character in a string is 0 and the index of the last character is one less than the length of the string The valid indexes of a string are the exact non negative integers less than the length of the string A number of the string procedures operate on substrings A substring is a segment of a string which is specified by two integers start and end satisfying these relationships O lt start lt end lt string length string Start is the index of the first character in the substring and end is one greater than the index of the last character in the substring Thus if start and end are equal they refer to an empty substring and if start is zero and end is the length of string they refer to all of string Some of the procedures that operate on strings ignore the difference between uppercase and lowercase The versions that ignore case include ci for case insensitive in their names 72 MIT Scheme Reference 6 1 Construction of Strings make string k char procedure Returns a newly allocated string of length k If you specify char all elements of the string are initialized to char otherwise the contents of the string are unspecified Char must satisfy the predicate char ascii make string 10 x gt XXXXXXXXXxx string char procedure Returns a newly allocated string consisting of the specified characters The arguments mus
288. ich variable is bound If expression is omitted variable is altered to be unassigned a subsequent reference to such a variable is an error In either case the value of the set expression is unspecified Variable must be bound either in some region enclosing the set expression or at the top level However variable is permitted to be unassigned when the set form is entered define x 2 gt unspecified x 1 8 set x 4 unspecified x 1 gt 5 Variable may be an access expression see Chapter 13 Environments page 155 This allows you to assign variables in an arbitrary environment For example define x let y 0 the environment define y a y gt a access y x gt 0 set access y x 1 gt unspecified y gt a access y x gt 1 2 6 Quoting This section describes the expressions that are used to modify or prevent the evaluation of objects quote datum special form quote datum evaluates to datum Datum may be any external representation of a Scheme object see Section 1 2 6 External Representations page 9 Use quote to include literal constants in Scheme code quote a a quote a b c gt a b c quote 1 2 gt 1 2 quote datum may be abbreviated as datum The two notations are equivalent in all respects Chapter 2 Special Forms la a b c oe 1 2 gt quote a a V V V 25 a a b c 1 2 quote a quote a Numeric con
289. ics device window s frame 268 MIT Scheme Reference set window position x y operation on os2 graphics device The graphics device window is moved to the screen position specified by x and y The coordinates x and y are in units of pels pixels and measure the distance between the lower left hand corner of the desktop and the lower left hand corner of the graphics device window s frame window size operation on os2 graphics device This operation returns the size of the client area of the graphics device window The client area is the part of the window that you draw on it does not include the window frame title bar etc The size is returned as two values see Section 12 3 Continuations page 149 which are the width and height of the client area in units of pels pixels set window size width height operation on os2 graphics device This operation sets the size of the client area of the graphics device window to the specified width and height which are in units of pels pixels The client area is the part of the window that you draw on it does not include the window frame title bar etc window frame size operation on os2 graphics device This operation returns the size of the graphics device window s frame This includes the client area as well as the border title bar etc The size is returned as two values see Section 12 3 Continuations page 149 which are the width and height of the frame in units of pels pixels Th
290. ih pait i yi iva de de baw es 145 we tree tank its 145 wt tree set equal seesssss 143 wb tree sTZze l ilisexedu dcs ede ROPA 141 305 wt tree split 2 nc drm pere 142 Wwb tree split i on2lses ne ee a wei 142 wt tree subset sse timit 143 wt tree uni nz cues RE Rene ad me 142 wt tree union merge lesse sss 144 Wt tree l2 o g e es eREMREEPUPUAPRPEYS 141 X x character bounds ascent 263 x character bounds descent 263 x character bounds lbearing 263 x character bounds rbearing 263 x character bounds width 263 x close all displayS codi dai 260 x font structure all chars exist 262 x font structure character bounds 262 x font structure default char 262 x font structure direction 262 x font structure max ascent 262 x font structure max bounds 262 x font structure max descent 262 x font structure min bounds 262 x font structure name s 262 x font structure start index 262 x geometry string ii sees pov e REIN 260 x graphics close display 259 x graphics open display 259 x open display mein iones c bees esate 259 x size on output port e Rn nn 182 Y y S3Z6 sa a a ee 177 y size on output port n ee em 182 306 MIT Scheme Reference Co
291. in This procedure is equivalent to lambda wt tree 1 wt tree 2 and wt tree subset wt tree 1 wt tree 2 wt tree subset wt tree 2 wt tree 1 In the worst case the time required by this operation is proportional to the size of the smaller tree wt tree fold combiner initial wt tree procedure This procedure reduces wt tree by combining all the associations using an reverse in order traversal so the associations are visited in reverse order Combiner is a proce dure of three arguments a key a datum and the accumulated result so far Provided combiner takes time bounded by a constant wt tree fold takes time proportional to the size of wt tree A sorted association list can be derived simply wt tree fold lambda key datum list cons cons key datum list 20 wt tree The data in the associations can be summed like this wt tree fold lambda key datum sum sum datum 0 wt tree 144 MIT Scheme Reference wt tree for each action wt tree procedure This procedure traverses wt tree in order applying action to each association The associations are processed in increasing order of their keys Action is a procedure of two arguments that takes the key and datum respectively of the association Provided action takes time bounded by a constant wt tree for each takes time proportional to the size of wt tree The example prints the tree wt tree for each lambda key value display list key value wt tree wt tree un
292. in the tree For the current implementation the constant of proportionality is six words per association Weight balanced trees can be used as an implementation for either discrete sets or dis crete maps associations Sets are implemented by ignoring the datum that is associated with the key Under this scheme if an association exists in the tree this indicates that the key of the association is a member of the set Typically a value such as t or f is associated with the key Many operations can be viewed as computing a result that depending on whether the tree arguments are thought of as sets or maps is known by two different names An example is wt tree member which when regarding the tree argument as a set computes the set membership operation but when regarding the tree as a discrete map wt tree member is the predicate testing if the map is defined at an element in its domain Most names in this package have been chosen based on interpreting the trees as sets hence the name wt tree member rather than wt tree defined at The weight balanced tree implementation is a run time loadable option To use weight balanced trees execute load option wt tree once before calling any of the procedures defined here 11 7 1 Construction of Weight Balanced Trees Binary trees require there to be a total order on the keys used to arrange the elements in the tree Weight balanced trees are organized by types where the type is an o
293. inexact A number is exact if it was written as an exact constant or was derived from exact numbers using only exact operations number is inexact if it was written as an inexact constant if it was derived using inexact ingredients or if it was derived using inexact operations Thus inexactness is a contagious property of a number If two implementations produce exact results for a computation that did not involve in exact intermediate results the two ultimate results will be mathematically equivalent This is generally not true of computations involving inexact numbers since approximate methods such as floating point arithmetic may be used but it is the duty of each implementation to make the result as close as practical to the mathematically ideal result Rational operations such as should always produce exact results when given exact arguments If the operation is unable to produce an exact result then it may either report the violation of an implementation restriction or it may silently coerce its result to an inexact value See Section 4 3 Implementation restrictions page 44 With the exception of inexact gt exact the operations described in this section must generally return inexact results when given any inexact arguments An operation may however return an exact result if it can prove that the value of the result is unaffected by the inexactness of its arguments For example multiplication of any number by an exact zero may p
294. ing file time procedure file time gt global time string file time procedure Converts an argument in file time format to a time string The result is in the local time zone or UTC respectively file time gt local time string file modification time Fri 23 Apr 1999 17 31 47 0400 file time gt global time string file modification time gt Fri 23 Apr 1999 21 31 47 0000 string gt universal time time string procedure Converts a time string argument to universal time format string gt universal time Fri 23 Apr 1999 21 31 47 0000 3133888307 string gt universal time Fri 23 Apr 1999 17 31 47 0400 3133888307 string gt decoded time time string procedure Converts a time string argument to decoded time format 212 MIT Scheme Reference pp string gt decoded time Fri 23 Apr 1999 17 31 47 0400 decoded time 30 second 47 minute 31 hour 17 4 day 23 month 4 4 year 1999 day of week 4 daylight savings time 0 zone 4 string gt file time time string procedure Converts a time string argument to file time format string gt file time Fri 23 Apr 1999 17 31 47 0400 gt 924899507 15 5 5 External Representation of Time The normal external representation for time is the time string as described above The procedures in this section generate alternate external representations of time which are more verbose and may be more suitabl
295. ing start end procedure string upcase returns a newly allocated copy of string in which all lowercase letters are changed to uppercase string upcase is the destructive version of string upcase it alters string and returns an unspecified value substring upcase de structively changes the case of the specified part of string 6 5 Cutting and Pasting Strings string append string procedure Returns a newly allocated string made from the concatenation of the given strings With no arguments string append returns the empty string string append Exo mH string append x ace nen xacex string append nu nn n gt nn eq str string append str gt f newly allocated substring string start end procedure Returns a newly allocated string formed from the characters of string beginning with index start inclusive and ending with end exclusive substring 0 0 zo un substring arduous 2 5 duo substring arduous 2 8 error 8 not in correct range define string copy s substring s 0 string length s string head string end procedure Returns a newly allocated copy of the initial substring of string up to but excluding end It could have been defined by define string head string end substring string O end string tail string start procedure Returns a newly allocated copy of the final substring of string starting at index start and going to the end of string It could
296. inition is evaluated to specify the unparser method and again whenever a predicate or constructor is called Because of this expression is normally a variable reference or a constant The value yielded by expression may be any object at all That object is stored in the structure instances in the same place that the type descriptor is normally stored as described above If expression is specified no type descriptor is defined only a predicate define structure foo type vector named foo a b c vector ref make foo 1 2 3 0 gt foo safe accessors boolean structure option This option allows the programmer to have some control over the safety of the slot accessors and modifiers generated by define structure If safe accessors is not specified or if boolean is f then the accessors are optimized for speed at the expense of safety when compiled the accessors will turn into very fast inline sequences usually one to three machine instructions in length However if safe accessors is specified and boolean is either omitted or stt then the accessors are optimized for safety will check the type and structure of their argument and will be close coded define structure foo safe accessors a b c initial offset offset structure option This is valid only in conjunction with the type option Offset must be an exact non negative integer and specifies the number of slots to leave open at the beginning of 36 MIT Scheme Refere
297. integers less than the length of the list The first element of a list has index 0 the second has index 1 and so on list ref list ref gt C ab cd 2 ab c d inexact gt exact round 1 8 gt Cc list ref list k is equivalent to car list tail list k first list second list third list fourth list fifth list sixth list seventh list eighth list ninth list tenth list procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure Returns the specified element of list It is an error if list is not long enough to contain the specified element for example if the argument to seventh is a list that contains only six elements Chapter 7 Lists 93 7 4 Cutting and Pasting Lists sublist list start end procedure Start and end must be exact integers satisfying O lt start lt end lt length list sublist returns a newly allocated list formed from the elements of list beginning at index start inclusive and ending at end exclusive list head list k procedure Returns a newly allocated list consisting of the first k elements of list K must not be greater than the length of list We could have defined list head this way define list head list k sublist list O k list tail list k procedure Returns the sublist of list obtained by omitting the first k elements The result if it is not the empty list shares structure with list K
298. ion involves two concepts usable size and physical size which we will now define The usable size of a hash table is the number of associations that the table can hold at a given time If the number of associations in the table exceeds the usable size the table will automatically grow increasing the usable size to a new value that is sufficient to hold the associations The physical size is an abstract measure of a hash table that specifies how much space is allocated to hold the associations of the table The physical size is always greater than or equal to the usable size The physical size is not interesting in itself it is interesting only for its effect on the performance of the hash table While the average performance of a hash table lookup is bounded by a constant the worst case performance is not For a table containing a given number of associations increasing the physical size of the table decreases the probability that worse than average performance will occur The physical size of a hash table is statistically related to the number of associations However it is possible to place bounds on the physical size and from this to estimate the amount of space used by the table define hash table space bounds count rehash size rehash threshold let tf 1 rehash threshold values if exact integer rehash size count 4 tf tf rehash size rehash size count 4 tf rehash size rehash size co
299. ion merge wt tree 1 wt tree 2 merge procedure Returns a new tree containing all the associations from both trees If both trees have an association for the same key the datum associated with that key in the result tree is computed by applying the procedure merge to the key the value from wt tree 1 and the value from wt tree 2 Merge is of the form lambda key datum 1 datum 2 If some key occurs only in one tree that association will appear in the result tree without being processed by merge so for this operation to make sense either merge must have both a right and left identity that correspond to the association being absent in one of the trees or some guarantee must be made for example all the keys in one tree are known to occur in the other These are all reasonable procedures for merge lambda key vali val2 vali val2 lambda key vali val2 append vali val2 lambda key vali val2 wt tree union vali val2 However a procedure like lambda key vali val2 vali val2 would result in a subtraction of the data for all associations with keys occuring in both trees but associations with keys occuring in only the second tree would be copied not negated as is presumably be intent The programmer might ensure that this never happens This procedure has the same time behavior as wt tree union but with a slightly worse constant factor Indeed wt tree union might have been defined like this define wt tree union
300. ional and rest We will use rest in these examples but anywhere it appears could be used instead a b c a b and c are all required The procedure must be passed exactly three arguments a b optional c a and b are required c is optional The procedure may be passed either two or three arguments GE optional a b c a b and c are all optional The procedure may be passed any number of arguments between zero and three inclusive a Gt rest a These two examples are equivalent a is a rest parameter The procedure may be passed any number of arguments Note this is the only case in which cannot be used in place of rest a b optional c d rest e a and b are required c and d are optional and e is rest The procedure may be passed two or more arguments Some examples of lambda expressions lambda x x x compound procedure 53 lambda x x x 4 gt 8 define reverse subtract lambda x y y x reverse subtract 7 10 gt 3 define foo let x 4 lambda y x y foo 6 gt 10 named lambda formals expression expression special form The named lambda special form is similar to lambda except that the first required parameter in formals is not a parameter but the name of the resulting procedure Chapter 2 Special Forms 19 thus formals must have at least one required parameter This name has no semantic meaning but is included
301. ional set of names hence protocols for common use By choosing the names of restarts from this set signalling code can indicate that it is able to perform a small set of fairly common actions abort continue muffle warning retry 232 MIT Scheme Reference store value use value In turn simple condition handling code can look for the kind of action it wishes to perform and simply invoke it by name All of Scheme s conventional names are symbols although in general restart names are not restricted to any particular data type In addition the object f is reserved to indicate the not for automated use protocol these restarts should be activated only under human control Restarts themselves are first class objects They encapsulate their name a procedure known as the effector to be executed if they are invoked and a thunk known as the reporter that can be invoked to display a description of the restart used for example by the interactive debugger Invoking a restart is an indication that a handler has chosen to accept control for a condition as a consequence the effector of the restart should not return since this would indicate that the handler declined to handle the condition Thus the effector should call a continuation captured before the condition signalling process began The most common pattern of usage by signalling code is encapsulated in with simple restart Within this chapter a parameter named restarts will a
302. ir defn 87 dotted pair see pair oooooocccccocco 87 double precision of inexact number 46 double quote as external representation T drawing arcs and circles graphics 260 261 drawing mode graphics defn 254 dynamic binding 21 230 231 dynamic binding and continuations 21 dynamic binding versus static scoping 8 dynamic types defn 0 0 005 3 E e as exponent marker in number 46 effector restart defn 00 000 231 element of list defn o oocococococoo 87 ellipse graphics ssc 00 e c 0s imc 265 ellipsis in entries nase eae a bere 5 else clause of case expression defn 2f else clause of cond expression defn 27 empty list dein seek rx Rr hr 87 empty list external representation 87 empty list predicate for oo o ooo 92 empty stream predicate for 119 empty string predicate for 3 end of file object see EOF object 166 Concept Index end of substring defn 00 pil end of subvector defn uuuuueu 101 entity delo coxeue foe b Ree RERO de 152 entry format ria Rua a 5 environment defn suesueesueuu 7 environment current def ooooooc oooo 7 environment extension defn
303. irectories other than a single global directory the list will have no other elements If the system supports flat directories i e a global set of directories with no subdirectories then the list will contain a second element which is either a string or wild In other words a non hierarchical file system is treated as if it were hierarchical but the hierarchical features are unused This representation is somewhat inconvenient for such file systems but it discourages programmers from making code depend on the lack of a file hierarchy A string which is a literal component or the symbol wild meaningful only when used in conjunction with the directory reader A string which is a literal component or the symbol wild meaningful only when used in conjunction with the directory reader An exact positive integer which is a literal component the symbol newest which means to choose the largest available version number for that file the symbol oldest which means to choose the smallest version number or the sym bol wild meaningful only when used in conjunction with the directory reader In the future some other possible values may be added e g installed Note that currently no file systems support version numbers thus this component is not used and should be specified as f Returns a pathname object whose components are the respective arguments Each argument must satisfy the restrictions for the corresponding component which w
304. is proportional to the number of associations in the tree This procedure is equivalent to lambda rb tree map cdr rb tree gt alist rb tree Chapter 11 Associations 137 rb tree equal rb tree 1 rb tree 2 datum procedure Compares rb tree 1 and rb tree 2 for equality returning stt iff they are equal and otherwise The trees must have been constructed with the same equality and order predicates same in the sense of eq The keys of the trees are compared using the key predicate used to build the trees while the datums of the trees are compared using the equivalence predicate datum The worst case time required by this operation is proportional to the number of associations in the tree rb tree empty rb tree procedure Returns stt iff rb tree contains no associations Otherwise returns f rb tree size rb tree procedure Returns the number of associations in rb tree an exact non negative integer The av erage and worst case times required by this operation are proportional to the number of associations in the tree rb tree height rb tree procedure Returns the height of rb tree an exact non negative integer This is the length of the longest path from a leaf of the tree to the root The average and worst case times required by this operation are proportional to the number of associations in the tree The returned value satisfies the following lambda rb tree let size rb tree size rb tree 1g lambda
305. is the inverse operation to directory pathname as file pathname as directory gt pathname usr blisp rel5 pathname usr blisp rel5 15 1 4 Miscellaneous Pathname Procedures This section gives some standard operations on host objects and some procedures that return some useful pathnames local host variable This variable has as its value the host object that describes the local host s file system host object procedure Returns t if object is a pathname host otherwise returns f host hostl host2 procedure Returns t if host1 and host2 denote the same pathname host otherwise returns f init file pathname host procedure Returns a pathname for the user s initialization file on host The host argument defaults to the value of local host If the initialization file does not exist this procedure returns f Under unix the init file is called scheme init under Windows and OS 2 the init file is called scheme ini In either case it is located in the user s home directory which is computed by user homedir pathname 196 MIT Scheme Reference user homedir pathname host procedure Returns a pathname for the user s home directory on host The host argument defaults to the value of local host The concept of a home directory is itself somewhat implementation dependent but it should be the place where the user keeps personal files such as initialization files and mail Under unix the us
306. its from loops or procedure bodies but in fact call with current continuation is quite useful for implementing a wide variety of advanced control structures Whenever a Scheme expression is evaluated a continuation exists that wants the result of the expression The continuation represents an entire default future for the computation If the expression is evaluated at top level for example the continuation will take the result print it on the screen prompt for the next input evaluate it and so on forever Most of the time the continuation includes actions specified by user code as in a continuation that will take the result multiply it by the value stored in a local variable add seven and give the answer to the top level continuation to be printed Normally these ubiquitous continuations are hidden behind the scenes and programmers don t think much about them On the rare occasions that you may need to deal explicitly with continuations call with current continuation lets you do so by creating a procedure that acts just like the current continuation continuation object procedure Returns t if object is a continuation otherwise returns f within continuation continuation thunk procedure Thunk must be a procedure of no arguments Conceptually within continuation invokes continuation on the result of invoking thunk but thunk is executed in the dynamic context of continuation In other words the cur rent continuation is aband
307. ivalent to the following expression substring string re match start index n registers re match end index n registers regexp group alternative procedure Each alternative must be a regular expression The returned value is a new regular expression that consists of the alternatives combined by a grouping operator For example regexp group foo bar baz gt foo bar baz 6 9 Modification of Strings string replace string charl char2 procedure substring replace string start end charl char2 procedure string replace string charl char2 procedure substring replace string start end charl char2 procedure These procedures replace all occurrences of charl with char2 in the original string substring string replace and substring replace return a newly allocated string containing the result string replace and substring replace destruc tively modify string and return an unspecified value Chapter 6 Strings 83 define str a few words gt unspecified string replace str space a few words substring replace str 2 9 space gt a few words str a few words string replace str space gt unspecified str a few words string fill string char procedure Stores char in every element of string and returns an unspecified value substring fill string start end char procedure Stores char in elements start inclusive to end exclusive of string and returns an unspecifi
308. ive integer or a real number that is greater than one Sets the rehash size of hash table to x and returns an unspecified result This operation adjusts the shrink threshold of the table the table might shrink if the number of associations is less than the new threshold Chapter 11 Associations 131 hash table rehash threshold hash table procedure Returns the rehash threshold of hash table set hash table rehash threshold hash table x procedure X must be a real number between zero exclusive and one inclusive Sets the rehash threshold of hash table to x and returns an unspecified result This operation does not change the usable size of the table but it usually changes the physical size of the table which causes the table to be rehashed 11 4 4 Address Hashing The procedures described in this section may be used to make very efficient key hashing procedures for arbitrary objects All of these procedures are based on address hashing which uses the address of an object as its hash number The great advantage of address hashing is that converting an arbitrary object to a hash number is extremely fast and takes the same amount of time for any object The disadvantage of address hashing is that the garbage collector changes the addresses of most objects The hash table implementation compensates for this disadvantage by automatically rehashing tables that use address hashing when garbage collections occur Thus in order to use these proc
309. k with string output port procedure procedure Procedure is called with one argument an output port The value yielded by pro cedure is ignored When procedure returns with string output port returns the port s accumulated output as a newly allocated string with output to string thunk procedure Thunk must be a procedure of no arguments with output to string creates a new output port that accumulates output makes that port the default value returned by current output port and calls thunk with no arguments When thunk returns with output to string restores the previous default and returns the accumulated output as a newly allocated string with output to string lambda write abc gt abc Note this procedure is equivalent to with string output port lambda port with output to port port thunk with output to truncated string k thunk procedure Similar to with output to string except that the output is limited to k characters If thunk attempts to write more than k characters it will be aborted by invoking an escape procedure that returns from with output to truncated string The value of this procedure is a pair the car of the pair is t if thunk attempted to write more than k characters and f otherwise The cdr of the pair is a newly allocated string containing the accumulated output This procedure is helpful for displaying circular lists as shown in this example define inf list inf with out
310. k pairs These procedures allow the programmer to specify the use Of some other data structure to maintain the association In this section the data structure that represents an association in a hash table is called an entry hash table constructor key hash key make entry entry valid procedure entry key entry datum set entry datum rehash after gc Creates and returns a hash table constructor procedure see Section 11 4 1 Construc tion of Hash Tables page 126 The arguments define the characteristics of the hash table as follows key hash The hashing procedure A procedure that accepts two arguments a key and an exact positive integer the modulus and returns an exact non negative integer that is less than the modulus key A equivalence predicate that accepts two keys and is true iff they are the same key If this predicate is true of two keys then key hash must return the same value for each of these keys given the same modulus in both cases make entry A procedure that accepts a key and a datum as arguments and returns a newly allocated entry entry valid A procedure that accepts an entry and returns f iff the entry s key has been reclaimed by the garbage collector Instead of a procedure this may be t which is equivalent to lambda entry t entry key A procedure that accepts an entry as an argument and returns the entry s key entry datum A procedure that accepts an entry as an argument and returns th
311. k s title preceding the beginning of the body of the text VERBATIM COPYING You may copy and distribute the Document in any medium either commercially or noncommercially provided that this License the copyright notices and the license notice saying this License applies to the Document are reproduced in all copies and that you add no other conditions whatsoever to those of this License You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute However you may accept compensation in exchange for copies If you distribute a large enough number of copies you must also follow the conditions in section 3 You may also lend copies under the same conditions stated above and you may publicly display copies COPYING IN QUANTITY If you publish printed copies of the Document numbering more than 100 and the Document s license notice requires Cover Texts you must enclose the copies in covers that carry clearly and legibly all these Cover Texts Front Cover Texts on the front cover and Back Cover Texts on the back cover Both covers must also clearly and legibly identify you as the publisher of these copies The front cover must present the full title with all words of the title equally prominent and visible You may add other material on the covers in addition Copying with changes limited to the covers as long GNU Free Documentation License 285 as they preserve the title
312. l symbol gt string obj2 gt dt objl and obj2 are both numbers are numerically equal according to the pro cedure and are either both exact or both inexact see Chapter 4 Numbers page 43 objl and obj2 are both characters and are the same character according to the char procedure see Chapter 5 Characters page 63 both objl and obj2 are the empty list objl and obj2 are procedures whose location tags are equal objl and obj2 are pairs vectors strings bit strings records cells or weak pairs that denote the same locations in the store eqv procedure returns sf if objl and obj2 are of different types one of objl and obj2 is t but the other is f objl and obj2 are symbols but string symbol gt string objl symbol gt string obj2 gt df one of objl and obj2 is an exact number but the other is an inexact number objl and obj2 are numbers for which the procedure returns sf objl and obj2 are characters for which the char procedure returns ttf one of obj1 and obj2 is the empty list but the other is not objl and obj2 are procedures that would behave differently return a different value or have different side effects for some arguments objl and obj2 are pairs vectors strings bit strings records cells or weak pairs that denote distinct locations MIT Scheme Reference Some examples equ a a gt dit eqv a b gt df eqv 2 2 gt dit eqv O OD gt t eqv 1
313. l condition creates a new REPL prior to its normal operation when its argument is a condition that is a specialization of any of these types The procedure break on signals establishes this set of condition types 230 MIT Scheme Reference ignore errors thunk procedure Executes thunk with a condition handler that intercepts the signalling of any special ization of condition type error including those produced by calls to error and immediately terminates the execution of thunk and returns from the call to ignore errors with the signalled condition as its value If thunk returns normally its value is returned from ignore errors Notice that ignore errors does not turn off signalling or condition handling Con dition handling takes place in the normal manner but conditions specialized from condition type error are trapped rather than propogated as they would be by default bind condition handler condition types handler thunk procedure Invokes thunk after adding handler as a condition handler for the conditions specified by condition types Condition types must be a list of condition types signalling a condition whose type is a specialization of any of these types will cause the handler to be invoked See signal condition for a description of the mechanism used to invoke handlers By special extension if condition types is the empty list then the handler is called for all conditions bind default condition handler condition types han
314. l errors in the result T he errors affect a few of the least significant bits of the result and consequently can be tolerated by many applications flonum unparser cutoff variable This variable controls the action of number gt string when number is a flonum and consequently controls all printing of flonums The value of this variable is normally a list of three items rounding type One of the following symbols normal relative or absolute The sym bol normal means that the number should be printed with full precision The symbol relative means that the number should be rounded to a specific number of digits The symbol absolute means that the number should be rounded so that there are a specific number of digits to the right of the decimal point Chapter 4 Numbers 55 precision An exact integer If rounding type is normal precision is ignored If rounding type is relative precision must be positive and it specifies the number of digits to which the printed representation will be rounded If rounding type is absolute the printed representation will be rounded precision digits to the right of the decimal point if precision is negative the representation is rounded precision digits to the left of the decimal point format type One of the symbols normal scientific or engineering This speci fies the format in which the number will be printed scientific specifies that the number will be printed using scientific no tati
315. level REP loop in the initial envi ronment define x 1 define f x g 2 define g y x y f 5 gt 3 not 7 Here f and g are bound to procedures created in the initial environment Because Scheme is statically scoped the call to g from f extends the initial environment the one in which g was created with a binding of y to 2 In this extended environment y is 2 and x is 1 In a dynamically bound Lisp the call to g would extend the environment in effect during the call to in which x is bound to 5 by the call to and the answer would be 7 Note that with static scoping you can tell what binding a variable reference refers to just from looking at the text of the program the referenced binding cannot depend on how the program is used That is the nesting of environments their parent child relationship corresponds to the nesting of binding expressions in program text Because of this connection to the text of the program static scoping is also called lexical scoping For each place where a variable is bound in a program there is a corresponding region of the program text within which the binding is effective For example the region of a binding established by a lambda expression is the entire body of the lambda expression The documentation of each binding expression explains what the region of the bindings it makes is A use of a variable that is a reference to or assignment of a variable refers to the innermo
316. licated to describe here See the OS 2 toolkit documentation for details 4 4 device xl xh yl yh A paint event Part of the graphics device window that was obscured has been revealed and the Presentation Manager is informing the window that it must repaint that area Scheme will take care of the painting for you so this event isn t very useful 5 device width height A size change event The size of the graphics device window has changed and width and height specify the new size in pels pixels 6 device shown A visibility event Indicates that the graphics device window has been hidden or revealed If shown is f the window is hidden and if it is t the window is shown 7 device source mouse 8 device source mouse A menu command Source specifies which menu item was selected to cause this event and mouse is a boolean indicating whether the item was selected with the mouse or the keyboard The event type number 7 indicates a command from a WM_COMMAND message while 8 is a command from a WM_HELP message 9 device x y hit test flags The mouse was moved X and y specify the position of the mouse hit test contains the hit test information and flags specifies the modifier keys that were pressed at the time discard events operation on os2 graphics device This operation discards any events that are in the user event queue This is sometimes useful when you want to prompt the user for some input and don
317. like the comments of the programming language C which have a similar syntax This is a comment about the FACT procedure Scheme 333 ignores all of this comment The FACT procedure computes 335 the factorial of a non negative integer This is an extended comment Such comments are useful for commenting out code fragments 3 define fact lambda n if n 0 This is another comment 1 Base case return 1 n fact n 1 1 3 7 Additional Notations The following list describes additional notations used in Scheme See Chapter 4 Num bers page 43 for a description of the notations used for numbers gem The plus sign minus sign and period are used in numbers and may also occur in an identifier A delimited period not occurring within a number or identifier is used in the notation for pairs and to indicate a rest parameter in a formal parameter list see Section 2 1 Lambda Expressions page 17 CO Parentheses are used for grouping and to notate lists see Chapter 7 Lists page 87 i The double quote delimits strings see Chapter 6 Strings page 71 The backslash is used in the syntax for character constants see Chapter 5 Characters page 63 and as an escape character within string constants see Chapter 6 Strings page 71 The semicolon starts a comment The single quote indicates literal data it suppresses evaluation see Section 2 6 Quoting page 24 Chapter 1
318. loop this means that when a new REP loop is started for example by an error each of these ports is dynamically bound to the 1 0 port of the REP loop When the REP loop exits the ports revert to their original values current input port procedure Returns the current input port This is the default port used by many input proce dures Initially current input port returns the value of console i o port current output port procedure Returns the current output port This is the default port used by many output procedures Initially current output port returns the value of console i o port notification output port procedure Returns an output port suitable for generating notifications that is messages to the user that supply interesting information about the execution of a program For example the load procedure writes messages to this port informing the user that a file is being loaded Initially notification output port returns the value of console i o port trace output port procedure Returns an output port suitable for generating tracing information about a pro gram s execution The output generated by the trace procedure is sent to this port Initially trace output port returns the value of console i o port interaction i o port procedure Returns an I O port suitable for querying or prompting the user The stan dard prompting procedures use this port by default see Section 14 8 Prompting page 175 Initially int
319. lue Then if the body is reentered by invoking a continuation the old value is saved and the variable is set to the new value In addition side effects to the variable that occur both inside and outside of body are preserved even if continuations are used to jump in and out of body repeatedly Here is a complicated example that shows the interaction between dynamic binding and continuations 22 MIT Scheme Reference define complicated dynamic binding let variable 1 inside continuation write line variable call with current continuation lambda outside continuation fluid let variable 2 write line variable set variable 3 call with current continuation lambda k set inside continuation k outside continuation t write line variable set inside continuation f write line variable if inside continuation begin set variable 4 inside continuation f Evaluating complicated dynamic binding writes the following on the console Commentary the first two values written are the initial binding of variable and its new binding after the fluid let s body is entered Immediately after they are written variable is set to 3 and then outside continuation is invoked causing us to exit the body At this point 1 is written demonstrating that the original value of variable has been restored because we have left the body Then we set variable to 4 and reenter the body by
320. lusive log 0 is undefined The value of log z when z is complex is defined according to the formula log z log magnitude z iangle z With log defined this way the values of arcsine arccosine and arctangent are accord ing to the following formulae sin z ilog iz V1 22 ES ee cos z 7 2 sin z tan z log 1 iz log 1 iz 2i The above specification follows Common Lisp the Language which in turn cites Principal Values and Branch Cuts in Complex APL refer to these sources for more detailed discussion of branch cuts boundary conditions and implementation of these functions When it is possible these procedures produce a real result from a real argument Chapter 4 Numbers 53 sqrt z procedure Returns the principal square root of z The result will have either positive real part or zero real part and non negative imaginary part expt z1 z2 procedure Returns z1 raised to the power z2 27 en log z 0 is defined to be equal to 1 make rectangular x1 x2 procedure make polar x3 x4 procedure real part z procedure imag part z procedure magnitude z procedure angle z procedure conjugate z procedure Suppose x1 x2 x3 and x4 are real numbers and z is a complex number such that z i Tzi 23 04 Then make rectangular and make polar return z real part returns xl imag part returns x2 magnitude returns x3 and angle returns x4 In the case of angle whose value is not
321. ly a few kinds of objects may have custom representation specified for them specifically records see Section 10 4 Records page 114 vectors that have special tags in their zero th elements see Chapter 8 Vectors page 101 and pairs that have special tags in their car fields see Chapter 7 Lists page 87 There is a different procedure for specifying the written representation of each of these types set record type unparser method record type unparser method procedure Changes the unparser method of the type represented by record type to be unparser method and returns an unspecified value Subsequently when the unparser encoun ters a record of this type it will invoke unparser method to generate the written representation unparser set tagged vector method tag unparser method procedure Changes the unparser method of the vector type represented by tag to be unparser method and returns an unspecified value Subsequently when the unparser en counters a vector with tag as its zero th element it will invoke unparser method to generate the written representation unparser set tagged pair method tag unparser method procedure Changes the unparser method of the pair type represented by tag to be unparser method and returns an unspecified value Subsequently when the unparser encoun 174 MIT Scheme Reference ters a pair with tag in its car field it will invoke unparser method to generate the written representation A
322. ly allocated bit string of length bits Signals an error of type condition type bad range argument if integer is too large to be represented in length bits signed integer gt bit string length integer procedure Length must be an exact non negative integer and integer may be any exact inte ger Converts integer into a newly allocated bit string of length bits using two s complement encoding for negative numbers Signals an error of type condition type bad range argument if integer is too large to be represented in length bits bit string gt unsigned integer bit string procedure bit string gt signed integer bit string procedure Converts bit string into an exact integer bit string gt signed integer regards bit string as a two s complement representation of a signed integer and produces an integer of like sign and absolute value bit string gt unsigned integer regards bit string as an unsigned quantity and converts to an integer accordingly Chapter 10 Miscellaneous Datatypes 109 10 Miscellaneous Datatypes 10 1 Booleans The boolean objects are true and false The boolean constant true is written as t and the boolean constant false is written as f The primary use for boolean objects is in the conditional expressions if cond and and or the behavior of these expressions is determined by whether objects are true or false These expressions count only f as false They count everything else including stt pairs
323. mbol in port type If port type has no such operation returns sf 14 9 2 Constructors and Accessors for Ports The procedures in this section provide means for constructing ports accessing the type of a port and manipulating the state of a port make port port type state procedure Returns a new port with type port type and the given state The port will be an input output or 1 0 port according to port type port type port procedure Returns the port type of port port state port procedure Returns the state component of port set port state port object procedure Changes the state component of port to be object Returns an unspecified value port operation port symbol procedure Equivalent to port type operation port type port symbol Chapter 14 Input Output 179 port operation names port procedure Equivalent to port type operation names port type port make eof object input port procedure Returns an object that satisfies the predicate eof object This is sometimes useful when building input ports 14 9 3 Input Port Operations This section describes the standard operations on input ports Following that some useful custom operations are described read char input port operation on input port Removes the next character available from input port and returns it If input port has no more characters and will never have any e g at the end of an input file this operation returns an end of file object
324. measured by an ordinary clock real time clock gt 33474836 internal time ticks gt seconds ticks procedure Returns the number of seconds corresponding to ticks The result is always a real number internal time ticks gt seconds 21290 gt 21 29 internal time ticks gt seconds 33474836 gt 33474 836 internal time seconds gt ticks seconds procedure Returns the number of ticks corresponding to seconds Seconds must be a real num ber 214 MIT Scheme Reference internal time seconds gt ticks 20 88 gt 20880 internal time seconds gt ticks 20 83 gt 20830 system clock procedure Returns the amount of process time in seconds that has elapsed since Scheme was started Roughly equivalent to internal time ticks gt seconds process time clock Example system clock gt 20 88 runtime procedure Returns the amount of process time in seconds that has elapsed since Scheme was started However it does not include time spent in garbage collection runtime gt 20 83 with timings thunk receiver procedure Calls thunk with no arguments After thunk returns receiver is called with three arguments describing the time spent while computing thunk the elapsed run time the amount of time spent in the garbage collector and the elapsed real time All three times are in ticks This procedure is most useful for doing performance measurements and is designed to have relatively low overhead with timing
325. med structures are tagged with a unique object of some kind In Common Lisp the structures are tagged with symbols This depends on the Common Lisp package system to help generate unique tags MIT Scheme has no such way to generate unique symbols The named option may optionally take an argument which is normally the name of a variable any expression may be used but it is evaluated whenever the tag name is needed If used structure instances will be tagged with that variable s value The variable must be defined when define structure is evaluated The type option is restricted to the values vector and list The include option is not implemented Chapter 3 Equivalence Predicates 37 3 Equivalence Predicates A predicate is a procedure that always returns a boolean value t or 4f An equiva lence predicate is the computational analogue of a mathematical equivalence relation it is symmetric reflexive and transitive Of the equivalence predicates described in this sec tion eq is the finest or most discriminating and equal is the coarsest equ is slightly less discriminating than eq eqv objl obj2 procedure The eqv procedure defines a useful equivalence relation on objects Briefly it returns t if objl and obj2 should normally be regarded as the same object The e eqv procedure returns stt if objl and obj2 are both t or both f objl and obj2 are both interned symbols and string symbol gt string obj
326. members Alphabetic characters are the 52 upper and lower case letters Numeric characters are the 10 decimal digits Alphanumeric characters are those in the union of these two sets Whitespace characters are space tab page linefeed and return Graphic characters are the printing characters and space Standard characters are the printing characters space and newline These are the printing characters In h amp a 01234567809 35 lt gt 7 ABCDEFGHIJKLMNOPQRSTUVWXYZ X d m uos abcdefghijklmnopqrstuvwxyz td char upper case char procedure char lower case char procedure char alphabetic char procedure char numeric char procedure char alphanumeric char procedure char whitespace char procedure char graphic char procedure char standard object procedure These predicates are defined in terms of the respective character sets defined above char set members char set procedure Returns a newly allocated list of the characters in char set char set member char set char procedure Returns t if char is in char set otherwise returns f char set char procedure Returns a character set consisting of the specified ASCII characters With no argu ments char set returns an empty character set chars gt char set chars procedure Returns a character set consisting of chars which must be a list of ASCII characters This is equivalent to apply char set chars 70 MIT Scheme Reference st
327. ments because the arguments to the constructor specify the initial contents the structure s slots by the order in which they are given This is as opposed to keyword constructors which specify the initial contents using keywords and in which the order of arguments is irrelevant If name is not given a constructor is defined with the default name and arguments see above If name is f no constructor is defined argument list may not be specified in this case Otherwise name must be a symbol and a constructor is defined with that symbol as its name If name is a symbol argument list is optionally allowed if it is omitted the constructor accepts one argument for each slot in the structure definition in the same order in which the slots appear in the definition Otherwise argument list must be a lambda list see Section 2 1 Lambda Expressions page 17 and each of the parameters of the lambda list must be the name of a slot in the structure The arguments accepted by the constructor are defined by this lambda list Any slot that is not specified by the lambda list is initialized to the default init as specified above likewise for any slot specified as an optional parameter when the corresponding argument is not supplied If the constructor option is specified the default constructor is not defined Addi tionally the constructor option may be specified multiple times to define multiple constructors with different names and arg
328. mmunicate between computers over a TCP IP network TCP sockets are supported on all operating systems 220 MIT Scheme Reference TCP sockets have two distinct interfaces one interface to implement a client and another to implement a server The basic protocol is that servers set up a listening port and wait for connections from clients Implementation of clients is simpler and will be treated first The socket procedures accept two special arguments called host name and service Host name is a string which must be the name of an internet host It is looked up using the ordinary lookup rules for your computer For example if your host is foo mit edu and host name is bar then it specifies bar mit edu Service specifies the service to which you will connect A networked computer normally provides several different services such as telnet or FTP Each service is associated with a unique port number for example the www service is associated with port 80 The service argument specifies the port number either as a string or directly as an exact non negative integer Port strings are decoded by the operating system using a table for example on unix the table is in etc services Usually you will use a port string rather than a number open tcp stream socket host name service buffer size procedure line translation open tcp stream socket opens a connection to the host specified by host name Host name is looked up using the ordina
329. modes The integer zero represents a set of modes in which none of these bits are set 202 MIT Scheme Reference nt file mode read only variable nt file mode hidden variable nt file mode system variable nt file mode directory variable nt file mode archive variable nt file mode normal variable nt file mode temporary variable nt file mode compressed variable The values of these variables are the mode bits that comprise the value returned by file modes under Windows These bits are small integers that are combined by adding to form a complete set of modes The integer zero represents a set of modes in which none of these bits are set file modification time filename procedure Returns the modification time of filename as an exact non negative integer The result may be compared to other file times using ordinary integer arithmetic If filename names a file that does not exist file modification time returns f In operating systems that support symbolic links if filename names a symbolic link file modification time returns the modification time of the file linked to An alternate procedure file modification time direct returns the modification time of the link itself in all other respects it is identical to file modification time For symmetry file modification time indirect is a synonym of file modification time file access time filename procedure Returns the access time of filename as an exact non negative integer
330. mple 3 is an integer Therefore 3 is also a rational a real and a complex The same is true of the Scheme numbers that model 3 For Scheme numbers these types are defined by the predicates number complex real rational and integer There is no simple relationship between a number s type and its representation inside a computer Although most implementations of Scheme will offer at least two different representations of 3 these different representations denote the same integer Scheme s numerical operations treat numbers as abstract data as independent of their representation as possible Although an implementation of Scheme may use fixnum flonum and perhaps other representations for numbers this should not be apparent to a casual programmer writing simple programs It is necessary however to distinguish between numbers that are represented exactly and those that may not be For example indexes into data structures must be known exactly as must some polynomial coefficients in a symbolic algebra system On the other hand the results of measurements are inherently inexact and irrational numbers may be approximated by rational and therefore inexact approximations In order to catch uses of inexact numbers where exact numbers are required Scheme explicitly distinguishes exact from inexact numbers This distinction is orthogonal to the dimension of type 44 MIT Scheme Reference 4 2 Exactness Scheme numbers are either exact or
331. must not be greater than the length of list append list procedure Returns a list consisting of the elements of the first list followed by the elements of the other lists append x y gt xy append a b c d gt abc d append a b c gt a b c append gt 0 The resulting list is always newly allocated except that it shares structure with the last list argument The last argument may actually be any object an improper list results if the last argument is not a proper list append a b c d gt abc d append a gt a append list procedure Returns a list that is the argument lists concatenated together The arguments are changed rather than copied Compare this with append which copies arguments rather than destroying them For example define x a b c define y d e f define z g h append x y z gt abcdef gh x gt abcdef gh y gt def gh Zz gt gh 94 MIT Scheme Reference last pair list procedure Returns the last pair in list which may be an improper list last pair could have been defined this way define last pair lambda x if pair cdr x last pair cdr x x except last pair list procedure except last pair list procedure These procedures remove the last pair from list List may be an improper list except that it must consist of at least one pair except last pair returns a newly allocated
332. n Specifies the working directory in which the subprocess will run The default value of this option is working directory pathname run shell command ls la working directory etc use pty boolean subprocess option This option is meaningful only on unix systems on other systems it is ignored Spec ifies whether to communicate with the subprocess using PTY devices if true PTYs will be used otherwise pipes will be used The default value of this option is f run shell command ls la etc use pty stt shell file name pathname subprocess option Specifies the shell program to use for run shell command The default value of this option is os shell file name This is the value of the environment variable SHELL or if SHELL is not set the value is operating system dependent as follows e On unix systems bin sh is used e On OS 2 systems the value of the environment variable COMSPEC is used or if that is not set cmd exe on the current path e On Windows systems the value of the environment variable COMSPEC is used If that is not set cmd exe is used for Windows NT or command com is used for Windows 9x in each case the shell is found by searching the path run shell command ls la etc shell file name usr local bin bash 15 8 TCP Sockets MIT Scheme provides access to sockets which are a mechanism for inter process commu nication TCP stream sockets are supported which co
333. n formation file pathname returns a pathname with just the name type and version Chapter 15 Operating System Interface 195 components of pathname The result of directory pathname is a pathname contain ing the host device and directory components of pathname enough pathname takes another argument defaults It returns an abbreviated path name that is just sufficient to identify the file named by pathname when considered relative to the defaults which defaults to default pathname defaults These procedures are similar to file namestring directory namestring and enough namestring but they return pathnames instead of strings directory pathname as file pathname procedure Returns a pathname that is equivalent to pathname but in which the directory com ponent is represented as a file The last directory is removed from the directory component and converted into name and type components This is the inverse oper ation to pathname as directory directory pathname as file gt pathname usr blisp gt pathname usr blisp pathname as directory pathname procedure Returns a pathname that is equivalent to pathname but in which any file components have been converted to a directory component If pathname does not have name type or version components it is returned without modification Otherwise these file components are converted into a string and the string is added to the end of the list of directory components This
334. n 102 MIT Scheme Reference H handler condition defn 0 229 hard linking of fle eios rs 198 hash table dete ia dba 125 hashing of key in hash table 126 hashing of Object 0ooooooooooo 133 hashing of string serii deere rara 74 hashing of symbol eere eee mes 113 home directory as pathname 195 196 hook application defn ssssuss 147 host in filenames ises 2 emet RREED s 188 host pathname component 189 hostname TOP cmo carac pis bis 220 hyper bucky bit prefix defn 63 I 1 0 to lei oim REFER PREUPRRLERYR 161 1 0 to SUDBS ore rt eae eles 2a 163 identifier def 0 eee eee eee eee 11 identity additive ress rca 48 identity multiplicative oo o oooooo ooo 48 Images graphics oa o ot eee id 257 immutable i22 ri xg a 10 implementation restricti0M o ooo 44 implicit begin 3232 deeey ter od ued eed ties 29 improper list defn 00 005 87 index of bit string defn 0 105 index of list defn 0 004 92 index of string defn 04 71 index of subvector defn 0 101 index of vector defn 00 00 101 inheritance of environment bindings defn 7 initial environment defn 04 7 initial size of hash table 130 IDDUt
335. n and object procedure This procedure returns stt if none of its arguments are f Otherwise it returns f boolean or object procedure This procedure returns f if all of its arguments are f Otherwise it returns stt 10 2 Symbols MIT Scheme provides two types of symbols interned and uninterned Interned symbols are far more common than uninterned symbols and there are more ways to create them Interned symbols have an external representation that is recognized by the procedure read uninterned symbols do not Interned symbols have an extremely useful property any two interned symbols whose names are the same in the sense of string are the same object i e they are eq to one another The term interned refers to the process of interning by which this is accomplished Uninterned symbols do not share this property The names of interned symbols are not distinguished by their alphabetic case Because of this MIT Scheme converts all alphabetic characters in the name of an interned symbol to a specific case lower case when the symbol is created When the name of an interned symbol is referenced using symbol gt string or written using write it appears in this case It is a bad idea to depend on the name being lower case In fact it is preferable to take this one step further don t depend on the name of a symbol being in a uniform case The rules for writing an interned symbol are the same as the rules for writing an id
336. n appropriate descriptor record type descriptor record procedure Returns the record type descriptor representing the type of record That is for ex ample if the returned descriptor were passed to record predicate the resulting predicate would return t when passed record Note that it is not necessarily the case that the returned descriptor is the one that was passed to record constructor in the call that created the constructor procedure that created record record type object procedure Returns t if object is a record type descriptor otherwise returns f record type name record type procedure Returns the type name associated with the type represented by record type The returned value is eqv to the type name argument given in the call to make record type that created the type represented by record type record type field names record type procedure Returns a list of the symbols naming the fields in members of the type represented by record type The returned value is equal to the field names argument given in the call to nake record type that created the type represented by record type 3 In MIT Scheme the returned list is always newly allocated 116 MIT Scheme Reference 10 5 Promises delay expression special form The delay construct is used together with the procedure force to implement lazy evaluation or call by need delay expression returns an object called a promise which at some point in the future may be a
337. n associated hash number Otherwise it is false valid hash number k table procedure This predicate is true if k is the hash number associated with some object Otherwise it is false The following two procedures provide a lower level interface to the object hashing mech anism object hash object table insert procedure object hash is like hash except that it accepts an additional optional argument insert If insert is supplied and is f object hash will return an integer for object only if there is already an association in the table otherwise it will return f If insert is not supplied or is not f object hash always returns an integer creating an association in the table if necessary object hash additionally treats f differently than does hash Calling object hash with f as its argument will return an integer that when passed to unhash will signal an error rather than returning amp f Likewise valid hash number will return f for this integer Chapter 11 Associations 135 object unhash k table procedure object unhash is like unhash except that when k is not associated with any object or was previously associated with an object that has been reclaimed object unhash returns f This means that there is an ambiguity in the value returned by object unhash if 4f is returned there is no way to tell if k is associated with f or is not associated with any object at all Finally this procedure makes new obje
338. n empty vectors and empty strings eq eq eq eq eq eq eq eq eq let u a a a list a list a Wan may m my 20 20 2 2 HA HA car car n 2 339 eg n n let Cx 222 eq x x let C O02 eq x x let Cp lambda x x eq p p Rationale It will usually be possible to implement eq much more efficiently than eqv for example as a simple pointer comparison instead of as some more compli cated operation One reason is that it may not be possible to compute eqv of two numbers in constant time whereas eq implemented as pointer comparison will always finish in constant time eq may be used like eqv in applications using procedures to implement objects with state since it obeys the same constraints as eqv V V YI y tt unspecified Hf unspecified unspecified tt unspecified unspecified tt unspecified tt tt t Chapter 3 Equivalence Predicates 41 equal objl obj2 procedure equal recursively compares the contents of pairs vectors and strings applying eqv on other objects such as numbers symbols and records A rule of thumb is that objects are generally equal if they print the same equal may fail to terminate if its arguments are circular data structures equal a a gt t equal a a gt t equal a b c a b c gt dit equal abc abc gt dit equal 2 2 gt
339. n type This condition type is a subtype of condition type subprocess abnormal termination It is signalled when the subprocess is stopped or suspended Subprocess is an object that represents the subprocess involved The internals of this object can be accessed but the interface is not documented at this time see the source code for details Reason is interesting only on unix systems where it is the signal that stopped the process On other systems it has a fixed value that conveys no useful information condition type subprocess abnormal termination condition type subprocess reason This condition type is a subtype of condition type error This is an abstract type that is never signalled It is provided so that condition handlers can be bound to it 15 7 3 Subprocess Options The following subprocess options may be passed to run shell command or run synchronous subprocess These options are passed as alternating keyword value pairs for example Chapter 15 Operating System Interface 217 run shell command 1s output my output port output buffer size 8192 The example shows a shell command being run with two options specified output and output buffer size input port subprocess option Specifies the standard input of the subprocess Port may be an input port in which case characters are read from port and fed to the subprocess until port reaches end of file Alternatively port may be f indicating that the subproce
340. n types if generalization is For debugging purposes the condition type has a name and instances of this type contain storage for the fields specified by field names a list of symbols in addition to the fields common to all conditions type continuation and restarts Reporter is used to produce a description of a particular condition of this type It may be a string describing the condition a procedure of arity two the first argument will be a condition of this type and the second a port that will write the message to the given port or 4f to specify that the reporter should be taken from the condition type generalization or produce an undocumented condition of type message if generalization is The conventions used to form descriptions are spelled out in Section 16 2 Error Messages page 228 condition type error condition type procedure Returns t if the condition type is condition type error or a specialization of it 4f otherwise condition type field names condition type procedure Returns a list of all of the field names for a condition of type condition type This is the set union of the fields specified when this condition type was created with the condition type field names of the generalization of this condition type Chapter 16 Error System 241 condition type generalizations condition type procedure Returns a list of all of the generalizations of condition type Notice that every condi tion type is
341. n unparser method is a procedure that is invoked with two arguments an unparser state and an object An unparser method generates a written representation for the object writing it to the output port specified by the unparser state The value yielded by an unparser method is ignored Note that an unparser state is not an output port rather it is an object that contains an output port as one of its components Application programs generally do not construct or examine unparser state objects but just pass them along There are two ways to create an unparser method which is then registered by one of the above procedures The first and easiest is to use standard unparser method The second is to define your own method using the procedure with current unparser state We encourage the use of the first method as it results in a more uniform appearance for objects Many predefined datatypes for example procedures and environments already have this appearance standard unparser method name procedure procedure Returns a standard unparser method Name may be any object and is used as the name of the type with which the unparser method is associated name is usually a symbol Procedure must be f or a procedure of two arguments If procedure is f the returned method generates an external representation of this form name hash Here name is the external representation of the argument name as generated by write and hash is the external repres
342. name must be both readable and executable If filename doesn t exist or if it does not satisfy the selected predicates f is returned file eq filenamel filename2 procedure Determines whether filenamel and filename2 refer to the same file Under unix this is done by comparing the inodes and devices of the two files Under OS 2 and Windows this is done by comparing the filename strings file modes filename procedure If filename names an existing file file modes returns an exact non negative integer encoding the file s permissions The encoding of this integer is operating system dependent Under unix it is the least significant 12 bits of the st_mode element of the struct stat structure Under OS 2 and Windows it is the file attribute bits which are described below If filename does not name an existing file is returned set file modes filename modes procedure Filename must name an existing file Modes must be an exact non negative integer that could have been returned by a call to file modes set file modes modifies the file s permissions to be those encoded by modes os2 file mode read only variable os2 file mode hidden variable os2 file mode system variable os2 file mode directory variable os2 file mode archived variable The values of these variables are the mode bits that comprise the value returned by file modes under OS 2 These bits are small integers that are combined by adding to form a complete set of
343. name will be interpreted as a string although you may specify it as a pathname object if you wish The contents of this string will be stored in the file system as the soft link When a file operation attempts to open the link the contents of the link are interpreted relative to the link s location at that time This currently works only on unix systems make directory filename procedure Creates a new directory named filename Signals an error if filename already exists or if the directory cannot be created delete directory filename procedure Deletes the directory named filename Signals an error if the directory does not exist is not a directory or contains any files or subdirectories gt truename filename procedure This procedure attempts to discover and return the true name of the file associ ated with filename within the file system An error of type condition type file operation error is signalled if the appropriate file cannot be located within the file system call with temporary file pathname procedure procedure Calls temporary file pathname to create a temporary file then calls procedure with one argument the pathname referring to that file When procedure returns if the temporary file still exists it is deleted then the value yielded by procedure is returned If procedure escapes from its continuation and the file still exists it is deleted temporary file pathname directory procedure Creates a new
344. named let and do They are also binding expressions but are more commonly referred to as iteration expressions Because Scheme is properly tail recursive you don t need to use these special forms to express iteration you can simply use appropriately written recursive procedure calls let name variable init expression expression special form MIT Scheme permits a variant on the syntax of let called named let which pro vides a more general looping construct than do and may also be used to express recursions Named let has the same syntax and semantics as ordinary let except that name is bound within the expressions to a procedure whose formal arguments are the variables and whose body is the expressions Thus the execution of the expressions may be repeated by invoking the procedure named by name MIT Scheme allows any of the inits to be omitted in which case the corresponding variables are unassigned Note the following expressions are equivalent 30 MIT Scheme Reference let name variable init expression expression letrec name named lambda name variable expression expression name init Here is an example let loop numbers 3 2 1 6 5 nonneg neg cond null numbers list nonneg neg gt car numbers 0 loop cdr numbers cons car numbers nonneg neg else loop cdr numbers nonneg cons car numbers neg
345. natively the dash style alternates between foreground and background colors to generate a dashed line This capability is useful for plotting several things on the same graph Here is a table showing the name and approximate pattern of the different styles A 1 in the pattern represents a foreground pixel while a represents a background pixel Note that the precise output for each style will vary from device to device The only style that is guaranteed to be the same for every device is solid Style Name Pattern 0 solid 1111111111111111 1 dash 11111111 2 dot 1 1 1 1 1 1 1 1 3 dash dot 1111111111111 1 4 dash dot dot 11111111111 1 1 5 long dash 111111111 l 6 center dash 111111111111 11 7 center dash dash 111111111 11 11 graphics bind drawing mode graphics device drawing mode procedure thunk graphics bind line style graphics device line style thunk procedure These procedures bind the drawing mode or line style respectively of graphics device invoke the procedure thunk with no arguments then undo the binding when thunk returns The value of each procedure is the value returned by thunk Graphics operations performed during thunk s dynamic extent will see the newly bound mode or style as current 256 MIT Scheme Reference graphics set drawing mode graphics device drawing mode procedure graphics set line style graphics device line style procedure These procedures change the drawing mode
346. nce the structure instance before the specified slots are allocated Specifying an offset of zero is equivalent to omitting the initial offset option If the named option is specified the structure tag appears in the first slot followed by the offset slots and then the regular slots Otherwise the offset slots come first followed by the regular slots define structure foo type vector initial offset 3 a b c make foo 1 2 3 gt 0 0 O 1 2 3 The essential differences between MIT Scheme s define structure and Common Lisp s defstruct are The default constructor procedure takes positional arguments in the same order as specified in the definition of the structure A keyword constructor may be specified by giving the option keyword constructor BOA constructors are described using Scheme lambda lists Since there is nothing corresponding to amp aux in Scheme lambda lists this functionality is not implemented By default no copier procedure is defined The side effect procedure corresponding to the accessor foo is given the name set foo Keywords are ordinary symbols use foo instead of foo The option values false nil true and t are treated as if the appropriate boolean constant had been specified instead The print function option is named print procedure Its argument is a procedure of two arguments the unparser state and the structure instance rather than three as in Common Lisp By default na
347. ncept Index Concept Index in mutation procedure names 11 as format parameter esses 172 in external representation of number 46 HH as external representation 101 as external representation 105 as external representation 174 as external representation 12 as external representation 63 b as external representation 46 d as external representation ls 46 e as external representation 46 HH as external representation 109 i as external representation 46 0 as external representation 46 t as external representation 109 Fx as external representation 46 9 as external representation 24 as external representation 87 as external representation 0 87 9 as external representation 26 as external representation 26 notational convention lesse esses 5 ci in string procedure name 71 307 as external representation 87 A weet eens S pU RU RETE 5 as external representati0O 12 gt in Cond C AUSE secsec sii re 27 gt notational convention 04 4 E in predicate Ma
348. nd expression If the selected clause contains only the predicate and no expressions cond returns the value of the predicate as the result 3 If all predicates evaluate to false values and there is no else clause the result of the conditional expression is unspecified if there is an else clause cond evaluates its expressions left to right and returns the value of the last one cond 3 2 greater 3 2 less gt greater cond gt 3 3 greater 3 3 less else equal gt equal Normally programs should not depend on the value of a cond expression that has no else clause However some Scheme programmers prefer to write cond expressions in which at least one of the predicates is always true In this style the final clause is equivalent to an else clause Scheme supports an alternative clause syntax predicate gt recipient where recipient is an expression If predicate evaluates to a true value then recipient is evaluated Its value must be a procedure of one argument this procedure is then invoked on the value of the predicate cond assv b a 1 b 2 gt cadr else f 9 case key clause clause special form Key may be any expression Each clause has this form Cobject expression expression No object is evaluated and all the objects must be distinct The last clause may be an else clause which has the form else expression expression A case expr
349. ndition type for file system errors The filename field contains the filename or pathname that was being operated on The verb field contains a string which is the verb or verb phrase describing the operation being performed and the noun field contains a string which is a noun or noun phrase describing the object being operated on The reason field contains a string describing the error that occurred The operator field contains the procedure performing the operation or a symbol naming that procedure and the operands field contains a list of the arguments that were passed to that procedure For example an attempt to delete a nonexistent file would have the following field values filename zu cph tmp no such file verb delete noun file reason no such file or directory operator file remove operands zu cph tmp no such file and would generate a message like this delete file zu cph tmp no such file error Unable to delete file zu cph tmp no such file because No such file or directory To continue call RESTART with an option number RESTART 3 gt Try to delete the same file again RESTART 2 gt Try to delete a different file RESTART 1 gt Return to read eval print level 1 error file operation error filename verb noun reason operator procedure operands This procedure signals a condition of type condition type file operation error The fields of the condition are filled in from
350. ndomly initialized by some means such as by a time of day clock random state object procedure Returns t if object is a random state object otherwise returns f 62 MIT Scheme Reference Chapter 5 Characters 63 5 Characters Characters are objects that represent printed characters such as letters and digits 5 1 External Representation of Characters Characters are written using the notation character or character name For exam ple Ha lowercase letter HA uppercase letter left parenthesis space the space character newline the newline character Case is significant in character but not in character name If character in character is a letter character must be followed by a delimiter character such as a space or parenthesis Characters written in the notation are self evaluating you don t need to quote them A character name may include one or more bucky bit prefixes to indicate that the character includes one or more of the keyboard shift keys Control Meta Super Hyper or Top note that the Control bucky bit prefix is not the same as the ASCII control key The bucky bit prefixes and their meanings are as follows case is not significant Key Bucky bit prefix Bucky bit Meta M or Meta 1 Control C or Control 2 Super S or Super 4 Hyper H or Hyper 8 Top T or Top 16 For example c a Control a meta b Meta b c s m h a Control Meta Super Hyper A The
351. ng them easy to use and offer the feature that they do not prevent their keys from being reclaimed by the garbage collector Like association lists their average lookup time is linear in the number of associations but 1D tables aren t as flexible e The association table is MIT Scheme s equivalent to the property lists of Lisp It has the advantages that the keys may be any type of object and that it does not prevent the keys from being reclaimed by the garbage collector However two linear time lookups must be performed one for each key whereas for traditional property lists only one lookup is required for both keys e Hash tables are a powerful mechanism with constant time access to large amounts of data Hash tables are not as flexible as association lists but because their access times are independent of the number of associations in the table for most applications they are the mechanism of choice e Balanced binary trees are another association mechanism that is useful for applications in which the keys are ordered Binary trees have access times that are proportional to the logarithm of the number of associations in the tree While they aren t as fast as hash tables they offer the advantage that the contents of the tree can be converted to a sorted alist in linear time Additionally two trees can be compared for equality in worst case linear time e Red Black trees are a kind of balanced binary tree The implementation supports dest
352. ngs page 105 This notation is an MIT Scheme extension This character sequence is used to denote objects that do not have a readable external representation see Section 14 7 Custom Output page 173 A close bracket terminates the object s notation This notation is an MIT Scheme extension This character sequence is a convenient shorthand used to refer to objects by their hash number see Section 14 7 Custom Output page 173 This notation is an MIT Scheme extension These character sequences introduce a notation used to show circular structures in printed output or to denote them in input The notation works much like that in Common Lisp and is an MIT Scheme extension 1 4 Expressions A Scheme expression is a construct that returns a value An expression may be a literal a variable reference a special form or a procedure call 14 MIT Scheme Reference 1 4 1 Literal Expressions Literal constants may be written by using an external representation of the data In general the external representation must be quoted see Section 2 6 Quoting page 24 but some external representations can be used without quotation abc gt abc 145932 gt 145932 t gt t a gt a The external representation of numeric constants string constants character constants and boolean constants evaluate to the constants themselves Symbols pairs lists and vectors require quoting 1 4 2 Variable References
353. nly some of them For example an implementation in which all numbers are real need not support the rectangular and polar notations for complex num bers If an implementation encounters an exact numerical constant that it cannot represent as an exact number then it may either report a violation of an implementation restriction or it may silently represent the constant by an inexact number MIT Scheme implements all of the written notations for numbers 46 MIT Scheme Reference 4 4 Syntax of numerical constants A number may be written in binary octal decimal or hexadecimal by the use of a radix prefix The radix prefixes are b binary 0 octal std decimal and x hexadecimal With no radix prefix a number is assumed to be expressed in decimal A numerical constant may be specified to be either exact or inexact by a prefix The prefixes are tte for exact and sti for inexact An exactness prefix may appear before or after any radix prefix that is used If the written representation of a number has no exactness prefix the constant may be either inexact or exact lt is inexact if it contains a decimal point an exponent or a character in the place of a digit otherwise it is exact In systems with inexact numbers of varying precisions it may be useful to specify the precision of a constant For this purpose numerical constants may be written with an exponent marker that indicates the desired precision of the inexact represen
354. nt procedure This is the simplest and most common way to signal a condition that requires inter vention before a computation can proceed when intervention is not required warn is more appropriate error signals a condition using signal condition and if no handler for that condition alters the flow of control by invoking a restart for example it calls the procedure standard error handler which normally prints an error message and stops the computation entering an error REPL Under normal circumstances error will not return a value although an interactive debugger can be used to force this to occur Precisely what condition is signalled depends on the first argument to error If reason is a condition then that condition is signalled and the arguments are ignored If reason is a condition type then a new instance of this type is generated and signalled the arguments are used to generate the values of the fields for this condition type they are passed as the field plist argument to make condition In the most common case however reason is neither a condition nor a condition type but rather a string or symbol In this case a condition of type condition type simple error is created with the message field containing the reason and the irritants field containing the arguments warn reason argument procedure When a condition is not severe enough to warrant intervention it is appropriate to signal the condition with warn rather t
355. nt of integers 0 2 00 49 quotient of numbers gt s sese socius es 48 QUOUNG iiu ecce esc EE eM decid ER eb 24 R RARO rd rn ERE 3 random number edt Ee a 60 rational simplest defn 0 05 51 raw mode of terminal port 184 record type descriptor defn 114 recursion see tail recursion o0ooooooo 3 red black binary trees o o ooo o 135 reduction oF litis uro ret RR e Ee 97 reference variable defn oo o o 14 region of variable binding do 30 region of variable binding internal definition 23 region of variable binding lambda EA region of variable binding let 19 region of variable binding let 19 region of variable binding letrec 20 region of variable binding defn 8 regular expression searching string for 81 regular file predicate for 200 rehash size of hash table defn 130 rehash threshold of hash table defn 130 relative pathname defn 197 remainder of imtegerS oooooccccccocoooooo 49 renaming Of file ese E ns 198 REP 100p 4 nre eres 227 229 230 234 REP loop deft 22 ir Per etw E REP loop environment OL ooccooococooo T replacement of string component 82 representation external defn
356. nts needed for restart s effector It then calls the effector passing these arguments to it invoke restart interactively is intended for calling interactive restarts those for which restart interactor is not 4f For convenience invoke restart interactively will call the restart s effector with no arguments if the restart has no interactor this behavior may change in the future 16 4 4 The Named Restart Abstraction A restart object is very simple since it encapsulates only a name effector interactor and description restart object procedure Returns f if and only if object is not a restart restart name restart procedure Returns the name of restart While the Scheme error system uses only symbols and the object for its predefined names programs may use arbitrary objects name equivalence is tested using eq Chapter 16 Error System 237 restart effector restart procedure Returns the effector encapsulated in restart Normally this procedure is not used since invoke restart and invoke restart interactively capture the most common invocation patterns restart interactor restart procedure Returns the interactor encapsulated in restart This is either a procedure of no argu ments or the object 4f Normally this procedure is not used since invoke restart interactively captures the most common usage Thus restart interactor is most useful as a predicate to determine if restart is intended to be invoked interac tively
357. nvironment are available when the current environment is user initial environment However any new bindings that you create in the REP loop with define forms or by loading files containing define forms occur in user initial environment system global environment variable The variable system global environment is bound to the environment that s the parent of the user initial environment Primitives and system procedures are bound and sometimes closed in this environment user initial environment variable The variable user initial environment is bound to the default environment in which typed expressions are evaluated by the top level REP loop Although all bindings in system global environment are visible to the REP loop definitions that are typed at or loaded by the REP loop occur in the user initial environment This is partly a safety measure if you enter a definition that happens to have the same name as a critical system procedure your definition will be visi ble only to the procedures you define in the user initial environment the MIT Scheme system procedures which are defined in the system global environment will continue to see the original definition 13 3 REPL Environment Chapter 13 Environments 157 nearest repl environment procedure Returns the current REP loop environment i e the current environment of the closest enclosing REP loop When Scheme first starts up this is the same as user initial environment
358. o 66 construction of character Seb 69 construction of circular list 99 construction of continuation 149 construction of environment 157 construction of EOF object 179 construction of file input port 162 construction of file output port 162 construction of hash table 126 construction of list ocasion ta 90 construction Of pair s ei e Rt rr 88 construction of pathname 188 191 construction of port type 04 177 construction of procedure oooocoooccoooo slg construction of promise 004 116 construction of stream 0000 118 construction of Strid8B 0oooooooooccccc 72 construction of string input port 163 construction of string output port 164 construction of symbols 4 111 construction of vector ooooooooooooo 101 construction of weak pair lusus 119 Continuation iria 149 continuation alternate invocation 150 continuation and dynamic binding 21 control bucky bit prefix defn 63 conventions for error messages 228 conventions lexical emmm iones 10 conventions naming eee 11 conventions notational o ooooooo 4 310 conversion pathname to string 188 194
359. o a port that you specify The current output port is initially console i o port but Scheme provides procedures that let you change the current output port to be a file or string All ports read or write only ASCII characters Every port is either an input port an output port or both The following predicates distinguish all of the possible cases port object procedure Returns stt if object is a port otherwise returns amp f input port object procedure Returns stt if object is an input port otherwise returns 4f Any object satisfying this predicate also satisfies port output port object procedure Returns stt if object is an output port otherwise returns 4f Any object satisfying this predicate also satisfies port i o port object procedure Returns t if object is both an input port and an output port otherwise returns f Any object satisfying this predicate also satisfies port input port and output port 160 MIT Scheme Reference guarantee port object procedure guarantee input port object procedure guarantee output port object procedure guarantee i o port object procedure These procedures check the type of object signalling an error of type condition type wrong type argument if it is not a port input port output port or 1 0 port respectively Otherwise they return object The next five procedures return the runtime system s standard ports All of the standard ports are dynamically bound by the REP
360. o the objects themselves read returns the next object parsable from input port updating input port to point to the first character past the end of the written representation of the object If an end of file is encountered in the input before any characters are found that can begin an object read returns an end of file object The input port remains open and further attempts to read will also return an end of file object If an end of file is encountered after the beginning of an object s written representation but the written representation is incomplete and therefore not parsable an error is signalled eof object object procedure Returns t if object is an end of file object otherwise returns f read char no hang input port procedure If input port can deliver a character without blocking this procedure acts exactly like read char immediately returning that character Otherwise f is returned unless input port is a file port at end of file in which case an end of file object is returned In no case will this procedure block waiting for input read string char set input port procedure Reads characters from input port until it finds a terminating character that is a member of char set see Section 5 6 Character Sets page 68 or encounters end of file The port is updated to point to the terminating character or to end of file if no terminating character was found read string returns the characters up to but excluding the
361. ocedure Does a reverse DNS lookup on ip address returning the internet host name corre sponding to that address or f if there is no such host get host by address N022N027N000N020 gt swissnet ai mit edu canonical host name host name procedure Finds the canonical internet host name for host name For example canonical host name zurich gt zurich ai mit edu canonical host name www swiss swissnet ai mit edu In both examples the default internet domain ai mit edu is added to host name In the second example www swiss is an alias for another computer named swissnet get host name procedure Returns the string that identifies the computer that MIT Scheme is running on Usually this is an unqualified internet host name i e the host name without the domain suffix get host name gt aarau Chapter 15 Operating System Interface 223 os hostname procedure Returns the canonical internet host name of the computer that MIT Scheme is running on So in contrast to the example for get host name os hostname gt aarau ai mit edu allocate host address procedure Allocates and returns an IP address object This is just a string of a fixed length current 4 bytes into which an IP address may be stored This procedure is used to generate an appropriate argument to be passed to tcp server connection accept allocate host address gt Xe 034 241 host address any procedure Return an IP add
362. ocedure Returns t if object is a 1D table otherwise returns f Any object that satisfies this predicate also satisfies list 1d table put 1d table key datum procedure Creates an association between key and datum in 1d table Returns an unspecified value 1d table remove 1d table key procedure Removes any association for key in 1d table and returns an unspecified value 1d table get 1d table key default procedure Returns the datum associated with key in 1d table If there is no association for key default is returned 1d table lookup 1d table key if found if not found procedure If found must be a procedure of one argument and if not found must be a procedure of no arguments If 1d table contains an association for key if found is invoked on the datum of the association Otherwise if not found is invoked with no arguments In either case the result of the invoked procedure is returned as the result of 1d table lookup 1d table alist 1d table procedure Returns a newly allocated association list that contains the same information as 1d table 11 3 The Association Table MIT Scheme provides a generalization of the property list mechanism found in most other implementations of Lisp a global two dimensional association table This table is indexed by two keys called x key and y key in the following procedure descriptions These keys and the datum associated with them can be arbitrary objects eq is used to discriminate ke
363. ocument 1 1 1 Errors When this manual uses the phrase an error will be signalled it means that Scheme will call error which normally halts execution of the program and prints an error message When this manual uses the phrase it is an error it means that the specified action is not valid in Scheme but the system may or may not signal the error When this manual says that something must be it means that violating the requirement is an error 1 1 2 Examples This manual gives many examples showing the evaluation of expressions The examples have a common format that shows the expression being evaluated on the left hand side an arrow in the middle and the value of the expression written on the right For example 1 2 gt 3 Sometimes the arrow and value will be moved under the expression due to lack of space Occasionally we will not care what the value is in which case both the arrow and the value are omitted If an example shows an evaluation that results in an error an error message is shown prefaced by error Chapter 1 Overview 5 1 foo Illegal datum An example that shows printed output marks it with 4 begin write foo bar 4 foo bar When this manual indicates that the value returned by some expression is unspecified it means that the expression will evaluate to some object without signalling an error but that programs should not depend on the value in any
364. oe Rucker 194 file pathname 9 b ia cec dus 194 file readable riadas RUD 201 file regular pcia wei ee bd nds 200 file symbolic l3nk 242 5 212 9 iria 200 file time gt global decoded time 210 file time gt global time string 211 file time gt local decoded time 210 file time gt local time string 211 file time gt universal time 210 file touch i i ese a ic 203 file type direct il liebe Pa bi 200 file typ indirect ceid aripi kinine eas eas 200 file writeable 9 o dus rei 201 fill cirel6 22 oem EC bu aes P PETS 261 fill circle on x graphics device 261 firLI pOTXyBOn ille xen DEus 265 fill polygon on win32 graphics device 265 find color on os2 graphics device 267 find color on win32 graphics device 265 find module 2 or oa aa ea 277 find restart wise v oes peter 231 235 236 first e vacuecga ee A A 92 295 ds C 57 o M Em 57 PP heb MeL 57 PPA a8 E E E EE A E E AAA 57 O i 57 sh AE EEE EEE 57 fir RR 57 o ep EEEE EE EE 57 an e E E E NE EE E E YES 5T PA ied ea cons Eie deeds 57 ol ee ea aai 58 fTxldldd6s l sbeszeePWe Ren L4 QUE Raed 58 fix divide seb RASSE 58 o e AA rin E E EAE 57 nnb N eoe ehh obe d epu oy ER dac deris ds 57 Pax Shee ose ea aed ale eae UOTE Wes 58 fiz negative lese onadan kiea a gaa 57 EDISTO RN 58 Fie A T 58 f1x poBTUtive iaa 5T fix quotient lr th RR 5T fixiremadjnder g i
365. of an implementation restriction or it may silently coerce its result to an inexact number Such a coercion may cause an error later An implementation may use floating point and other approximate representation strate gies for inexact numbers This report recommends but does not require that the IEEE 32 bit and 64 bit floating point standards be followed by implementations that use flonum representations and that implementations using other representations should match or ex ceed the precision achievable using these floating point standards In particular implementations that use flonum representations must follow these rules A flonum result must be represented with at least as much precision as is used to express any of the inexact arguments to that operation It is desirable but not required for potentially inexact operations such as sqrt when applied to exact arguments to produce exact answers whenever possible for example the square root of an exact 4 ought to be an exact 2 If however an exact number is operated upon so as to produce an inexact result as by sqrt and if the result is represented as a flonum then the most precise flonum format available must be used but if the result is represented in some other way then the representation must have at least as much precision as the most precise flonum format available Although Scheme allows a variety of written notations for numbers any particular im plementation may support o
366. ogram 12 3 Continuations call with current continuation procedure procedure Procedure must be a procedure of one argument Packages up the current continua tion see below as an escape procedure and passes it as an argument to procedure The escape procedure is a Scheme procedure of one argument that if it is later passed a value will ignore whatever continuation is in effect at that later time and will give the value instead to the continuation that was in effect when the escape procedure was created The escape procedure created by call with current continuation has unlimited extent just like any other procedure in Scheme It may be stored in variables or data structures and may be called as many times as desired The following examples show only the most common uses of this procedure If all real programs were as simple as these examples there would be no need for a procedure with the power of call with current continuation call with current continuation lambda exit for each lambda x if negative x exit x 54 0 37 3 245 19 t gt 3 150 MIT Scheme Reference define list length lambda obj call with current continuation lambda return letrec r lambda obj cond null obj 0 pair obj r cdr obj 1 else return f r obj list length 1 2 3 4 gt 4 list length ab c gt df A common use of call with current continuation is for structured non local ex
367. ogram performs an arithmetic operation that results in a floating point overflow The operator field contains the procedure that imple ments the operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure condition type floating point underflow operator operands condition type This type is generated when a program performs an arithmetic operation that results in a floating point underflow The operator field contains the procedure that im plements the operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure 248 MIT Scheme Reference condition type primitive procedure error operator condition type operands This is an abstract type It indicates that an error was generated by a primitive procedure call Primitive procedures are distinguished from ordinary procedures in that they are not written in Scheme but instead in the underlying language of the Scheme implementation The operator field contains the procedure that implements the operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure condition type system call error operator operands condition type system call error type This is the most common condition type generated by primitive procedures A con dition of this type indicates that the primitive made a
368. oks up a color previously defined by define color This returns the color in its most efficient form for operations set foreground color or set background color draw ellipse left top right bottom operation on win32 graphics device Draw an ellipse Left top right and bottom indicate the coordinates of the bounding rectangle of the ellipse Circles are merely ellipses with equal width and height Note that the bounding rectangle has horizontal and vertical sides Ellipses with rotated axes cannot be drawn The rectangle applies to the center of the line used to draw the ellipse if the line width has been set to greater than 1 then the ellipse will spill outside the bounding rectange by half of the line width fill polygon points operation on win32 graphics device Draws a filled polygon using the current foreground color Points is a vector of real numbers The numbers are in the order x1 yl x2 y2 xn yn For example graphics operation device fill polygon 0 0 0 1 1 0 draws a solid triangular region between the points 0 0 0 1 and 1 0 load bitmap pathname operation on win32 graphics device The graphics device contents and size are initialized from the windows bitmap file specified by pathname If no file type is supplied then a BMP extension is added If a clip rectangle is in effect when this procedure is called it is necessary to redefine the clip rectangle afterwards save bitmap pathname operation on win32 graphi
369. on text process lunar text no moon string find next char string char procedure substring find next char string start end char procedure string find next char ci string char procedure substring find next char ci string start end char procedure Returns the index of the first occurrence of char in the string substring returns f if char does not appear in the string For the substring procedures the index returned is relative to the entire string not just the substring The ci procedures don t distinguish uppercase and lowercase letters string find next char Adam HA gt 0 substring find next char Adam 1 4 HA gt H substring find next char ci Adam 1 4 HA gt 2 string find next char in set string char set procedure substring find next char in set string start end char set procedure Returns the index of the first character in the string or substring that is also in char set or returns f if none of the characters in char set occur in string For the substring procedure only the substring is searched but the index returned is relative to the entire string not just the substring string find next char in set my string char set alphabetic start position of the first word in my string Can be used as a predicate if string find next char in set my string char set contains parentheses no parentheses string find previous char string char procedure substring find previous char string st
370. on x xxxeyyy In other words the number is printed as a mantissa between zero inclusive and ten exclusive and an exponent engineering is like scientific except that the exponent is always a power of three and the mantissa is constrained to be between zero inclusive and 1000 exclusive If normal is specified the number will be printed in positional notation if 1t is small enough otherwise it is printed in scientific nota tion A number is small enough when the number of digits that would be printed using positional notation does not exceed the number of digits of precision in the underlying floating point number representation IEEE double precision floating point numbers have 17 digits of precision This three element list may be abbreviated in two ways First the symbol normal may be used which is equivalent to the list normal 0 normal Second the third element of the list format type may be omitted in which case it defaults to normal The default value for flonum unparser cutoff is normal If it is bound to a value different from those described here number gt string issues a warning and acts as though the value had been normal Some examples of flonum unparser cutoff number gt string 4 atan 1 1 gt 3 141592653589793 fluid let flonum unparser cutoff relative 5 number gt string 4 atan 1 1 3 1416 fluid let flonum unparser cutoff relative 5 number gt string 4000
371. oned before thunk is invoked dynamic wind before thunk after procedure Calls thunk without arguments returning the result s of this call Before and after are called also without arguments as required by the following rules note that in the absence of calls to continuations captured using call with current continuation the three arguments are called once each in order Before is called whenever execu tion enters the dynamic extent of the call to thunk and after is called whenever it exits that dynamic extent The dynamic extent of a procedure call is the period between when the call is initiated and when it returns In Scheme because of call with current continuation the dynamic extent of a call may not be a single connected time period It is defined as follows Chapter 12 Procedures 151 e The dynamic extent is entered when execution of the body of the called procedure begins e The dynamic extent is also entered when execution is not within the dynamic ex tent and a continuation is invoked that was captured using call with current continuation during the dynamic extent e It is exited when the called procedure returns e It is also exited when execution is within the dynamic extent and a continuation is invoked that was captured while not within the dynamic extent If a second call to dynamic wind occurs within the dynamic extent of the call to thunk and then a continuation is invoked in such a way that the afters from t
372. only be used within the dynamic extent of procedure 14 8 Prompting This section describes procedures that prompt the user for input Why should the programmer use these procedures when it is possible to do prompting using ordinary input and output procedures One reason is that the prompting procedures are more succinct However a second and better reason is that the prompting procedures can be separately customized for each user interface providing more natural interaction The interfaces for Edwin and for GNU Emacs have already been customized in this fashion because Edwin and Emacs are very similar editors their customizations provide very similar behavior Each of these procedure accepts an optional argument called port which if given must be an 1 0 port If not given this port defaults to the value of interaction i o port this is initially the console 1 0 port prompt for command expression prompt port procedure Prompts the user for an expression that is to be executed as a command This is the procedure called by the REP loop to read the user s expressions If prompt is a string it is used verbatim as the prompt string Otherwise 1t must be a pair whose car is standard and whose cdr is a string in this case the prompt string is formed by prepending to the string the current REP loop level number and a space Also a space is appended to the string unless it already ends in a space or is an empty string The default
373. or is equally useful if not more so but implementation restrictions prohibit a uniform interface The drawing mode an exact integer in the range O to 15 inclusive determines how the figure being drawn is combined with the background over which it is drawn to generate the final result Initially the drawing mode is set to source so that the new output overwrites whatever appears in that place Useful alternative drawing modes can for example erase what was already there or invert it Altogether 16 boolean operations are available for combining the source what is being drawn and the destination what is being drawn over The source and destination are combined by the device on a pixel by pixel basis as follows Chapter 17 Graphics 255 Mode Meaning 0 ZERO erase use background color 1 source AND destination 2 source AND NOT destination 3 source 4 NOT source AND destination 5 destination 6 source XOR destination 7 source OR destination 8 NOT source OR destination 9 NOT source XOR destination 10 NOT destination 11 source OR NOT destination 12 NOT source 13 NOT source OR destination 14 NOT source OR NOT destination 15 ONE use foreground color The line style an exact integer in the range O to 7 inclusive determines which parts of a line are drawn in the foreground color and which in the background color The default line style solid draws the entire line in the foreground color Alter
374. or RET En 91 s bvector fill 4i s 26 090m v ES 104 subvector move left esses 104 subvector move Tigbt oo o ooooo 104 Symbol BStrl g 2M eo ide I0 97 111 Symbol append s spieri bsan pee priui 113 symbol hash accion cd e 113 symbol hash mod hls ge b s 113 Symbol in rad 111 SynbOol a E 113 system clockitaledariid idas Be bv p eden 214 system global environment 156 system library directory pathname 196 system library pathname 196 T pr 109 GAN o iccebeseve e unit o 52 tcp server connection accept 221 template rra ras 5 temporary directory pathname 199 temporary file pathname 199 OTC iors sie ii ive Re eet ed og china ee es 92 the environment cece eee eee 157 thero ezists trebis neice se RARE Seed 99 A Ace en em a 92 time zone string esee eee eee 213 time zone i 9 RR dda eet eS evan 208 trace output port x M pedo deus 160 itree CODpy cec her dea 90 aA a e E E dio 109 il A E EAE EA EEEE ETE 51 304 truncate e xact cii re bis ie 51 EPs E a EE Ba ia 32 34 type descriptor tise esos ll 34 MAG oye aos Seatac Fere etisalat eas 276 UR ida es 276 unchecked sehera arenira iraa ds chp ind de 275 hast aid 134 universal time gt file time 209 universal time gt global decoded time 209 universal time gt global time string 210 universal time gt loc
375. or a more complete description of this Another name for the procedure call expression is combination This word is more specific in that it always refers to the expression procedure call sometimes refers to the process of calling a procedure Unlike some other dialects of Lisp Scheme always evaluates the operator expression and the operand expressions with the same evaluation rules and the order of evaluation is unspecified 3 4 of Cf 3 4 gt 12 A number of procedures are available as the values of variables in the initial environment for example the addition and multiplication procedures in the above examples are the values of the variables and New procedures are created by evaluating lambda expressions If the operator is a syntactic keyword then the expression is not treated as a procedure call it is a special form Thus you should not use syntactic keywords as procedure names If you were to bind one of these keywords to a procedure you would have to use apply to call the procedure MIT Scheme signals an error when such a binding is attempted 16 MIT Scheme Reference Chapter 2 Special Forms 17 2 Special Forms A special form is an expression that follows special evaluation rules This chapter de scribes the basic Scheme special forms 2 1 Lambda Expressions lambda formals expression expression special form A lambda expression evaluates to a procedure The environment in effect when
376. or line style respectively of graphics device The mode or style will remain in effect until subsequent changes or bindings 17 5 Buffering of Graphics Output To improve performance of graphics output most graphics devices provide some form of buffering By default Scheme s graphics procedures flush this buffer after every drawing operation The procedures in this section allow the user to control the flushing of the output buffer graphics enable buffering graphics device procedure Enables buffering for graphics device In other words after this procedure is called graphics operations are permitted to buffer their drawing requests This usually means that the drawing is delayed until the buffer is flushed explicitly by the user or until it fills up and is flushed by the system graphics disable buffering graphics device procedure Disables buffering for graphics device By default all graphics devices are initialized with buffering disabled After this procedure is called all drawing operations perform their output immediately before returning Note graphics disable buffering flushes the output buffer if necessary graphics flush graphics device procedure Flushes the graphics output buffer for graphics device l his operation has no effect for devices that do not support buffering or if buffering is disabled for the device 17 6 Clipping of Graphics Output Scheme provides a rudimentary mechanism for restricting graphics ou
377. ound foreground color pointerColor Foreground foreground color The window is created with a backing store attribute of Always The window s name and icon name are initialized to scheme graphics 17 9 2 Utilities for X Graphics x graphics open display display name procedure Opens a connection to the display whose name is display name returning a display object If unable to open a connection f is returned Display name is normally a string which is an X display name in the usual form however f is also allowed meaning to use the value of the unix environment variable DISPLAY x graphics close display display Closes display after calling this procedure it is an error to use display for any purpose Any windows that were previously opened on display are destroyed and their resources returned to the operating system procedure 260 MIT Scheme Reference x close all displays procedure Closes all open connections to X displays Equivalent to calling x close display on all open displays x geometry string x y width height procedure This procedure creates and returns a standard X geometry string from the given arguments X and y must be either exact integers or while width and height must be either exact non negative integers or Usually either x and y are both specified or both similarly for width and height If only one of the elements of such a pair is specified it is ignored Examples x geometry
378. ow is returned Display specifies which X display the window is to be opened on if it is f or a string it is passed as an argument to x open display and the value returned by that procedure is used in place of the original argument Geometry is an X geometry string or which means to use the default geometry which is specified as a resource Suppress map if given may take two forms First it may be a boolean if the default the window is automatically mapped after it is created otherwise t means to suppress this automatic mapping The second form is a vector of three elements The first element is a boolean with the same meaning as the boolean form of suppress map The second element is a string which specifies an alternative resource name to be used for looking up the window s resources The third element is also a string which specifies a class name for looking up the window s resources The default value for suppress map is f The default resource and class names are schemeGraphics and SchemeGraphics respectively The window is initialized using the resource and class names specified by suppress map and is sensitive to the following resource properties Property Class Default geometry Geometry 512x384 0 0 font Font fixed borderWidth BorderWidth 2 internalBorder BorderWidth border width background Background white foreground Foreground black borderColor BorderColor foreground color cursorColor Foregr
379. owercase letters string suffix ous bulbous gt dit string suffix any string gt dit Chapter 6 Strings 81 6 8 Regular Expressions MIT Scheme provides support for using regular expressions to search and match strings This manual does not define regular expressions instead see section Syntax of Regular Expressions in The Emacs Editor The regular expression support is a run time loadable option To use it execute load option regular expression once before calling any of the procedures defined here Procedures that perform regular expression match and search accept standardized argu ments Regexp is the regular expression it is a string String is the string being matched or searched Procedures that operate on substrings also accept start and end index arguments with the usual meaning The optional argument case fold says whether the match search is case sensitive if case fold is f it is case sensitive otherwise it is case insensitive The optional argument syntax table is a character syntax table that defines the character syntax such as which characters are legal word constituents This feature is primarily for Edwin so character syntax tables will not be documented here Supplying f for or omitting syntax table will select the default character syntax equivalent to Edwin s fundamental mode re string match regexp string case fold syntax table procedure re substring match regexp string
380. parse the string If host is not given or f the host component from defaults is used instead if defaults is not given the host component from default pathname defaults is used gt namestring pathname procedure namestring returns a newly allocated string that is the filename corresponding to pathname gt namestring gt pathname usr morris minor van gt usr morris minor van This introduction is adapted from Common Lisp The Language second edition section 23 1 Chapter 15 Operating System Interface 189 pathname simplify pathname procedure Returns a pathname that locates the same file or directory as pathname but is in some sense simpler Note that pathname simplify might not always be able to simplify the pathname e g on unix with symbolic links the directory usr morris need not be the same as usr In cases of uncertainty the behavior is conservative returning the original or a partly simplified pathname pathname simplify usr morris morris dance gt pathname usr morris dance 15 1 2 Components of Pathnames A pathname object always has six components described below These components are the common interface that allows programs to work the same way with different file systems the mapping of the pathname components into the concepts peculiar to each file system is taken care of by the Scheme implementation host The name of the file system on which the file reside
381. pe as being like another type except for certain aspects which are redefined Name is the name of the type Model is the name of a type Check convert return and revert are procedures or the value f A means use the default value which in the second form means use the definition provided for model The defaults are check lambda x t i e unchecked convert lambda x x ie no translation performed return lambda x x ie no translation performed revert lambda x y unspecific i e no update performed The unchecked windows type see below is defined as define windows type unchecked f f f f Windows types are not first class values so they cannot be stored in variables or defined using define define my type unchecked Unbound variable define similar windows type my type unchecked the correct way Scheme characters must be converted to integers This is accomplished as follows define windows type char char check char gt integer convert integer gt char convert return value uf cannot be passed by reference unchecked windows type The type which is not checked and undergoes only the basic conversion from a Scheme integer to a C integer or from a Scheme string to a C pointer to the first byte of the string Returned unchecked values are returned as integers bool windows type Scheme booleans are analogous to C integers 0 and 1 Windows type bool have been defined as define window
382. pec may be any acceptable color specification Note that the color names defined this way are available to any OS 2 graphics device and the names do not have to be defined for each device Color names defined by this interface may also be used when setting the colors of the Scheme console window or the colors of Edwin editor windows find color name operation on os2 graphics device Looks up a color previously defined by define color This returns the color in its most efficient form for operations set foreground color or set background color 17 11 3 Window Operations for OS 2 Graphics These operations control the window that contains the OS 2 graphics device They provide facilities to change the window s size and position to raise and lower the window relative to other windows on the desktop to hide or minimize the window and to restore it from the hidden or minimized state to activate or deactivate the window that is control the keyboard focus and to control the text that appears in the window s title bar window position operation on os2 graphics device This operation returns the position of the graphics device window on the desktop The position is returned as two values see Section 12 3 Continuations page 149 which are the x and y coordinates of the position These coordinates are in units of pels pixels and measure the distance between the lower left hand corner of the desktop and the lower left hand corner of the graph
383. pecified by the elements to its left The first element of the list is either the symbol absolute or the symbol relative If the first element in the list is the symbol absolute then the directory component and subsequently the pathname is absolute the first component in the sequence is to be found at the root of the file system If the directory is relative then the first component is to be found in some as yet unspecified directory typically this is later specified to be the current working directory Aside from absolute and relative which may only appear as the first element of the list each subsequent element in the list is either a string which is a literal component the symbol wild meaningful only when used in conjunction with the directory reader or the symbol up meaning the next directory is the This description is adapted from Common Lisp The Language second edition section 23 1 1 Chapter 15 Operating System Interface 191 name type version make pathname host device directory name type version 6 parent of the previous one up corresponds to the file in unix and PC file systems The following note does not refer to any file system currently supported by MIT Scheme but is included for completeness In file systems that do not have hierarchical structure a specified directory component will always be a list whose first element is absolute If the system does not support d
384. peration on x graphics device Returns a Scheme equivalent of the X font structure for the font named font name If the string font name does not name a font known to the X server or names a 16 bit font is returned x font structure name font structure procedure x font structure direction font structure procedure x font structure all chars exist font structure procedure x font structure default char font structure procedure x font structure min bounds font structure procedure x font structure max bounds font structure procedure x font structure start index font structure procedure x font structure character bounds font structure procedure x font structure max ascent font structure procedure x font structure max descent font structure procedure These procedures extract the components of the font description structure returned by the X graphics operation font structure A more complete description of these com ponents appears in documentation of the XLoadQueryFont Xlib call start index is the index of the first character available in the font The min bounds and max bounds components are structures of type x character bounds and the character bounds component is a vector of the same type Chapter 17 Graphics 263 x character bounds lbearing character bounds procedure x character bounds rbearing character bounds procedure x character bounds width character bounds procedure x character bounds ascent character bounds procedure
385. pes 109 10 1 Booleans ese obsecro edad en 109 10 2 Symbol tei baee denned selina Bip abend ade ad Bee 110 10 3 Celis iusacertai meter p aw tee Ed d Cep aS Rea 113 I0 4 Records c iuda decis pi 114 10 9 E O rne b tete ipee n Red 116 10 6 Streams em Rede ree Oeo ce blades 118 10 7 Weak PaltS22 22 2 ue bero ententa cod ERR ns a 119 11 lASSOCLULlOlS rzesxew x99 REA CER REG ORE RE 121 11 1 Association Lists sssseeeeessee ese 121 11 2 1D Tables elt eR rr e 123 11 3 The Association Table ooooooooooomcmmooo 124 11 4 Hash Tables sacco er tbt tnt Rn 125 11 4 1 Construction of Hash Tables 126 11 4 2 Basic Hash Table Operations 127 11 4 3 Resizing of Hash Tables o 129 11 4 4 Address Hashing 00 00 eee ee eee 131 11 4 5 Low Level Hash Table Operations 132 11 5 Object Hashing sass sa eee na aed agen eee ans eee be 133 11 6 Red Black Trees 0 00 e eee 135 11 7 Weight Balanced Trees 0 000 cee eee ee eens 138 11 7 1 Construction of Weight Balanced Trees 139 11 7 2 Basic Operations on Weight Balanced Trees 141 11 7 3 Advanced Operations on Weight Balanced Trees vi MIT Scheme Reference 12 JProced fes sse ek e rx RR Roe 147 12 1 Procedure Operations lsssssseees else eese 147 12 2 Primitive Procedures oo oooocooocoorrmoorooo 149 12 3 Qontmnuatilong aou idis edente ex
386. ple restart george This restart is named george lambda 3 gt 3 with simple restart george This restart is named george lambda invoke restart find restart george unspecific with simple restart george This restart is named george lambda car 3 The object 3 passed as the first argument to car is not the correct type To continue call RESTART with an option number 5 5 E RESTART 3 gt Specify an argument to use in its place RESTART 2 This restart is named george RESTART 1 gt Return to read eval print level 1 with restart name reporter effector interactor thunk procedure Invokes thunk in a dynamic environment created by adding a restart named name to the existing named restarts Reporter may be used during the execution of thunk to produce a description of the newly created restart it must either be a procedure of one argument a port or a string Effector is a procedure which will be called when the restart is invoked by invoke restart Interactor specifies the arguments that are to be passed to effector when it is invoked interactively it may be either a procedure of no arguments or f If interactor is f this restart is not meant to be invoked interactively The value returned by with restart is the value returned by thunk Should the restart be invoked by a condition handler however the effector will not return back to the handler that invoked it Inst
387. plied Probability Vol 1 No 3 1991 At the time it was implemented this was a good algorithm for general purposes but the state of the art in random number gen eration is constantly changing If necessary the implementation will be updated to use a new algorithm while retaining the same interface The interface described here is very similar to that of Common Lisp random modulus state procedure Modulus must be a positive real number random returns a pseudo random number between zero inclusive and modulus exclusive The exactness of the returned number is the same as the exactness of modulus Additionally if modulus is an exact integer the returned number will be also Usually modulus is either an exact integer or an inexact real the current implementation has been tuned to make these two cases fast If state is given and not f it must be a random state object otherwise it defaults to the value of the variable random state This object is used to maintain the Chapter 4 Numbers 61 state of the pseudo random number generator and is altered as a side effect of the random procedure random 1 0 gt 32744744667719056 random 1 0 gt 01668326768172354 random 10 gt 3 random 10 gt 8 random 100 gt 38 random 100 gt 63 random 100 3 130501475769920525 6755399441055744 random 100 3 gt 170571694016427575 13510798882111488 flo random unit state procedure State must be a random stat
388. ppear in the written representation are enclosed in doublequotes and within those strings backslash and doublequote are escaped by backslashes write performs discretionary output flushing and returns an unspecified value display object output port procedure Writes a representation of object to output port Strings appear in the written repre sentation as if written by write string instead of by write Character objects ap pear in the representation as if written by write char instead of by write display performs discretionary output flushing and returns an unspecified value newline output port procedure Writes an end of line to output port performs discretionary output flushing and returns an unspecified value Equivalent to write char newline output port fresh line output port procedure Most output ports are able to tell whether or not they are at the beginning of a line of output If output port is such a port this procedure writes an end of line to the port only if the port is not already at the beginning of a line If output port is not such a port this procedure is identical to newline In either case fresh line performs discretionary output flushing and returns an unspecified value write line object output port procedure Like write except that it writes an end of line to output port after writing object s representation This procedure performs discretionary output flushing and returns an unspecified value fl
389. presentation of the given number in the given radix such that let number number radix radix eqv number string gt number number gt string number radix radix is true It is an error if no possible result makes this expression true If number is inexact the radix is 10 and the above expression can be satisfied by a result that contains a decimal point then the result contains a decimal point and is expressed using the minimum number of digits exclusive of exponent and trailing zeroes needed to make the above expression true otherwise the format of the result is unspecified The result returned by number gt string never contains an explicit radix prefix Note The error case can occur only when number is not a complex number or is a complex number with an non rational real or imaginary part Rationale If number is an inexact number represented using flonums and the radix is 10 then the above expression is normally satisfied by a result containing a decimal point The unspecified case allows for infinities NaNs and non flonum representa tions flonum parser fast variable This variable controls the behavior of string gt number when parsing inexact numbers Specifically it allows the user to trade off accuracy against speed When set to its default value f the parser provides maximal accuracy as required by the Scheme standard If set to t the parser uses faster algorithms that will sometimes introduce smal
390. program should use one of the two procedures above to dispatch on the available types This procedure opens and initializes the device which remains valid until explicitly closed by the procedure graphics close Depending on the implementation of the 252 MIT Scheme Reference graphics device if this object is reclaimed by the garbage collector the graphics device may remain open or it may be automatically closed While a graphics device remains open the resources associated with it are not released graphics close graphics device procedure Closes graphics device releasing its resources Subsequently it is an error to use graphics device 17 2 Coordinates for Graphics Each graphics device has two different coordinate systems associated with it device coordinates and virtual coordinates Device coordinates are generally defined by low level characteristics of the device itself and often cannot be changed Most device coordinate systems are defined in terms of pixels and usually the upper left hand corner is the origin of the coordinate system with x coordinates increasing to the right and y coordinates increasing downwards In contrast virtual coordinates are more flexible in the units employed the position of the origin and even the direction in which the coordinates increase A virtual coordinate system is defined by assigning coordinates to the edges of a device Because these edge coordinates are arbitrary real numbers any Car
391. program arguments option procedure Runs program passing it the given command line arguments Program must be either the name of a program on the path or else a pathname to a specific program 216 MIT Scheme Reference Arguments must be a list of strings each string is a single command line argument to the program The options are a sequence of keyword value pairs that specify optional behavior See below for more information about options run synchronous subprocess waits until the subprocess completes its execution and returns the exit code from the subprocess If the subprocess is killed or stopped an error is signalled and the procedure does not return 15 7 2 Subprocess Conditions If a subprocess spawned by one of the above procedures is killed or suspended then one of the following errors will be signalled condition type subprocess signalled subprocess reason condition type This condition type is a subtype of condition type subprocess abnormal termination It is signalled when the subprocess is killed Subprocess is an object that represents the subprocess involved The internals of this object can be accessed but the interface is not documented at this time see the source code for details Reason is interesting only on unix systems where it is the signal that killed the process On other systems it has a fixed value that conveys no useful information condition type subprocess stopped subprocess reason conditio
392. pter 2 Special Forms 31 A step may be omitted in which case the effect is the same as if variable init variable had been written instead of variable init do vec make vector 5 i10 i 1 i 5 vec vector set vec i i gt 0 1 2 3 4 let Ox 13 5 7 9 do x x cdr x sum O sum car x null x sum gt 25 2 10 Structure Definitions This section provides examples and describes the options and syntax of define structure an MIT Scheme macro that is very similar to defstruct in Common Lisp The differences between them are summarized at the end of this section For more information see Steele s Common Lisp book define structure name structure option slot description special form Each slot description takes one of the following forms slot name slot name default init slot option value The fields name and slot name must both be symbols The field default init is an expression for the initial value of the slot It is evaluated each time a new instance is constructed If it is not specified the initial content of the slot is undefined Default values are only useful with a BOA constructor with argument list or a keyword constructor see below Evaluation of a define structure expression defines a structure descriptor and a set of procedures to manipulate instances of the structure These instances are repre sented as records by default see Section 10 4 Records page 114
393. put to truncated string 40 lambda write inf gt f inf set cdr inf inf with output to truncated string 40 lambda write inf gt t inf inf inf inf inf inf inf inf inf inf Chapter 14 Input Output 165 write to string object k procedure Writes object to a string output port and returns the resulting newly allocated string If k is supplied and not f this procedure is equivalent to with output to truncated string k lambda write object otherwise it is equivalent to with output to string lambda write object 14 4 Input Procedures This section describes the procedures that read input Input procedures can read either from the current input port or from a given port Remember that to read from a file you must first open a port to the file Input ports can be divided into two types called interactive and non interactive Interac tive input ports are ports that read input from a source that is time dependent for example a port that reads input from a terminal or from another program Non interactive input ports read input from a time independent source such as an ordinary file or a character string All optional arguments called input port if not supplied default to the current input port read char input port procedure Returns the next character available from input port updating input port to point to the following character If no more characters are available
394. r a b c gt tab c vector copy vector procedure Returns a newly allocated vector that is a copy of vector 102 MIT Scheme Reference list gt vector list procedure Returns a newly allocated vector initialized to the elements of list The inverse of list gt vector is vector gt list list gt vector dididit dah gt dididit dah make initialized vector k initialization procedure Similar to make vector except that the elements of the result are determined by calling the procedure initialization on the indices For example make initialized vector 5 lambda x x x gt H 0 149 16 vector grow vector k procedure K must be greater than or equal to the length of vector Returns a newly allocated vector of length k The first vector length vector elements of the result are initialized from the corresponding elements of vector The remaining elements of the result are unspecified vector map procedure vector procedure Procedure must be a procedure of one argument vector map applies procedure element wise to the elements of vector and returns a newly allocated vector of the results in order from left to right The dynamic order in which procedure is applied to the elements of vector is unspecified vector map cadr a b d e g h gt be h vector map lambda n expt n n 1 2 3 4 gt 1 4 27 256 vector map 5 7 9 gt 5 7 9 8 2 Selecting Vector Components vector o
395. r of the characters in the given string or substring reverse string and reverse substring return newly allocated strings reverse string and reverse substring modify their argument strings and return an unspecified value 84 MIT Scheme Reference zab rab oof rab reverse string foo bar baz reverse substring foo bar baz 4 7 let foo foo bar baz reverse string foo foo gt zab rab oof let foo foo bar baz reverse substring foo 4 7 foo gt foo rab baz V 4 6 10 Variable Length Strings MIT Scheme allows the length of a string to be dynamically adjusted in a limited way When a new string is allocated by whatever method it has a specific length At the time of allocation it is also given a maximum length which is guaranteed to be at least as large as the string s length Sometimes the maximum length will be slightly larger than the length but it is a bad idea to count on this Programs should assume that the maximum length is the same as the length at the time of the string s allocation After the string is allocated the operation set string length can be used to alter the string s length to any value between 0 and the string s maximum length inclusive string maximum length string procedure Returns the maximum length of string The following is guaranteed lt string length string string maximum length string gt dit The maximum length of a string never changes set strin
396. r system provides a mechanism known as restarts that helps coordinate condition signalling code with condition handling code module of code that detects and signals conditions can provide procedures using with simple restart or with restart to be invoked by handlers that wish to continue abort or restart the computation These procedures called restart effectors are encapsulated in restart objects When a condition object is created it contains a set of restart objects each of which contains a restart effector Condition handlers can inspect the condition they are han dling using find restart to find restarts by name or condition restarts to see the entire set and they can invoke the associated effectors using invoke restart or invoke restart interactively Effectors can take arguments and these may be computed directly by the condition handling code or by gathering them interactively from the user The names of restarts can be chosen arbitrarily but the choice of name is significant These names are used to coordinate between the signalling code which supplies names for restarts and the handling code which typically chooses a restart effector by the name of its restart Thus the names specify the restart protocol implemented by the signalling code and invoked by the handling code The protocol indicates the number of arguments required by the effector code as well as the semantics of the arguments Scheme provides a convent
397. r wt type make wt tree type lt string wt type variable A standard tree type for trees with string keys String wt type could have been defined by define string wt type make wt tree type string lt make wt tree wt tree type procedure This procedure creates and returns a newly allocated weight balanced tree The tree is empty i e it contains no associations Wt tree type is a weight balanced tree type obtained by calling make wt tree type the returned tree has this type singleton wt tree wt tree type key datum procedure This procedure creates and returns a newly allocated weight balanced tree The tree contains a single association that of datum with key Wt tree type is a weight balanced tree type obtained by calling make wt tree type the returned tree has this type alist gt wt tree tree type alist procedure Returns a newly allocated weight balanced tree that contains the same associations as alist This procedure is equivalent to Chapter 11 Associations 141 lambda type alist let tree make wt tree type for each lambda association wt tree add tree car association cdr association alist tree 11 7 2 Basic Operations on Weight Balanced Trees This section describes the basic tree operations on weight balanced trees These opera tions are the usual tree operations for insertion deletion and lookup some predicates and a procedure for determining the number of associations in a tree
398. re This procedure is a generalization of car and cdr Path encodes a particular sequence of car and cdr operations which general car cdr executes on object Path is an exact non negative integer that encodes the operations in a bitwise fashion a zero 90 MIT Scheme Reference bit represents a cdr operation and a one bit represents a car The bits are executed LSB to MSB and the most significant one bit rather than being interpreted as an operation signals the end of the sequence For example the following are equivalent general car cdr object b1011 cdr car car object Here is a partial table of path operation equivalents b10 cdr b11 car b100 cddr b101 cdar b110 cadr b111 caar b1000 cdddr tree copy tree procedure This copies an arbitrary tree constructed from pairs copying both the car and cdr elements of every pair This could have been defined by define tree copy tree let loop tree tree if pair tree cons loop car tree loop cdr tree tree 7 2 Construction of Lists list object procedure Returns a list of its arguments list a 3 4 c gt a7 c list e x These expressions are equivalent list objl obj2 objN cons objl cons obj2 cons objN O make list k element procedure This procedure returns a newly allocated list of length k whose elements are all element If element is not supplied it defaults to the empty list 2 Not
399. ress object that specifies any host This object is useful only when passed as the address argument to open tcp server socket host address any 000 000 000 000 host address loopback procedure Return an IP address object that specifies the local loopback network interface The loopback interface is a software network interface that can be used only for commu nicating between processes on the same computer This address object is useful only when passed as the address argument to open tcp server socket host address loopback gt 177 000 000 001 224 MIT Scheme Reference Chapter 16 Error System 225 16 Error System The MIT Scheme error system provides a uniform mechanism for the signalling of errors and other exceptional conditions The simplest and most generally useful procedures in the error system are error is used to signal simple errors specifying a message and some irritant objects see Section 16 1 Condition Signalling page 226 Errors are usually handled by stopping the computation and putting the user in an error REPL warn is used to signal warnings see Section 16 1 Condition Signalling page 226 Warnings are usually handled by printing a message on the console and contin uing the computation normally ignore errors is used to suppress the normal handling of errors within a given dynamic extent see Section 16 3 Condition Handling page 229 Any error that occurs within the extent is trapp
400. returns t if the display supports color set background color color name operation on os2 graphics device set foreground color color name operation on os2 graphics device These operations change the colors associated with a window Color name must be one of the valid color specification forms listed below set background color and Chapter 17 Graphics 267 set foreground color change the colors to be used when drawing but have no effect on anything drawn prior to their invocation Because changing the background color affects the entire window we recommend calling graphics clear on the window s device afterwards The foreground color affects the drawing of text points and lines Colors are specified in one of these ways An integer between O and xffffff inclusive This is the OS 2 internal RGB value By name A limited number of names are understood by the system Names are strings e g red blue black More names can be registered with the define color operation RGB Red Green Blue triples A triple is a list of three integers between 0 and xff inclusive which specify the intensity of the red green and blue components of the color Thus 0 0 0 is black 0 0 128 is dark blue and 255 255 255 is white If the color is not available in the graphics device then the nearest available color is used instead define color name spec operation on os2 graphics device Define the string name to be the color specified by spec S
401. ring gt char set string procedure Returns a character set consisting of all the characters that occur in string ascii range gt char set lower upper procedure Lower and upper must be exact non negative integers representing ASCH character codes and lower must be less than or equal to upper This procedure creates and returns a new character set consisting of the characters whose ASCII codes are between lower inclusive and upper exclusive predicate gt char set predicate procedure Predicate must be a procedure of one argument predicate gt char set creates and returns a character set consisting of the ASCII characters for which predicate is true char set difference char set1 char set2 procedure Returns a character set consisting of the characters that are in char set1 but aren t in char set2 char set intersection char set procedure Returns a character set consisting of the characters that are in all of the char sets char set union char set procedure Returns a character set consisting of the characters that are in at least one o the char sets char set invert char set procedure Returns a character set consisting of the ASCII characters that are not in char set Chapter 6 Strings 71 6 Strings A string is a mutable sequence of characters In the current implementation of MIT Scheme the elements of a string must all satisfy the predicate char ascii if someone ports MIT Scheme to a non ASCII operating system
402. ring not substring The following procedure uses bit substring find next set bit to find all the set bits and display their indexes define scan bitstring bs let end bit string length bs let loop start 0 let next bit substring find next set bit bs start end if next begin write line next if lt next end loop next 1 9 3 Cutting and Pasting Bit Strings bit string append bit string 1 bit string 2 procedure Appends the two bit string arguments returning a newly allocated bit string as its result In the result the bits copied from bit string 1 are less significant smaller indices than those copied from bit string 2 Chapter 9 Bit Strings 107 bit substring bit string start end procedure Returns a newly allocated bit string whose bits are copied from bit string starting at index start inclusive and ending at end exclusive 9 4 Bitwise Operations on Bit Strings bit string zero bit string procedure Returns t if bit string contains only 0 bits otherwise returns f bit string bit string 1 bit string 2 procedure Compares the two bit string arguments and returns t if they are the same length and contain the same bits otherwise returns sf bit string not bit string procedure Returns a newly allocated bit string that is the bitwise logical negation of bit string bit string movec target bit string bit string procedure The destructive version of bit string not The argument
403. rinted using write typ ically with a space between each irritant To allow simple formatting we introduce a noise object printed using display The irritant list may contain ordinary objects interspersed with noise objects Each noise object is printed using display with no extra whitespace while each normal object is printed using write prefixed by a single space character Here is an example define error within procedure message irritant procedure error message irritant error irritant noise within procedure procedure error irritant noise This would format as follows Chapter 16 Error System 229 error within procedure Bad widget widget 32 invert widget Bad widget widget 32 within procedure invert widget Here are the operations supporting error messages format error message message irritants port procedure Message is typically a string although this is not required irritants a list of irritant objects and port an output port Formats message and irritants to port in the standard way Note that during the formatting process the depth and breadth to which lists are printed are each limited to small numbers to guarantee that the output from each irritant is not arbitrarily large error irritant noise value procedure Creates and returns a noise object whose value is value 16 3 Condition Handling The occurrence of a condition is signalled using signal condition signal condition att
404. rned with potentially disastrous effect on the garbage collector 58 MIT Scheme Reference fix divide fixnum fixnum procedure This procedure is like integer divide except that its arguments and its results must be fixnums It should be used in conjunction with integer divide quotient and integer divide remainder The following are bitwise logical operations on fixnums fix not fixnum procedure This returns the bitwise logical inverse of its argument When compiled it does not check the type of its argument fix not 0 gt 1 fix not 1 gt 0 fix not 1 gt 2 fix not 34 gt 33 fix and fixnum fixnum procedure This returns the bitwise logical and of its arguments When compiled it does not check the types of its arguments fix and x43 x0f gt 3 fix and x43 xf0 gt x40 fix andc fixnum fixnum procedure Returns the bitwise logical and of the first argument with the bitwise logical inverse of the second argument When compiled it does not check the types of its arguments fix andc x43 x0f gt x40 fix andc x43 xf0 gt 3 fix or fixnum fixnum procedure This returns the bitwise logical inclusive or of its arguments When compiled it does not check the types of its arguments fix or x40 3 gt x43 fix or x41 3 gt x43 fix xor fixnum fixnum procedure This returns the bitwise logical exclusive or of its arguments When compiled it does not check th
405. rocedure list list append map procedure list list procedure append map initial value procedure list list procedure Similar to map and map respectively except that the results of applying procedure to the elements of lists are concatenated together by append rather than by cons The following are equivalent except that the former is more efficient append map procedure list list apply append map procedure list list append map procedure list list procedure append map initial value procedure list list procedure Similar to map and map respectively except that the results of applying procedure to the elements of lists are concatenated together by append rather than by cons The following are equivalent except that the former is more efficient append map procedure list list apply append map procedure list list for each procedure list list procedure The arguments to for each are like the arguments to map but for each calls proce dure for its side effects rather than for its values Unlike map for each is guaranteed to call procedure on the elements of the lists in order from the first element to the last and the value returned by for each is unspecified let v make vector 5 for each lambda i vector set v i i i 01232 v gt 0 149 16 7 8 Reduction of Lists reduce procedure initial list procedure Combines all the elements of list using th
406. rocode id operating system name 221 microcode id operating system variant 221 y E ORO PS O bee tibeelonbe tia beset biases 48 minimize window on os2 graphics device 269 modulo i da epp bh PER dde pars 49 nonth long string so 206 bye IRL 212 fonth max days reu b ERR Ie daga 208 month short string 000 212 move window on win32 graphics device 265 move window on x graphics device 262 muffle warning 227 231 234 N Name gt Chay ereire resno ehh ae beh eda Sees 64 named ssa e coe hed Aare ved ee x E RO Ra ados 35 named lambda 4 2 2 2 err ren 18 22 29 nearest repl environment 157 D gativet rossa dios ea URN EP bep SS 48 Binding Index DOWLIDO cui a ii opo e rb Rui 169 MV cs ode et e pedes 109 ninth zc a hades EE wee ae AG 92 DOE da ia Glad eed sien 109 notification output port 160 231 nt file mode archive sssssu 202 nt file mode compressed 202 nt file mode directory 202 nt file mode hidden 04 202 nt file mode normal sess 202 nt file mode read only 202 nt file mode system 0 202 nt file mode temporary 202 a ele oa eg a ea E 91 92 119 number gt StLings iii seh cadens 54 number wt type et Rx ERRARE 140 nu mber d neevy es Pd he ed E 46 numeratobE eur 50 O
407. roduce an exact zero result even if the other argument is inexact 4 3 Implementation restrictions Implementations of Scheme are not required to implement the whole tower of subtypes see Section 4 1 Numerical types page 43 but they must implement a coherent subset consistent with both the purposes of the implementation and the spirit of the Scheme language For example an implementation in which all numbers are real may still be quite useful Implementations may also support only a limited range of numbers of any type subject to the requirements of this section The supported range for exact numbers of any type may be different from the supported range for inexact numbers of that type For example an implementation that uses flonums to represent all its inexact real numbers may support a practically unbounded range of exact integers and rationals while limiting the range of inexact reals and therefore the range of inexact integers and rationals to the dynamic range of the flonum format Furthermore the gaps between the representable inexact integers and rationals are likely to be very large in such an implementation as the limits of this range are approached MIT Scheme implements the whole tower of numerical types It has unlimited precision exact integers and exact rationals Flonums are used to implement all inexact reals on machines that support IEEE floating point arithmetic these are double precision floating point numbers
408. rsements Such a section may not be included in the Modified Version N Do not retitle any existing section as Endorsements or to conflict in title with any Invariant Section If the Modified Version includes new front matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document you may at your option designate some or all of these sections as invariant To do this add their titles to the list of Invariant Sections in the Modified Version s license notice These titles must be distinct from any other section titles You may add a section entitled Endorsements provided it contains nothing but endorsements of your Modified Version by various parties for example statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard You may add a passage of up to five words as a Front Cover Text and a passage of up to 25 words as a Back Cover Text to the end of the list of Cover Texts in the Modified Version Only one passage of Front Cover Text and one of Back Cover Text may be added by or through arrangements made by any one entity If the Document already includes a cover text for the same cover previously added by you or by arrangement made by the same entity you are acting on behalf of you may not add another but you may replace the old one on explicit permission from the previous publisher that added the old one
409. rts an argument in decoded time format to file time format decoded time gt file time local decoded time gt 925423191 decoded time gt file time global decoded time gt 925423195 decoded time gt string decoded time procedure Convert an argument in decoded time format to a time string decoded time gt string local decoded time Thu 29 Apr 1999 18 00 43 0400 decoded time gt string global decoded time gt Thu 29 Apr 1999 22 00 46 0000 file time gt universal time file time procedure Converts an argument in universal time format to file time format file time gt universal time file modification time 3133891907 file time gt local decoded time file time procedure file time gt global decoded time file time procedure Converts an argument in file time format to decoded time format The result is in the local time zone or UTC respectively Chapter 15 Operating System Interface 211 pp file time gt local decoded time file modification time decoded time 26 second 47 minute 31 hour 17 4 day 23 month 4 4 year 1999 day of week 4 daylight savings time 1 zone 5 pp file time gt global decoded time file modification time decoded time 27 second 47 minute 31 hour 21 4 day 23 month 4 4 year 1999 day of week 4 daylight savings time 0 zone 0 file time gt local time str
410. ructive insertion and deletion operations with a good constant factor e Weight Balanced trees are a kind of balanced binary tree The implementation provides non destructive operations There is a comprehensive set of operations including a constant time size operation many high level operations such as the set operations union intersection and difference and indexing of elements by position 11 1 Association Lists An association list or alist is a data structure used very frequently in Scheme An alist is a list of pairs each of which is called an association The car of an association is called the key An advantage of the alist representation is that an alist can be incrementally augmented simply by adding new entries to the front Moreover because the searching procedures 122 MIT Scheme Reference assv et al search the alist in order new entries can shadow old entries If an alist is viewed as a mapping from keys to data then the mapping can be not only augmented but also altered in a non destructive manner by adding new entries to the front of the alist alist object procedure Returns t if object is an association list including the empty list otherwise returns 4f Any object satisfying this predicate also satisfies list assq object alist procedure assv object alist procedure assoc object alist procedure These procedures find the first pair in alist whose car field is object and return that pair the re
411. rval the simpler 2 5 lies between 2 7 and 3 5 Note that 0 0 1 is the simplest rational of all 52 MIT Scheme Reference rationalize inexact gt exact 3 1 10 1 3 exact rationalize 3 1 10 gt i1 3 inexact rationalize gt exact is similar to rationalize except that it always returns an exact result simplest rational x y procedure simplest exact rational x y procedure simplest rational returns the simplest rational number between x and y inclusive simplest exact rational is similar except that it always returns an exact result These procedures implement the same functionality as rationalize and rationalize gt exact except that they specify the input range by its endpoints rationalize specifies the range by its center point and its half width exp z procedure log z procedure sin z procedure cos z procedure tan z procedure asin z procedure acos z procedure atan z procedure atan yx procedure These procedures compute the usual transcendental functions log computes the natural logarithm of z not the base ten logarithm asin acos and atan compute arcsine arccosine and arctangent respectively The two argument variant of atan computes angle make rectangular x y see below In general the mathematical functions log arcsine arccosine and arctangent are multiply defined For nonzero real x the value of log x is defined to be the one whose imaginary part lies in the range minus pi exclusive to pi inc
412. ry lookup rules for your computer The connection is established to the service specified by service The returned value is an 1 0 port to which you can read and write characters using ordinary Scheme 1 0 procedures such as read char and write char Buffer size specifies the size of the read and write buffers used by the port if this is unspecified or f the buffers will hold 4096 bytes Line translation specifies how end of line characters will be translated when reading or writing to the socket If this is unspecified or amp then lines will be terminated by CR LF which is the standard for most internet protocols Otherwise it must be a string which specifies the line ending character sequence to use When you wish to close the connection just use close port As an example here is how you can open a connection to a web server open tcp stream socket web mit edu www Next we will treat setting up a TCP server which is slightly more complicated Creating a server is a two part process First you must open a server socket which causes the operating system to listen to the network on a port that you specify Once the server socket is opened the operating system will allow clients to connect to your computer on that port In the second step of the process you accept the connection which completes the con nection initiated by the client and allows you to communicate with the client Accepting a connection does not affect the
413. s The aspects are check A predicate that returns t if the argument is of an acceptable Scheme type otherwise returns The check procedure is used for type checking convert A procedure of one argument which returns a Scheme object of one of the basic types It is used to convert an object into a simpler object that will eventually be converted into a C object The legal simpler objects are integers and strings return convert A procedure of one argument that given an integer returns a Scheme object of a type satisfying check Its purpose is to convert the result returned by the foreign procedure into a Scheme value revert Some C procedures modify one or more of their arguments l hese arguments are passed by reference i e as a pointer to their address Since a Scheme object might have a different memory layout and storage conventions it must be passed by copy in and copy out rather than by reference Revert is a procedure of two parameters the original object passed and the result of convert on that object Revert may then inspect the converted object and copy back the changes to the original Chapter 18 Win32 Package Reference 275 define windows type name check convert return revert special form define similar windows type name model check convert special form return revert Both forms define a windows type The first form defines a type in terms of its aspects as described above The second defines the ty
414. s lambda hairy computation lambda run time gc time real time write internal time ticks gt seconds run time write char space write internal time ticks gt seconds gc time write char space write internal time ticks gt seconds real time newline measure interval runtime procedure procedure Calls procedure passing it the current process time in seconds as an argument The result of this call must be another procedure When procedure returns the resulting procedure is tail recursively called with the ending time in seconds as an argument If runtime is f the elapsed time is deducted from the elapsed system time returned by runtime While this procedure can be used for time measurement its interface is somewhat clumsy for that purpose We recommend that you use with timings instead because it is more convenient and has lower overhead Chapter 15 Operating System Interface 215 measure interval t lambda start time let v hairy computation lambda end time write end time start time newline v 15 7 Subprocesses MIT Scheme provides the ability to run and control subprocesses This support is divided into two parts a low level set of primitives that maps onto the underlying operating system s process control primitives and a high level set of procedures for starting a subprocess and running it to completion in a single call Subprocesses that are run in t
415. s In the current implemen tation this component is always a host object that is filled in automatically by the runtime system When specifying the host component use either f or the value of the variable local host device Corresponds to the device or file structure concept in many host file sys tems the name of a logical or physical device containing files This component is the drive letter for PC file systems and is unused for unix file systems directory Corresponds to the directory concept in many host file systems the name of a group of related files typically those belonging to a single user or project This component is always used for all file systems name The name of a group of files that can be thought of as conceptually the same file This component is always used for all file systems type Corresponds to the filetype or extension concept in many host file systems This says what kind of file this is Files with the same name but different type are usually related in some specific way such as one being a source file another the compiled form of that source and a third the listing of error messages from the compiler This component is currently used for all file systems and is formed by taking the characters that follow the last dot in the namestring version Corresponds to the version number concept in many host file systems Typ ically this is a number that is incremented ev
416. s and compares those keys with eq The keys are held weakly These are the fastest of the standard hash tables make eqv hash table initial size procedure Returns a newly allocated hash table that accepts arbitrary objects as keys and compares those keys with eqv The keys are held weakly except that booleans characters and numbers are held strongly These hash tables are a little slower than those made by make eq hash table make equal hash table initial size procedure Returns a newly allocated hash table that accepts arbitrary objects as keys and compares those keys with equal The keys are held strongly These hash tables are quite a bit slower than those made by make eq hash table make string hash table initial size procedure Returns a newly allocated hash table that accepts character strings as keys and compares them with string The keys are held strongly The next two procedures are used to create new hash table constructors All of the above hash table constructors with the exception of make eqv hash table could have been created by calls to these constructor constructors see the examples below strong hash table constructor key hash key rehash after gc procedure weak hash table constructor key hash key rehash after gc7 procedure Each of these procedures accepts two arguments and returns a hash table constructor The key argument is an equivalence predicate for the keys of the hash table The
417. s and customizable hash procedures The average times for the insertion deletion and lookup operations on a hash table are bounded by a constant The space required by the table is proportional to the number of as sociations in the table the constant of proportionality is described below see Section 11 4 3 Resizing of Hash Tables page 129 The hash table implementation is a run time loadable option To use hash tables exe cute load option hash table once before calling any of the procedures defined here 126 MIT Scheme Reference 11 4 1 Construction of Hash Tables The next few procedures are hash table constructors All hash table constructors are procedures that accept one optional argument initial size and return a newly allocated hash table If initial size is given it must be an exact non negative integer or 4f The meaning of initial size is discussed below see Section 11 4 3 Resizing of Hash Tables page 129 Hash tables are normally characterized by two things the equivalence predicate that is used to compare keys and whether or not the table allows its keys to be reclaimed by the garbage collector If a table prevents its keys from being reclaimed by the garbage collector it is said to hold its keys strongly otherwise it holds its keys weakly see Section 10 7 Weak Pairs page 119 make eq hash table initial size procedure Returns a newly allocated hash table that accepts arbitrary objects as key
418. s a higher level abstraction called streams Streams are similar to lists except that the tail of a stream is not computed until it is referred to This allows streams to be used to represent infinitely long lists stream object procedure Returns a newly allocated stream whose elements are the arguments Note that the expression stream returns the empty stream or end of stream marker list gt stream list procedure Returns a newly allocated stream whose elements are the elements of list Equivalent to apply strean list stream gt list stream procedure Returns a newly allocated list whose elements are the elements of stream If stream has infinite length this procedure will not terminate This could have been defined by define stream gt list stream if stream null stream ae cons stream car stream stream gt list stream cdr stream cons stream object expression special form Returns a newly allocated stream pair Equivalent to cons object delay expres sion stream pair object procedure Returns t if object is a pair whose cdr contains a promise Otherwise returns f This could have been defined by define stream pair object and pair object promise cdr object stream car stream procedure stream first stream procedure Returns the first element in stream stream car is equivalent to car stream first is a synonym for stream car stream cdr stream procedure stream rest stream pro
419. s target bit string and bit string must be bit strings of the same length The bitwise logical negation of bit string is computed and the result placed in target bit string The value of this procedure is unspecified bit string and bit string 1 bit string 2 procedure Returns a newly allocated bit string that is the bitwise logical and of the arguments The arguments must be bit strings of identical length bit string andc bit string 1 bit string 2 procedure Returns a newly allocated bit string that is the bitwise logical and of bit string 1 with the bitwise logical negation of bit string 2 The arguments must be bit strings of identical length bit string or bit string 1 bit string 2 procedure Returns a newly allocated bit string that is the bitwise logical inclusive or of the arguments The arguments must be bit strings of identical length bit string xor bit string 1 bit string 2 procedure Returns a newly allocated bit string that is the bitwise logical exclusive or of the arguments The arguments must be bit strings of identical length bit string and target bit string bit string procedure bit string or target bit string bit string procedure bit string xor target bit string bit string procedure bit string andc target bit string bit string procedure These are destructive versions of the above operations The arguments target bit string and bit string must be bit strings of the same length Each of these
420. s the contents of the rectangle specified by source x left source y top width and height to the rectangle of the same dimensions at destination x left and destination y top 17 11 OS 2 Graphics MIT Scheme supports graphics under the OS 2 Presentation Manager in OS 2 version 2 1 and later The OS 2 graphics device type is implemented as a top level window In addition to the usual operations there are operations to control the size position and colors of a graphics window OS 2 graphics devices support images which are implemented as memory presentation spaces The custom graphics operations defined in this section are invoked using the procedure graphics operation For example graphics operation device set foreground color blue 17 11 1 OS 2 Graphics Type OS 2 graphics devices are created by specifying the symbol os 2 as the graphics device type argument to make graphics device The OS 2 graphics device type is implemented as a top level window and supports color drawing in addition to the standard Scheme graphics operations Graphics devices are opened as follows make graphics device os 2 optional width height where width and height specify the size in pixels of the drawing area in the graphics window i e excluding the frame 17 11 2 Color Operations for OS 2 Graphics These operations control the colors used when drawing on an OS 2 graphics device color operation on os2 graphics device This operation
421. s the number of pairs The empty list is a special object of its own type it is not a pair it has no elements and its length is zero The most general notation external representation for Scheme pairs is the dotted notation cl c2 where cl is the value of the car field and c2 is the value of the cdr field For example 4 5 is a pair whose car is 4 and whose cdr is 5 Note that 4 5 is the external representation of a pair not an expression that evaluates to a pair A more streamlined notation can be used for lists the elements of the list are simply enclosed in parentheses and separated by spaces The empty list is written For example the following are equivalent notations for a list of symbols abcd e a b c d e 0 Whether a given pair is a list depends upon what is stored in the cdr field When the set cdr procedure is used an object can be a list one moment and not the next define x list a b c define y x y gt abc list y gt dit set cdr x 4 unspecified x gt a 4 equ x y gt dit y gt a 4 list y gt df set cdr x x unspecified list y gt df A chain of pairs that doesn t end in the empty list is called an improper list Note that an improper list is not a list The list and dotted notations can be combined to represent improper lists as the following equivalent notations show The above definitions imply that all lists have fini
422. s type bool boolean lambda x if x 1 0 lambda x if eq x 0 f t f char windows type Scheme characters are converted into C objects of type char which are indistinguish able from small integers 276 MIT Scheme Reference int windows type uint windows type long windows type ulong windows type short windows type ushort windows type word windows type byte windows type Various integer types that are passed without conversion string windows type A string that is passed as a C pointer of type char to the first character in the string char windows type A string or 4f The string is passed as a pointer to characters The string is correctly null terminated f is passed as the null pointer This is an example where there is a more complex mapping between C objects and Scheme objects C s char type is represented as one of two Scheme types depending on its value This allows us us to distinguish between the C string pointer that points to the empty sequence of characters and the null pointer which doesnt point anywhere handle windows type hbitmap windows type hbrush windows type hcursor windows type hdc windows type hicon windows type hinstance windows type hmenu windows type hpalette windows type hpen windows type hrgn windows type hwnd windows type resource id Various kinds of Win32 handle These names correspond to the same but all up percase names in the Windows C language header files Win32 API
423. s2 graphics device pt A a anto Pr arae 268 set window size on os2 graphics device 268 set window title on os2 graphics device 269 set working directory pathname 197 SV ies 92 Shell file na me n ie 219 Sliortu re ai 276 signal condition 226 227 230 281 signed integer bit string 108 simplest exact rational 52 simpl st rationadl i ieHeL owns sao et vent 52 S n c caeso prb pa d REGE d be Rn 52 Singletom wt tree cir ee Rem des 140 SURCH udo ERE Hexe E E qr rb ETE 92 Soft link file6 2 0 rU ii 199 SO uri EROR tee s Seas 99 BOE Loses nami sup Sth PERA gas dee BOR ROR FUR E SCR 104 A Rep e ee eee ae ete 45 53 standard error handler 230 standard error hook esses 230 standard unparser method 174 standard warning handler 231 standard warning hook 231 StOVe Valule iii REC R 291 235 SM PERS qe PROS 118 Stream LYSt ov prse PAX noes Leelee 118 SULSAM CAR 2e reram ee aer Pages Repo 118 Stream cdt 221 PP chad nee hed URP EE REFS 118 Stre m first sco ise dale God RERO OSEE Reus 118 stream head civics cies ka erm ea vene RA 119 stream length il2 csiis ev be RS 119 Stream Map eri 119 Stream null irrita na 119 SLroam payt 22s mex c e a io 118 Stream Pef u c ev9 4 EE EQ Ig ede 119 Stream rest rai ir REY REDDE CORRI 118 Stream tail 22 xp erba rd es 119
424. seb EE pd 66 ASCII character defd o ooooococccoo 68 SI eR RR 24 association list defn ooooooooooo 121 association table defn 0ooooo o o o 124 asterisk as external representation 105 attribute of Me escribis 203 B backquote as external representation 26 backslash as escape character in string ja balanced binary trees 135 138 bell ringing on console 04 170 binary file ports cim RE Re 161 binary irees ek oro EY PP eee nad ce ii 135 138 binary trees as discrete maps 139 binary trees as sets eee 139 binding expression defn iusuusue 8 binding expression dynamic or fluid 2f binding expression lexical 19 binding of variable ir teens 6 MIT Scheme Reference bit string defn c ede id 105 bit string index defn usuuuusue 105 bit string length defn 0 00 105 oinuc HTTP 265 bitmaps graphics 0c eee ee eee 257 bitwise logical operations on fixnums 58 block sUruet tez sU eus 19 blocking mode of POTb 0 coooocccooccoooo 182 BOA Construct0r 24 045 peed exe nme ERES 31 BOA constructor defn 00 0000 33 body of special form defn 5 boolean object or it etdsigiateepeedas es 8 boolean object defn 0 0 00 109 boolean object equival
425. sed one so paying a cost for this unless it is used seems silly The following options are allowed with reversions The reversions are included in the type conversions expand A synonym for with reversions Scheme code The Scheme code is placed between steps a and b in the default pro cess The Scheme code can enforce constraints on the arguments includ ing constraints between arguments such as checking that an index refers to a valid position in a string If both options i e with reversions and Scheme code are used with reversions must appear first There can be arbitrarily many Scheme expression 18 2 3 Win32 API names and procedures This section is a moving target The define values from wingdi h and winuser h are available as bindings in the win32 package environment The define symbols are all uppercase these have been translated to all lowercase Scheme identifiers thus WM LBUTTONUP is the scheme variable wm lbuttonup As Scheme is case insensitive the upper case version may be used and probably should to make the code look more like conventional Windows code The Scheme bindings have been produced automagically Most of the define symbols contain an underscore so there are not many name clashes There is one very notable name clash however ERROR is defined to 0 which shadows the scheme procedure error in the root package environment To signal an error use access to get error from the syst
426. seessse eee 10 1 32 Delimiters 0 E ee eee eee eee 10 1 3 9 Identifiers cima a eee aded ga wa 11 1 3 4 Uppercase and Lowercase o ooooooooo 11 1 35 Naming Conventions sees eee eee 11 1 9 6 Comments 5423322 2 ced ea eked a sits 12 1 8 7 Additional Notations esses eese 12 1 4 Expressions eeseeee hh hh 13 1 4 1 Literal Expressions 00 00000 eee esee 14 1 4 2 Variable References 00 00 ee eeeee 14 1 43 Special Form Syntax 0 0 0 cece eee eee 14 1 4 4 Procedure Call Syntax 0020 000 0 14 2 Special FOLIOS ida da 17 2 1 Lambda Expressions sssesssseeee ene 17 2 2 Lexical Binding 0 0 00 teens 19 2 3 Dynamic Binding seis 24440 nde Hn tad red aed oe 20 2 4 Delito encia pereas eie epi akon d hdd eee aed 22 2 4 1 Top Level Definitions 0ooooooooooccoooo 23 2 4 2 Internal DefinitioMS 0ooooooooocooooo omo 23 2 5 Assignments 2 224 roe AREA T d PR ede PE d 24 2 0 QUOTING Loi Shore di it d HR RR b BL Re ie 24 2 7 QOOonditionals sioe eger ped eA eR eher eb ee 26 2 8 Sequenmclpg ze ed etae Aet oben Ee EUER a 28 2 0 o peter EC a see a dor pak e eee 29 2 10 Structure Definitions ee RR Peabo eben eee al ii iv MIT Scheme Reference 3 Equivalence Predicates 37 4 INwmnbers 2 3x99 x ke 09595488 PETS 43 4 Numerical tyD68 2 452 44d rettet deeded ebd 43 42 EXa
427. selection of bit string component 106 selection of cell component 114 selection of character component 67 selection of list component 91 selection of pair component 88 selection of string component 13 selection of vector component 102 selection of weak pair component 120 semicolon as external representation 12 sensitivity to case in programs defn 11 sequencing expressions sese 28 server SOCkeb ooooooooooocooooooo 219 220 service TOP air aria ose 220 Seb of Characters sis beef sep ai 68 sets using binary trees ooooooocooooooooo 139 shadowing of variable binding defn T short precision of inexact number 46 signal an error def ooooocccoooocoooooo 4 signalling of condition defn 226 simplest rational defn iussus 51 simplification of pathname 189 single precision of inexact number 46 MIT Scheme Reference size of hash table defn ssusuee 129 Socket en sem ie pb padrone dtes eid ipie 219 soft linking o file ep RR 199 special characters in programs 12 Sp cial OM tiara AE eR 17 special form def ooooocccocccccccccc 14 special form entry category 0000 5 specialization of condition types 226 2
428. sh table and returns an unspecified result The average and worst case times required by this operation are bounded by a constant hash table count hash table procedure Returns the number of associations in hash table as an exact non negative integer If hash table holds its keys weakly this is a conservative upper bound that may count some associations whose keys have recently been reclaimed by the garbage collector The average and worst case times required by this operation are bounded by a constant hash table gt alist hash table procedure Returns the contents of hash table as a newly allocated alist Each element of the alist is a pair key datum where key is one of the keys of hash table and datum is its associated datum The average and worst case times required by this operation are linear in the number of associations in the table hash table key list hash table procedure Returns a newly allocated list of the keys in hash table The average and worst case times required by this operation are linear in the number of associations in the table hash table datum list hash table procedure Returns a newly allocated list of the datums in hash table Each element of the list corresponds to one of the associations in hash table if the table contains multiple associations with the same datum so will this list The average and worst case times required by this operation are linear in the number of associations in the table hash table
429. size window on win32 graphics device 265 resize window on x graphics device 262 resoutce id inde ves reg ao dee 276 restart effector cuicos 237 restart interactor ss 236 237 restart name cite Ra Rye wees 236 resStatt ic le e a a M ved as 236 restore window on os2 graphics device 269 a egest Reese beter E Ead res 231 235 A ee Ree NP GER E beam 99 Pfeverse l bx A rRNA aie EES 99 IGVverse Strihg e c e vec wee PPS 83 reoverso striHgl aiii ori ii 83 FEVELSE SUDStLING coo nee pt iS 83 revers substring i slerecis ea gee sri 83 A tute fob E twee eb eta hee d 51 round xaC t roscas dei 51 run shell command eere tran 215 run synchronous subprocesS 215 r til e geibirigq pst eG Ree eX eg plene 214 301 S fe accesSOrS esso ee daa bx E de 35 save bitmap on win32 graphics device 265 scheme subprocess environment 218 A UE HERI Y d deed ders 92 select user events on os2 graphics device 270 sequence ae aodan ka DE Ea D EAE ARE ded es 29 SO a E E UP E Ore 23 24 set apply hook extr mico ind rr 152 set apply hook procedure 152 set background color 264 266 set background color on os2 graphics device aros aes US ack E AP RAE 266 set background color on win32 graphics device AAA AAA A od 264 set background color on x graphics device 260 set border color on x graphics device 260 set bord
430. sked by the force procedure to evaluate expression and deliver the resulting value force promise procedure Forces the value of promise If no value has been computed for the promise then a value is computed and returned The value of the promise is cached or memoized so that if it is forced a second time the previously computed value is returned without any recomputation force delay 1 2 gt 3 let p delay 1 2 list force p force p gt 33 define head car define tail lambda stream force cdr stream define a stream letrec next lambda n cons n delay next n 1 next 0 head tail tail a stream gt 2 promise object procedure Returns t if object is a promise otherwise returns f promise forced promise procedure Returns t if promise has been forced and its value cached otherwise returns f promise value promise procedure If promise has been forced and its value cached this procedure returns the cached value Otherwise an error is signalled force and delay are mainly intended for programs written in functional style The following examples should not be considered to illustrate good programming style but they illustrate the property that the value of a promise is computed at most once Chapter 10 Miscellaneous Datatypes define count 0 define p delay begin set count count 1 x 3 define x 5 count P
431. solute or relative so if this procedure returns f the argument is a relative pathname directory pathname pathname procedure Returns stt if pathname has only directory components and no file components This is roughly equivalent to define directory pathname pathname string null file namestring pathname except that it is faster pathname wild pathname procedure Returns t if pathname contains any wildcard components otherwise returns f merge pathnames pathname defaults default version procedure Returns a pathname whose components are obtained by combining those of pathname and defaults Defaults defaults to the value of default pathname defaults and default version defaults to newest The pathnames are combined by components if pathname has a non missing com ponent that is the resulting component otherwise the component from defaults is used The default version can be f to preserve the information that the component was missing from pathname The directory component is handled specially if both pathnames have directory components that are lists and the directory component from pathname is relative i e starts with relative then the resulting directory component is formed by appending pathname s component to defaults s component For example define pathi gt pathname scheme foo scm define path2 gt pathname usr morris pathi gt ttlpathname 74 scheme foo scm path2 gt pathn
432. ss has no standard input The default value of this option is f call with input file foo in lambda port run shell command cat gt dev null input port input line translation line ending subprocess option Specifies how line endings should be translated when writing characters to the subpro cess Ignored if the input option is f Line ending must be either a string specifying the line ending or the symbol default meaning to use the operating system s stan dard line ending In either case newline characters to be written to the input port are translated to the specified line ending before being written The default value of this option is default call with input file foo in lambda port run shell command cat gt dev null input port input line translation r n input buffer size n subprocess option Specifies the size of the input buffer for the standard input of the subprocess This is the buffer on the Scheme side and has nothing to do with any buffering done on the subprocess side Ignored if the input option is f N must be an exact positive integer specifying the number of characters the buffer can hold The default value of this option is 512 call with input file foo in lambda port run shell command cat gt dev null input port input buffer size 4096 output port subprocess option Specifies the standard output and standard error of the subprocess Port may be an ou
433. ssociations in the table This resizing cost is amortized across the insertions required to fill the table to the point where it needs to grow again If the table grows by an amount proportional to the number of associations then the cost of resizing and the increase in size are both proportional to the number of associations so the amortized cost of an insertion operation is still bounded by a constant However if the table grows by a constant amount this is not true the amortized cost of an insertion is not bounded by a constant Thus using a constant rehash size means that the average cost of an insertion increases proportionally to the number of associations in the hash table The rehash threshold is a real number between zero exclusive and one inclusive that specifies the ratio between a hash table s usable size and its physical size Decreasing the rehash threshold decreases the probability of worse than average insertion deletion and lookup times but increases the physical size of the table for a given usable size The default rehash threshold of a newly constructed hash table is 1 hash table size hash table procedure Returns the usable size of hash table as an exact positive integer This is the number of associations that hash table can hold before it will grow hash table rehash size hash table procedure Returns the rehash size of hash table set hash table rehash size hash table x procedure X must be either an exact posit
434. st binding of that variable whose region contains the variable use If there is no such region the use refers to the binding of the variable in the global environment which is an ancestor of all other environments and can be thought of as a region in which all your programs are contained 1 2 5 True and False In Scheme the boolean values true and false are denoted by stt and f However any Scheme value can be treated as a boolean for the purpose of a conditional test This manual uses the word true to refer to any Scheme value that counts as true and the word false to refer to any Scheme value that counts as false In conditional tests all values count as true except for f which counts as false see Section 2 7 Conditionals page 26 Chapter 1 Overview 9 Implementation note In MIT Scheme amp f and the empty list are the same object and the printed representation of f is always As this contradicts the Scheme standard MIT Scheme will be changed to make f and the empty list different objects 1 2 6 External Representations An important concept in Scheme is that of the external representation of an object as a sequence of characters For example an external representation of the integer 28 is the sequence of characters 28 and an external representation of a list consisting of the integers 8 and 13 is the sequence of characters 8 13 The external representation of an object is not necessarily unique
435. stands for Coordinated Universal Time and is the modern name for Greenwich Mean Time This format is produced by get universal time and decoded time gt universal time The second representation decoded time is a record structure in which the time is broken down into components such as month minute etc Decoded time is always relative to a particular time zone which is a component of the structure This format is produced by global decoded time and local decoded time The third representation file time is an exact non negative integer that is larger for increasing time Unlike universal time this representation is operating system depen dent This format is produced by all of the file attribute procedures for example file modification time and file attributes The fourth representation the time string is an external representation for time This format is defined by RFC 822 Standard for the format of ARPA Internet text messages with the modification that years are represented as four digit numbers rather than two digit numbers This format is the standard format for Internet email and numerous other network protocols Within this section argument variables named universal time decoded time file time and time string are respectively required to be of the corresponding format 15 5 1 Universal Time get universal time procedure Return the current time in universal format get universal time 3131453078 epoch variable
436. stants string constants character constants and boolean constants eval uate to themselves so they don t need to be quoted 2 abc abc 145932 145932 dt dt Ha Ha V V VV VE quasiquote template abc abc 145932 145932 t t a a special form Backquote or quasiquote expressions are useful for constructing a list or vector structure when most but not all of the desired structure is known in advance If no commas appear within the template the result of evaluating template is equivalent in the sense of equal to the result of evaluating template If a comma appears within the template however the expression following the comma is evaluated un quoted and its result is inserted into the structure instead of the comma and the expression If a comma appears followed immediately by an at sign 0 then the following expression shall evaluate to a list the opening and closing parentheses of the list are then stripped away and the elements of the list are inserted in place of the comma at sign expression sequence list 12 4 gt let name a a 1 2 map abs 4 5 6 b gt foo 10 3 cdr c 10 5 sqrt 4 map sqrt 16 9 8 list name name list 3 4 list a a a3456 b car cons gt foo 7 cons gt 10 5 2 4 3 8 y Rod 3 gt b Quasiquote forms may be neste
437. start end case fold procedure syntax table These procedures match regexp against the respective string or substring returning f for no match or a set of match registers see below if the match succeeds Here is an example showing how to extract the matched substring let r re substring match regexp string start end and r substring string start re match end index 0 r re string search forward regexp string case fold syntax table procedure re substring search forward regexp string start end case fold procedure syntax table Searches string for the leftmost substring matching regexp Returns a set of match registers see below if the search is successful or f if it is unsuccessful re substring search forward limits its search to the specified substring of string re string search forward searches all of string re string search backward regexp string case fold syntax table procedure re substring search backward regexp string start end case fold procedure syntax table Searches string for the rightmost substring matching regexp Returns a set of match registers see below if the search is successful or f if it is unsuccessful re substring search backward limits its search to the specified substring of string re string search backward searches all of string 82 MIT Scheme Reference When a successful match or search occurs the above procedures return a set of match registers The match r
438. stems and what equivalent file names might look like for each one System File Name TOPS 20 lt LISPIO gt FORMAT FASL 13 TOPS 10 FORMAT FAS 1 4 ITS LISPIO FORMAT FASL MULTICS gt udd gt Lisp10 gt format fasl TENEX lt LISPIO gt FORMAT FASL 13 VAX VMS LISPIO FORMAT FAS 13 UNIX usr lispio format fasl DOS C NUSRALISPIONFORMAT FAS It would be impossible for each program that deals with file names to know about each different file name format that exists a new operating system to which Scheme was ported might use a format different from any of its predecessors Therefore MIT Scheme provides two ways to represent file names filenames also called namestrings which are strings in the implementation dependent form customary for the file system and pathnames which are special abstract data objects that represent file names in an implementation independent way Procedures are provided to convert between these two representations 188 MIT Scheme Reference and all manipulations of files can be expressed in machine independent terms by using pathnames In order to allow MIT Scheme programs to operate in a network environment that may have more than one kind of file system the pathname facility allows a file name to specify which file system is to be used In this context each file system is called a host in keeping with the usual networking terminology Note that the examples given in this section are specific to unix pathnames
439. stency with the rounding modes required by the IEEE floating point standard Note If the argument to one of these procedures is inexact then the result will also be inexact If an exact value is needed the result should be passed to the inexact gt exact procedure or use one of the procedures below floor 4 3 gt 5 0 ceiling 4 3 gt 4 0 truncate 4 3 gt 4 0 round 4 3 gt 4 0 floor 3 5 gt 3 0 ceiling 3 5 gt 4 0 truncate 3 5 gt 3 0 round 3 5 gt 4 0 inexact round 7 2 gt 4 exact round 7 gt 7 floor gt exact x procedure ceiling gt exact x procedure truncate gt exact x procedure round gt exact x procedure These procedures are similar to the preceding procedures except that they always return an exact result For example the following are equivalent floor gt exact x inexact gt exact floor x except that the former is faster and has fewer range restrictions rationalize x y procedure rationalize gt exact x y procedure rationalize returns the simplest rational number differing from x by no more than y A rational number rl is simpler than another rational number r2 if rl p1 q1 and r2 p2 q2 both in lowest terms and p1 lt p2 and q1 lt q2 Thus 3 5 is simpler than 4 7 Although not all rationals are comparable in this ordering consider 2 7 and 3 5 any interval contains a rational number that is simpler than every other rational number in that inte
440. string f 4f 100 200 100x200 x geometry string 2 3 100 200 gt 100x200 2 3 x geometry string 2 3 f Hf gt 42 3 Note that the x and y arguments cannot distinguish between 0 and 0 even though these have different meanings in X If either of those arguments is O it means 0 in X terminology If you need to distinguish these two cases you must create your own geometry string using Scheme s string and number primitives 17 9 3 Custom Operations on X Graphics Devices Custom operations are invoked using the procedure graphics operation For example graphics operation device set foreground color blue set background color color name operation on x graphics device set foreground color color name operation on x graphics device set border color color name operation on x graphics device set mouse color color name operation on x graphics device These operations change the colors associated with a window Color name must be a string which is the X server s name for the desired color set border color and set mouse color immediately change the border and mouse cursor colors set background color and set foreground color change the colors to be used when drawing but have no effect on anything drawn prior to their invocation Because changing the background color affects the entire window we recommend calling graphics clear on the window s device afterwards Color names include both mnemonic names like red and intensity n
441. symbols numbers strings vectors and procedures as true but see Section 1 2 5 True and False page 8 Programmers accustomed to other dialects of Lisp should note that Scheme distinguishes f and the empty list from the symbol nil Similarly t is distinguished from the symbol t In fact the boolean objects and the empty list are not symbols at all Boolean constants evaluate to themselves so you don t need to quote them dt gt idit Hf gt dif Bf gt df t Unbound variable false variable true variable These variables are bound to the objects f and t respectively The compiler given the usual integrations declaration replaces references to these variables with their respective values Note that the symbol true is not equivalent to t and the symbol false is not equivalent to f boolean object procedure Returns t if object is either t or f otherwise returns f boolean ttf gt t boolean 0 gt f not object procedure false object procedure These procedures return t if object is false otherwise they return f In other words they invert boolean values These two procedures have identical semantics their names are different to give different connotations to the test not t gt f not 3 gt Hf not list 3 gt f not f gt t 110 MIT Scheme Reference boolean objl obj2 procedure This predicate is true iff obj1 and obj2 are either both true or both false boolea
442. system call to the operating system and that the system call signalled an error The system call error is reflected back to Scheme as a condition of this type except that many common system call errors are automatically translated by the Scheme implementation into more useful forms for example a system call error that occurs while trying to delete a file will be translated into a condition of type condition type file operation error The operator field contains the procedure that implements the operation or a symbol naming the procedure and the operands field contains a list of the arguments that were passed to the procedure The system call and error type fields contain symbols that describe the specific system call that was being made and the error that occurred respectively these symbols are completely operating system dependent condition type control error condition type This is an abstract type It describes a class of errors relating to program control flow condition type no such restart name condition type This type indicates that a named restart was not active when it was expected to be Conditions of this type are signalled by several procedures that look for particular named restarts for example muffle warning The name field contains the name that was being searched for muffle warning The restart named muffle warning is not bound To continue call RESTART with an option number RESTART 1 gt Return to read e
443. t below refers to any such manual or work Any member of the public is a licensee and is addressed as you A Modified Version of the Document means any work containing the Document or a portion of it either copied verbatim or with modifications and or translated into another language A Secondary Section is a named appendix or a front matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document s overall subject or to related matters and contains nothing that could fall directly within that overall subject For example if the Document is in part a textbook of mathematics a Secondary Section may not explain any mathematics The relationship could be a matter of historical connection with the subject or with related matters or of legal commercial philosophical ethical or political position regarding them The Invariant Sections are certain Secondary Sections whose titles are designated as being those of Invariant Sections in the notice that says that the Document is released under this License 284 MIT Scheme Reference The Cover Texts are certain short passages of text that are listed as Front Cover Texts or Back Cover Texts in the notice that says that the Document is released under this License A Transparent copy of the Document means a machine readable copy represented in a format whose specification is available
444. t stringl string2 procedure string gt stringl string2 procedure string ci lt stringl string2 procedure substring ci lt string start1 endl string2 start2 end2 procedure string ci gt stringl string2 procedure string ci lt stringl string2 procedure string ci gt stringl string2 procedure These procedures compare strings substrings according to the order of the charac ters they contain also see Section 5 2 Comparison of Characters page 65 The arguments are compared using a lexicographic or dictionary order If two strings differ in length but are the same up to the length of the shorter string the shorter string is considered to be less than the longer string string lt cat dog gt dit string cat DOG gt f string ci lt cat DOG gt dit string gt catkin cat dtt shorter is lesser string compare stringl string2 if eq if It if gt procedure string compare ci string string2 if eq if It if gt procedure If eq if lt and if gt are procedures of no arguments thunks The two strings are compared if they are equal if eq is applied if string is less than string2 if It is applied else if stringl is greater than string2 if gt is applied The value of the procedure is the value of the thunk that is applied string compare distinguishes uppercase and lowercase letters string compare ci does not define cheer display Hooray define boo display Boo hiss string
445. t defd oooooocccccccc 5 up as pathname component 190 UDpDercasQ conse oer ed UG ue a Ped 11 318 uppercase character conversion 65 Uppercase STi a rd 75 usable size of hash table defn 129 V V as format parameter 00 05 172 valid index of bit string defn 105 valid index of list defn suuusuuu 92 valid index of string defn uusueu rii valid index of subvector defn 101 valid index of vector defn e 101 value of variable defn 0 2 00 6 values multiple mi 151 variable binding ecc pidiera wee 6 variable binding dO 0ooooooooooo ooo 30 variable binding fluid let 21 variable binding internal definition 23 variable binding lambda Iy variable binding let 19 variable binding let o ooo oo oo 19 variable binding letrec 20 variable binding top level definition 23 variable reference defn 2000 14 variable adding to environment 22 variable assigning values to 24 variable binding region defn 8 variable entry category oooooooooo oo 5 variable identifier aS o ooooooooooo 11 vector del leeis sitiar airis 101 vector index
446. t all satisfy char ascii string Ha gt a string a b c gt abc string Ha space b space c gt abc string EX M list gt string char list procedure Char list must be a list of ASCII characters list gt string returns a newly allocated string formed from the elements of char list This is equivalent to apply string char list The inverse of this operation is string gt list list gt string a b gt ab string gt list Hello gt H e 1 1 o string copy string procedure Returns a newly allocated copy of string Note regarding variable length strings the maximum length of the result depends only on the length of string not its maximum length If you wish to copy a string and preserve its maximum length do the following define string copy preserving max length string let length dynamic wind lambda set length string length string set string length string string maximum length string lambda string copy string lambda set string length string length Chapter 6 Strings 73 6 2 Selecting String Components string object procedure Returns stt if object is a string otherwise returns f string Hi gt dit string Hi gt f string length string procedure Returns the length of string as an exact non negative integer string length gt 0 string length The length 10 string null string pro
447. t be a multiple of two The contents of the vectors are alternating start end pairs For example the following are equivalent graphics draw line device xs ys xe ye graphics operation device draw lines vector xs xe vector ys ye Chapter 18 Win32 Package Reference 273 18 Win32 Package Reference 18 1 Overview The Win32 implementation is still in a state of development It is expected that changes will be necessary when MIT Scheme is ported to Windows NT on the DEC Alpha ar chitecture In particular the current system is not arranged in a way that adequately distinguishes between issues that are a consequence of the NT operating system and those which are a consequence of the Intel x86 architecture Thus this documentation is not definitive it merely outlines how the current system works Parts of the system will change and any project implemented using the win32 system must plan for a re implementation stage The Win32 implementation has several components e Special microcode primitives e A foreign function interface FFI for calling procedures in dynamically linked libraries DLLs e An interface for Edwin e The Win32 package provides support for using the features of the Windows 3 1 and Windows NT 3 1 environments e Device Independent Bitmap utilities These are used by the win32 Scheme Graphics implementation The Scheme Graphics implementation is described in the Reference Manual Note that all the
448. t is proportional to the number of associations in the tree For the current implementation the constant of proportionality is eight words per association Red black trees hold their keys strongly In other words if a red black tree contains an association for a given key that key cannot be reclaimed by the garbage collector The red black tree implementation is a run time loadable option To use red black trees execute load option rb tree once before calling any of the procedures defined here make rb tree key key lt procedure This procedure creates and returns a newly allocated red black tree The tree con tains no associations Key and key lt are predicates that compare two keys and 136 MIT Scheme Reference determine whether they are equal to or less than one another respectively For any two keys at most one of these predicates is true rb tree object procedure Returns t if object is a red black tree otherwise returns sf rb tree insert rb tree key datum procedure Associates datum with key in rb tree and returns an unspecified value If rb tree already has an association for key that association is replaced The average and worst case times required by this operation are proportional to the logarithm of the number of assocations in rb tree rb tree lookup rb tree key default procedure Returns the datum associated with key in rb tree If rb tree doesn t contain an association for key default is returne
449. t local decoded time get universal time decoded time 21 second 23 minute 57 hour 17 4 day 29 month 4 4 year 1999 4 day of week 3 daylight savings time 1 4 zone 5 pp universal time gt global decoded time get universal time decoded time 22 second 27 minute 57 hour 21 4 day 29 month 4 4 year 1999 day of week 3 daylight savings time 0 zone 0 universal time gt file time universal time procedure Converts an argument in universal time format to file time format universal time gt file time get universal time gt 925422988 210 MIT Scheme Reference universal time gt local time string universal time procedure universal time gt global time string universal time procedure Converts an argument in universal time format to a time string The result is in the local time zone or UTC respectively universal time gt local time string get universal time gt Thu 29 Apr 1999 17 55 31 0400 universal time gt global time string get universal time gt Thu 29 Apr 1999 21 55 51 0000 decoded time gt universal time decoded time procedure Converts an argument in decoded time format to universal time format decoded time gt universal time local decoded time gt 3134411942 decoded time gt universal time global decoded time 3134411947 decoded time gt file time decoded time procedure Conve
450. t pai aiii id Ra 94 AP A nagd me cibi E 52 Pri did Pueden PEE et 53 ngu E 109 falsear dada ld up NIE 109 PDE Die uses pee ae at hah e ETT 92 PUL access mutter 201 file access tim e an a A 202 file access time direct 202 file access time indirect 202 LIDS Attributes zw oi RU REP 203 file attributes direct 203 file attributes indirect 203 Binding Index file attributes access time 203 file attributes allocated length 204 file attributes change time 203 file attributes gid o o oooooooooo 204 file attributes inode number 204 file attributes length 203 file attributes mode string 203 file attributes modes 204 file attributes modification time 203 file attributes n links 203 file attributes tyPe ooooooccccccccc 203 file attributes uid 004 204 tile dite cto Tacita is 200 file eg sd dd meer er wedges 201 file executable s se see n 201 file exists dire ct 21 peg e eR XR 198 file exists indirect o es ne 198 fil exists s ve REC PY 198 file length pete e eR a 203 file modes sso meter ERRORS 201 file modification time 202 file modification time direct 202 file modification time indirect 202 file namesString 4j kii d d
451. t s usually a bad idea to create such symbols because they cannot be read as them selves See symbol gt string eq mISSISSIppi mississippi gt dit string gt symbol mISSISSIppi the symbol with the name mISSISSIppi eq bitBlt string gt symbol bitBlt gt sf eq JollyWog string gt symbol symbol gt string JollyWog gt t string K Harper M D symbol gt string string gt symbol K Harper M D gt dit string gt uninterned symbol string procedure Returns a newly allocated uninterned symbol whose name is string It is unimportant what case or characters are used in string Note this is the fastest way to make a symbol generate uninterned symbol object procedure Returns a newly allocated uninterned symbol that is guaranteed to be different from any other object The symbol s name consists of a prefix string followed by the exact non negative integer value of an internal counter The counter is initially zero and is incremented after each call to this procedure The optional argument object is used to control how the symbol is generated It may take one of the following values e If object is omitted or f the prefix is G e If object is an exact non negative integer the internal counter is set to that integer prior to generating the result e If object is a string it is used as the prefix e If object is a symbol its name is used as the prefix Chapter 10 Miscellan
452. tation The letters s f d and 1 specify the use of short single double and long precision respectively When fewer than four internal inexact representations exist the four size specifications are mapped onto those available For example an implementation with two internal repre sentations may map short and single together and long and double together In addition the exponent marker e specifies the default precision for the implementation The default precision has at least as much precision as double but implementations may wish to allow this default to be set by the user 3 14159265358979F0 Round to single 3 141593 0 6LO Extend to long 600000000000000 4 5 Numerical operations See Section 1 1 3 Entry Format page 5 for a summary of the naming conventions used to specify restrictions on the types of arguments to numerical routines The examples used in this section assume that any numerical constant written using an exact notation is indeed represented as an exact number Some examples also assume that certain numerical constants written using an inexact notation can be represented without loss of accuracy the inexact constants were chosen so that this is likely to be true in implementations that use flonums to represent inexact numbers number object procedure complex object procedure real object procedure rational object procedure integer object procedure These numerical type predicates can be applied to an
453. te length and are terminated by the empty list 88 MIT Scheme Reference abc d a Bw c d Within literal expressions and representations of objects read by the read procedure the forms datum datum datum and datum denote two element lists whose first elements are the symbols quote quasiquote unquote and unquote splicing respectively The second element in each case is datum This convention is supported so that arbitrary Scheme programs may be represented as lists Among other things this permits the use of the read procedure to parse Scheme programs 7 1 Pairs This section describes the simple operations that are available for constructing and manipulating arbitrary graphs constructed from pairs pair object procedure Returns t if object is a pair otherwise returns f pair a b gt t pair a b c gt dit pair O gt f pair a b gt df cons objl obj2 procedure Returns a newly allocated pair whose car is objl and whose cdr is obj2 The pair is guaranteed to be different in the sense of eqv from every previously existing object cons a 0 gt a cons a bc d gt a bc d cons a b c gt a b c cons a 3 gt a 3 cons a b c gt ab c car pair procedure Returns the contents of the car field of pair Note that it is an error to take the car of the empty list car a b c a car a b c d
454. ted condition continuation condition procedure Returns the continuation specified when condition was created This is provided for inspecting the state of the system when the condition occurred not for continuing or restarting the computation write condition report condition port procedure Writes a description of condition to port using the reporter function from the condi tion type associated with condition See also condition report string 16 5 3 Simple Operations on Condition Instances The simple procedures described in this section are built on top of the more detailed abstraction of condition objects described above While these procedures are sometimes easier to use they are often less efficient make condition condition type continuation restarts field plist procedure Create a new condition object as an instance of condition type associated with con tinuation The continuation is provided for inspection purposes only not for restart ing the computation The restarts argument is described in Section 16 4 Restarts page 231 The field plist is an alternating list of field names and values for those fields where the field names are those that would be returned by condition type field names condition type It is used to provide values for fields in the condition object fields with no value specified are set to Once a condition object has been created there is no way to alter the values of these fields 240 MIT Sch
455. tely available the result of the operation depends on the blocking mode of the port If the port is in non blocking mode read string read substring immediately returns the value Otherwise the operation blocks until a character is available As soon as at least one character is available the region is filled using the available characters The procedure then returns immediately without waiting for further characters even if the number of available characters is less than the size of the region The returned value is the number of characters actually filled in 168 MIT Scheme Reference The importance of read string and read substring are that they are both flex ible and extremely fast especially for large amounts of data The following variables may be dynamically bound to change the behavior of the read procedure parser radix variable This variable defines the radix used by the reader when it parses numbers This is similar to passing a radix argument to string gt number The value of this variable must be one of 2 8 10 or 16 any other value is ignored and the reader uses radix 10 Note that much of the number syntax is invalid for radixes other than 10 The reader detects cases where such invalid syntax is used and signals an error However problems can still occur when parser radix is set to 16 because syntax that normally denotes symbols can now denote numbers e g abc Because of this it is usually undesira
456. tensions 9 1 Construction of Bit Strings make bit string k initialization procedure Returns a newly allocated bit string of length k If initialization is the bit string is filled with 0 bits otherwise the bit string is filled with 1 bits make bit string 7 f gt 0000000 bit string allocate k procedure Returns a newly allocated bit string of length k but does not initialize it bit string copy bit string procedure Returns a newly allocated copy of bit string 106 MIT Scheme Reference 9 2 Selecting Bit String Components bit string object procedure Returns t if object is a bit string otherwise returns f bit string length bit string procedure Returns the length of bit string bit string ref bit string k procedure Returns t if the kth bit is 1 otherwise returns 4f K must be a valid index of bit string bit string set bit string k procedure Sets the kth bit in bit string to 1 and returns an unspecified value K must be a valid index of bit string bit string clear bit string k procedure Sets the kth bit in bit string to 0 and returns an unspecified value K must be a valid index of bit string bit substring find next set bit bit string start end procedure Returns the index of the first occurrence of a set bit in the substring of bit string from start inclusive to end exclusive If none of the bits in the substring are set f is returned The index returned is relative to the whole bit st
457. ter 1 Overview 11 Finally these next characters act as delimiters despite the fact that Scheme does not define any special meaning for them 3 For example if the value of the variable name is max list Hi name 1 2 gt Hi max 3 1 3 3 Identifiers An identifier is a sequence of one or more non delimiter characters Identifiers are used in several ways in Scheme programs e Certain identifiers are reserved for use as syntactic keywords they should not be used as variables for a list of the initial syntactic keywords see Section 1 4 3 Special Form Syntax page 14 e Any identifier that is not a syntactic keyword can be used as a variable e When an identifier appears as a literal or within a literal it denotes a symbol Scheme accepts most of the identifiers that other programming languages allow MIT Scheme allows all of the identifiers that standard Scheme does plus many more MIT Scheme defines a potential identifier to be a sequence of non delimiter characters that does not begin with either of the characters or Any such sequence of characters that is not a syntactically valid number see Chapter 4 Numbers page 43 is considered to be a valid identifier Note that although it is legal for 4 and to appear in an identifier other than in the first character position it is poor programming practice Here are some examples of identifiers lambda q list gt vector soup Vi
458. tesian coordinate system can be defined All graphics procedures that use coordinates are defined on virtual coordinates For example to draw a line at a particular place on a device the virtual coordinates for the endpoints of that line are given When a graphics device is initialized its virtual coordinate system is reset so that the left edge corresponds to an x coordinate of 1 the right edge to x coordinate 1 the bottom edge to y coordinate 1 and the top edge to y coordinate 1 graphics device coordinate limits graphics device procedure Returns as multiple values the device coordinate limits for graphics device The values which are exact non negative integers are x left y bottom x right and y top graphics coordinate limits graphics device procedure Returns as multiple values the virtual coordinate limits for graphics device The values which are real numbers are x left y bottom x right and y top graphics set coordinate limits graphics device x left y bottom procedure x right y top Changes the virtual coordinate limits of graphics device to the given arguments X left y bottom x right and y top must be real numbers Subsequent calls to graphics coordinate limits will return the new limits This operation has no effect on the device s displayed contents Note This operation usually resets the clip rectangle although it is not guaranteed to do so If a clip rectangle is in effect when this procedure is called
459. th g lambda O if equ f g g both eqv f g gt H Objects of distinct types must never be regarded as the same object Since it is an error to modify constant objects those returned by literal expressions the implementation may share structure between constants where appropriate Thus the value of eqv on constants is sometimes unspecified let x a equ x x gt dit eqv a a gt unspecified eqv a a gt unspecified equ b cdr a b gt unspecified Rationale The above definition of eqv allows implementations latitude in their treatment of procedures and literals implementations are free either to detect or to fail to detect that two procedures or two literals are equivalent to each other and can decide whether or not to merge representations of equivalent objects by using the same pointer or bit pattern to represent both 40 eq objl obj2 MIT Scheme Reference procedure eq is similar to eqv except that in some cases it is capable of discerning distinctions finer than those detectable by equ eq and eqv are guaranteed to have the same behavior on symbols booleans the empty list pairs records and non empty strings and vectors eq s behavior on numbers and characters is implementation dependent but it will always return either true or false and will return true only when eqv would also return true eq may also behave differently from eqv o
460. th output file foo out lambda port run shell command ls la etc output port output buffer size 4096 redisplay hook thunk subprocess option Specifies that thunk is to be run periodically when output from the subprocess is available Thunk must be a procedure of no arguments or f indicating that no hook is supplied This option is mostly useful for interactive systems For example the Edwin text editor uses this to update output buffers when running some subprocesses The default value of this option is f run shell command ls la etc redisplay hook lambda update buffer contents buffer environment environment subprocess option Specifies the environment variables that are to be used for the subprocess Environ ment must be either a vector of strings or f indicating the default environment If it is a vector of strings each string must be a name value pair where the name and value are separated by an equal sign for example foo bar To define a variable with no value just omit the value as in foo Chapter 15 Operating System Interface 219 Note that the variable scheme subprocess environment is bound to the default subprocess environment The default value of this option is tf run shell command ls la etc environment let v scheme subprocess environment n vector length v v vector grow v n 1 vector set v n TERM none v working directory pathname subprocess optio
461. the corresponding arguments to the procedure 246 MIT Scheme Reference condition type derived file error filename condition condition type This is another kind of file error which is generated by obscure file system errors that do not fit into the standard categories The filename field contains the filename or pathname that was being operated on and the condition field contains a condition describing the error in more detail Usually the condition field contains a condition of type condition type system call error error derived file filename condition procedure This procedure signals a condition of type condition type derived file error The filename and condition fields of the condition are filled in from the corresponding arguments to the procedure condition type port error port condition type This is an abstract type It indicates that an error associated with a I O port has occurred For example writing output to a file port can signal an error if the disk containing the file is full that error would be signalled as a port error The port field contains the associated port condition type derived port error port condition condition type This is a concrete type that is signalled when port errors occur The port field contains the port associated with the error and the condition field contains a condition object that describes the error in more detail Usually the condition field contains a condition of type condition type system
462. the left rather than the right e This outputs a newline character n outputs n newlines No ar gument is used Simply putting a newline in control string would work but is often used because it makes the control string look nicer in the middle of a program This outputs a tilde n outputs n tildes newline Tilde immediately followed by a newline ignores the newline and any following non newline whitespace characters With an the newline is left in place but any following whitespace is ignored This directive is typically used when control string is too long to fit nicely into one line of the program Chapter 14 Input Output 173 define type clash error procedure arg spec actual format t Procedure S requires its A argument to be of type S but it was called with an argument of type S procedure arg spec actual type clash error vector ref first integer vector prints Procedure vector ref requires its first argument to be of type integer but it was called with an argument of type vector Note that in this example newlines appear in the output only as specified by the directives the actual newline characters in the control string are suppressed because each is preceded by a tilde 14 7 Custom Output MIT Scheme provides hooks for specifying that certain kinds of objects have special written representations There are no restrictions on the written representations but on
463. this requirement will change A string is written as a sequence of characters enclosed within double quotes To include a double quote inside a string precede the double quote with a backslash escape it as in The word recursion has many meanings The printed representation of this string is The word recursion has many meanings To include a backslash inside a string precede it with another backslash for example Use Control q to quit The printed representation of this string is Use Control q to quit The effect of a backslash that doesn t precede a double quote or backslash is unspecified in standard Scheme but MIT Scheme specifies the effect for three other characters Nt Nn and Mf These escape sequences are respectively translated into the following characters tab newline and page Finally a backslash followed by exactly three octal digits is translated into the character whose ASCII code is those digits If a string literal is continued from one line to another the string will contain the newline character newline at the line break Standard Scheme does not specify what appears in a string literal at a line break The length of a string is the number of characters that it contains This number is an exact non negative integer that is established when the string is created but see Section 6 10 Variable Length Strings page 84 Each character in a string has an index which is a number that ind
464. tion 16 7 Taxonomy page 241 is rooted at condition type serious condition condition type warning condition type simple condition and condition type breakpoint users are encouraged to add new subtypes to these condition types rather than create new trees in the forest To summarize the error system provides facilities for the following tasks The sections that follow will describe these facilities in more detail Signalling a condition A condition may be signalled in a number of different ways Simple errors may be signalled without explicitly defining a condition type using error The signal condition procedure provides the most general signalling mechanism Handling a condition The programmer can dynamically specify handlers for particular condition types or for classes of condition types by means of the bind condition handler procedure Individual handlers have complete control over the han dling of a condition and additionally may decide not to handle a particular condition passing it on to previously bound handlers Restarting from a handler The with restart procedure provides a means for condition signalling code to communicate to condition handling code what must be done to proceed past the condition Handlers can examine the restarts in effect when a condition was signalled allowing a structured way to continue an interrupted computation Packaging condition state Each condition is represented by an explicit object Con
465. tions are divided into two classes Standard operations There is a specific set of standard operations for input ports and a different set for output ports Applications can assume that the standard input operations are implemented for all input ports and likewise the standard output operations are implemented for all output ports Custom operations Some ports support additional operations For example ports that implement output to terminals or windows may define an operation named y size that returns the height of the terminal in characters Because only some ports will implement these operations programs that use custom operations must test each port for their existence and be prepared to deal with ports that do not implement them 14 9 1 Port Types The procedures in this section provide means for constructing port types with standard and custom operations and accessing their operations make port type operations port type procedure Creates and returns a new port type Operations must be a list each element is a list of two elements the name of the operation a symbol and the procedure that implements it Port type is either f or a port type if it is a port type any operations implemented by port type but not specified in operations will be implemented by the resulting port type Operations need not contain definitions for all of the standard operations the pro cedure will provide defaults for any standard operations that
466. to carriage return linefeed pairs In general the precise meaning of cooked mode is operating system dependent and furthermore might be customizable by means of operating system utilities The basic idea is that cooked mode does whatever is necessary to make the terminal handle all of the usual user interface conventions for the operating system while keeping the program s interaction with the port as normal as possible A terminal port in raw mode disables all of that processing In raw mode characters are directly read from and written to the device without any translation or interpretation by the operating system On input characters are available as soon as they are typed and are not echoed on the terminal by the operating system In general programs that put ports in raw mode have to know the details of interacting with the terminal In particular raw mode is used for writing programs such as text editors Terminal ports are initially in cooked mode this can be changed at any time with the procedures defined in this section These procedures represent cooked mode by the symbol cooked and raw mode by the symbol raw Additionally the value f represents no mode it is the terminal mode of a port that is not a terminal n argument called mode must be one of these three values A port argument to any of these procedures may be any port even if that port does not support terminal mode in that case the port is not modified in any w
467. to larger Thus if vector and vector2 are the same this proce dure moves the elements toward the left inside the vector subvector move right The copy starts at the right end and moves toward the left from larger indices to smaller Thus if vector and vector2 are the same this pro cedure moves the elements toward the right inside the vector sort vector procedure procedure merge sort vector procedure procedure quick sort vector procedure procedure Procedure must be a procedure of two arguments that defines a total ordering on the elements of vector The elements of vector are rearranged so that they are sorted in the order defined by procedure The elements are rearranged in place that is vector is destructively modified so that its elements are in the new order sort returns vector as its value Two sorting algorithms are implemented merge sort and quick sort The pro cedure sort is an alias for merge sort See also the definition of sort Chapter 9 Bit Strings 105 9 Bit Strings A bit string is a sequence of bits Bit strings can be used to represent sets or to manipulate binary data The elements of a bit string are numbered from zero up to the number of bits in the string less one in right to left order the rightmost bit is numbered zero When you convert from a bit string to an integer the zero th bit is associated with the zero th power of two the first bit is associated with the first power and so
468. to output port and returns an unspecified value write substring output port string start end operation on output port Writes the substring specified by string start and end to output port and returns an unspecified value Equivalent to writing the characters of the substring one by one to output port but is implemented very efficiently fresh line output port operation on output port Most output ports are able to tell whether or not they are at the beginning of a line of output If output port is such a port end of line is written to the port only if the port is not already at the beginning of a line If output port is not such a port and end of line is unconditionally written to the port Returns an unspecified value flush output output port Operation on output port If output port is buffered this causes its buffer to be written out Otherwise it has no effect Returns an unspecified value discretionary flush output output port Operation on output port Normally this operation does nothing However ports that support discretionary output flushing implement this operation identically to flush output output port write char output port char procedure output port write substring output port string start end procedure output port fresh line output port procedure output port flush output output port procedure output port discretionary flush output output port procedure Each of these procedures invokes the respective operation on
469. to the general public whose contents can be viewed and edited directly and straightforwardly with generic text editors or for images composed of pixels generic paint programs or for drawings some widely avail able drawing editor and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent A copy that is not Transparent is called Opaque Examples of suitable formats for Transparent copies include plain ASCII without markup Texinfo input format LaTeX input format SGML or XML using a publicly available DTD and standard conforming simple HTML designed for human modifica tion Opaque formats include PostScript PDF proprietary formats that can be read and edited only by proprietary word processors SGML or XML for which the DTD and or processing tools are not generally available and the machine generated HTML produced by some word processors for output purposes only The Title Page means for a printed book the title page itself plus such following pages as are needed to hold legibly the material this License requires to appear in the title page For works in formats which do not have any title page as such Title Page means the text near the most prominent appearance of the wor
470. tput port in which case characters are read from the subprocess and fed to port until the subprocess finishes Alternatively port may be f indicating that the subprocess has no standard output or standard error The default value of this option is the value of current output port 218 MIT Scheme Reference call with output file foo out lambda port run shell command ls la etc output port output line translation line ending subprocess option Specifies how line endings should be translated when reading characters from the standard output of the subprocess Ignored if the output option is 4f Line ending must be either a string specifying the line ending or the symbol default meaning to use the operating system s standard line ending In either case newline characters read from the subprocess port are translated to the specified line ending The default value of this option is default call with output file foo out lambda port run shell command ls la etc output port output line translation r n output buffer size n subprocess option Specifies the size of the output buffer for the standard output of the subprocess This is the buffer on the Scheme side and has nothing to do with any buffering done on the subprocess side Ignored if the output option is f N must be an exact positive integer specifying the number of characters the buffer can hold The default value of this option is 512 call wi
471. tput to a given rectangular subsection of a graphics device By default graphics output that is drawn anywhere within the device s virtual coordinate limits will appear on the device When a clip rectangle is specified however output that would have appeared outside the clip rectangle is not drawn Note that changing the virtual coordinate limits for a device will usually reset the clip rectangle for that device as will any operation that affects the size of the device such as a window resizing operation However programs should not depend on this graphics set clip rectangle graphics device x left y bottom x right procedure y top Specifies the clip rectangle for graphics device in virtual coordinates X left y bottom x right and y top must be real numbers Subsequent graphics output is clipped to the intersection of this rectangle and the device s virtual coordinate limits Chapter 17 Graphics 257 graphics reset clip rectangle graphics device procedure Eliminates the clip rectangle for graphics device Subsequent graphics output is clipped to the virtual coordinate limits of the device 17 7 Custom Graphics Operations In addition to the standard operations a graphics device may support custom operations For example most devices have custom operations to control color graphics operation is used to invoke custom operations graphics operation graphics device name object procedure Invokes the graphics operation on grap
472. tree size wt tree 253 maximum wt tree index wt tree wt tree size wt tree 1 wt tree rank wt tree key procedure Determines the 0 based position of key in the sorted sequence of the keys under the tree s ordering relation or f if the tree has no association with for key This procedure returns either an exact non negative integer or tf The average and worst case times required by this operation are proportional to the logarithm of the number of associations in the tree wt tree min wt tree procedure wt tree min datum wt tree procedure wt tree min pair wt tree procedure Returns the association of wt tree that has the least key under the tree s ordering relation wt tree min returns the least key wt tree min datum returns the da tum associated with the least key and wt tree min pair returns a new pair key datum which is the cons of the minimum key and its datum The average and worst case times required by this operation are proportional to the logarithm of the number of associations in the tree These operations signal an error if the tree is empty They could have been written define wt tree min tree wt tree index tree 0 define wt tree min datum tree wt tree index datum tree 0 define wt tree min pair tree wt tree index pair tree 0 wt tree delete min wt tree procedure Returns a new tree containing all of the associations in wt tree except the association with the least key under the wt tree s or
473. tructure options are Chapter 2 Special Forms 33 predicate name structure option This option controls the definition of a predicate procedure for the structure If name is not given the predicate is defined with the default name see above If name is f the predicate is not defined at all Otherwise name must be a symbol and the predicate is defined with that symbol as its name copier name structure option This option controls the definition of a procedure to copy instances of the struc ture This is a procedure of one argument a structure instance that makes a newly allocated copy of the structure and returns it If name is not given the copier is defined and the name of the copier is copy followed by the structure name e g copy foo If name is f the copier is not defined Otherwise name must be a symbol and the copier is defined with that symbol as its name print procedure expression structure option Evaluating expression must yield a procedure of two arguments which is used to print instances of the structure The procedure is an unparser method see Section 14 7 Custom Output page 173 If the structure instances are records this option has the same effect as calling set record type unparser method constructor name argument list structure option This option controls the definition of constructor procedures These constructor pro cedures are called BOA constructors for By Order of Argu
474. ts 108 moving of string elements 82 moving of vector elements o 104 multiple values from procedure 151 multiplication of numberS ooo oooo 48 must be notational convention 4 mutable 2 eS rele ER RERUM dia 10 mutation procedure defn 0 11 N name of character oooocoooooccorommooo 63 name OF fle s irrita a 198 name of symbol de sheds osi eR nets did name of value defh ooooocccccocccccco 6 name pathname component 189 named lambda defn 00 000005 18 named let d fn rr ccecireririgiisrriser srei 29 naming conventions oo oooooccooooo 11 278 negative MUMbED cae 48 nesting of quasiquote expressions 25 newest as pathname component 191 newline character defn susuusu 64 newline character output to port 169 newline translation 0oooo oooooc oooo 161 non local exit visse RA Eee RUE RES SA 150 notation dotted defn ssuusuueue 87 notational conventions sess eeeee es 4 null string predicate for 4 T9 HUMID PEE 43 number external representation 46 number pseudo random usus 60 numeric character defn issues 69 numeric precision Nexact ooooooooooo 46 numerical input and output suus 54 num
475. turned pair is always an element of alist not one of the pairs from which alist is composed If no pair in alist has object as its car f n b not the empty list is returned assq uses eq to compare object with the car fields of the pairs in alist while assv uses eqv and assoc uses equa1 define e a 1 b 2 c 3 assq a e gt a 1 assq b e gt b 2 assq d e gt df assq list a a b 00 f assoc list a a b c gt a aseq 5 2 3 b 7 11 13 gt unspecified assv 5 Q 3 5 7 11 13 gt 57 association procedure predicate selector procedure Returns an association procedure that is similar to assv except that selector a pro cedure of one argument is used to select the key from the association and predicate an equivalence predicate is used to compare the key to the given item This can be used to make association lists whose elements are say vectors instead of pairs also see Section 7 6 Searching Lists page 95 For example here is how assv could be implemented define assv association procedure eqv car Another example is a reverse association procedure define rassv association procedure eqv cdr del assq object alist procedure del assv object alist procedure del assoc object alist procedure These procedures return a newly allocated copy of alist in which all associations with keys equal to object have b
476. um out of range datum condition type This type indicates the class of errors in which a program discovers an object that is of the correct type but is otherwise out of range Most often this type indicates that an index to some data structure is outside of the range of indices for that structure The datum field contains the offending object error datum out of range 3 error The object 3 is not in the correct range To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 error datum out of range datum procedure This procedure signals a condition of type condition type datum out of range The datum field of the condition is filled in from the corresponding argument to the procedure condition type bad range argument datum operator condition type operand This type indicates that a procedure was passed an argument that is of the correct type but is otherwise out of range Most often this type indicates that an index to some data structure is outside of the range of indices for that structure The operator field contains the procedure or a symbol naming the procedure the operand field indicates the argument position that was involved this field contains either a symbol a non negative integer or t and the datum field is the offending argument string ref abc 3 error The object 3 passed as the second argument to string ref is not in the correct range
477. ument lists define structure foo constructor make foo optional a b a 6 read only t b 9 34 MIT Scheme Reference keyword constructor name structure option This option controls the definition of keyword constructor procedures A keyword constructor is a procedure that accepts arguments that are alternating slot names and values If name is omitted a keyword constructor is defined and the name of the constructor is make followed by the name of the structure e g make foo Otherwise name must be a symbol and a keyword constructor is defined with this symbol as its name If the keyword constructor option is specified the default constructor is not defined Additionally the keyword constructor option may be specified multiple times to define multiple keyword constructors this is usually not done since such constructors would all be equivalent define structure foo keyword constructor make bar a b foo a make bar b 20 a 19 gt 19 type descriptor name structure option This option cannot be used with the type or named options By default structures are implemented as records The name of the structure is defined to hold the type descriptor of the record defined by the structure The type descriptor option specifies a different name to hold the type descriptor define structure foo a b foo gt dt record type 18 define structure bar type descriptor bar rtd a b bar Unbound variable
478. uniquely determined by the preceding rule the value returned will be the one in the range minus pi exclusive to pi inclusive conjugate returns the complex conjugate of z exact gt inexact z procedure inexact gt exact z procedure exact gt inexact returns an inexact representation of z The value returned is the in exact number that is numerically closest to the argument If an exact argument has no reasonably close inexact equivalent then a violation of an implementation restriction may be reported MIT Scheme signals an error of type condition type bad range argument in this case inexact gt exact returns an exact representation of z The value returned is the exact number that is numerically closest to the argument If an inexact argument has no reasonably close exact equivalent then a violation of an implementation restriction may be reported in MIT Scheme this case does not occur because all inexact numbers are representable as exact numbers These procedures implement the natural one to one correspondence between exact and inexact integers throughout an implementation dependent range See Section 4 3 Implementation restrictions page 44 54 MIT Scheme Reference 4 6 Numerical input and output number gt string number radix procedure Radix must be an exact integer either 2 8 10 or 16 If omitted radix defaults to 10 The procedure number gt string takes a number and a radix and returns as a string an external re
479. unt 4 tf What this formula shows is that for a normal rehash size that is not an exact integer the amount of space used by the hash table is proportional to the number of associations in the table The constant of proportionality varies statistically with the low bound being 4 1 rehash threshold rehash size rehash size and the high bound being 4 1 rehash threshold which for the default values of these parameters are 4 25 and 5 respectively Reducing the rehash size will tighten these bounds but increases the amount of time spent resizing so you can see that the rehash size gives some control over the time space tradeoff of the table The programmer can control the size of a hash table by means of three parameters e Each table s initial size may be specified when the table is created e Each table has a rehash size that specifies how the size of the table is changed when it is necessary to grow or shrink the table e Each table has a rehash threshold that specifies the relationship of the table s physical size to its usable size 130 MIT Scheme Reference If the programmer knows that the table will initially contain a specific number of items initial size can be given when the table is created If initial size is an exact non negative integer it specifies the initial usable size of the hash table the table will not change size until the number of items in the table exceeds initial si
480. ure invokes the custom operation whose name is the symbol x size if it exists If the x size operation is both defined and returns a value other than f that value is returned as the result of this procedure Otherwise output port x size returns a default value currently 80 output port x size is useful for programs that tailor their output to the width of the display a fairly common practice If the output device is not a display such programs normally want some reasonable default width to work with and this procedure provides exactly that output port y size output port procedure This procedure invokes the custom operation whose name is the symbol y size if it exists If the y size operation is defined the value it returns is returned as the result of this procedure otherwise f is returned 14 9 5 Blocking Mode An interactive port is always in one of two modes blocking or non blocking This mode is independent of the terminal mode each can be changed independent of the other Furthermore if it is an interactive I O port there are separate blocking modes for input and for output If an input port is in blocking mode attempting to read from it when no input is available will cause Scheme to block i e suspend itself until input is available If an input port is in non blocking mode attempting to read from it when no input is available will cause the reading procedure to return immediately indicating the lack of input
481. urn multiple values using the values proce dure Then procedure is called with the multiple values as its arguments The result yielded by procedure is returned as the result of call with values 152 MIT Scheme Reference values object procedure Returns multiple values The continuation in effect when this procedure is called must be a multiple value continuation that was created by call with values Fur thermore it must accept as many values as there are objects 12 4 Application Hooks Application hooks are objects that can be applied like procedures Each application hook has two parts a procedure that specifies what to do when the application hook is applied and an arbitrary object called extra Often the procedure uses the extra object to determine what to do There are two kinds of application hooks which differ in what arguments are passed to the procedure When an apply hook is applied the procedure is passed exactly the same arguments that were passed to the apply hook When an entity is applied the entity itself is passed as the first argument followed by the other arguments that were passed to the entity Both apply hooks and entities satisfy the predicate procedure Each satisfies either compiled procedure compound procedure or primitive procedure depending on its procedure component An apply hook is considered to accept the same number of arguments as its procedure while an entity is considered to accept one l
482. us filename can be either a string or a pathname and it is merged with the current pathname defaults to produce the pathname that is then opened 162 MIT Scheme Reference Any file can be opened in one of two modes normal or binary Normal mode is for accessing text files and binary mode is for accessing other files Unix does not distinguish these modes but Windows and OS 2 do in normal mode their file ports perform newline translation mapping between the carriage return linefeed sequence that terminates text lines in files and the newline that terminates lines in Scheme In binary mode such ports do not perform newline translation Unless otherwise mentioned the procedures in this section open files in normal mode open input file filename procedure Takes a filename referring to an existing file and returns an input port capable of delivering characters from the file If the file cannot be opened an error of type condition type file operation error is signalled open output file filename append procedure Takes a filename referring to an output file to be created and returns an output port capable of writing characters to a new file by that name If the file cannot be opened an error of type condition type file operation error is signalled The optional argument append is an MIT Scheme extension If append is given and not f the file is opened in append mode In this mode the contents of the file are not overwritten inste
483. use eq hash tables are much faster symbol lt symboll symbol2 procedure This procedure computes a total order on symbols It is equivalent to string lt symbol gt string symboll symbol gt string symbol2 10 3 Cells Cells are data structures similar to pairs except that they have only one element They are useful for managing state 114 MIT Scheme Reference cell object procedure Returns t if object is a cell otherwise returns f make cell object procedure Returns a newly allocated cell whose contents is object cell contents cell procedure Returns the current contents of cell set cell contents cell object procedure Alters the contents of cell to be object Returns an unspecified value bind cell contents cell object thunk procedure Alters the contents of cell to be object calls thunk with no arguments then re stores the original contents of cell and returns the value returned by thunk This is completely equivalent to dynamic binding of a variable including the behavior when continuations are used see Section 2 3 Dynamic Binding page 21 10 4 Records MIT Scheme provides a record abstraction which is a simple and flexible mechanism for building structures with named components Records can be defined and accessed using the procedures defined in this section A less flexible but more concise way to manipulate records is to use the define structure special form see Section 2 10 Structure Defini
484. ush output output port procedure If output port is buffered this causes the contents of its buffer to be written to the output device Otherwise it has no effect Returns an unspecified value 1 write is intended for producing machine readable output and display is for producing human readable output 170 MIT Scheme Reference beep output port procedure Performs a beep operation on output port performs discretionary output flushing and returns an unspecified value On the console port this usually causes the console bell to beep but more sophisticated interactive ports may take other actions such as flashing the screen On most output ports e g file and string output ports this does nothing clear output port procedure Clears the screen of output port performs discretionary output flushing and re turns an unspecified value On a terminal or window this has a well defined effect On other output ports e g file and string output ports this does nothing pp object output port as code procedure pp prints object in a visually appealing and structurally revealing manner on output port If object is a procedure pp attempts to print the source text If the optional argument as code is true pp prints lists as Scheme code providing appropriate indentation by default this argument is false pp performs discretionary output flushing and returns an unspecified value The following variables may be dyn
485. usr blisp rel15 pathname default device pathname device procedure pathname default directory pathname directory procedure pathname default name pathname name procedure pathname default type pathname type procedure pathname default version pathname version procedure These operations are similar to the pathname new component operations except that they only change the specified component if it has the value f in pathname 15 1 3 Operations on Pathnames pathname object procedure Returns stt if object is a pathname otherwise returns f pathname pathnamel pathname2 procedure Returns t if pathnamel is equivalent to pathname2 otherwise returns f Path names are equivalent if all of their components are equivalent hence two pathnames that are equivalent must identify the same file or equivalent partial pathnames How ever the converse is not true non equivalent pathnames may specify the same file e g via absolute and relative directory components and pathnames that specify no file at all e g name and directory components unspecified may be equivalent Chapter 15 Operating System Interface 193 pathname absolute pathname procedure Returns stt if pathname is an absolute rather than relative pathname object otherwise returns Specifically this procedure returns t when the directory component of pathname is a list starting with the symbol absolute and returns f in all other cases All pathnames are either ab
486. va lt a34kTMNs the word recursion has many meanings 1 3 4 Uppercase and Lowercase Scheme doesn t distinguish uppercase and lowercase forms of a letter except within character and string constants in other words Scheme is case insensitive For example Foo is the same identifier as FOO and x1AB is the same number as X1ab But Ha and HA are different characters 1 3 5 Naming Conventions A predicate is a procedure that always returns a boolean value tt or By convention predicates usually have names that end in A mutation procedure is a procedure that alters a data structure By convention mu tation procedures usually have names that end in 12 MIT Scheme Reference 1 3 6 Comments The beginning of a comment is indicated with a semicolon Scheme ignores everything on a line in which a semicolon appears from the semicolon until the end of the line The entire comment including the newline character that terminates 1t is treated as whitespace An alternative form of comment sometimes called an extended comment begins with the characters tl and ends with the characters This alternative form is an MIT Scheme extension As with ordinary comments all of the characters in an extended com ment including the leading and trailing are treated as whitespace Comments of this form may extend over multiple lines and additionally may be nested un
487. val print level 1 error no such restart name procedure This procedure signals a condition of type condition type no such restart The name field of the condition is filled in from the corresponding argument to the pro cedure condition type not loading condition type A condition of this type is generated when the procedure current load pathname is called from somewhere other than inside a file being loaded Chapter 16 Error System 249 current load pathname No file being loaded To continue call RESTART with an option number RESTART 1 gt Return to read eval print level 1 condition type warning condition type This is an abstract type All warnings should inherit from this type Warnings are a class of conditions that are usually handled by informing the user of the condition and proceeding the computation normally condition type simple warning message irritants condition type This is the condition generated by the warn procedure The fields message and irritants are taken directly from the arguments to warn message contains an object usually a string and irritants contains a list of objects The reporter for this type uses format error message to generate its output from message and irritants condition type simple condition message irritants condition type This is an unspecialized condition that does not fall into any of the standard condition classes The message field contains an object usually a string and
488. volved in that computation are exact The value returned by quotient always has the sign of the product of its arguments remainder and modulo differ on negative arguments the remainder always has the sign of the dividend the modulo always has the sign of the divisor modulo 13 4 gt 1 remainder 13 4 gt 1 modulo 13 4 gt 3 remainder 13 4 gt 1 modulo 13 4 gt 3 remainder 13 4 gt 1 modulo 13 4 gt 1 remainder 13 4 gt 1 remainder 13 4 0 gt 1 0 inexact Note that quotient is the same as integer truncate integer floor n1 n2 procedure integer ceiling n1 n2 procedure integer truncate nl n2 procedure integer round n1 n2 procedure These procedures combine integer division with rounding For example the following are equivalent 50 MIT Scheme Reference integer floor nl n2 floor n1 n2 However the former is faster and does not produce an intermediate result Note that integer truncate is the same as quotient integer divide n1 n2 procedure integer divide quotient qr procedure integer divide remainder qr procedure integer divide is equivalent to performing both quotient and remainder at once The result of integer divide is an object with two components the procedures integer divide quotient and integer divide remainder select those compo nents These procedures are useful when both the quotient and remainder are needed often computing both of these numbers
489. w problems or concerns See http www gnu org copyleft Each version of the License is given a distinguishing version number If the Document specifies that a particular numbered version of this License or any later version applies to it you have the option of following the terms and conditions either of that specified version or of any later version that has been published not as a draft by the Free Software Foundation If the Document does not specify a version number of this License you may choose any version ever published not as a draft by the Free Software Foundation ADDENDUM How to use this License for your documents To use this License in a document you have written include a copy of the License in the document and put the following copyright and license notices just after the title page Copyright C year your name Permission is granted to copy distribute and or modify this document under the terms of the GNU Free Documentation License Version 1 1 or any later version published by the Free Software Foundation with the Invariant Sections being list their titles with the Front Cover Texts being list and with the Back Cover Texts being list A copy of the license is included in the section entitled GNU Free Documentation License If you have no Invariant Sections write with no Invariant Sections instead of saying which ones are invariant If you have no Front Cover Texts write no Front Cover Texts
490. waits for an event to arrive before returning An event is a vector whose first element is the event type number whose second ele ment is the graphics device that the event refers to and whose remaining elements provide information about the event Here is a table of the possible event types and their vector layout 0 device number type x y flags A button event Number is the button number for example button number O is usually the left mouse button 1 is usually the right button etc Type specifies what occurred O means the button was pressed 1 means the button was released 2 means the button was clicked and 3 means the button was double clicked X and y are the position of the mouse pointer at the time of the event in units of pels pixels measured from the lower left corner of the client area of the associated window Finally flags specifies what shift keys were pressed at the time of the button event it is a mask word created by combining zero or more of the following flags x08 means the shift key was pressed x10 means the control key was pressed and x20 means the alt key was pressed 1 device A close event The user has selected the close button from the system menu or typed Alt f4 Chapter 17 Graphics 271 2 device gained A focus event If gained is t the keyboard focus is being gained and if gained is it is being lost 3 device code flags repeat A keyboard event This is much too comp
491. way 1 1 3 Entry Format Each description of an MIT Scheme variable special form or procedure begins with one or more header lines in this format template category where category specifies the kind of item variable special form or procedure and how the item conforms to standard Scheme as follows category Category with no extra marking indicates that the item is described in the Revised 4 Report on the Algorithmic Language Scheme category A plus sign after category indicates that the item is an MIT Scheme extension The form of template is interpreted depending on category Variable Template consists of the variable s name Special Form Template starts with the syntactic keyword of the special form followed by a description of the special form s syntax The description is written using the following conventions Named components are italicized in the printed manual and uppercase in the Info file Noise keywords such as the else keyword in the cond special form are set in a fixed width font in the printed manual in the Info file they are not distinguished Parentheses indicate themselves A horizontal ellipsis is describes repeated components Specifically thing indicates zero or more occurrences of thing while thing thing indicates one or more occurrences of thing Brackets enclose optional components Several special forms e g lambda have an internal component consisting of a s
492. wt tree object procedure Returns t if object is a weight balanced tree otherwise returns f wt tree empty wt tree procedure Returns t if wt tree contains no associations otherwise returns f wt tree size wt tree procedure Returns the number of associations in wt tree an exact non negative integer This operation takes constant time wt tree add wt tree key datum procedure Returns a new tree containing all the associations in wt tree and the association of datum with key If wt tree already had an association for key the new association overrides the old The average and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree wt tree add wt tree key datum procedure Associates datum with key in wt tree and returns an unspecified value If wt tree already has an association for key that association is replaced The average and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree wt tree member key wt tree procedure Returns stt if wt tree contains an association for key otherwise returns amp f The aver age and worst case times required by this operation are proportional to the logarithm of the number of associations in wt tree wt tree lookup wt tree key default procedure Returns the datum associated with key in wt tree If wt tree doesn t contain an association for key default is returned T
493. x log x log 2 lt lg size rb tree height rb tree 2 1g size 1 rb tree copy rb tree procedure Returns a newly allocated copy of rb tree The copy is identical to rb tree in all respects except that changes to rb tree do not affect the copy and vice versa The time required by this operation is proportional to the number of associations in the tree alist gt rb tree alist key key lt procedure Returns a newly allocated red black tree that contains the same associations as alist This procedure is equivalent to lambda alist key key lt let tree make rb tree key key lt for each lambda association rb tree insert tree car association cdr association alist tree 138 MIT Scheme Reference The following operations provide access to the smallest and largest members in a red black tree They are useful for implementing priority queues rb tree min rb tree default procedure Returns the smallest key in rb tree or default if the tree is empty rb tree min datum rb tree default procedure Returns the datum associated with the smallest key in rb tree or default if the tree is empty rb tree min pair rb tree procedure Finds the smallest key in rb tree and returns a pair containing that key and its associated datum If the tree is empty returns f rb tree max rb tree default procedure Returns the largest key in rb tree or default if the tree is empty rb tree ma
494. x character bounds descent character bounds procedure These procedures extract components of objects of type x character bounds A more complete description of them appears in documentation of the XLoadQueryFont Xlib call 17 10 Win32 Graphics MIT Scheme supports graphics on Microsoft Windows 95 Windows 98 and Windows N T In addition to the usual operations there are operations to control the size position and colors of a graphics window Win32 devices support images which are implemented as device independent bitmaps DIBs The Win32 graphics device type is implemented as a top level window graphics enable buffering is implemented and gives a 2x to 4x speedup on many graphics op erations As a convenience when buffering is enabled clicking on the graphics window s title bar effects a graphics flush operation The user has the benefit of the increased performance and the ability to view the progress in drawing at the click of a mouse button 17 10 1 Win32 Graphics Type Win32 graphics devices are created by specifying the symbol win32 as the graphics device type argument to make graphics device The Win32 graphics device type is im plemented as a top level window and supports color drawing in addition to the standard Scheme graphics operations Graphics devices are opened as follows make graphics device win32 optional width height palette where width and height specify the size in pixels of the drawing area in the grap
495. x datum rb tree default procedure Returns the datum associated with the largest key in rb tree or default if the tree is empty rb tree max pair rb tree procedure Finds the largest key in rb tree and returns a pair containing that key and its asso ciated datum If the tree is empty returns sf rb tree delete min rb tree default procedure rb tree delete min datum rb tree default procedure rb tree delete min pair rb tree procedure rb tree delete max rb tree default procedure rb tree delete max datum rb tree default procedure rb tree delete max pair rb tree procedure These operations are exactly like the accessors above in that they return information associated with the smallest or largest key except that they simultaneously delete that key 11 7 Weight Balanced Trees Balanced binary trees are a useful data structure for maintaining large sets of ordered objects or sets of associations whose keys are ordered MIT Scheme has a comprehensive implementation of weight balanced binary trees which has several advantages over the other data structures for large aggregates e n addition to the usual element level operations like insertion deletion and lookup there is a full complement of collection level operations like set intersection set union and subset test all of which are implemented with good orders of growth in time and space This makes weight balanced trees ideal for rapid prototyping of functionally derived speci
496. xtension of the environment containing the system s bindings Thus system names are visible to your programs but your names do not interfere with system programs The environment in effect at some point in a program is called the current environment at that point In particular every REP loop has a current environment REP stands for read eval print the REP loop is the Scheme program that reads your input evaluates it and prints the result The environment of the top level REP loop the one you are in when Scheme starts up starts as user initial environment although it can be changed by the ge procedure When a new REP loop is created its environment is determined by the program that creates it 8 MIT Scheme Reference 1 2 4 Static Scoping Scheme is a statically scoped language with block structure In this respect it is like Algol and Pascal and unlike most other dialects of Lisp except for Common Lisp The fact that Scheme is statically scoped rather than dynamically bound means that the environment that is extended and becomes current when a procedure is called is the environment in which the procedure was created i e in which the procedure s defining lambda expression was evaluated not the environment in which the procedure is called Because all the other Scheme binding expressions can be expressed in terms of procedures this determines how all bindings behave Consider the following definitions made at the top
497. y kind of argument including non numbers They return stt if the object is of the named type and otherwise they return 4f In general if a type predicate is true of a number then all higher type Chapter 4 Numbers 47 predicates are also true of that number Consequently if a type predicate is false of a number then all lower type predicates are also false of that number If z is an inexact complex number then real z is true if and only if zero imag part z is true If x is an inexact real number then integer x is true if and only if x round x complex 3 4i gt t complex 3 gt t real 3 gt t real 2 5 0 0i gt t real tele10 gt t rational 6 10 t rational 6 3 gt t integer 3 0i gt dit integer 3 0 gt dit integer 8 4 gt t Note l he behavior of these type predicates on inexact numbers is unreliable since any inaccuracy may affect the result exact z procedure inexact z procedure These numerical predicates provide tests for the exactness of a quantity For any Scheme number precisely one of these predicates is true exact integer object procedure exact nonnegative integer object procedure exact rational object procedure These procedures test for some very common types of numbers These tests could be written in terms of simpler predicates but are more efficient zl z2 z8 procedure X1 x2 x3 454 procedure gt xl x2 x3 proce
498. y on the Windows system drive e Finally if all else fails the Windows system drive is used as the home directory system library pathname pathname procedure Locates pathname in MIT Scheme s system library directory An error of type condition type file operation error is signalled if pathname cannot be located on the library search path system library pathname compiler com ttlpathname 45 usr local lib mit scheme compiler com system library directory pathname pathname procedure Locates the pathname of an MIT Scheme system library directory An error of type condition type file operation error is signalled if pathname cannot be located on the library search path system library directory pathname options gt pathname 44 usr local lib mit scheme options Chapter 15 Operating System Interface 197 15 2 Working Directory When MIT Scheme is started the current working directory or simply working direc tory is initialized in an operating system dependent manner usually it is the directory in which Scheme was invoked The working directory can be determined from within Scheme by calling the pwd procedure and changed by calling the cd procedure Each REP loop has its own working directory and inferior REP loops initialize their working directory from the value in effect in their superior at the time they are created working directory pathname procedure pwd procedure Returns the current working directory as
499. y that an object has a false value or is false when the conditional expressions treat it as false if predicate consequent alternative special form Predicate consequent and alternative are expressions An if expression is evaluated as follows first predicate is evaluated If it yields a true value then consequent is evaluated and its value is returned Otherwise alternative is evaluated and its value is returned If predicate yields a false value and no alternative is specified then the result of the expression is unspecified An if expression evaluates either consequent or alternative never both Programs should not depend on the value of an if expression that has no alternative if gt 3 2 yes no gt yes if gt 2 3 yes no gt no Gf gt 3 2 3 2 3 2 1 cond clause clause special form Each clause has this form Chapter 2 Special Forms 27 predicate expression where predicate is any expression The last clause may be an else clause which has the form else expression expression A cond expression does the following 1 Evaluates the predicate expressions of successive clauses in order until one of the predicates evaluates to a true value 2 When a predicate evaluates to a true value cond evaluates the expressions in the associated clause in left to right order and returns the result of evaluating the last expression in the clause as the result of the entire co
500. ys Think of the association table as a matrix a single datum can be accessed using both keys a column using x key only and a row using y key only Chapter 11 Associations 125 2d put x key y key datum procedure Makes an entry in the association table that associates datum with x key and y key Returns an unspecified result 2d remove x key y key procedure If the association table has an entry for x key and y key it is removed Returns an unspecified result 2d get x key y key procedure Returns the datum associated with x key and y key Returns f if no such association exists 2d get alist x x key procedure Returns an association list of all entries in the association table that are associated with x key The result is a list of Cy key datum pairs Returns the empty list if no entries for x key exist 2d put foo bar 5 2d put foo baz 6 2d get alist x foo gt baz 6 bar 5 2d get alist y y key procedure Returns an association list of all entries in the association table that are associated with y key The result is a list of x key datum pairs Returns the empty list if no entries for y key exist 2d put bar foo 5 2d put baz foo 6 2d get alist y foo gt baz 6 bar 5 11 4 Hash Tables Hash tables are a fast powerful mechanism for storing large numbers of associations MIT Scheme s hash tables feature automatic resizing customizable growth parameter
501. ze after which automatic resizing is enabled and initial size no longer has any effect Otherwise if initial size is not given or is f the table is initialized to an unspecified size and automatic resizing is immediately enabled The rehash size specifies how much to increase the usable size of the hash table when it becomes full It is either an exact positive integer or a real number greater than one If it is an integer the new size is the sum of the old size and the rehash size Otherwise it is a real number and the new size is the product of the old size and the rehash size Increasing the rehash size decreases the average cost of an insertion but increases the average amount of space used by the table The rehash size of a table may be altered dynamically by the application in order to optimize the resizing of the table for example if the table will grow quickly for a known period and afterwards will not change size performance might be improved by using a large rehash size during the growth phase and a small one during the static phase The default rehash size of a newly constructed hash table is 2 0 Warning The use of an exact positive integer for a rehash size is almost always unde sirable this option is provided solely for compatibility with the Common Lisp hash table mechanism The reason for this has to do with the time penalty for resizing the hash table The time needed to resize a hash table is proportional to the number of a
Download Pdf Manuals
Related Search
Related Contents
EN Instruction for use Samsung GT-E2652W Hướng dẫn sử dụng Confirmation - GE Healthcare 取扱説明書 User`s Manual - V1 Putt Universität Bern Page 1 Page 2 うかのように、 「知性」と「野性」 。 日本発の独創とも言う モルセレーターⅡの付属品 Contents Kenmore 183.134013 Freezer User Manual Copyright © All rights reserved.
Failed to retrieve file