Home
STK Reference manual
Contents
1. 24 open output string 25 26 open output virtual 26 Mina as pe eke eS 9 output file port 23 OUEPULEPOT EP 326 De ee tu ed 22 output string port 23 output virtual port 23 P palr 41d deu Pert db geris 12 parent environment 37 pattern matching 50 peek char colo DM ERR 26 Pid pita eee ladies uA 52 53 POTT TIE Luna nette 30 31 port gt sexp list 30 31 107 port strfing cusco 30 port gt string list 30 31 port closed He iii done des fat 30 positive Nadia lead bandadas 16 A O uA ESTE eee eae 43 primitive dus dessine de Rd e TAREA 21 procedure body 21 procedure environment 38 procedure eine ere c P EID UNE Sse 20 Process alive oon s vh eigene 53 process continue 54 process error ev e ee ea 53 process exit status 54 process inp t veria e xen 53 process licita 54 process list aia A AS 54 process outp t io eco eds 53 POCOS Pi cite hopes bet deed 53 process send signal 54 process stOp oe les RN VOI T ees 54 process wWait iie dd e b repe 53 processf lobees ilb let eh E bibis 53 promise ivt A det on a Sek rd 21 provider dis ne e eee RE Hes 29 101 provided sssr strie pue Puinen siluas 29 2 TUI aia
2. 55 socket shutdown 56 SOCket coco rei like sai res 54 BOLE weeds ded a dd saan 64 41 Split SUring i s er dens 19 pa EE 17 St ing od d Ra ee 19 14 20 String list iii drain b Edd DEED 19 string gt number 17 string gt regexp 48 49 StCING gt syMboOl surement 14 string gt uninterned symbol 14 string widget ss ns ste ds eee 33 string append 19 String cisS ur sis desde date esa 19 STING CLP eine uen es diner 19 String CiS iia dia dla ii 19 string ci 4 2 5 4 0 1 IRR ie 19 String Cl2T iik ka wash b uv A erg ud 19 string CODy ilie Vea LAT A Date 19 String fil serraria ve RESP S 19 e AAA retis 19 string index 4 sense 19 String length 3 ve st 19 STEINE LOOT eec Pete beer 19 string ref o o dp GG I UAE RR 19 String seb m sb p eR GR amenant 19 string uppef ie bb bee pee en 20 SEINE PL Sein eS ea 19 SETE tia e da ee eis wie eine hh 19 SLIDES uve seta veh pr etre 19 String al so oc ep I ELE EIE E P ELS 19 String irreal 19 EE doe ah vss RES IR e e fuu a 18 SUbSLIIDE c De Mees ian PR reek 19 symbol gt string 14 symbol bound 38 SYMbDOL TP su rames A Lau 14 SySbOl i seed cen melee E O ns 42 STK Reference Manual CAN sonne seb Y Ye ai UR PR PR AS 16 temporary file name 42 the environment tsunami eue 37
3. 41 file is readable 41 files TO aa 41 file is writable 41 find mod le ee RR ER ete 34 LLOOF en ren nue p e E T S PUN qa 16 fluid let i c pex ai 10 fl shuiiete Laden des teer uev rd 28 foreach sisi dns ads done 20 POT CS aa a be de Oka 20 FOLMA 45458 aus de matos eat 27 63 G garbage collector 59 BO Lee ee nee ile ote oops 63 EBc 8tatsSu wath Visi dia SA Yea etd 63 Bed codi ea Gh dle IN ere 16 PONS YM ccs od Se I A RU p et 15 get internal info 63 64 Pet Keyword sess e nee conne Legs 32 get output string 25 get signal handlers A4 get widget data 33 BetCcWd ioicnee lr dense bn ro 42 Eetenyioiis guia a eee dais patet red 42 Betpidccuin Xu ARV PR EVER 42 BE sus tints Line IGI A 82 POD dt taste shaded oe dence fo idea tnter 41 global environment 37 H hash table list gas 47 hash table for each A7 hash table get 46 hash table hash 46 45 hash table map A7 hash table put 46 hash table remove 46 hash table stats 48 hash table i m int eser tes 46 help getting 76 D S toast dat pua pU ped 9 ilisp packages ciego I RR 101 imag part e sn
4. 2 3 list obj procedure list is like list except that the last argument to list is used as the cdr of the last pair constructed list 1 2 3 12 3 list 1 2 3 4 5 1234 5 copy tree obj procedure Copy tree recursively copies trees of pairs If obj is not a pair it is returned otherwise the result is a new pair whose car and cdr are obtained by calling copy tree on the car and cdr of obj respectively Last pair was a standard procedure in R RS 14 STK Reference Manual 6 4 Symbols The STK reader can cope with symbols whose names contain special characters or letters in the non standard case When a symbol is read the parts enclosed in bars will be entered verbatim into the symbol s name The characters are not part of the symbol they only serve to delimit the sequence of characters that must be entered as is In order to maintain read write invariance symbols containing such sequences of special characters will e be written between a pair of x gt x string gt symbol X gt XI symbol gt string X gt X la bl gt la bl alBlc gt laBc write Fo0l gt writes the string Fo0 display Fo0l gt writes the string Fo0 Note This notation has been introduced because RRS states that case must not be significant in symbols whereas the Tk toolkit is case significant or more precisely thinks it runs over Tcl which is case signific
5. define class Z X Y 25599 In this case the Z class is more specific than the X or Y class for instances of Z However the initform specified in X and Y leads to a problem which one overrides the other The rule in STKLOS as in CLOS is that the superclasses listed earlier are more specific than those listed later So Rule 2 For a given class superclasses listed earlier are more specific than those listed later These rules are used to compute a linear order for a class and all its superclasses from most specific to least specific This order is called the class precedence list of the class Given these two rules we can claim that the initial form for the x slot of previous example is 1 since the class X is placed before Y in class precedence list of Z This two rules are not always enough to determine a unique order however but they give an idea of how things work STKLOS algorithm for calculating the precedence list is a little simpler than the CLOS one described in 15 for breaking ties Consequently the calculated class precedence list could be different Taking the F class shown in Figure 1 the STKLOS calculated class precedence list is f de ab c lt object gt lt top gt whereas it would be the following list with a CLOS like algorithm f de a c b lt object gt lt top gt 2This section is an adaptation of Jeff Dalton s J Dalton ed ac uk Brief introduction to CLOS 86 STK Reference Manual Howev
6. e String ports are similar to file ports except that characters are read from or written to a string rather than a file External command input or output ports are implemented with Unix pipes and are called pipe ports A pipe port is created by specifying the command to execute prefixed with the string Specification of a pipe port can occur everywhere a file name is needed Virtual ports creation needs that the basic I O functions are at the port creation time This functions will be used to simulate low level accesses a virtual device This kind of port is particularly convenient for reading or writing in a graphical window as if it was a file Once virtual port is created it can be accessed as a normal port with the standard Scheme primitives call with input file string proc procedure call with output file string proc procedure Note if string starts with the two characters these procedures return a pipe port Consequently it is not possible to open a file whose name starts with those two characters call with input string string proc procedure behaves exactly as call with input file except that the port passed to proc is the string port obtained from string call with input string 123 456 lambda x read x 123 call with output string proc procedure Proc should be a procedure of one argument Call with output string calls proc with a freshly opened output string port The result of this pro
7. scm scheme mode stk scheme mode stklos scheme mode auto mode alist Using Emacs and CMU Scheme CMU Scheme package package permits to run the STK interpreter in an Emacs window Once the package is loaded you can send text to the inferior S TK interpreter from other buffers containing Scheme source The CMU Scheme package is distributed with Emacs both FSF Emacs and Xemacs and you should have it if you are running this editor To use the CMU Scheme package with STK place the following lines in your emacs startup file Use cmu scheme rather than xscheme which is launched by default whence running run scheme xscheme is wired with CScheme autoload run scheme cmuscheme Run an inferior Scheme t setq scheme program name stk setq inferior scheme mode hook lambda split window After having entered those lines in your emacs file you can simply run the STK interpreter by typing M x run scheme STK Reference Manual 101 Read the CMU Scheme documentation or use the describe mode Elisp command for a complete description of this package Using Emacs and the Ilisp package Ilisp is another scheme package which allows to run the STK interpreter in an Emacs window This is a rich package with a lot of nice features lisp comes pre installed with Xemacs it has to be installed with FSF Emacs the last version of flisp can be ftp ed anonymously from ftp cs cmu edu 128 2 206 173
8. a gt real M 3 a gt real M t f top M 1 2 3 error since no method exists for 3 parameters The preceding methods use only one specializer per parameter list Of course each parameter can use a specializer In this case the parameter list is scanned from left to right to determine the applicability of a method Suppose we declare now define method M a lt integer gt b lt number gt integer number define method M a lt integer gt b lt real gt gt integer real define method M a b lt number gt top number In this case M 1 2 gt integer integer M 1 1 0 gt integer real M 1 stt gt integer M a 1 gt top number 4 2 Next method When a generic function is called the list of applicable methods is built As mentioned before the most specific method of this list is applied see 4 1 This method may call the next method in the list of applicable methods This is done by using the special form next method Consider the following definitions define method Test a lt integer gt cons integer next method define method Test a lt number gt cons number next method define method Test a list top 88 STK Reference Manual With those definitions Test 1 integer number top Test 1 0 gt number top Test t top 4 3 Example In this section we shall continue to define operations on the comp
9. x 2 the environment 2 read from string string procedure Performs a read from the given string If string is the empty string an end of file object is returned If an error occurs during string reading the result of read from string is undefined read from string 123 456 123 read from string gt an eof object dump string procedure Dump grabs the current continuation and creates an image of the current STK interpreter in the file whose name is stringP This image can be used later to restart the interpreter from the saved state See the STK man page about the image option for more details Note lmage creation cannot be done if Tk is initialized trace var symbol thunk procedure Trace var call the given thunk when the value of the variable denoted by symbol is changed Image creation is not yet implemented on all systems The current version 4 0 allows image dumping only on some platforms SunOs 4 1 x Linux 1 FreeBsd STK Reference Manual 63 define x 1 define y 0 trace var x lambda set y 1 set x 2 cons x y gt 2 1 Note Several traces can be associated with a single symbol They are executed in reverse order to their definition For instance the execution of begin trace var z lambda display One trace var z lambda display Two set z 10 will display the string Two before the string One on the current output port untrace
10. Of course a function which gives a key depending of the characters composing the string gives a better repartition and should probably enhance performances For instance the following call to make hash table should return a more efficient even if not perfect hash table make hash table string ci lambda s let len string length s do h 0 i O i 1 i len h set h h char gt integer char downcase string ref s i 46 STK Reference Manual Note Hash tables with a comparison function equal to eq or string are handled in an more efficient way in fact they don t use the hash table hash fucntion to speed up hash table retrievals hash table obj procedure Returns stt if obj is a hash table returns f otherwise hash table hash obj procedure hash table hash computes a hash code for an object and returns the hash code as a non negative integer A property of hash table hash is that equal x y implies equal hash table hash x hash table hash y q y P q y as the the Common Lisp sxhash function from which this procedure is modeled hash table put hash key value procedure Hash table put enters an association between key and value in the hash table The value returned by hash table put is undefined hash table get hash key procedure hash table get hash key default procedure Hash table get returns the value associated with key in the given hash table If no value has
11. e a matches any expression and binds the variable a to this expression e integer matches any integer e a a b matches the only list a a b pattern atom kwote lt atom gt and pat gt pata gt or pat lt paty gt not lt pat gt predicate STK Reference Manual Matches any expression eq to atom if all of pat gt match if any of pat gt through pat gt match if pat doesn t match if predicate is true lt pat gt 9 pat gt a list of n elements paloma a possibly empty repetition of lt pat gt in a list lt pat gt lt patn gt a vector of n elements identifier anything and binds identifier as a variable a anything any possibly empty repetition of anything in a list any end of list Table 3 Pattern Syntax e can only appear at the end of a list and always succeeds For instance a is equivalent to a e when occurring in a list matches any sequence of anything a b matches any list whose car is a and last car is b e a matches any list of a s possibly empty e x x matches any list of length 2 whose car is eq to its cadr e and not a x x matches any list of length 2 whose car is not eq to a but is eq to its cadr e 7 matches any vector whose length is at least 2 Note a b or a are invalid patterns whe
12. in the user ai lang lisp util emacs ilisp directory To use the lisp package with STK place the following lines in your emacs startup file autoload run ilisp ilisp Select a new inferior LISP t autoload stk ilisp Run stk in ILISP t add hook ilisp load hook lambda O require completer Define STk dialect characteristics defdialect stk STk Scheme Scheme setq comint prompt regexp STk gt setq ilisp program stk interactive setq comint ptyp t setq comint always scroll t setq ilisp last command After having entered those lines in your emacs file you can simply run the STK interpreter by typing M x stk The Ilisp package comes with a rich documentation which describe how to customize the package Other packages Another way to use S TK and Emacs consists to use a special purpose STK mode You can find two such modes in the pub Contrib directory of kaolin unice fr 3 1 Using the SLIB package with STK Aubrey Jaffer maintains a package called SLIB which is a portable Scheme library which provides compatibility and utility functions for all standard Scheme implementations To use this package you have just to type require slib and follow the instructions given in the SLIB library to use a particular package Note SLIB uses also the require provide mechanism to load components of the library Once SLIB has been loaded the standard S TK require and provide are overl
13. procedure write obj port procedure Writes a written representation of obj to the given port The main difference with the write procedure is that write handles data structures with cycles Circular structure written by this procedure use the x and x notations see 2 3 As write the port argument can be omitted defaulting to the value returned by current output port and the value returned by write is undefined let 1 cons 1 2 set cdr 1 1 write 1 writes 0 1 0 let Q1 12 12 3 2 13 5 6 append 11 12 13 list 11 12 13 gt writes 1 2 0 3 4 1 5 6 0 1 display obj procedure display obj port procedure newline procedure newline port procedure write char char procedure write char char port procedure Identical to RA RS format port string obj objo procedure Writes the objs to the given port according to the format string string String is written literally except for the following sequences e a or A is replaced by the printed representation of the next obj e sor S is replaced by the slashified printed representation of the next obj 28 STK Reference Manual e w or W is replaced by the printed representation of the next obj circular structures are correctly handled and printed using writes e is replaced by a single tilde e is replaced by a newline Port can be a boolean a port or a string p
14. tilde expansion 40 O Regent ene eer Mie edad 65 th OOK 24e dure RE 7 32 63 tk command 32 33 72 tk command 42 2s ko re e Re 32 A db ceeded eyed be aa 7 32 63 top level environment 11 37 82 brace Var ldilwegeiwe vp ek oe eee chs d 62 transcript Off iler vb ada 3l 7T transcript Ohee drone ds eer 3l 77 tr ncate iil eda ah eese eder epa 16 try load dye EM EPIS 29 U UNCOME 55 n n yeh xe qe EIER 64 A p i pa E a 9 11 o EEE hited Re be M Ra EEEE 11 untrace Var onere er da ot d e 63 V Valu S iiii eg ar yeh se cale 96 MECO P 20 vector li8t sir aT ga AER chats 20 VECTOR COPY tulipe au d inde a dut 20 vector filll sus steam seen 20 yector lengthi i pt eR 20 Vector ref o wis vA 3 eee 20 vector resize vore beet 20 vector setl suisses sation 20 NeCtOrT uu eve ple ERREUR woud 20 Version nores eet dte red Vaud duis 61 Vi no AR etre ee tates 65 W WHEN sushi ka RA sieste ds Sete ARR IR 9 when port readable 28 when port writable 29 when socket ready 57 While A se enter ne mes AAA met 11 Widget dedu ent ie NT an nn 32 widget string ule Iber 33 Widget NAME movi e eR n es 33 Widget 2s de puer e asd en 32 with error to file 4ii 226 S 23 with error to port 24 with error to string 24 with input from file
15. 2 Class definition and instantiation 2 1 Class d finitions ca a a DAS Re ee mod 3 Inheritance 305 x RoDass A 303 SA tos Ros ubi le Bote 3 1 Class hierarchy and inheritance of slots 3 2 Instance creation and slot access 3 3 Slot description 2 0 4 208 Dios ne rere ANSE AAA 3 4 Class precedence list 4 Generic functions 444 4 1 Generic functions and methods 4 2 Next2miethod titi Meek RME Seb tet ee le i Se RS 4 3 Exampl z s e Roe x um Yo abcy eee D Modules Examples E Changes F Miscellaneous Informations 1 Introduction s 4 5 2 2 e margo E enu amp sale fe een ee di ns 2 About s TK s a Mis ta tes wai ade ow eB oe I fu qat V 2 1 Latest release s ce Mas tSc m ee Ea ne nus 2 2 sharing Code ss dues helene A Ee oO ue des 2 3 STK Mailing list 4 4 4 42 pe RIRs ge um las A 2 4 STR FAQ i5 rag ses ve nets ne Liu eh PA UE e eter Sedis 2 5 Reportmg bug Roos RE ae peg em dox aa 3 oTr and Macs os de deze WA a Batol os ap ast aa x 3 1 Using the SLIB package with STK 4 Getting information about Scheme 4 1 The HAS document s e dv re E od ee ed RO os 4 2 The Scheme Repository 4 3 Usenet newsgroup and other addresses 69 71 71 72 73 75 75 77 77 79 Part I Reference Manual I
16. 23 109 with input from port 24 with input from string 24 With modul sis OD LACE eas 36 with output to file 23 with output to port 24 with output to string 24 A t iuesbgt de e neben a 27 HEITER ihre edent ta dae diaii seen det 27 WIite chariis du sg a a Di 27 WIlLOS ilskl4iRA os 28 x window system 7 rA d al 15
17. a variable and textvariable in a given environment This environment is given with the new environment option e About STklos The MOP of STKLOS is now very similar to the CLOS s MOP In particular generic function has been added for controlling slot accesses as well as numerous introspection functions When a class is redefined the instances and methods which uses it are redefined accord ingly as in CLOS i e if anew slot is added in a class all its direct or indirect instances will have the new slot added dynamically Release 3 1 1 Release date 09 26 96 This release is a bug correction release It corrects a lot of bugs A lot of these bugs prevent to install it on some architectures Release 3 1 Release date 07 24 96 e Version of Tk is now at Tk4 1 level e STk has been ported on Windows 95 and Windows NT STK Reference Manual 97 Ports can have a handler which is executed when port becomes readable or writable see prim itives when port readable and when port writable Sockets in server mode allow multiple concurrent connection STKLOs Two new methods object eqv and object equal which are called when applying eqv or equal to instances New primitive setenv Release 3 0 Release date 01 22 96 Version of Tk is at Tk4 0p2 level Closures are fully supported by Tk That means that a callback can be now a Scheme clo sure with its environment GC problems with closures and usage o
18. appendix shows some usages of the STK modules Most of the examples which are exhibited here are derived from the Tung and Dybvig paper 5 Interactive Redefinition Consider first the definitions define module A export square define square lambda x x x define module B import A define distance lambda x y sqrt square x square y Obviously the square function exported from A is incorrect as we can see in its usage below with module B round distance 3 4 gt 4 0 The function can be redefined corrected by the following expression with module A set square lambda x x x And now with module B round distance 3 4 Ep which is correct 91 92 STK Reference Manual Lexical principle This example reuses the modules A and B of previous section and adds a Compare module that exports the less than 4 predicates which states if the distance from a point to the origin is less than 4 define module A export square define square lambda x x x define module B import A export distance define distance lambda x y sqrt square x square y define module Compare import B define less than 4 lambda x y distance x y 4 define square lambda x x x Consider now the call with module compare less than 4 3 4 gt Hf The call to distance done from less than 4 indirectly calls the square
19. been associated with key in hash the specified default is returned if given otherwise an error is raised define hi make hash table hash table put hi foo list 1 2 3 hash table get hi foo gt 1 2 3 hash table get hi bar absent absent hash table get hi bar gt error hash table put hi a b c present hash table get hi a b c absent gt absent define h2 make hash table equal hash table put h2 a b c present hash table get h2 a b c gt present hash table remove hash key procedure hash must be a hash table containing an entry for key Hash table remove deletes the entry for key in hash if it exists Result of Hash table remove is unspecified STK Reference Manual A7 define h make hash table hash table put h foo list 1 2 3 hash table get h foo 123 hash table remove h foo hash table get h foo absent absent hash table for each hash proc procedure Proc must be a procedure taking two arguments Hash table for each calls proc on each key value association in hash with the key as the first argument and the value as the second The value returned by hash table for each is undefined Note The order of application of proc is unspecified let h make hash table sum 0 hash table put h foo 2 hash table put h bar 3 hash table for each h lambda key value set sum sum value
20. body foo gt lambda a b let x a y b 1 cons x y STK Reference Manual 65 General inspector 3 4 5 6 lt Tk command I gt lt Tk command 11 gt Figure 1 A view of the Inspector Note When a macro has been directly expanded into the macro call code it is not possible to retrieve the original macro call Set debug to t to avoid macro expansion in lining time expr macro Evaluates the expression expr in the current environment Prints the elapsed CPU time and the number of conses used before returning the result of this evaluation apropos symbol procedure Apropos returns a list of symbol whose print name contains the characters of symbol Symbols are searched for in the current environment apropos cadd gt caddar caddr cadddr inspect obj procedure Inspect permits to graphically inspect an object The first call of this procedure creates a top level window containing the object to inspect and its current value If the inspector window is already on screen obj will be appended to the list of inspected objects The inspector window contains menus which permit to call the viewer or detailer on each inspected object See the on line documentation for further details A view of the general inspector is given in figure 1 Note Tk must be initialized to use inspect view obj procedure View permits to obtain a graphical representation of an STK object The type of re
21. cadr pair procedure cdddar pair procedure cddddr pair procedure null obj procedure list obj procedure list obj procedure length list procedure append list procedure Identical to RA RS append list procedure Returns a list consisting of the elements of the first list followed by the elements of the other lists as with append The differenece with append is that the arguments are changed rather than copied append 1 2 3 4 5 65 gt 1234596 let 201 1 2 12 3 4 13 5 6 append 11 12 13 list 11 12 13 gt 123456 3 4 5 6 56 STK Reference Manual 13 reverse list procedure list tail list k procedure list ref list k procedure memq obj list procedure memv obj list procedure member obj list procedure assq obj alist procedure assv obj alist procedure assoc obj alist procedure Identical to R RS remq obj list procedure remv obj list procedure remove obj list procedure Each function return a copy of list where all the occurences of obj have been deleted The predicate used to test the presence of obj in list is respectively eq eqv and equal Note It is not an error if obj does not appear in list remq 1 12 3 23 remq foo gt foo bar foo bar remove foo foo bar bar last pair list procedure Returns the last pair of list last pair 1 2 3 gt 3 last pair 1 2 3
22. complex numbers are not implemented real obj procedure Returns t if obj is a float number otherwise returns f rational obj procedure Returns the same result as number Note that rational numbers are not implemented integer obj procedure Returns stt if obj is an integer otherwise returns f Note The STK interpreter distinguishes between integers which fit in a C long int minus 8 bits and integers of arbitrary length aka bignums This should be transparent to the user though exact z procedure inexact z procedure In this implementation integers C long int or bignums are exact numbers and floats are inexact z 29 Z3 procedure lt T1 la r3 procedure gt 11 2 r3 procedure lt r4 T2 3 procedure gt r4 T2 3 procedure zero z procedure 16 positive z negative z odd z even z max r4 x9 min r4 z2 21 zy z 22 2 21 2 z 22 2z 21 22 is abs x quotient nj n remainder n na modulo ny na gcd n lem m4 Identical to R RS numerator q denominator q Not implemented floor x ceiling x truncate r round r Identical to R RS rationalize x y not yet implemented exp z log 2 sin z cos z tan z asin z acos z atan z atan y x STK Reference Manual procedure procedure procedure pr
23. define method sers ons de dau 86 define module 34 36 DELAY dew e CREER ERAS 10 21 denominator 16 77 describe i leac e petet bed 81 detail aa eons ERU E 65 68 dirname i ire eh eee e eS adie 40 display isses re is 27 6 Ko ik eae v orsa be eed E GR He ae eds 10 dtme UM Gk tN MN des 11 dump esiti CDU eee Senes ee 62 dynamic wind 21 E emacs editor 100 environment gt list 37 environment sess dessus 37 Os in Eee whi tate tel E Is oak 13 Ea as 12 14 45 46 A be ele obrero rh redes 13 SOU aN tree ede aaah te Ale heads GARE SE 12 OQ Vis shee gid Gite du Md ul per he ne 13 OVS atin cab AA eae And us 11 12 ETOL in ques mourant ba pee La gr 63 e6V l c iioi ebd pede edes e re wed 61 eval Strict dan tes sd 62 SS p geid ieegake ieie ipia aie 16 exact inexact ridad tds nated wat 17 exact ns a bs DE 15 CXOC uit TANT Reit deutet dae tie een d 42 OXI Dei ee iat dune Ute ques qe 68 ppp ETE 16 expand file name 40 expand heap 63 EXPTE Mita du tia ed east 35 export all symbols 36 export Symbol slk wk eh 35 OXP sci carre RUD SURE et ee ae 17 external exists 61 F Ls ia ds 100 Pile exists Pia dia RE UE Al file is directory Al 106 file is executable
24. down socket procedure Returns stt if socket has been previously closed with socket shutdown It returns f other wise socket dup socket procedure Returns a copy of socket The original and the copy socket can be used interchangeably However if a new connection is accepted on one socket the characters exchanged on this socket are not visible on the other socket Duplicating a socket is useful when a server must accept multiple simultaneous connections The following example creates a server listening on port 1234 This server is duplicated and once two clients are present a message is sent on both connections define si make server socket 1234 define s2 socket dup s1 socket accept connection s1 socket accept connection s2 blocks until two clients are present display Hello n socket output s1 display world n socket output s2 flush socket output s1 flush socket output s2 STK Reference Manual 57 when socket ready socket handler procedure when socket ready socket procedure Defines a handler for socket The handler is a thunk which is executed when a connection is available on socket If the special value f is provided as handler the current handler for socket is deleted If a handler is provided the value returned by when socket ready is undefined Otherwise it returns the handler currently associated to socket This procedure in conjunction with socket dup permits to build multipl
25. from file 1s 1s lambda do 1 read line read line Ceof object 1 display 1 newline Hereafter is another example of Unix command redirection This time it is the standard input of the Unix command which is redirected with output to file mail root lambda format t A simple mail sent from STk n 24 STK Reference Manual with input from port port thunk procedure with output to port port thunk procedure with error to port port thunk procedure These procedure are similar to the above function except that the thunk is called with the input output or error port redirected to the given port port can be any kind of port let p open input string 123 456 with input from port p lambda read p 123 with input from string string thunk procedure A string port is opened for input from string Current input port is set to the port and thunk is called When thunk returns the previous default input port is restored With input from string returns the value yielded by thunk with input from string 123 456 lambda read gt 123 with output to string thunk procedure A string port is opened for output Current output port is set to it and thunk is called When the thunk returns the previous default output port is restored With output to string returns the string containing all the text written on the string port with output to string lambda write 12
26. init keyword may be provided during instance creation i e in the make optional parameter list Specifying such a keyword during instance initialization will supersede the default slot initialization possibly given with initform getter permits to supply the name for the slot getter The name binding is done in the global environment setter permits to supply the name for the slot setter The name binding is done in the global environment accessor permits to supply the name for the slot accessor The name binding is done in the global environment An accessor permits to get and set the value of a slot Setting the value of a slot is done with the extended version of set allocation permits to specify how storage for the slot is allocated Three kinds of allocation are provided They are described below instance indicates that each instance gets its own storage for the slot This is the default class indicates that there is one storage location used by all the direct and indirect instances of the class This permits to define a kind of global variable which can be accessed only by in direct instances of the class which defines this slot virtual indicates that no storage will be allocated for this slot It is up to the user to define a getter and a setter function for this slot Those functions must be defined with the slot ref and slot set options See the example below To illustrate slot description we s
27. is replaced by the substitution string If there is no match regexp replace returns string unmodified Note that the given pattern could be here either a string or a regular expression If pattern contains strings of the form n where n is a digit between 1 and 9 then it is replaced in the substitution with the portion of string that matched the n th parenthesized subexpression of pattern If n is equal to 0 then it is replaced in substitution with the portion of string that matched pattern 50 STK Reference Manual regexp replace a b aaabbcccc X gt Xbcccc regexp replace string gt regexp a b aaabbcccc X gexp rep g gexp gt Xbcccc regexp replace a b aaabbcccc X 1Y gt XaaaYbcccc regexp replace a b aaabbcccc X 0Y gt XaaabYbcccc regexp replace a z a z john brown 2 NM gexp rep J gt brown john Regexp replace replaces the first occurence of pattern in string To replace all the occurences of the pattern use regexp replace all regexp replace a b aaabbcccc X gt Xbcccc regexp replace all a b aaabbcccc X gt XXcccc 6 21 Pattern matching Pattern matching is a key feature of most modern functional programming languages since it allows clean and secure code to be written Internally pattern matching forms should be translated compiled into cascades of elementary tests where code is made as efficient as possible av
28. list which only contains lt object gt the root of all the classes defined by define class D E F use multiple inheritance each class inherits from two previously defined classes Those class definitions define a hierarchy which is shown in Figure 1 In this figure the class lt top gt is also shown this class is the super class of all Scheme objects In particular top is the super class of all standard Scheme types The set of slots of a given class is calculated by unioning the slots of all its super class For instance each instance of the class D defined before will have three slots a b and d The slots of a class can be obtained by the class slots primitive For instance class slots A a class slots E aec class slots F d a b c f Note The order of slots is not significant IWith this definition a real is not a lt complex gt since real inherits from number rather than lt complex gt In practice inheritance could be modified a posteriori if needed However this necessitates some knowledge of the meta object protocol and it will not be shown in this document STK Reference Manual 81 top pair procedure lt number gt real quee M Figure C 1 A class hierarchy object 3 2 Instance creation and slot access Creation of an instance of a previously defined class can be done with the make procedure This procedure takes one mandatory param
29. macro expand 1 1 10 gt 10 1 macro expand 1 10 gt 10 1 macro expand 1 10 1 10 macro expand 10 10 1 macro expand form procedure Returns the macro expansion of form if it is a macro call otherwise form is returned un changed Macro expansion continue until the form obtained is define 1 macro form list cadr form 1 macro expand 1 10 gt 10 1 macro body macro procedure Returns the body of macro macro body 1 gt macro form list cadr form 1 define macro name formals body macro Define macro is a macro which permits to define a macro more easily than with the macro form It is similar to the defmacro of Common Lisp 6 40 STK Reference Manual define macro incr x set x x 1 let a 1 incr a a 2 define macro when test body if test if null cdr body body begin body macro expand when a b gt if a b macro expand when a b c d if a begin b c d Note Calls to macros defined by define macro are physically replaced by their macro expansion if the variable debug is f i e their body is in lined in the macro call To avoid this feature and to ease debugging you have to set this variable to stt See also 6 25 6 16 System procedures This section lists a set of procedures which permits to access some system internals expand file name string
30. procedure Expand file name expands the filename given in string to an absolute path This function understands the tilde convention for filenames Current directory is users eg STk expand file name gt users eg expand file name root bin bin expand file name STk gt users eg STk canonical path path procedure Expands all symbolic links in path and returns its canonicalized absolute pathname The resulting path do not have symbolic links If path doesn t designate a valid pathname canonical path returns f dirname string procedure Returns a string containing all but the last component of the path name given in string dirname a b c stk a p basename string procedure Returns a string containing the last component of the path name given in string basname a b c stk gt c stk STK Reference Manual 41 decompose file name string procedure Returns an exploded list of the path name components given in string The first element in the list denotes if the given string is an absolute path or a relative one being or respectively Each component of this list is a string decompose file name a b c stk na p e stk decompose file name a b c stk gt un a p c stk file is directory string procedure file is regular string procedure file is readable string procedure file is writable string procedure file is exe
31. procedure of module A rather than the one defined locally in module Compare Mutually Referential Modules This example uses two mutually referential modules taht import and export to each other to implement mutually recursive even and odd procedures define module Odd 3 Forward declaration define module Even import Odd export even define even lambda x if zero x t odd x 1 define module Odd import Even export odd define odd lambda x if zero x ttf even x 1 Hereafter are some usages of theses procedures STK Reference Manual with module Odd odd 3 gt dit with module Odd odd 10 gt df with module Even even 3 gt df with module Even even 10 gt dit 93 94 STK Reference Manual Appendix E Changes Introduction This appendix lists the main differences among the various recent versions of STk Differences with older versions as well as implementation changes are described in the CHANGES file located in the main directory of the STk distribution Release 4 0 0 Release date 09 03 99 Mains changes modifications since 3 99 4 e define syntax e Integration of SRFI 0 2 6 8 Release 3 99 4 Release date 02 02 99 Mains changes modifications since 3 99 3 e Virtuals ports Release 3 99 3 Release date 09 30 98 Mains changes modifications since 3 99 2 e Tk version is 8 0 3 e Dase64 Encoding Decoding extension e Local
32. result is com pared with each successive patterns If the pattern in some clause yields a match then the expressions in that clause are evaluated from left to right in an environment where the pattern variables are bound to the corresponding subparts of the datum and the result of the last expression in that clause is returned as the result of the match case expression If no pat in any clause matches the datum then if there is an else clause its expressions are evaluated and the result of the last is the result of the whole match case expression otherwise the result of the match case expression is unspecified The equality predicate used is eq match case a b a x x foo x x bar gt bar match lambda clause clause2 syntax The form match lambdaexpands into a lambda expression expecting an argument which once applied to an expression behaves exactly like a match case expression match lambda x x foo x x bar bar gt bar The pattern language The syntax is presented in Table 3 It is described below in the same way and nearly in the same words as in 10 Note and or not check and kwote must be quoted in order to be treated as literals This is the only justification for having the kwote pattern since by convention any atom which is not a keyword is quoted Explanations through examples e matches any s expr e a matches the atom a
33. setenv var value procedure Sets the environment variable var to value Var and value must be strings The result of setenv is undefined getenv SHELL gt bin zsh STK Reference Manual 43 6 17 Addresses An address is a Scheme object which contains a reference to another Scheme object This type can be viewed as a kind of pointer to a Scheme object Addresses even though they are very dangerous have been introduced in STK so that objects that have no readable external representation can still be transformed into strings and back without loss of information Adresses were useful with pre 3 0 version of S TK their usage is now stongly discouraged unless you know what you do In particular an address can designate an object at a time and another one later i e after the garbage collector has marked the zone as free Addresses are printed with a special syntax pNNN where NNN is an hexadecimal value Reading this value back yields the original object whose location is NNN address of obj procedure Returns the address of obj address obj procedure Returns t if obj is an address returns f otherwise 6 18 Signals STK allows the use to associate handlers to signals Signal handlers for a given signal can even be chained in a list When a signal occurs the first signal of the list is executed Unless this signal yields the symbol break the next signal of the list is evaluated When a signal handler is call
34. sum hash table map hash proc procedure Proc must be a procedure taking two arguments Hash table map calls proc on each entry in hash with the entry s key as the first argument and the entry s value as the second The result of hash table map is a list of the values returned by proc in unspecified order Note The order of application of proc is unspecified let h make hash table dotimes i 5 hash table put h i number gt string i hash table map h lambda key value cons key value 0 O 3 3 2 2 1 1 4 4 hash table gt list hash procedure hash table gt list returns an association list built from the entries in hash Each entry in hash will be represented as a pair whose car is the entry s key and whose cdr is its value Note The order of pairs in the resulting list is unspecified let h make hash table dotimes i 5 hash table put h i number gt string i 48 STK Reference Manual hash table gt list h CO 10 3 3 131 2 2 1 131 4 a 1410 hash table stats hash procedure Hash table stats returns a string with overall information about hash such as the number of entries it contains the number of buckets in its hash array and the utilization of the buckets 6 20 Regular expressions Regular expressions are first class objects in STK A regular expression is created by the string gt regexp procedure Matching a regular expre
35. symbol bound symbol procedure symbol bound symbol environment procedure Returns stt if symbol has a value in the given environment otherwise returns f Environment may be omitted in which case it defaults to the global environment 6 15 Macros STK provides low level macros Note STK macros are not the sort of macros defined in the appendix of R4RS but rather the macros one can find in most of Lisp dialects macro formals body syntax Macro permits to create a macro When a macro is called the whole form i e the macro itself and its parameters is passed to the macro body Binding association is done in the environment of the call The result of the binding association is called the macro expansion The result of the macro call is the result of the evaluation of the macro expansion in the call environment STK Reference Manual 39 define foo macro f quote f foo 1 2 3 gt foo 1 2 3 define 1 macro form list cadr form 1 let x 1 1 xD 2 macro obj procedure Returns stt if obj is a macro otherwise returns f macro expand 1 form procedure macro expand form procedure Macro expand 1 returns the macro expansion of form if it is a macro call otherwise form is returned unchanged Macro expand is similar to macro expand 1 but repeately expand form until it is no longer a macro call define 1 macro form cadr form 1 define macro form 1 cadr form
36. the most specific method of this list i e the first method of the sorted methods list The definition of a generic function is done with the define generic macro Definition of a new method is done with the define method macro Note that define method automatically defines the generic function if it has not been defined before Consequently most of the time the define generic needs not be used Consider the following definitions define generic M define method M a lt integer gt b integer define method M a lt real gt b real define method M a b top The define generic call defines M as a generic function Note that the signature of the generic function is not given upon definition contrarily to CLOS This will permit methods with different signatures for a given generic function as we shall see later T he three next lines define methods for the M generic function Each method uses a sequence of parameter STK Reference Manual 87 specializers that specify when the given method is applicable A specializer permits to indicate the class a parameter must belong to directly or indirectly to be applicable If no speciliazer is given the system defaults it to lt top gt Thus the first method definition is equivalent to define method M a lt integer gt b lt top gt integer Now let us look at some possible calls to generic function M M 2 3 gt integer M 2 t gt integer M 1 2
37. 1 export a b define a Mi a define b M1 b define module M2 export b c define b M2 b define c M2 c define module M3 import M1 M2 display list a b c gt displays mi a mi b m2 c Note There is no kind of transitivity in module importations when the module C imports the module B which an importer of A the symbols of A are not visible from C except by explicitly importing the A module from C Note The module STk which contains the global variables is always implicitly imported from a module Furthermore this module is always placed at the end of the list of imported modules export symbol symbol module procedure Exports symbol from module This procedure can be useful when debugging a program to make visible a given symbol without reloading or redefining the module where this symbol was defined 36 STK Reference Manual export all symbols procedure Exports all the symbols of current module If symbols are added to the current module after the call to export all symbols they are automatically exported Note The STk module export all the symbols which are defined in it i e global variables are visible if not hidden from all the modules of a program with module name expri expro syntax Evaluates the expressions of expri expra in the environment of module name Module name must have been created previously by a define module The result of with module is the result
38. 3 write Hello gt 123Hello with error to string thunk procedure A string port is opened for output Current error port is set to it and thunk is called When the thunk returns the previous default error port is restored With error to string returns the string containing all the text written on the string port with error to string lambda write 123 current error port 123 open input file filename procedure open output file filename procedure Identical to R RS STK Reference Manual 25 Note if filename starts with the string these procedure return a pipe port Consequently it is not possible to open a file whose name starts with those two characters open input string string procedure Returns an input string port capable of delivering characters from string open output string procedure Returns an output string port capable of receiving and collecting characters get output string port procedure Returns a string containing all the text that has been written on the output string port let p open output string display Hello world p get output string p gt Hello world open input virtual getc readyp eofp close procedure Returns a virtual port using the getc procedure to read a character from the port readyp to know if there is to read from the port eofp to know if the end of file is reached on the port and finally close to close the port All theses p
39. 78 MAKES sms cass durer RR DR ERG E ERR 81 make client socket 54 55 make hash table 45 make keyword 31 make pola umi sente soute 17 77 84 make rectangular 17 77 84 make server socket 55 make strahg s ts 18 make vecbOt sio eee rm Re P P ane 20 STK Reference Manual Map Seger dad 20 match ca se dile ege Pe eren 50 96 match lambd ceo eve Rv ws 51 96 Ma ea d ee ur re en ers 16 member da a a ete eres e xe 13 MOM cc edes vel ee Pe eR UP pe UA 13 MENT derem 13 A 32 Mii td dada ace NE 16 module environment 38 module exportSiu icd omis eT VAS 37 module imports 37 MOdule NaME vito cade rele eme leues 37 module symbols 37 module ecole p veo e a 34 modulos tie etude bis es eov ee eee 16 N negative eer ida tede a aides 16 hewlline i ebd tr eI Ge LSU 27 Next method oie E it 87 NOC nee Mash eee hee Vb Sa EEE 11 DOLL Trga OEI 12 number gt string 17 DU mbGr ua den ent dant ne hades 15 n merator ioc sectes den 16 77 O Objetos ii reme d ils ae qa des eli ga 13 43 Odd 5s eae us gud Na Rent duet Peek eed 16 Open File cos iad a Ee rui d 29 open inp t file uk eA ARAS 24 open input string 25 open input virtual 25 open output file
40. 9 when port writable port handler procedure when port writable port procedure When port is ready for writing handler which must be a thunk is called leaving the current evaluation suspended When handler execution is terminated normal evaluation is resumed at its suspension point If the special value f is provided as handler the current handler for port is deleted If a handler is provided the value returned by when port writable is undefined Otherwise it returns the handler currently associated to port load filename procedure load filename module procedure The first form is identical to R RS The second one loads the content of filename in the given module environment Note The load primitive has been extended to allow loading of object files though this is not implemented on all systems This extension uses dynamic loading on systems which support it See 4 for more details try load filename procedure try load filename module procedure Tries to load the file named filename If filename exists and is readable it is loaded and try load returns t Otherwise the result of the call is f The second form of try load tries to load the content of filename in the given module environment autoload filename symboli symbolo syntax Defines symbol s as autoload symbols associated to file filename First evaluation of an autoload symbol will cause the loading of its associated file in the module environmen
41. Edition Digital Press 12 Crosby Drive Bedford MA 01730 USA 1990 POSIX Committee System Application Program Interface API C Language Information technology Portable Operating System Interface POSIX IEEE Computer Society Press 1109 Spring Street Suite 300 Silver Spring MD 20910 USA 1990 Manuel Serrano Bigloo User s Manual v1 9b June 1997 C Queinnec and J M Geffroy Partial Evaluation Applied to Symbolic Pattern Matching with Intelligent Backtrack In et al M Billaud editor Workshop in Static Analysis number 81 82 in Bigre Bordeaux France September 1992 A Wright and B Duba Pattern Matching for Scheme Technical report Department of Computer Science Rice University October 1993 John K Ousterhout Tcl and the Tk toolkit Addison Wesley 1994 Gregor Kickzales Tiny clos Source available on parcftp xerox com in directory pub mops December 1992 Apple Computer Dylan an Object Oriented Dynamic Language Apple April 1992 Chris Hanson The sos reference manual version 1 5 in line documentation of the SOS package Source available on martigny ai mit edu in archive cph directory March 1993 Jim de Rivi res Gregor Kickzales and Daniel G Bobrow The Art of Meta Object Protocol MIT Press 1991 103 be Pee etl ait RLM D RO 42 Won dd eese A p ETE 16 KargC manne nd ERAT AR 75 HAT EV eu da dre qudd ere ed 75 debU g i enu ie ru dea 40 65 75 gc verbose oc isole Wee ie E 75 belp
42. RS Furthermore operator can be a macro see section 6 15 lambda formals body syntax if test consequent alternate syntax if test consequent syntax set variable expression syntax Identical to R RS 4 2 Derived expression types cond clause clause2 syntax case key clause clause syntax and testi syntax or testi syntax Identical to R RS when test expression expressions syntax If the test expression yields a true value the expression s are evaluated from left to right and the value of the last expression is returned unless test expression expression gt syntax If the test expression yields a false value the expression s are evaluated from left to right and the value of the last expression is returned 10 let bindings body let variable bindings body let bindings body Identical to R RS fluid let bindings body STK Reference Manual syntax syntax syntax syntax The bindings are evaluated in the current environment in some unspecified order the current values of the variables present in bindings are saved and the new evaluated values are assigned to the bindings variables Once this is done the expressions of body are evaluated sequentially in the current environment the value of the last expression is the result of fluid let Upon exit the stored variables values are restored A
43. STx Reference manual Version 4 0 Erick Gallesio Universit de Nice Sophia Antipolis Laboratoire 135 CNRS URA 1376 ESSI Route des Colles B P 145 06903 Sophia Antipolis Cedex FRANCE email eg unice fr September 1999 Document Reference Erick Gallesio STk Reference Manual RT 95 31d I3S CNRS Universit de Nice Sophia Antipolis juillet 1995 Contents I Reference Manual 5 1 OVerVi Ww OL SAR ER not siden Bite editae Ne din ost I Nee OG sit ie er Moos 7 2 Lexical conventions T 2 1 Identifiersi ir Sot eos Se ace A as A 7 2 2 Comments car ais GP eB act ee Hoa he le Rw ds 7 2 3 Other notations 8 3 Basic Concepts Le Oviatt aks cte Vul dovete AE ei dag AUD a M 8 4 EXPLESSIONS een EE pe get A Vc C pe EPI AT AP RUN ORC mt YR 9 4 1 Primitive expression types 9 4 2 Derived expression types 9 5 Program structure 11 6 Standard procedures 23 5 ke ario be iy Reb ae c gum He 11 6 1 Booleans e sissy Ditch ade e e hA Nen rm Due 11 6 2 Equivalence predicates 11 6 3 Pamana lists 2x20 ER Ie unas er Bs RT LS 12 6 4 Symbols a sos Bae cts dm SER ee eR Rb ie RU RAS des 14 6 5 Numbers ass nes a ee ae ee aes E RIS Rime 15 6 6 Characters tt onc Le IR M SD ed sea ot RIS MA 17 6 7 MISS Be ee wor ely oe qox do FERRI Ne A VOR CX AO Ed 18 6 8 Metti
44. ae 10 QUINA PEE 68 QUOC S 9 quotient Saal cad di aa 16 h TUS I p sop Ue iras 7 101 randomsiicis files da e RE TUER 62 rational epeta iei Mee epe RE erp 15 rationalize s sodo 440 RR 16 77 read dire D E RV AH ee RES 26 8 read char le is woes ude ow lates 26 read from string 62 read line cl RR UIS 27 Teal partida dde dre 17 78 Teal sas does ane de delete ai west 15 regexp replace 49 50 regexp replace all 49 50 DST ASE E 49 regular expression 48 remalnder 422 sia ous user dies 16 Iemove ie tren ue lepores 13 remove file iiziciosa ki aeg bx ra iud 41 108 TV Tbeb e epe 13 rename file i 2l tut Iw SI 42 repl display prompt 76 repl display result 76 Sport erro opu otal eerie 76 requlfe c iit ei y added coy 29 101 IeVersOu cele per eer pp added aed 13 toot WIDdOW sx e e E dy pie de 72 found seis SUO PON Peer Us 16 f h process i8 weh lan UU Ga OA 52 S scheme repository 102 Select module si sig ler pes X pue 36 send sign l iici Idee minibus 44 STE gg e e eR ERR 9 82 83 St Carl is sis dau caeesanneoavanttls 12 Set cdr iisuinio dh a sepe hired hii ae 12 set random seed 62 set signal handler 43 44 set widget datal 33 S tenv ie ie mas eel dee eius 42 SEEGER ais po ne Peer nr C
45. al info procedure Returns a 7 length vector which contains the following informations STK Reference Manual 0 total cpu used in milli seconds E number of cells currently in use 2 total number of allocated cells 3 number of cells used since the last call to get internal info 4 number of gc runs 5 total time used in the gc 6 a boolean indicating if Tk is initialized sort obj predicate procedure Obj must be a list or a vector Sort returns a copy of obj sorted according to predicate Predicate must be a procedure which takes two arguments and returns a true value if the first argument is strictly before the second sort 1 2 4 12 9 1 2 3 lt 4 1 1 2 2 3 9 12 sort one two three four lambda x y gt string length x string length y gt three four one two uncode form procedure When STK evaluates an expression it encodes it so that further evaluations of this expression will be more efficient Since encoded forms are generally difficult to read uncode can be used to re obtain the original form define foo a b let x a y b 1 cons x y procedure body foo gt lambda a b let x a y b 1 cons x y foo 1 2 1 3 procedure body foo gt lambda a b let x y lt local a 0 0 gt lt global gt lt local b 00 1 1 lt global cons gt lt local x 0 0 gt lt local y 0 1 gt uncode procedure
46. aluation of a sexpr to write the result This procedure is described in repl display result n STK Reference Manual 77 2 Types STK implements all the types defined as mandatory in R RS However complex numbers and rational numbers which are defined but not required in R RS are not implemented The lack of these types implies that some functions of RIRS are not defined Some types which are not defined in R4RS are implemented in STK Those types are listed below e input string port type 6 10 e output string port type 6 10 keyword type 6 11 e Tk command type 6 12 e environment type 6 14 macro type 6 15 address type 6 17 hash table type 6 19 Regular expression type 6 20 process type 6 22 socket type 6 23 3 Procedures The following procedures are required by R RS and are not implemented in the STK inter preter e transcript off e transcript on Transcript off and transcript on can be simulated with various Unix tools such as script or fep The following procedures are not implemented in the STK interpreter whereas they are defined in RIRS but not required They are all related to complex or rational numbers e numerator e denominator rationalize e make rectangular e make polar 78 real part imag part magnitude angle STK Reference Manual Appendix C An introduction to STKLOS 1 Introduction S TKLOS is the object oriented layer of STK Its implementati
47. ant However symbols containing the character itself still can t be read in symbol obj procedure Returns stt if obj is a symbol otherwise returns f symbol foo gt dt symbol car a b dit symbol bar df symbol nil dit symbol dH symbol f df symbol key df symbol gt string symbol procedure string gt symbol string procedure Identical to R RS string gt uninterned symbol string procedure Returns a symbol whose print name is made from the characters of string This symbol is guaranteed to be unique i e not eq to any other symbol let ua string gt uninterned symbol a list eq a ua eqv a ua eq ua string gt uninterned symbol a eqv ua string gt uninterned symbol a gt f dt Hf t STK Reference Manual 15 gensym procedure gensym prefir procedure Gensym creates a new symbol The print name of the generated symbol consists of a prefix which defaults to G followed by the decimal representation of a number If prefix is specified it must be a string gensym 6100 gensym foo gt foo 101 6 5 Numbers The only numbers recognized by S TK are integers with arbitrary precision and reals im plemented as C double floats number obj procedure Returns stt if obj is a number otherwise returns f complex obj procedure Returns the same result as number Note that
48. bject procedure Returns t if object is a module and f otherwise module find module STk gt dit module STk In fact define module on a given name defines a new module only the first time it is invoked on this name By this way inteactively reloading a module does not define a new entity and the other modules which use it are not altered STK Reference Manual 35 gt df module 1 gt df export symbol symbolz syntax Specifies the symbols which are exported i e visible outside the current module By default symbols defined in a module are not visible outside this module excepted the symbols which appear in an export clause If several export clauses appear in a module the set of exported symbols is determined by unioning symbols exported in all the export clauses The result of export is undefined import module module2 syntax Specifies the modules which are imported by the current module Importing a module makes the symbols it exports visible to the importer if not hidden by local definitions When a symbol is exported by several of the imported modules the location denoted by this symbol in the importer module correspond to the one of the first module in the list modulei modulez which export it If several import clauses appear in a module the set of imported modules is determined by appending the various list of modules in their apparition order define module M
49. blems Since this problem arises so often the variable root has been introduced in STK to denote the Tk main window Managing Widget Scrollbars When using scrollbars Tk library passes parameters to the widget associated to the scrollbar and vice versa Let us look at a text widget with an associated scrollbar When the scrollbar is moved the command of the associated widget is invoked to change its view On the other side when browsing the content of the text widget with arrows for example the scrollbar is updated by calling it s associated closure Tk library passes position informations to scrolling closures This informations are the parameters of the closure Hereafter is an example implementing a text widget with a scrollbar see the help pages for details Old syntax for callbacks i e strings is always supported but its use is deprecated STK Reference Manual 73 text txt yscrollcommand lambda 1 apply scroll set 1 scrollbar scroll command lambda 1 apply txt yview 1 pack txt side left pack scroll fill y expand t side left 3 Tk bindings Bindings are Scheme closures The Tk bind command associates Scheme scripts with X events Starting with version 3 0 those scripts must be Scheme closures Binding closures can have parameters Those pa rameters are one char symbols with the same conventions than the Tcl char see the bind help page for details For instance the follow
50. cedure is a string containing all the text that has been written on the string port call with output string lambda x write 123 x display Hello x gt 123Hello input port obj procedure output port obj procedure Identical to R RS STK Reference Manual 23 input file port obj procedure output file port obj procedure Returns stt if obj is either an input or an output file port otherwise returns f input string port obj procedure output string port obj procedure Returns t if obj is either an input or an output string port otherwise returns f input virtual port obj procedure output virtual port obj procedure Returns t if obj is either an input or an output virtual port otherwise returns f current input port procedure current output port procedure Identical to R RS current error port procedure Returns the current default error port with input from file string thunk procedure with output to file string thunk procedure with error to file string thunk procedure With input from file and with output to file are identical to R4RS With error to file is similar to with output to file except that this is the error port which is redirected to the file The following example uses a pipe port opened for reading It permits to read all the lines produced by an external 1s command i e the ouput of the 1s command is redirected to the Scheme pipe port with input
51. cutable string procedure file exists string procedure Returns stt if the predicate is true for the path name given in string returns f otherwise or if string denotes a file which does not exist glob pattern patterna procedure The code for glob is taken from the Tcl library It performs file name globbing in a fashion similar to the csh shell Glob returns a list of the filenames that match at least one of the pattern arguments The pattern arguments may contain the following special characters e Matches any single character e Matches any sequence of zero or more characters e chars Matches any single character in chars If chars contains a sequence of the form a b then any character between a and b inclusive will match e x Matches the character x e a b Matches any of the strings a b etc As with csh a at the beginning of a file s name or just after a must be matched explicitly or with a construct In addition all characters must be matched explicitly If the first character in a pattern is then it refers to the home directory of the user whose name follows the If the is followed immediately by then the value of the environment variable HOME is used Glob differs from csh globbing in two ways First it does not sort its result list use the sort procedure if you want the list sorted Second glob only returns the names of files that ac
52. e 17 char whitespace 17 CHATS din men Ne E REIN 17 CHALET na id nd utet aA eis dere 17 Charis s oda so Le M ee eee ee 17 CAT Pao A Toce nA en nn 17 ChAT fu dos ceto utes ade anode 17 Char Trier ci Acier d da VEDO 17 Characters a ie A 17 CHATT Mitek ed cays Hie ahah eaten ES A 42 circular structures 8 26 27 Chasse oa tics cupis Sel ttu d tame tutes Da 79 class precedence list 86 CLASSES LOS Lente wate ee med Aa 80 close input portos sueur 26 close output port 26 ClOSe POrb inie es ete T s 30 CLOS EOT7 coge a tae or a 20 emu scheme 5 41 se aie iud 100 complex os scele a pU bU 15 CONG od eder e Tat ee Talat ek deae ege 9 CODB ous o uc ea uer de Ati 12 continuation 20 21 62 continuation os secede sind its dre 21 COpY pOErt i eese n die teintes 30 COPY the as ies one e rep 13 COS cy EUR at nt a en nn 16 current error port 23 24 current input port 23 24 27 current modul en e ex 36 current output port 23 24 28 currentdiscretionary outputdiscretionary R POFE n idee de ii eme ot 27 105 D decompose file name Al default slot value 82 define class 00s seh ga e es 79 80 define external 58 57 defihe generice i ic iix IR den 86 define Macro is ee ER S 39 40
53. e allocation virtual slot ref lambda o atan slot ref o i slot ref o r slot set lambda o a let m slot ref o m slot set o r m cos a slot set o i m sin a Figure C 2 A complex number class definition using virtual slots lambda o m let m slot ref o m slot set o r m cos a slot set o i m sin a c 3 A more complete example is given below define c make complex r 12 i 20 real part c gt 12 angle c gt 1 03037682652431 slot set c i 10 set real part c 1 describe c lt complex gt 128bf8 is an instance of class complex Slots are 1 10 10 0498756211209 1 47112767430373 D BH HH Il Since initialization keywords have been defined for the four slots we can now define the make rectangular and make polar standard Scheme primitives STK Reference Manual 85 define make rectangular lambda x y make complex r x i y define make polar lambda x y make complex magn x angle y 3 4 Class precedence list A class may have more than one superclass With single inheritance one superclass it is easy to order the super classes from most to least specific This is the rule Rule 1 Each class is more specific than its superclasses With multiple inheritance ordering is harder Suppose we have define class X x initform 1 define class Y x initform 2
54. e small STK community you can deposit it in the directory pub STk Incoming of kaolin unice fr Mail me a small note when you deposit a file in this directory so I can put in in its definitive place pub STk Contrib directory contains the contributed code 2 3 STK Mailing list There is a mailing list for STK located on kaolin unice fr The intent of this mailing list is to permit to STK users to share experiences expose problems submit ideas and everything which you find interesting and which is related to S TK To subscribe to the mailing list simply send a message with the word subscribe in the Subject field of you mail Mail must be sent to the following address stk request kaolin unice fr To unsubscribe from the mailing list send a mail at previous email address with the word unsubscribe in the Subject field For more information on the mailing list management send a message with the word help in the Subject field of your mail In particular it is possible to find all the messages which have already been sent on the S TK mailing list Subscription un subscription information requests are processed automatically without human inter vention If you something goes wrong send a mail to egQunice fr Once you have properly subscribe to the mailing list e you can send your messages about STK to stk kaolin unice fr 99 100 STK Reference Manual e you will receive all the messages of the mailing list to the email address
55. e C world the library which defines this function The type of the ln release 4 0 FFI is known to work on the following architectures ix86 but not yet MS Windows Sun Sparc HP 9000 SGI 58 STK Reference Manual Corresponding C type Corresponding Scheme Type char char Scheme character or Scheme integer ishort short int ushort unsigned short int uint unsigned integer Tong Tong integer ulong unsigned long integer float float Scheme Real double double Scheme Real static ptr pointer on a static area Scheme C pointer object or dynamic ptr or pointer on a dynamic area Scheme C pointer object or void mallocated string or char pointer on a dynamic Scheme C pointer object or char string Scheme String boolean int Scheme boolean Table 4 FFI predefined types function result and the types of its arguments are defined in Table 4 This table lists the various keywords reserved for denoting types and their equivalence between the C and the Scheme worlds define external name parameters options syntax The form define external binds a new procedure to name The arity of this new procedure is defined by the typed list of parameters given by parameters This parameters list is a list of couples whose first element is the name of the parameter and the second one is is a keyword representing its type see table for equivalence All the types defined in Table 4 except void are a
56. e clients servers which work asynchronously Such a server is shown below define p make server socket 1234 when socket ready p let count 0 lambda set count count 1 register connection socket dup p count define register connection let sockets lambda s cnt Accept connection socket accept connection s Save socket somewhere to avoid GC problems set sockets cons s sockets Create a handler for reading inputs from this new connection let in socket input s out socket output s when port readable in lambda let 1 read line in if eof object 1 delete current handler when port readable in f Just write the line read on the socket begin format out On A gt A n cnt 1 flush out 6 24 Foreign Function Interface The STK Foreign Function Interface FFI for short has been defined to allow an easy access to functions written in C without needing to build C wrappers and consequently without any need to write C code Note that the FFI is very machine dependent and that it works only on a limited set of architectures Moreover since FFI allows very low level access it is easy to crash the interpreter when using an external C function The definition of an external function is done with the syntax define external This form takes as arguments a typed list of parameters and accepts several options to define the name of the function in th
57. e dite 82 S BADTE lg loni a detente 43 Sigal rm ii Pat ni ID Y 43 SIgbus il cc wi ere us LE VEDI 43 S gchld icol BS li 43 SIgcld eec Pages deinen 43 SIgCOnt ig wel d e eru pee ot a 43 SIB PO Licda e er Re RR re met 43 Sighupg loe lo bust PUR ture amet 43 Sigillo ul Ix Lx E pected 43 SIPING is b RIS REEL ERIT rand 43 SO s dis nia d e EI IRE RA 43 SIBYOLbug IR b edu eru er SEA 43 SIgktll 2255445 s MSc Per bees 43 siglos tica TA E 43 SIBplpe arbre ie 43 SYEpOll 1 21 32 2 dora ER ERN 43 SIEDIOI ee Ier eR Peeters 43 SIESOEV sos diosa o diem dto ode A ies 43 SYESLOD s v p ee alls MEER 43 SIESYSI Qi D A Row EA e quA EAST han 43 Sigterm i pee RM eer Red 43 Sigtrap i hA PLE TU AT Se 43 SIEUUlDh Ic Qi 9 40 39 go wa bep Ope Sepe 43 SJIELUOU geo AR Ree eR S YER ES 43 SIPUT E coco sad ei esed bee ere 43 SIEBUSP zlol lige Da qa Eh da a das 43 sigwinch rcu er bo ds URS 43 SIPXCPU eel eds seeds ss Ge Hide thy ERG RES 43 SIgX SZ DD clawed ned ens 43 STK Reference Manual Sin conse teda id 16 SID package suisse Pub eur vibes 101 A ve bere bre A Di rera 79 SlOt ref ionis He Ert etat s 81 slotoset linia 81 socket accept connection 55 56 Socket down isi wv eli PI DRE 56 S0cket dup cuicos ii ru eee pest 56 57 socket host address 55 socket host name 54 Sockeb input eiii 55 socket local address 55 Ssocket output i ve ye see 55 socket port number
58. e extension to treat strings and character using locale information Release 3 99 2 Release date 04 27 98 Mainly a bugs correcting release New function write which handle circular structures Format accepts now the special tag W for circular structures writing lOnly the differences which affect the language or new ports are reported here In particular internal changes packages written in Scheme STklos or performance enhancements are not discussed here 95 96 STK Reference Manual Release 3 99 1 Release date 04 27 98 Mainly a bugs correcting release Release 3 99 0 Release date 04 10 98 Changes can be classified in three categories e About Scheme A module system has been added Integration of the Bigloo match case and match lambda primitives Furthermore the file bigloo stk provides some compatibility between STK and bigloo modules A simple Foreign Function Interface has been added integrates the R RS values and call with values multi line comments have been added new file primitives remove file rename file and temporary file name new list primitives append last pair remq remv and remove load try load and autoload can nw be called with a module as second parameter If this second parameter is present the loading is done in the environment of the given module e About Tk Integration of the Tk8 0 toolkit Buttons Checkbuttons and Radiobuttons can use
59. e of the dotimes expression If result is omitted dotimes returns f let A 0 dotimes i 4 1 set 1 cons i 1 3210 while test expression expressiono syntax While evaluates the expression s until test returns a false value The value of a while construct is unspecified until test expression expressiong syntax Until evaluates the expression s while test returns a false value The value of an unless construct is unspecified 5 Program structure Identical to RA RS 6 Standard procedures 6 1 Booleans In STK the boolean value is different from the empty list as required by R4RS not obj procedure boolean obj procedure Identical to RA RS 6 2 Equivalence predicates eqv obj obja procedure STK extends the eqv predicate defined in the RIRS to take keywords into account if obj and obj2 are both keywords the eqv predicate will yield t if and only if string keyword gt string obj1 keyword gt string obj2 dtt 12 STK Reference Manual eq obj obj2 procedure STK extends the eq predicate defined in RRS to take keywords into account On keywords eq behaves like equ eq key key gt dt equal obj obj2 procedure Identical to R RS 6 3 Pairs and lists pair obj procedure cons obj obja procedure car pair procedure cdr pair procedure set car pair obj procedure set cdr pair obj procedure caar pair procedure
60. e our implementation integration of complex numbers we can redefine stan dard Scheme predicates in the following manner define method complex c lt complex gt t define method complex c f define method number n lt number gt t define method number n 4f 3The third parameter of a define method is a parameter list which follow the conventions used for lambda expressions In particular it can use the dot notation or a symbol to denote an arbitrary number of parameters STK Reference Manual 89 define generic new et 2 define method new a lt real gt b lt real gt a b define method new a lt real gt b lt complex gt make rectangular a real part b imag part b define method new a lt complex gt b lt real gt make rectangular real part a b imag part a define method new a lt complex gt b lt complex gt make rectangular real part a real part b imag part a imag part b define method new a lt number gt a define method new 0 define method new args new car args apply new cdr args set new Figure C 3 Extending for dealing with complex numbers Standard primitives in which complex numbers are involved could also be redefined in the same manner This ends this brief presentation of the STKLOS extension 90 STK Reference Manual Appendix D Modules Examples This
61. eau 13 AbAN e A ener Pe ed 16 autoload iiie a iaa sert 29 a toload isxe sated esr eere 29 D DAS CNAME iu m erite veo re dd Er 40 beglnhosenescR tbv LORD ERE AR 10 DIN ee ee ERE eoe tt pube PES 73 bindt gs se de teases mas e Ra Ra 73 boolean ilg a eder 11 bresk o ede WR RR he a a 43 73 buttons desde and dat het ide 32 p CE 68 C Con e Ode UL dU UM Meo s 43 c string gt string 61 CAA ri dati dived E ne EH ade As int 12 Cad E dupe dede se douteuse an dits heu 12 call with current continuation 20 call with input file 22 call with input string 22 call with output file 22 call with output string 22 call With values cai ns Ni 96 Call Ceviche E IE 20 21 canoni Cal path us casas bna 40 Cal peal MO Pu LA PR aes Rie EP DAR 12 STK Reference Manual CASO o ipee i vb ove v EET WEE NEXU 9 o iip E RRRMbR eben ter bind 21 dddariiureliieer 4b i e Mb e eR 12 cddddr CE 12 COP wie it epe Vea EVER UC Pars 12 COLI Listen Media sh be bs 16 char integer le eR a 17 char alphabetic o cene ev e 17 ehar CIs i120 e p b lE 17 COSTE iniu ti Age 17 charccei o2 sk iR cda 17 CHATEA sn sede nn a tasmanian en ae o das 17 Charter rt cute ip Net EM 17 char downcase 17 char lower case 17 char n meric codi e e Rer des At 17 COTTON ii ai RI ERE 26 NA O 17 char upper cas
62. ed in an interactive environment define module name body syntax Define module evaluates the expressions which are in body in the environment of the module name name must be a valid symbol If this symbol has not already been used to define a module a new module named name is created Otherwise body is evaluated in the environment of the old module name Definitions done in a module are local to the module and do not interact with the definitions of other modules Consider the following definitions define module M1 define a 1 define module M2 define a 2 define b 2 x Here two modules are defined and they both bind the symbol a to a value However since a has been defined in two distincts modules they denote two different locations The STk module which is predefined is a special module which contains all the global variables of a R RS program A symbol defined in the STk module if not hidden by a local definition is always visible from inside a module So in the previous exemple the x symbol refers the x symbol defined in the STk module The result of define module is undefined find module name procedure find module name default procedure STK modules are first class objects and find module returns the module associated to name if it exists If there is no module associated to name an error is signaled if no default is provided otherwise find module returns default module o
63. ed the integer value of this signal is passed to it as the only parameter The following POXIX 1 constants for signal numbers are defined SIGABRT SIGALRM SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV SIGTERM SIGUSR1 SIGUSR2 SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN SIGTTOU Moreover the following constants which are often available on most systems are also defined SIGTRAP SIGIOT SIGEMT SIGBUS SIGSYS SIGURG SIGCLD SIGIO SIGPOLL SIGXCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGLOST See your Unix documentation for the exact meaning of each constant or 7 Use symbolic constants rather than their numeric value if you plan to port your program on another system A special signal managed by the interpreter is also defined SIGHADGC This signal is raised when the garbage collector phase terminates When the interpreter starts running all signals are sets to their default value excepted SIGINT generally bound to Control C which is handled specially set signal handler sig handler procedure Replace the handler for signal sig with handler Handler can be t to reset the signal handler for sig to the default system handler 4f to completly ignore sig Note that Posix 1 states that SIGKILL and SIGSTOP cannot be caught or ignored a one parameter procedure Some of these constants may be undefined if they are not supported by your system 44 STK Reference Manual This procedure returns t
64. edure char numeric char procedure char whitespace char procedure char upper case letter procedure char lower case letter procedure char gt integer char procedure integer gt char n procedure char upcase char procedure char downcase char procedure Identical to R RS 18 STK Reference Manual rane value alternate ame V name value olfemate nome backspace tab newline page return escape space delete Table 1 Valid character names Character inserted Backspace Escape Newline Horizontal Tab Carriage Return ASCII character with octal value abc lt newline gt None permits to enter a string on several lines lt other gt lt other gt Table 2 String escape sequences 6 7 Strings STK string constants allow the insertion of arbitrary characters by encoding them as escape sequences introduced by a backslash X The valid escape sequences are shown in Table 2 For instance the string ab 040c nd e is the string consisting of the characters Ha b space c newline Hd and He string obj procedure make string k procedure make string k char procedure STK Reference Manual 19 string char procedure string length string procedure string ref string k procedure string set string k char procedure string string string procedure string ci string strings procedure string lt string string procedure string gt string string pr
65. efined as define port gt string list lambda p port list read line p Port gt sexp list repeatedly reads data from the port until eof then returns the accumulated list of items This procedure is defined as define port gt sexp list lambda p port gt list read p For instance the following expression gives the list of users currently connected on the machine running the STK interpreter port gt sexp list open input file users transcript on filename procedure transcript off procedure Not implemented 6 11 Keywords Keywords are symbolic constants which evaluate to themselves keyword must begin with a colon keyword obj procedure Returns t if obj is a keyword otherwise returns f make keyword obj procedure Builds a keyword from the given obj obj must be a symbol or a string A colon is automat ically prepended make keyword test gt test make keyword test test make keyword hello gt hello keyword gt string keyword procedure Returns the name of keyword as a string The leading colon is included in the result 32 STK Reference Manual keyword gt string test gt test get keyword keyword list procedure get keyword keyword list default procedure List must be a list of keywords and their respective values Get keyword scans the list and returns the value associated with the given keyword If the keyword does not appear in an odd
66. er it is usually considered a bad idea for programmers to rely on exactly what the order is If the order for some superclasses is important it can be expressed directly in the class definition The precedence list of a class can be obtained by the function class precedence list This function returns a ordered list whose first element is the most specific class For instance class precedence list B gt lt class gt 12a248 lt class gt 1074e8 lt class gt 107498 However this result is not too much readable using the function class name yields a clearer result map class name class precedence list B gt b lt object gt lt top gt 4 Generic functions 4 1 Generic functions and methods Neither STKLOS nor CLOS use the message mechanism for methods as most Object Oriented language do Instead they use the notion of generic function A generic function can be seen as a methods tanker When the evaluator requestd the application of a generic function all the methods of this generic function will be grabbed and the most specific among them will be applied We say that a method M is more specific than a method M if the class of its parameters are more specific than the M ones To be more precise when a generic funtion must be called the system will 1 search among all the generic function those which are applicable 2 sort the list of applicable methods in the most specific order 3 call
67. eter which is the class of the instance which must be created and a list of optional arguments Optional arguments are generally used to initialize some slots of the newly created instance For instance the following form define c make lt complex gt will create a new complex object and will bind it to the c Scheme variable Accessing the slots of the new complex number can be done with the slot ref and the slot set primitives Slot set primitive permits to set the value of an object slot and slot ref permits to get its value slot set c r 10 slot set c i 3 slot ref c r gt 10 slot ref c i gt 3 Using the describe generic function is a simple way to see all the slots of an object at one time this function prints all the slots of an object on the standard output For instance the expression describe c will print the following informations on the standard output 82 STK Reference Manual lt complex gt 122398 is an instance of class complex Slots are r 10 i 3 3 3 Slot description When specifying a slot a set of options can be given to the system Each option is specified with a keyword The list of authorised keywords is given below initform permits to supply a default value for the slot This default value is obtained by evaluating the form given after the initform in the global environment init keyword permits to specify the keyword for initializing a slot The
68. f the dirty address of are definitively gone Strings can contain null charters printing of strings is more friendly in write mode Signals can be redirected to Scheme closures The end of a GC is seen as a signal Traces on variables are changed and re work now the associated trace must be a thunk New options for some widgets to be more friendly with Scheme world STKLOs if a method M is defined and if it is already bound to a procedure the old procedure is called when no method is applicable define method car x lt integer gt x 1 car 10 9 car cons a b gt a Small change in the STklos hierarchy widget is now a subclass of procedure and its meta class is lt procedure metaclass gt 98 STK Reference Manual Appendix F Miscellaneous Informations 1 Introduction This appendix lists a number of things which cannot go elsewhere in this document The only link between the items listed her is that they should ease your life when using STK 2 About STK 2 1 Latest release STK distribution is available on various sites The original distribution site is kaolin unice fr 134 59 132 7 Files are available through anonymous ftp and are located in the pub STk directory Distribution file names have the form STk x y z tar gz where x and y represent the version the release and sub release numbers of the package 2 2 Sharing Code If you have written code that you want to share with th
69. g closure breaks the chain of bindings if the typed character is not a digit Otherwise the following binding the one for the Entry class is executed and inserts the character typed a digit Consequently the simple previous binding makes e a controlled entry which only accepts integer numbers Old syntax for bindings i e strings is no more supported Old bindings scripts must hence be rewritten 74 STK Reference Manual Appendix B Differences with RARS This appendix summarizes the main differences between the STK Scheme implementation and the language described in R4RS 1 Symbols STK symbol syntax has been augmented to allow case significant symbols This extension is discussed in 6 4 STK also defines some symbols in the global environment which are described below debug Setting debug to t prevents macro inlining and expression recoding see 6 25 gc verbose If gc verbose is ftt a message will be printed before and after each run of garbage collector The message is printed on the standard error stream load verbose If load verbose is t the absolute path name of each loaded file is printed before its effective reading File names are printed on the standard error stream load path must contain a list of strings Each string is taken as a directory path name in which a file will be searched for loading This variable can be set automatically from the STK LOAD PATH shell variable See stk 1 f
70. g at the end of the input string a followed by a single character matching that character or a single character with no other significance matching that character A range is a sequence of characters enclosed in It normally matches any single character from the sequence If the sequence begins with it matches any single character not from the rest of the sequence If two characters in the sequence are separated by this is shorthand for the full list of ASCII characters between them e g 0 9 matches any decimal digit To include a literal in the sequence make it the first character following a possible To include a literal make it the first or last character In general there may be more than one way to match a regular expression to an input string Considering only the rules given so far could lead to ambiguities To resolve those ambiguities the generated regular expression chooses among alternatives using the rule first then longest In other words it considers the possible matches in order working from left to right across the e It matches anything that STK Reference Manual 49 input string and the pattern and it attempts to match longer pieces of the input string before shorter ones More specifically the following rules apply in decreasing order of priority 1 If a regular expression could match two different parts of an input string then it will matc
71. h rectangular coordinates as well as with polar coordinates One solution could be to have a definition of complex numbers which uses one particular representation and some conversion functions to pass from one representation to the other A better solution uses virtual slots A complete definition of the lt complex gt class using virtual slots is given in Figure 2 This class definition implements two real slots r and i Values of the m and a virtual slots are calculated from real slot values Reading a virtual slot leads to the application of the function defined in the slot ref option Writing such a slot leads to the application of the function defined in the slot set option For instance the following expression slot set c a 3 permits to set the angle of the c complex number This expression conducts in fact to the evaluation of the following expression 84 STK Reference Manual define class complex number True slots use rectangular coordinates r initform 0 accessor real part init keyword r i initform 0 accessor imag part init keyword i Virtual slots access do the conversion m accessor magnitude init keyword magn allocation virtual slot ref lambda o let r slot ref o r i slot ref o i sqrt r r x i i slot set lambda o m let a slot ref o a slot set o r m cos a slot set o i m sin a a accessor angle init keyword angl
72. h the one that begins earliest 2 Ifa regular expression contains operators then the leftmost matching sub expression is chosen 3 In and constructs longer matches are chosen in preference to shorter ones 4 In sequences of expression components the components are considered from left to right define ri string gt regexp abc ri xyz gt f ri 12abc345 25 define r2 string gt regexp a z r2 12abc345 25 If the regular expression contains parenthesis and if there is a match the result returned by the application will contain several couples of integers First couple will be the indexes of the first longest substring which match the regular expression Subsequent couples will be the indexes of all the sub parts of this regular expression in sequence define r3 string gt regexp a b c r3 abc 03 01 125 r3 c gt 0 1 00 0 0 string gt regexp a z a z XXabcd eXX 2 8 2 6 7 8 regexp obj procedure Returns t if obj is a regular expression created by string gt regexp otherwise returns f regexp string gt regexp a zA Z a zA Z0 9 tt regexp replace pattern string substitution procedure regexp replace all pattern string substitution procedure Regexp replace matches the regular expression pattern against string If there is a match the portion of string which match pattern
73. hall redefine the complex class seen before A definition could be define class complex number r initform 0 getter get r setter set r init keyword r i initform 0 getter get i setter set i init keyword i STK Reference Manual 83 With this definition the r and i slot are set to 0 by default Value of a slot can also be specified by calling make with the r and i keywords Furthermore the generic functions get r and set r resp get i and set i are automatically defined by the system to read and write the r resp i slot define ci make complex r 1 i 2 get r c1 1 set r ci 12 get r c1 gt 12 define c2 make lt complex gt r 2 get r c2 2 get i c2 0 Accessors provide an uniform access for reading and writing an object slot Writing a slot is done with an extended form of set which is close to the Common Lisp setf macro So another definition of the previous complex class using the accessor option could be define class complex number r initform 0 accessor real part init keyword r i initform 0 accessor imag part init keyword i Using this class definition reading the real part of the c complex can be done with real part c and setting it to the value contained in the new value variable can be done using the extended form of set set real part c new value Suppose now that we have to manipulate complex numbers wit
74. he new handler or length 1 handler list associated to sig let x Hf handler lambda i set x t set signal handler SIGHADGC handler gc x add signal handler sig handler procedure Adds handler to the list of handlers for signal sig If the old signal handler is a boolean this procedure is equivalent to set signal handler Otherwise the new handler is added in front of the previous list of handler This procedure returns the new handler or handler list associated to sig let x 20 handleri lambda i set x cons 1 x handler2 lambda i set x cons 2 x add signal handler SIGHADGC handler1 add signal handler SIGHADGC handler2 gc x gt 1 2 let x 20 handleri lambda i set x cons 1 x handler2 lambda i set x cons 2 x break add signal handler SIGHADGC handler1 add signal handler SIGHADGC handler2 gc x 2 procedure get signal handlers procedure get signal handlers sig Returns the handlers or the list of handlers associated to the signal sig If sig is omitted get signal handlers returns a vector of all the signal handlers currently in effect send signal sig procedure Sends the signal sig to the running program STK Reference Manual 45 6 19 Hash tables A hash table consists of zero or more entries each consisting of a key and a value Given the key for an entry the hashing function can
75. idget lab gt dit widget 12 gt df widget gt string widget procedure Returns the widget name of widget as a string begin label lab widget gt string lab gt lab string gt widget str procedure Returns the widget whose name is str if it exists otherwise returns sf begin label lab string gt widget lab gt the Tk command named lab widget name widget procedure Returns the widget name of widget as a symbol begin label lab widget gt name lab gt lab set widget data widget expr procedure Set widget data associates arbitrary data with a widget The system makes no assump tions about the type of expr the data is for programmer convenience only As shown below it could be used as a kind of property list for widgets get widget data widget procedure Returns the data previously associated with widget if it exists otherwise returns f begin set widget data w mapped t geometry 10x50 get keyword mapped get widget data w gt dit 34 STK Reference Manual 6 13 Modules STK modules can be used to organize a program into separate environments orname spaces Modules provide a clean way to organize and enforce the barriers between the components of a program STK provides a simple module system which is largely inspired from the one of Tung and Dybvig exposed in 5 As their modules system S TK modules are defined to be easily us
76. ing Tcl script bind w lt ButtonPress 3 gt puts Press on widget W at position x hy can be translated into bind w lt ButtonPress 3 gt lambda IWI x y format t Press on widget A at position A A n IWI x y Note Usage of verticals bars for the W symbol is necessary here because the Tk toolkit is case sensitive e g W in bindings is the path name of the window to which the event was reported whereas w is the width field from the event Bindings are chained In Tk4 0 and later bindings are chained since it is possible for several bindings to match a given X event If the bindings are associated with different tags then each of the bindings will be executed in order By default a class binding will be executed first followed by a binding for the widget a binding for its toplevel and an a11 binding The bindtags command may be used to change this order for a particular window or to associate additional binding tags with the window see corresponding help page for details If the result of closure in the bindings chain is the symbol break the next closures of the chain are not executed The example below illustrates this pack entry e bind e lt KeyPress gt lambda IAI unless string gt number A break Bindings for the entry e are executed before those for its class i e Entry This allows us to filter the characters which are effectively passed to the e widget The test in this bindin
77. it process procedure Process wait stops the current process until process completion Process wait returns f when process is already terminated it returns t otherwise 54 STK Reference Manual process exit status process procedure Process exit status returns the exit status of process if it has finished its execution returns f otherwise process send signal process n procedure Send the signal whose integer value is n to process Value of n is system dependant Use the defined signal constants to make your program indpendant of the running system see 6 18 The result of process send signal is undefined process kill process procedure Process kill brutally kills process The result of process kill is undefined This proce dure is equivalent to process send signal process SIGTERM process stop process procedure process continue process procedure Those procedures are only available on systems which support job control Process stop stops the execution of process and process continue resumes its execution They are equivalent to process send signal process SIGSTOP process send signal process SIGCONT process list procedure process list returns the list of processes which are currently running i e alive 6 23 Sockets STK defines sockets on systems which support them as first class objects Sockets permits processes to communicate even if they are on different machines Sockets are useful fo
78. le src lambda with output to file dst lambda copy port current input port current output port port closed port procedure Returns stt if port has been closed f otherwise copy port src dst procedure Copies the content of the input port src to the output port dest define copy file lambda src dst with input from file src lambda with output to file dst lambda copy port current input port current output port port gt string port procedure port gt list reader port procedure port gt string list port procedure port gt sexp list port procedure Those procedures are utility for generally parsing input streams Their specification has been stolen from scsh Port gt string reads the input port until eof then returns the accumulated string port gt string open input file echo AAA echo BBB gt AAA nBBB n define exec lambda command call with input file string append command port gt string exec ls 1 a string which contains the result of ls 1 STK Reference Manual 31 Port gt list uses the reader function to repeatedly read objects from port Thes objects are accumulated in a list which is returned upon eof port gt list read line open input file echo AAA echo BBB gt C AAA BBB Port gt string list reads the input port line by line until eof then returns the accumulated list of lines This procedure is d
79. lex class defined in Figure 2 Suppose that we want to use it to implement complex numbers completely For instance a definition for the addition of two complexes could be define method new a lt complex gt b lt complex gt make rectangular real part a real part b imag part a imag part b To be sure that the used in the method new is the standard addition we can do define generic new let define method new a lt complex gt b lt complex gt make rectangular real part a real part b imag part a imag part b The def ine generic ensures here that new will be defined in the global environment Once this is done we can add methods to the generic function new which make a closure on the symbol A complete writing of the new methods is shown in Figure 3 We use here the fact that generic function are not obliged to have the same number of parameters contrarily to CLOS The four first methods implement the dyadic addition The fifth method says that the addition of a single element is this element itself The sixth method says that using the addition with no parameter always return 0 The last method takes an arbitrary number of parameters This method acts as a kind of reduce it calls the dyadic addition on the car of the list and on the result of applying it on its rest To finish the set permits to redefine the symbol to our extended addition To terminat
80. llowed for the parameters of a foreign function Define external accepts several options e return type is used to define the type of the value returned by the foreign function The type returned must be chosen in the types specified in the table For instance define external maximum a int b int return type int defines the foreign function maximum which takes two C integers and returns an integer result Omitting this option default to a result type equal to void i e the returned value is undefined STK Reference Manual 59 e entry name is used to specify the name of the foreign function in the C world If this option is omitted the entry name is supposed to be name For instance define external minimum a int b int return type int entry name min defines the Scheme function minimum whose application executes the C function called min library name is used to specify the library which contains the foreign function If necessary the library is loaded before calling the C function So define external minimum a int b int return type int entry name min library name libminmax defines a function which will execute the function min located in the library libminmax xx where xx is the suffix used for shared libraries on the running system generally so or sl Hereafter there are some commented definitions of external functions define external isatty fd int return type bo
81. n For instance define external printf format string 1 return type int defines a Scheme function with one or more parameters the first one being a string Of course the parameters which constitute the variable parameters list must have a type which appears in the third column of Table 4 Some examples using the printf function printf This is a s test good gt displays This is a good test printf char c Dec 404d Hex 04x space 100 100 5 displays char Dec 70100 Hex 700642 Note The types dynamic ptr static ptr and string are compatible when used for foreign function parameter This gives a semantic which is similar to the one of C where void is a com patible with all other pointer types However differenciating those types is useful for converting the function return value to a proper Scheme type Note When a function has a return type which is string dynamic ptr or static ptr and the return value is the C NULL pointer the Scheme value returned by the function is by convention equal to f For instance the GNU readline function allows line editing Ja Emacs returns NULL when the user has typed an end of file The following lines show how to make a simple shell like toplevel using FFIs define external system var char return type int define external readline prompt string library name libreadline return type string A Shell like
82. n as a directory path name in which documentation files are searched This variable can be set automatically from the STK HELP PATH shell variable See stk 1 for more details image path must contain a list of strings Each string is taken as a directory path name in which images are searched by the function make image This variable can be set automatically from the STK IMAGE PATH shell variable See stk 1 and make image n for more details root designates the Tk main window see A 2 This variable is not set if the Tk toolkit is not initialized start withdrawn If start withdrawn is not false the root window is not mapped on screen until its first sub window is packed or some action is asked to the window manager for it tk version is a string which contains the version number of the Tk toolkit used by STK tk patch level is a string which contains the version and patch level of the Tk toolkit used by STK Furthermore S TK also defines the following procedures in the global environment report error This procedure is called by the error system to display the message error This procedure is described in report error n repl display prompt This procedure is called when the system is run interactively before reading a sexpr to evaluate to display a prompt This procedure is described in repl display prompt n repl display result This procedure is called when the system is run interactively after the ev
83. n error is signalled if any of the bindings variable is unbound let a out f lambda O a list a fluid let a in f a gt out in out When the body of a fluid let is exited by invoking a continuation the new variable values are saved and the variables are set to their old values Then if the body is reentered by invoking a continuation the old values are saved and new values are restored The following example illustrates this behaviour let cont f 1 09 a out set 1 cons a 1 fluid let a in set cont call cc lambda k k set 1 cons a 1 set 1 cons a 1 if cont cont f 1 gt out in out in out letrec bindings body begin expression expressiong do inits test body delay expression quasiquote template template Identical to R RS syntax syntax syntax syntax syntax syntax STK Reference Manual 11 dotimes var count expression expression syntax dotimes var count result expression expressiong syntax Dotimes evaluates the count form which must return an integer It then evaluates the expression s once for each integer from zero inclusive to count exclusive in order with the variable var bound to the integer if the value of count is zero or negative then the expression s are not evaluated When the loop completes result is evaluated and its value is returned as the valu
84. n of a variant of open output string using virtual ports The value of the output string is printed when the port is closed define open output string let str open output virtual lambda c p wrtc set str string append str char gt sting c lambda s p wrts set str string append str s f flush lambda p write str newline close Example let p Copen output string display Hello world p close port p gt prints Hello world on current output port close input port port procedure close output port port procedure Identical to R RS read procedure read port procedure The STK procedure is identical to the R RSprocedure It has bee extended to accept the x and x notations used for circular stuctures see 2 3 read char procedure read char port procedure peek char procedure peek char port procedure char ready procedure char ready port procedure Identical to RA RS STK Reference Manual 27 read line procedure read line port procedure Reads the next line available from the input port port and returns it as a string The terminating newline is not included in the string If no more characters are available an end of file object is returned Port may be omitted in which case it defaults to the value returned by current input port write obj procedure write obj port procedure Identical to RA RS write obj
85. ne Consequently to work with the Tk toolkit a little set of rewriting rules must be known These rules are described hereafter Note This appendix is placed here to permit an STK user to make programs with the original Tcl Tk documentation by hand In no case will it substitute to the abundant Tcl Tk manual pages nor to the excellent book by J Ousterhout 11 1 Calling a Tk command Since Tcl uses strings to communicate with the Tk toolkit parameters to a Tk command must be translated to strings before calling the C function which implement it The following conversions are done depending on the type of the parameter that STK must give to the toolkit symbol the print name of the symbol number the external representation of the number expressed in radix 10 string no conversion keyword the print name of the keyword where the initial semicolon has been replaced by a dash boolean the string 0 if tf and 1 if stt tk command the name of the tk command closure the address of the closure using the representation shown in 6 17 otherwise the external slashified version of the object As an example let us make a button with a label containing the string Hello word According the original Tk Tcl documentation this can be done in Tcl with button hello text Hello world Following the rewriting rules expressed above this can be done in STK with 71 72 STK Reference Manual button hello
86. ntroduction This document provides a complete list of procedures and special forms implemented in version 4 0 of STK Since STK is nearly compliant with the language described in the Revised Report on the Algorithmic Language Scheme denoted RRS hereafter 1 the organization of this manual follows the R RS and only describes extensions 1 Overview of STK Today s graphical toolkits for applicative languages are often not satisfactory Most of the time they ask the user to be an X window system expert and force him her to cope with arcane details such as server connections and event queues This is a real problem since programmers using this kind of languages are generally not inclined to system programming and few of them will bridge the gap between the different abstraction levels Tk is a powerful graphical toolkit promising to fill that gap It was developed at the University of Berkeley by John Ousterhout 2 The toolkit offers high level widgets such as buttons or menus and is easily programmable requiring little knowledge of X fundamentals Tk relies on an interpretative shell like language named Tcl 3 STK is an implementation of the Scheme programming language providing a full integration of the Tk toolkit In this implementation Scheme establishes the link between the user and the Tk toolkit replacing Tcl 2 Lexical conventions 2 1 Identifiers Syntactic keywords can be used as variables in STK Users must be aware tha
87. o redirect the standard error to a pipe e wait must be followed by a boolean value This value specifies if the process must be run asynchronously or not By default the process is run asynchronously i e wait is f e host must be followed by a string This string represents the name of the machine on which the command must be executed This option uses the external command rsh The shell variable PATH must be correctly set for accessing it without specifying its abolute path The following example launches a process which execute the Unix command 1s with the arguments 1 and bin The lines printed by this command are stored in the file tmp X run process ls 1 bin output tmp X wait f process process procedure Returns stt if process is a process otherwise returns f process alive process procedure Returns stt if process if the process is currently running otherwise returns f process pid process procedure Returns an integer value which represents the Unix identification PID of process process input process procedure process output process procedure process error process procedure Returns the file port associated to the standard input output or error of process if it is redirected in or to a pipe otherwise returns f Note that the returned port is opened for reading when calling process output or process error it is opened for writing when calling process input process wa
88. oaded such as if their parameter is a string this is the old STK procedure which is called and if their parameter is a symbol this is the SLIB one which is called 4 Getting information about Scheme 4 1 The R RS document R RS is the document which fully describe the Scheme Programming Language it can be found in the Scheme repository see in the directory 102 STK Reference Manual ftp cs indiana edu pub scheme repository doc Aubrey Jaffer has also translated this document in HTML A version of this document is available at file swiss ftp ai mit edu pub scm HTML r4rs toc html 4 2 The Scheme Repository The main site where you can find many informations about Scheme is located in the University of Indiana The Scheme repository is maintained by David Eby The repository currently consists of the following areas e Lots of scheme code meant for benchmarking library support research education and fun e On line documents Machine readable standards documents standards proposals various Scheme related tech reports conference papers mail archives etc e Most of the publicly distributable Scheme Implementations e Material designed primarily for instruction e Freely distributable promotional or demonstration material for Scheme related products e Utilities e g Schemeweb SLaTeX e Extraneous stuff extensions etc You can access the Scheme repository with e ftp cs indiana edu pub scheme repository e h
89. ocedure string lt string stringo procedure string gt string string procedure string ci lt string stringa procedure string ci gt string stringa procedure string ci lt string stringa procedure string ci gt string string procedure substring string start end procedure string append string procedure string gt list string procedure list gt string chars procedure string copy string procedure string fill string char procedure Identical to R RS string find string stringa procedure Returns stt if string appears somewhere in string otherwise returns f string index string stringo procedure Returns the index of where string is a substring of strings if it exists returns f otherwise string index ca abracadabra gt 4 string index ba abracadabra gt df split string string procedure split string string delimiters procedure This function parses string and returns a list of tokens ended by a character of the delimiters string If delimiters is omitted it defaults to a string containing a space a tabulation and a newline characters split string usr local bin hsr local bin split string once upon a t m dnce upon a time string lower string procedure Returns a string in which all upper case letters of string have been replaced by their lower case equivalent 20 STK Reference Manual string upper string procedure Return
90. ocedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure procedure STK Reference Manual 17 sqrt z procedure expt 21 22 procedure Identical to RA RS make rectangular 11 12 procedure make polar 211 22 procedure real part z procedure imag part z procedure magnitude z procedure angle 2 procedure These procedures are not implemented since complex numbers are not defined exact gt inexact z procedure inexact gt exact z procedure number gt string number procedure number gt string number radix procedure string gt number string procedure string gt number string radix procedure Identical to R RS 6 6 Characters Table 1 gives the list of allowed character names together with their ASCII equivalent ex pressed in octal char obj procedure char char chan procedure char lt char chara procedure char gt char chan procedure char lt char chan procedure char gt char chan procedure char ci char chan procedure char ci char chara procedure char ci char chan procedure char ci lt char chara procedure char ci gt char chara procedure char alphabetic char proc
91. of the evaluation of the last expr define module M define a 1 define b 2 with module M a b gt 3 current module procedure Returns the current module define module M sa with module M cons eq current module find module M eq current module find module STk Ht Sf select module name syntax Evaluates the expressions which follows in module name environment Module name must have been created previously by a define module The result of select module is undefined Select module is particularly useful when debugging since it allows to place toplevel evalu ation in a particular module The following transcript shows an usage of select module STk gt define foo 1 STk gt define module bar define foo 2 STk gt foo 1 STk gt select module bar 5This transcript uses the default value for the function repl display prompt see page 76 which displays the name of the current module in the prompt STK Reference Manual 37 bar gt foo 2 bar select module STk STk gt module name module procedure Returns the name a symbol associated to a module module imports module procedure Returns the list modules that module imports module exports module procedure Returns the list of symbols exported by module module symbols module procedure Returns the list symbols that ere defined in module all modules procedure Returns a list of all
92. oiding redundant tests the STK pattern matching compiler provides this The technique used is described in details in 9 and the code generated can be considered optimal due to the way this pattern compiler was obtained The pattern language allows the expression of a wide variety of patterns including e Non linear patterns pattern variables can appear more than once allowing comparison of subparts of the datum through eq e Recursive patterns on lists for example checking that the datum is a list of zero or more as followed by zero or more bs e Pattern matching on lists as well as on vectors Pattern Matching Facilities Only two special forms are provided for this match case and match lambda and these also exist for example in Andrew Wright and Bruce Duba s 10 pattern matching package match case key clausei clause2 syntax In this form key may be any expression and each clause has the form The pattern matching compiler has been written by Jean Marie Geffroy and is part of the Manuel Serrano s Bigloo compiler 8 since several years The code and documentation included in STK has been stolen from the Bigloo package v1 9 the only difference between both package is the pattern matching of structures whisch is absent in STK STK Reference Manual 51 pat expression lt expression2 gt A match case expression is evaluated as follows lt key gt is evaluated and the
93. olean define external system cmd char or cmd string return type int define external malloc size ulong return type void define external free p void All these functions are defined in the C standard library hence it is not necessary to specify the library name option e istty is declared here as a function which takes an integer and returns a boolean in fact the value returned by the C function isatty is an int but we ask here to the FFI system to translate this result as a boolean value in the Scheme world e system is a function which takes a string as parameter and returns an int Note that the type of the parameter can be specified as a char or string as indicated in Table 4 e malloc is a function which takes one parameter an unsigned long int and which returns a void or dynamic ptr Specifying that the result is a dynamic pointer instead of a static one means that we want that the Garbage Collector takes into 60 STK Reference Manual account the area allocated by the C function malloc i e if this area becomes no more accessible the GC disposes it with the free function e free is a function which takes a dynamic pointer and deallocates the area it points Since the definition of this function specifies no result type it is supposed to be void External functions can also have a variable number of parameters by using the standard Scheme dot notatio
94. on is derived from version 1 3 of the Gregor Kickzales Tiny Clos package 12 However it has been extended to be as close as possible to CLOS the Common Lisp Object System 6 Some features of STKLOS are also issued from Dylan 13 or SOS 14 Briefly stated the STKLOS extension gives the user a full object oriented system with meta classes multiple inheritance generic functions and multi methods Furthermore the whole implementation relies on a true meta object protocol in the spirit of the one defined for CLOS 15 This model has also been used to embody the predefined Tk widgets in a hierarchy of S TKLos classes This set of classes permits to simplify the core T k usage by providing homogeneous accesses to widget options and by hiding the low level details of Tk widgets such as naming conventions Furthermore as expected using of objects facilitates code reuse and definition of new widgets classes The purpose of this appendix is to introduce briefly the STKLOS package and in no case will it replace the STKLOS reference manual which needs to be urgently written now In particular methods relative to the meta object protocol and access to the Tk toolkit will not be described here 2 Class definition and instantiation 2 1 Class definition A new class is defined with the define class macro The syntax of define class is close to CLOS defclass define class class superclassi superclassa slot description slot desc
95. oper Scheme string define external sprintf str string format string 1 return type int let str make string 5 sprintf str Ax 100 cons str C string gt string str 64N0 64 6 25 Miscellaneous This section lists the primitives defined in STK that did not fit anywhere else eval expr syntax eval expr environment syntax Evaluates expr in the given environment Environment may be omitted in which case it defaults to the global environment define foo let a 1 lambda a foo zo eval set a 2 procedure environment foo foo 2 version procedure returns a string identifying the current version of STK 62 STK Reference Manual machine type procedure returns a string identifying the kind of machine which is running the interpreter The form of the result is os name os version processor type random n procedure returns an integer in the range 0 n 1 inclusive set random seed seed procedure Set the random seed to the specified seed Seed must be an integer which fits in a C long int eval string string environment procedure Evaluates the contents of the given string in the given environment and returns its result If environment is omitted it defaults to the global environment If evaluation leads to an error the result of eval string is undefined define x 1 eval string x 1 2 eval string x let
96. or more details load suffixes must contain a list of strings When the system try to load a file in a given directory according to load path value it will first try to load it without suffix If this file does not exist the system will sequentially try to find the file by appending each suffix of this list A typical value for this variable may be stk stklos scm so argc contains the number of arguments 0 if none not including interpreter options See stk 1 for more details argv contains a Scheme list whose elements are the arguments not including the interpreter options in order or an empty list if there are no arguments See stk 1 for more details 75 76 STK Reference Manual program name contains the file name specified with the file option if present Otherwise it contains the name through which the interpreter was invoked See stk 1 for more details print banner If print banner is tf the usual copyright message is not displayed when the interpreter is started stk library contains the path name of the installation directory of the S TK library This variable can be set automatically from the STK LIBRARY shell variable See stk 1 for more details The following symbols are defined only when Tk is loaded root designates the Tk main window see A 2 This variable is not set if the Tk toolkit is not initialized help path must contain a list of strings Each string is take
97. ort If port is ttt output goes to the current output port if port is f the output is returned as a string Otherwise the output is printed on the specified port format f A test gt A test format f A a test gt A test format f A s test A test S flush procedure flush port procedure Flushes the buffer associated with the given port The port argument may be omitted in which case it defaults to the value returned by current output port when port readable port handler procedure when port readable port procedure When port is ready for reading handler which must be a thunk is called leaving the current evaluation suspended When handler execution is terminated normal evaluation is resumed at its suspension point If the special value f is provided as handler the current handler for port is deleted If a handler is provided the value returned by when port readable is undefined Otherwise it returns the handler currently associated to port The example below shows a simple usage of the when port readable procedure the com mand cmd is run with its output redirected in a pipe associated to the p Scheme port define p open input file cmd when port readable p lambda let 1 read line p if eof object 1 begin delete handler when port readable p f and close port close input port p format t Line read A n 1 STK Reference Manual 2
98. path 41 4 musette 76 image path 76 load path ile bin ee ta 75 xload suffixes 75 load verbose 75 print banner 76 program name 76 RLTOO BE sien dou dr erp e Re ted 72 16 start withdrawn x 76 stk librarys o videli dedans 76 tk patch level x 76 DE VerSsilOon o vn esca rn set 76 Pasha a tates opera orbe eDbr e eaten 16 ledere ae 16 TRES 16 accessories OM exi 82 allocation ns r ie kaa 82 E TE 82 PROCTOR A E E 82 UnitckeyWOId A cc eR E P EE I 82 CADA CLIO ica e e RR tbe 82 instante e loe bee lee erreur 82 PSCULCT e EPI HE ED p 82 islot ref ci cliches eee dax Phe ed 82 83 PSLOCHSOU 212 eet ev 82 83 A stad tents aan atch a epe 82 ADA MPs 15 A 15 COD JO Ai AAA 80 HOP teg ue deli LPS 80 87 Re 15 A dex Ge pO 15 Dh es E eee aaa 15 A ADS 4 c ede dur des dre np dre bte 16 ACCESSOL dai ca nw eae hr Pee ne 82 104 ACOS Ch ELM GL HAT TAN 16 add signal handler 44 addresS Ofiiic dae nd REIHE TES 43 address ireira ciraire e be a 43 all modules 37 and Lega pat bete a ne Et ET Us 9 Men 17 78 APPCN it id AUS 12 APPO Nadal ete v bo M ee 12 app ys pud pere a 20 Aproposs cse eae d I aa des 65 ASIN lcg in ate QN HM EPI 16 AO Cia 13 ASS ondes Hobe QE cago Ea 13 ASSV rd gaged b
99. pd on ao 17 78 importe Pine ne A eR tan dat 39 inexact gt exact 17 TNOXACE T 2340050 go VR het ren lt 15 initial environment 11 inp ut file port ee es 23 STK Reference Manual input port i onsil l lee ck MR app 22 input string port 23 input virtual port 23 inspect elo ede ne vec eei een an amet 65 E M ER 81 integer 2charfoo illius picar ia 17 A e RES px A 15 ip n mbe 4244 esr de er REPRE 55 K keyword i c iran eh bete S beds 82 keyword gt string 31 keyword sie din t Res DEM E dti 31 L label i e IDEM E PEE 32 lambda cos e A EE Ee 9 last padr side delaras se 13 TC ue ee dd 16 T ngth i oes accion PUE MS p 12 let iss RA eR Ra ER tales 10 A pidina e aeaa iep i api 10 letrec iis dans eri zs rA LE aa 10 listo RR a EE eara e dade 12 13 list i 1i carr riata RA p E 13 Tist Str inp i gib fece pa RhA 19 list vectoric oido e e gas 20 liSt ref x o d uote a Hehe d 13 list tail dee lo DIRECTS 13 Tist A aise ee dime is ta ete seio 12 load iere RR seb niet 29 NO Bee satis Gasca vot uin E isses 16 M machine type eel ia 62 MACTO EE o diede ULP e te Ee 38 39 macro bodyic os lad e e til de dates 39 macro expand eren weet EIL ed vA 39 macro expand 1 c Rl eee 39 MaCrO EXPANSION 38 MACTO iu 48 dans bare ao a a 39 magnitude 17
100. position in list the specified default is returned or an error is raised if no default was specified get keyword one one 1 two 2 1 get keyword four one 1 two 2 f gt df get keyword four one 1 two 2 error 6 12 Tk commands As we mentioned in the introduction STK can easily communicate with the Tk toolkit All the commands defined by the Tk toolkit are visible as Tk commands a basic type recognized by the interpreter Tk commands can be called like regular scheme procedures serving as an entry point into the Tk library Note Some Tk commands can dynamically create other Tk commands For instance execution of the expression label 1ab will create a new Tk command called lab This new object which was created by a primitive Tk command will be called a widget Note When a new widget is created it captures its creation environment This permits to have bindings which access variables in the scope of the widget creation call see 6 17 tk command obj procedure Returns stt if obj is a Tk command otherwise returns f tk command label gt dit begin label lab tk command lab gt dit tk command 12 gt df widget obj procedure Returns t if obj is a widget otherwise returns f A widget is a Tk command created by a primitive Tk command such as button label menu etc STK Reference Manual 33 widget label gt df begin label 1ab w
101. presenta tion depends on the type of the viewed object Here again menus are provided to switch to the inspector or to the detailer See the on line documentation for more details A snapshot of the viewer is given in figure 2 Note Tk must be initialized to use view detail obj procedure detail permits to display the fields of a composite Scheme object The type of detailer depends on the type of the composite object detailed Here again menus are provided to go 66 STK Reference Manual DEG um 1 2 3 4 5 6 Figure 2 A view of the Viewer STK Reference Manual ENSE lt Tk command 11 gt Figure 3 A view of the Detailer 67 68 STK Reference Manual to the inspector or to the viewer See the on line documentation for more details Figure 3 shows the detailer examining a tk command Note Tk must be initialized to use detail quit retcode procedure quit procedure exit retcode procedure exit procedure bye retcode procedure bye procedure Exits the STK interpreter with the specified integer return code If omitted the interpreter terminates with a return code of 0 Part II Annexes 69 Appendix A Using the Tk toolkit When STK detects that a tk command must be called parameters are processed to be recog nized by the corresponding toolkit function Since the Tk toolkit is left mostly unmodified all its primitives think there is a running Tcl interpreter behind the sce
102. r creating client server applications make client socket hostname port number procedure make client socket returns a new socket object This socket establishes a link between the running application listening on port port number of hostname socket socket procedure Returns itt if socket is a socket otherwise returns f socket host name socket procedure Returns a string which contains the name of the distant host attached to socket If socket has been created with make client socket this procedure returns the official name of the STK Reference Manual 55 distant machine used for connection If socket has been created with make server socket this function returns the official name of the client connected to the socket If no client has used yet the socket this function returns f socket host address socket procedure Returns a string which contains the IP number of the distant host attached to socket If socket has been created with make client socket this procedure returns the IP number of the distant machine used for connection If socket has been created with make server socket this function returns the address of the client connected to the socket If no client has used yet the socket this function returns f socket local address socket procedure Returns a string which contains the IP number of the local host attached to socket socket port number socket procedure Returns the integer number of the port u
103. reas a is valid and matches any vector and patterns can not appear inside a vector where you should use For example whose first element is the atom a 6 22 Processes STK provides access to Unix processes as first class objects Basically a process contains four informations the standard Unix process identification aka PID and the three standard files of the process run process command pi po ps procedure run process creates a new process and run the executable specified in command The p correspond to the command line arguments The following values of p have a special meaning e input permits to redirect the standard input file of the process Redirection can come from a file or from a pipe To redirect the standard input from a file the name of this file must be specified after input Use the special keyword pipe to redirect the standard input from a pipe STK Reference Manual 53 e output permits to redirect the standard output file of the process Redirection can go to a file or to a pipe To redirect the standard output to a file the name of this file must be specified after output Use the special keyword pipe to redirect the standard output to a pipe e error permits to redirect the standard error file of the process Redirection can go to a file or to a pipe To redirect the standard error to a file the name of this file must be specified after error Use the special keyword pipe t
104. returns f continuation obj procedure returns t if obj is a continuation obtained by call cc otherwise returns f dynamic wind thunk thunko thunk3 procedure Thunk thunk gt and thunk3 are called in order The result of dynamic wind is the value returned by thunk2 If thunk escapes from its continuation during evaluation by calling a continuation obtained by call cc or on error thunk3 is called If thunkg is later reentered thunk is called catch expression expressiong syntax The expression s are evaluated from left to right If an error occurs evaluation of the expression s is aborted and stt is returned to catch s caller If evaluation finishes without an error catch returns f let x O y catch set x 1 0 causes a division by 0 error set x 2 cons x y 1 t procedure body procedure procedure returns the body of procedure If procedure is not a closure procedure body returns Hf define f a b a b 2 procedure body f gt lambda a b a b 2 procedure body car gt df 22 STK Reference Manual 6 10 Input and output The R4RS states that ports represent input and output devices However it defines only ports which are attached to files In STK ports can also be attached to strings to a external command input or output or even be completely virtual i e the behavior of the port is given by the user
105. ription2 metaclass option The metaclass option will not be discussed in this appendix The superclass es list specifies the super classes of class see 3 for more details A slot description gives the name of a slot and eventually some properties of this slot such as its initial value the function which permit to access its value Slot descriptions will be discussed in 3 3 79 80 STK Reference Manual As an exemple consider now that we have to define a complex number This can be done with the following class definition define class complex number r i This binds the symbol complex to a new class whose instances contain two slots These slots are called r an i and we suppose here that they contain respectively the real part and the imaginary part of a complex number Note that this class inherits from number which is a pre defined class lt number gt is the super class of the real and integer pre defined classes 3 Inheritance 3 1 Class hierarchy and inheritance of slots Inheritance is specified upon class definition As said in the introduction STKLOS supports multiple inheritance Hereafter are some classes definition define class A O a define class B O b define class C O c define class D A B d a define class E A C e c define class F D E f A B C have a null list of super classes In this case the system will replace it by the
106. rocedure takes one parameter which is the port from which the input is done Open input virtual accepts also the special value f for the I O procedures with the following conventions e if getc or eofp is any attempt to read the virtual port will an eof object e if readyp is f the file will always be ready for reading e if clos is f no action is done when the port is closed Hereafter is a possible implementation of open input string using virtual ports define open input string str let index 0 open input virtual lambda p getc test on eof is already done by the system let res string ref str index set index index 1 res f readyp lambda p index string length str eofp lambda p set index 0 close 26 STK Reference Manual open output virtual wrtc wrts flush close procedure Returns a virtual port using the wrtc procedure to write a character to the port wrts to write a string to the port flush to flush the character on the port and finally close to close the port Wrtc takes two parameters a character and the port to which the output must be done Wrts takes two parameters a string and a port Flush and close takes one parameter which is the port on which the action must be done Open input virtual accepts also the special value f for the I O procedures If a procedure is f nothing is done on the corresponding action Hereafter is an very inefficient implementatio
107. s a string in which all lower case letters of string have been replaced by their upper case equivalent 6 8 Vectors vector obj procedure make vector k procedure make vector k fil procedure vector obj procedure vector length vector procedure vector ref vector k procedure vector set vector k obj procedure vector gt list vector procedure list vector list procedure vector fill vector fill procedure Identical to R RS vector copy vector procedure returns a copy of vector vector resize vector size procedure vector resize physically changes the size of vector If size is greater than the old vector size the contents of the newly allocated cells are undefined 6 9 Control features procedure obj procedure apply proc args procedure apply proc arg args procedure map proc list listo procedure for each proc list liste procedure force promise procedure Identical to R RS call with current continuation proc procedure call cc proc procedure Call cc is a shorter name for call with current continuation closure obj procedure returns t if obj is a procedure created by evaluating a lambda expression otherwise returns Hf STK Reference Manual 21 primitive obj procedure returns t if obj is a procedure and is not a closure otherwise returns ttf promise obj procedure returns t if obj is an object returned by the application of delay otherwise
108. s output port 10Port 13 is generally used for testing making a connection to it permits to know the distant system s idea of the time of day Under Unix you can simply connect to listening socket with the telnet command With the given example this can be achieved by typing the following command in a window shell telnet localhost 1234 56 STK Reference Manual let s make server socket 1234 socket accept connection s let 1 read line socket input s format socket output s Length is A n string length 1 flush socket output s socket shutdown s socket shutdown socket procedure socket shutdown socket close procedure Socket shutdown shutdowns the connection associated to socket Close is a boolean it indi cates if the socket must be closed or not when the connection is destroyed Closing the socket forbids further connections on the same port with the socket accept connection procedure Omitting a value for close implies the closing of socket The result of socket shutdown is undefined The following example shows a simple server when there is a new connection on the port number 1234 the server displays the first line sent to it by the client discards the others and go back waiting for further client connections let s make server socket 1234 let loop O socket accept connection s format t I ve read Ain read line socket input s socket shutdown s f loop socket
109. s u s Qoa orar es ee Donne De Reid metum Ht past 20 6 9 Control features dis atk fames Wer ool gle es Pe 20 6 10 Input and output 22 6 11 Keywords 6 22a de oon a doe Gea cw x 4 9 uox ck E09 BOX i3 31 62 LEK Commands in mede epis euni E eat eh ets 32 6 13 Modules mia d ghetto ie eee ede e i MAR hoa as 34 6 14 Environments lGoenoln9sRos e den dun ae ee Ba he nn nue 37 6 155 Macros uu x ue Bice Dudum hoe CA Pere RE end 38 6 16 System procedures a 40 6 17 Addresses 2 vot hae Awol a nue Kee ea wt e ES 43 6 18 Signals oce e cae pe a eI A wow EON qe 43 6 19 Hash tables sii Posey AO ewe Hoe Pook NE ROO E SECRET LS 45 6 20 Regular expressions 48 6 21 Pattern matching a 50 6 22 Processes 46 nr a te un a dans Ee Se ie a EG 52 0 295 5SOCkels uu n ao LE eee WERE Be eI ede Bes 54 6 24 Foreign Function Interface 57 6 25 Miscellaneous 61 STK Reference Manual II Annexes A Using the Tk toolkit 1 Calling Tk command 441 444 444 RR RE 2 Associating Callbacks to Tk commands 3 L bindings A 25 ss on Cine MER rs UE e Us si B Differences with RARS 1 SYIBnbOlg std Sede e tes ben onus e ee a EE RUBIA AO 2 RV PES pucr 3 Procedures iex a Gr ek bese es Ghee ad gain de MO nd ab a nes C An introduction to STKLOS 1 Introduetion s ect a bo ee red CECI OA EO ea a
110. sed for socket socket input socket procedure socket output socket procedure Returns the file port associated for reading or writing with the program connected with socket If no connection has already been established these functions return f The following example shows how to make a client socket Here we create a socket on port 13 of the machine kaolin unice fr let s make client socket kaolin unice fr 13 format t Time is A n read line socket input s socket shutdown s make server socket procedure make server socket port number procedure make server socket returns a new socket object If port number is specified the socket is listening on the specified port otherwise the communication port is chosen by the system socket accept connection socket procedure Socket accept connection waits for a client connection on the given socket If no clien t is already waiting for a connection this procedure blocks its caller otherwise the first connection request on the queue of pending connections is connected to socket This pro cedure must be called on a server socket created with make server socket The result of Socket accept connection is undefined The following example is a simple server which waits for a connection on the port 1234 Once the connection with the distant program is established we read a line on the input port associated to the socket and we write the length of this line on it
111. ssion against a string is simply done by applying a previously created regular expression to this string Regular expressions are implemented using code in the Henry Spencer s package and much of the description of regular expressions below is copied from his manual string gt regexp string procedure String gt regexp compiles the string and returns the corresponding regular expression Matching a regular expression against a string is done by applying the result of string gt regexp to this string This application yields a list of integer couples if a matching occurs it returns f otherwise Those integers correspond to indexes in the string which match the regular expression A regular expression is zero or more branches separated by matches one of the branches A branch is zero or more pieces concatenated It matches a match for the first followed by a match for the second etc A piece is an atom possibly followed by or An atom followed by matches a sequence of 0 or more matches of the atom An atom followed by matches a sequence of 1 or more matches of the atom An atom followed by matches a match of the atom or the null string An atom is a regular expression in parentheses matching a match for the regular expression a range see below matching any single character matching the null string at the beginning of the input string matching the null strin
112. t in which the autoload was done Filename must provide a definition for the symbol which lead to its loading otherwise an error is signaled autoload symbol module procedure Returns t if symbol is an autoload symbol in module environment returns f otherwise require string procedure provide string procedure provided string procedure Require loads the file whose name is string if it was not previously provided Provide permits to store string in the list of already provided files Providing a file permits to avoid subsequent loads of this file Provided returns t if string was already provided it returns f otherwise open file filename mode procedure 6699 Opens the file whose name is filename with the specified mode Mode must be r to open for reading or w to open for writing If the file can be opened open file returns the port 3Current version 4 0 allows dynamic loading only on some platforms SunOs 4 1 x SunOs 5 x NetBSD 1 0 Linux 2 0 HPUX Irix 5 3 30 STK Reference Manual associated with the given file otherwise it returns f Here again the magic string permit to open a pipe port close port port procedure Closes port If port denotes a string port further reading or writing on this port is disallowed copy port src dst procedure Copies the content of the input port src to the output port dest define copy file lambda src dst with input from fi
113. t this extension of the language could lead to ambiguities in some situations 2 2 Comments There are three types of comments in STK 1 a semicolon indicates the start of a comment This kind of comment extends to the end of the line as described in RRS 2 multi lines comment use the classical Lisp convention a comment begins with and ends with 3 comments can also be introduced by This extension is particularly useful for building STK scripts On most Unix implementations if the first line of a script looks like this usr local bin stk file The Revised Report on the Algorithmic Language Scheme is available through anonymous FTP from ftp cs indiana edu in the directory pub scheme repository doc T 8 STK Reference Manual then the script can be started directly as if it were a binary STK is loaded behind the scenes and reads and executes the script as a Scheme program Of course this assumes that STK is located in usr local bin 2 3 Other notations STK accepts all the notations defined in R RS plus Brackets are equivalent to parentheses They are used for grouping and to notate lists A list opened with a left square bracket must be closed with a right square bracket section 6 3 A colon at the beginning of a symbol introduces a keyword Keywords are described in section 6 11 lt expr gt is read as the evaluation of the Scheme expression lt expr gt The evaluation is done during
114. text Hello world This call defines a new widget object which is stored in the STK variable hello This object can be used as a procedure to customize our button For instance setting the border of this button to 5 pixels wide and its background to gray would be done in Tcl with hello configure border 5 background gray In STK this would be expressed as hello configure border 5 background gray Since keyword colon is replaced by a dash when a Tk command is called this expression could also have been written as hello configure border 5 background gray 2 Associating Callbacks to Tk commands Starting with version 3 0 STK callbacks are Scheme closures Apart scroll commands callbacks are Schemes procedures without parameter Suppose for example that we want to associate a command with the previous hello button In Tcl such a command can be expressed as hello configure command puts stdout Hello world destroy In S TK we can write hello configure command lambda display Hello world n destroy root When the user will press the mouse left button the closure associated to the command option will be evaluated in the global environment Evaluation of the given closure will display the message and call the destroy Tk command Note The root widget is denoted in Tcl This convention is ambiguous with the dotted pair convention and the dot must be quoted to avoid pro
115. the living modules 6 14 Environments Environments are first class objects in STk The following primitives are defined on environ ments environment obj procedure Returns stt if obj is an environment otherwise returns f the environment procedure Returns the current environment global environment procedure Returns the global environment i e the toplevel environment parent environment env procedure Returns the parent environment of env If env is the global environment i e the toplevel environment parent environment returns f environment gt list environment procedure Returns a list of a lists representing the bindings in environment Each a list describes one level of bindings with the innermost level coming first 38 STK Reference Manual define E let a 1 b 2 let c 3 the environment car environment gt list E gt c 3 cadr environment gt list E b 2 a 1 procedure environment procedure procedure Returns the environment associated with procedure Procedure environment returns f if procedure is not a closure define foo let a 1 lambda O a car environment gt list procedure environment foo a 1 module environment module procedure Returns the environment associated to the module module define module M define a 1 car environment gt list module environment find module M a 1
116. the read process when the is encountered Evaluation is done in the environment of the current module define foo 1 foo gt 1 foo foo foo foo gt foo 1 2 let foo 2 foo gt 1 n is used to represent circular structures The value given of nmiust be number It is used as a label which can be referenced later by a n syntax see below The scope of the label is the expression being read by the outermost read n is used to reference a some object labeled by a n syntax that is n represents a pointer to the object labeled exactly by n For instance the object created returned by the following expression let a list 1 2 b append x y a list a b caen be represented in this way 0 1 2 x y 0 3 Basic concepts Identical to R RS STK Reference Manual 9 4 Expressions 4 1 Primitive expression types quote datum syntax datum syntax The quoting mechanism is identical to R RS Keywords see section 6 11 as numerical con stants string constants character constants and boolean constants evaluate to themselves they need not be quoted abc gt abc abc gt abc 145932 gt 145932 145932 gt 145932 dt dit t dit gt key gt key key gt ikey Note R RS requires to quote constant lists and constant vectors This is not necessary with STK operator operandi syntax Identical to R
117. toplevel do 1 readline gt readline gt not 1 system 1 3Pointers defined with dynamic ptr are always unallocated with free Consequently areas allocated with another allocator than the standard one must be declared as static ptr and freed by hand Usage of malloc and free are for illustration purpose here Their usage in a program must be avoided if possible because it can have interact badly with the way the interpreter manages memory or it can conduct to crashing programs if you don t take care STK Reference Manual 61 Note The same convention also applies for parameters of type string dynamic ptr or static ptr they accept the special value f as a synonym of the C NULL pointer external exists entry procedure external exists entry library procedure Returns stt if entry is defined as an external symbol in library If library is not provided the symbol is searched in the STK interpreter or in libraries that it uses This function can be useful to define external functions conditionally when external exists dup2 define external dup2 oldfd int newfd int return type int c string gt string str procedure STk strings are more general than C strings since they accept null character c string gt string takes an area of characters built by a call to a foreign function typically the result of a func tion returning a static ptr dynamic ptr or string and convert it to a pr
118. ttp www cs indiana edu scheme repository SRhome html The Scheme Repository is mirrored in Europe e ftp inria fr lang Scheme e faui80 informatik uni erlangen de pub scheme yorku e ftp informatik uni muenchen de pub comp programming languages scheme scheme repository 4 3 Usenet newsgroup and other addresses There is a usenet newsgroup about the Scheme Programming language comp lang scheme Following addresses contains also material about the Scheme language e http www cs cmu edu 8001 Web Groups AI html faqs lang scheme top html contains the Scheme FAQ e http www swiss ai mit edu scheme home html is the Scheme Home page at MIT e http www ai mit edu projects su su html is the Scheme Underground web page Bibliography 10 11 12 13 14 15 William Clinger and Jonathan Rees editors Revised Report on the Algorithmic Language Scheme ACM Lisp Pointers 4 3 1991 John K Ousterhout An X11 toolkit based on the Tcl Language In USENIX Winter Conference pages 105 115 January 1991 John K Ousterhout Tcl an embeddable command language In USENIX Winter Conference pages 183 192 January 1990 Erick Gallesio Extending the STK interpreter Technical report IBS CNRS Universit de Nice Sophia Antipolis 1997 Sho Huan Simon Tung and R Kent Dybvig Reliable interactive programming with modules LISP and Symbolic Computation 9 343 358 1996 Guy L Steele Jr Common Lisp the Language 2nd
119. tually exist in csh no check for existence is made unless a pattern contains a or construct remove file string procedure Removes the file whose path name is given in string The result of remove file is undefined 42 STK Reference Manual rename file string string2 procedure Renames the file whose path name is contained in string in the path name given by string The result of rename file is undefined temporary file name string procedure Generates a unique temporary file name The value returned by temporary file name is the newly generated name of f if a unique name cannot be generated getcwd procedure Getcwd returns a string containing the current working directory chdir string procedure Chdir changes the current directory to the directory given in string getpid string procedure Returns the system process number of the current STK interpreter i e the Unix pid Result is an integer system string procedure string procedure Sends the given string to the system shell bin sh The result of system is the integer status code the shell returns exec string procedure Executes the command contained in string and redirects its output in a string This string constitutes the result of exec getenv string procedure Looks for the environment variable named string and returns its value as a string if it exists Otherwise getenv returns f getenv SHELL gt bin zsh
120. var symbol procedure Deletes all the traces associated to the variable denoted by symbol error string string obja procedure error prints the objs according to the specification given in string on the current error port or in an error window if Tk is initialized The specification string follows the tilde conventions of format see 6 10 Once the message is printed execution returns to toplevel gc procedure Runs the garbage collector See 6 18 for the signals associated to garbage collection gc stats procedure Provides some statistics about current memory usage This procedure is primarily for debug ging the STK interpreter hence its weird printing format expand heap n procedure Expand the heap so that it will contains at least n cells Normally the heap automatically grows when more memory is needed However using only automatic heap growing is some times very penalizing This is particularly true for programs which uses a lot of temporary data which are not pointed by any a variable and a small amount of global data In this case the garbage collector will be often called and the heap will not be automatically expand ed since most of the consumed heap will be reclaimed by the GC This could be annoying specially for program where response time is critical Using expand heap permits to enlarge the heap size which is set to 20000 cells by default to avoid those continual calls to the GC get intern
121. very quickly locate the entry and hence the corresponding value There may be at most one entry in a hash table with a particular key but many entries may have the same value STK hash tables grow gracefully as the number of entries increases so that there are always less than three entries per hash bucket on average This allows for fast lookups regardless of the number of entries in a table Note Hash table manipulation procedures are built upon the efficient Tcl hash table package make hash table procedure make hash table comparison procedure make hash table comparison hash procedure Make hash table admits three different forms The most general form admit two arguments The first argument is a comparison function which determine how keys are compared the second argument is a function which computes a hash code for an object and returns the hash code as a non negative integer Objets with the same hash code are stored in an A list registered in the bucket corresponding to the key If omitted e hash defaults to the hash table hash procedure e comparison defaults to the eq procedure Consequently define h make hash table is equivalent to define h make hash table eq hash table hash Another interesting example is define h make hash table string ci string length which defines a new hash table which uses string ci for comparing keys Here we use the string length as a very simple hashing function
122. you used when you subscribed to the list 2 4 STK FAQ Marc Furrer has set up a FAQ for STK This FAQ is regularly posted on the STK mailing list It can also be accessed through http ltiwww epfl ch furrer STk FAQ html ASCII version of the FAQ is available from http ltiwww epfl ch furrer STk FAQ txt 2 5 Reporting a bug When you find a bug in STK please send its description to the following address stk bugs kaolin unice fr Don t forget to indicate the version you use and the architecture the system is compiled on STK ver sion and architecture can be found by using the version and machine type Scheme primitives If possible try to find a small program which exhibit the bug 3 STK and Emacs The Emacs family editors can be customized to ease viewing and editing programs of a particular sort Hints given below enable a fine integration of STK in Emacs Automatic scheme mode setting Emacs mode can be chosen automatically on the file s name To edit file ended by stk or stklos in Scheme mode you have to set the Elisp variable auto mode alist to control the correspondence between those suffixes and the scheme mode The simpler way to set this variable consists to add the following lines in your emacs startup file Add the stk and stklos suffix in the auto mode alist Emacs variable Setting this variable permits to automagically place the buffer in scheme mode setq auto mode alist append
Download Pdf Manuals
Related Search
Related Contents
AMX RDM-3FDB User's Manual Lenovo ThinkCentre M93z 8~11ページ - アクションジャパン Copyright © All rights reserved.
Failed to retrieve file