raw
tinyscheme_genesi...    1 
tinyscheme_genesi... 2
tinyscheme_genesi... 3 TinySCHEME Version 1.41
tinyscheme_genesi... 4
tinyscheme_genesi... 5 "Safe if used as prescribed"
tinyscheme_genesi... 6 -- Philip K. Dick, "Ubik"
tinyscheme_genesi... 7
tinyscheme_genesi... 8 This software is open source, covered by a BSD-style license.
tinyscheme_genesi... 9 Please read accompanying file COPYING.
tinyscheme_genesi... 10 -------------------------------------------------------------------------------
tinyscheme_genesi... 11
tinyscheme_genesi... 12 This Scheme interpreter is based on MiniSCHEME version 0.85k4
tinyscheme_genesi... 13 (see miniscm.tar.gz in the Scheme Repository)
tinyscheme_genesi... 14 Original credits in file MiniSCHEMETribute.txt.
tinyscheme_genesi... 15
tinyscheme_genesi... 16 D. Souflis (dsouflis@acm.org)
tinyscheme_genesi... 17
tinyscheme_genesi... 18 -------------------------------------------------------------------------------
tinyscheme_genesi... 19 What is TinyScheme?
tinyscheme_genesi... 20 -------------------
tinyscheme_genesi... 21
tinyscheme_genesi... 22 TinyScheme is a lightweight Scheme interpreter that implements as large
tinyscheme_genesi... 23 a subset of R5RS as was possible without getting very large and
tinyscheme_genesi... 24 complicated. It is meant to be used as an embedded scripting interpreter
tinyscheme_genesi... 25 for other programs. As such, it does not offer IDEs or extensive toolkits
tinyscheme_genesi... 26 although it does sport a small top-level loop, included conditionally.
tinyscheme_genesi... 27 A lot of functionality in TinyScheme is included conditionally, to allow
tinyscheme_genesi... 28 developers freedom in balancing features and footprint.
tinyscheme_genesi... 29
tinyscheme_genesi... 30 As an embedded interpreter, it allows multiple interpreter states to
tinyscheme_genesi... 31 coexist in the same program, without any interference between them.
tinyscheme_genesi... 32 Programmatically, foreign functions in C can be added and values
tinyscheme_genesi... 33 can be defined in the Scheme environment. Being a quite small program,
tinyscheme_genesi... 34 it is easy to comprehend, get to grips with, and use.
tinyscheme_genesi... 35
tinyscheme_genesi... 36 Known bugs
tinyscheme_genesi... 37 ----------
tinyscheme_genesi... 38
tinyscheme_genesi... 39 TinyScheme is known to misbehave when memory is exhausted.
tinyscheme_genesi... 40
tinyscheme_genesi... 41
tinyscheme_genesi... 42 Things that keep missing, or that need fixing
tinyscheme_genesi... 43 ---------------------------------------------
tinyscheme_genesi... 44
tinyscheme_genesi... 45 There are no hygienic macros. No rational or
tinyscheme_genesi... 46 complex numbers. No unwind-protect and call-with-values.
tinyscheme_genesi... 47
tinyscheme_genesi... 48 Maybe (a subset of) SLIB will work with TinySCHEME...
tinyscheme_genesi... 49
tinyscheme_genesi... 50 Decent debugging facilities are missing. Only tracing is supported
tinyscheme_genesi... 51 natively.
tinyscheme_genesi... 52
tinyscheme_genesi... 53
tinyscheme_genesi... 54 Scheme Reference
tinyscheme_genesi... 55 ----------------
tinyscheme_genesi... 56
tinyscheme_genesi... 57 If something seems to be missing, please refer to the code and
tinyscheme_genesi... 58 "init.scm", since some are library functions. Refer to the MiniSCHEME
tinyscheme_genesi... 59 readme as a last resort.
tinyscheme_genesi... 60
tinyscheme_genesi... 61 Environments
tinyscheme_genesi... 62 (interaction-environment)
tinyscheme_genesi... 63 See R5RS. In TinySCHEME, immutable list of association lists.
tinyscheme_genesi... 64
tinyscheme_genesi... 65 (current-environment)
tinyscheme_genesi... 66 The environment in effect at the time of the call. An example of its
tinyscheme_genesi... 67 use and its utility can be found in the sample code that implements
tinyscheme_genesi... 68 packages in "init.scm":
tinyscheme_genesi... 69
tinyscheme_genesi... 70 (macro (package form)
tinyscheme_genesi... 71 `(apply (lambda ()
tinyscheme_genesi... 72 ,@(cdr form)
tinyscheme_genesi... 73 (current-environment))))
tinyscheme_genesi... 74
tinyscheme_genesi... 75 The environment containing the (local) definitions inside the closure
tinyscheme_genesi... 76 is returned as an immutable value.
tinyscheme_genesi... 77
tinyscheme_genesi... 78 (defined? <symbol>) (defined? <symbol> <environment>)
tinyscheme_genesi... 79 Checks whether the given symbol is defined in the current (or given)
tinyscheme_genesi... 80 environment.
tinyscheme_genesi... 81
tinyscheme_genesi... 82 Symbols
tinyscheme_genesi... 83 (gensym)
tinyscheme_genesi... 84 Returns a new interned symbol each time. Will probably move to the
tinyscheme_genesi... 85 library when string->symbol is implemented.
tinyscheme_genesi... 86
tinyscheme_genesi... 87 Directives
tinyscheme_genesi... 88 (gc)
tinyscheme_genesi... 89 Performs garbage collection immediatelly.
tinyscheme_genesi... 90
tinyscheme_genesi... 91 (gcverbose) (gcverbose <bool>)
tinyscheme_genesi... 92 The argument (defaulting to #t) controls whether GC produces
tinyscheme_genesi... 93 visible outcome.
tinyscheme_genesi... 94
tinyscheme_genesi... 95 (quit) (quit <num>)
tinyscheme_genesi... 96 Stops the interpreter and sets the 'retcode' internal field (defaults
tinyscheme_genesi... 97 to 0). When standalone, 'retcode' is returned as exit code to the OS.
tinyscheme_genesi... 98
tinyscheme_genesi... 99 (tracing <num>)
tinyscheme_genesi... 100 1, turns on tracing. 0 turns it off. (Only when USE_TRACING is 1).
tinyscheme_genesi... 101
tinyscheme_genesi... 102 Mathematical functions
tinyscheme_genesi... 103 Since rationals and complexes are absent, the respective functions
tinyscheme_genesi... 104 are also missing.
tinyscheme_genesi... 105 Supported: exp, log, sin, cos, tan, asin, acos, atan, floor, ceiling,
tinyscheme_genesi... 106 trunc, round and also sqrt and expt when USE_MATH=1.
tinyscheme_genesi... 107 Number-theoretical quotient, remainder and modulo, gcd, lcm.
tinyscheme_genesi... 108 Library: exact?, inexact?, odd?, even?, zero?, positive?, negative?,
tinyscheme_genesi... 109 exact->inexact. inexact->exact is a core function.
tinyscheme_genesi... 110
tinyscheme_genesi... 111 Type predicates
tinyscheme_genesi... 112 boolean?,eof-object?,symbol?,number?,string?,integer?,real?,list?,null?,
tinyscheme_genesi... 113 char?,port?,input-port?,output-port?,procedure?,pair?,environment?',
tinyscheme_genesi... 114 vector?. Also closure?, macro?.
tinyscheme_genesi... 115
tinyscheme_genesi... 116 Types
tinyscheme_genesi... 117 Types supported:
tinyscheme_genesi... 118
tinyscheme_genesi... 119 Numbers (integers and reals)
tinyscheme_genesi... 120 Symbols
tinyscheme_genesi... 121 Pairs
tinyscheme_genesi... 122 Strings
tinyscheme_genesi... 123 Characters
tinyscheme_genesi... 124 Ports
tinyscheme_genesi... 125 Eof object
tinyscheme_genesi... 126 Environments
tinyscheme_genesi... 127 Vectors
tinyscheme_genesi... 128
tinyscheme_genesi... 129 Literals
tinyscheme_genesi... 130 String literals can contain escaped quotes \" as usual, but also
tinyscheme_genesi... 131 \n, \r, \t, \xDD (hex representations) and \DDD (octal representations).
tinyscheme_genesi... 132 Note also that it is possible to include literal newlines in string
tinyscheme_genesi... 133 literals, e.g.
tinyscheme_genesi... 134
tinyscheme_genesi... 135 (define s "String with newline here
tinyscheme_genesi... 136 and here
tinyscheme_genesi... 137 that can function like a HERE-string")
tinyscheme_genesi... 138
tinyscheme_genesi... 139 Character literals contain #\space and #\newline and are supplemented
tinyscheme_genesi... 140 with #\return and #\tab, with obvious meanings. Hex character
tinyscheme_genesi... 141 representations are allowed (e.g. #\x20 is #\space).
tinyscheme_genesi... 142 When USE_ASCII_NAMES is defined, various control characters can be
tinyscheme_genesi... 143 referred to by their ASCII name.
tinyscheme_genesi... 144 0 #\nul 17 #\dc1
tinyscheme_genesi... 145 1 #\soh 18 #\dc2
tinyscheme_genesi... 146 2 #\stx 19 #\dc3
tinyscheme_genesi... 147 3 #\etx 20 #\dc4
tinyscheme_genesi... 148 4 #\eot 21 #\nak
tinyscheme_genesi... 149 5 #\enq 22 #\syn
tinyscheme_genesi... 150 6 #\ack 23 #\etv
tinyscheme_genesi... 151 7 #\bel 24 #\can
tinyscheme_genesi... 152 8 #\bs 25 #\em
tinyscheme_genesi... 153 9 #\ht 26 #\sub
tinyscheme_genesi... 154 10 #\lf 27 #\esc
tinyscheme_genesi... 155 11 #\vt 28 #\fs
tinyscheme_genesi... 156 12 #\ff 29 #\gs
tinyscheme_genesi... 157 13 #\cr 30 #\rs
tinyscheme_genesi... 158 14 #\so 31 #\us
tinyscheme_genesi... 159 15 #\si
tinyscheme_genesi... 160 16 #\dle 127 #\del
tinyscheme_genesi... 161
tinyscheme_genesi... 162 Numeric literals support #x #o #b and #d. Flonums are currently read only
tinyscheme_genesi... 163 in decimal notation. Full grammar will be supported soon.
tinyscheme_genesi... 164
tinyscheme_genesi... 165 Quote, quasiquote etc.
tinyscheme_genesi... 166 As usual.
tinyscheme_genesi... 167
tinyscheme_genesi... 168 Immutable values
tinyscheme_genesi... 169 Immutable pairs cannot be modified by set-car! and set-cdr!.
tinyscheme_genesi... 170 Immutable strings cannot be modified via string-set!
tinyscheme_genesi... 171
tinyscheme_genesi... 172 I/O
tinyscheme_genesi... 173 As per R5RS, plus String Ports (see below).
tinyscheme_genesi... 174 current-input-port, current-output-port,
tinyscheme_genesi... 175 close-input-port, close-output-port, input-port?, output-port?,
tinyscheme_genesi... 176 open-input-file, open-output-file.
tinyscheme_genesi... 177 read, write, display, newline, write-char, read-char, peek-char.
tinyscheme_genesi... 178 char-ready? returns #t only for string ports, because there is no
tinyscheme_genesi... 179 portable way in stdio to determine if a character is available.
tinyscheme_genesi... 180 Also open-input-output-file, set-input-port, set-output-port (not R5RS)
tinyscheme_genesi... 181 Library: call-with-input-file, call-with-output-file,
tinyscheme_genesi... 182 with-input-from-file, with-output-from-file and
tinyscheme_genesi... 183 with-input-output-from-to-files, close-port and input-output-port?
tinyscheme_genesi... 184 (not R5RS).
tinyscheme_genesi... 185 String Ports: open-input-string, open-output-string, get-output-string,
tinyscheme_genesi... 186 open-input-output-string. Strings can be used with I/O routines.
tinyscheme_genesi... 187
tinyscheme_genesi... 188 Vectors
tinyscheme_genesi... 189 make-vector, vector, vector-length, vector-ref, vector-set!, list->vector,
tinyscheme_genesi... 190 vector-fill!, vector->list, vector-equal? (auxiliary function, not R5RS)
tinyscheme_genesi... 191
tinyscheme_genesi... 192 Strings
tinyscheme_genesi... 193 string, make-string, list->string, string-length, string-ref, string-set!,
tinyscheme_genesi... 194 substring, string->list, string-fill!, string-append, string-copy.
tinyscheme_genesi... 195 string=?, string<?, string>?, string>?, string<=?, string>=?.
tinyscheme_genesi... 196 (No string-ci*? yet). string->number, number->string. Also atom->string,
tinyscheme_genesi... 197 string->atom (not R5RS).
tinyscheme_genesi... 198
tinyscheme_genesi... 199 Symbols
tinyscheme_genesi... 200 symbol->string, string->symbol
tinyscheme_genesi... 201
tinyscheme_genesi... 202 Characters
tinyscheme_genesi... 203 integer->char, char->integer.
tinyscheme_genesi... 204 char=?, char<?, char>?, char<=?, char>=?.
tinyscheme_genesi... 205 (No char-ci*?)
tinyscheme_genesi... 206
tinyscheme_genesi... 207 Pairs & Lists
tinyscheme_genesi... 208 cons, car, cdr, list, length, map, for-each, foldr, list-tail,
tinyscheme_genesi... 209 list-ref, last-pair, reverse, append.
tinyscheme_genesi... 210 Also member, memq, memv, based on generic-member, assoc, assq, assv
tinyscheme_genesi... 211 based on generic-assoc.
tinyscheme_genesi... 212
tinyscheme_genesi... 213 Streams
tinyscheme_genesi... 214 head, tail, cons-stream
tinyscheme_genesi... 215
tinyscheme_genesi... 216 Control features
tinyscheme_genesi... 217 Apart from procedure?, also macro? and closure?
tinyscheme_genesi... 218 map, for-each, force, delay, call-with-current-continuation (or call/cc),
tinyscheme_genesi... 219 eval, apply. 'Forcing' a value that is not a promise produces the value.
tinyscheme_genesi... 220 There is no call-with-values, values, nor dynamic-wind. Dynamic-wind in
tinyscheme_genesi... 221 the presence of continuations would require support from the abstract
tinyscheme_genesi... 222 machine itself.
tinyscheme_genesi... 223
tinyscheme_genesi... 224 Property lists
tinyscheme_genesi... 225 TinyScheme inherited from MiniScheme property lists for symbols.
tinyscheme_genesi... 226 put, get.
tinyscheme_genesi... 227
tinyscheme_genesi... 228 Dynamically-loaded extensions
tinyscheme_genesi... 229 (load-extension <filename without extension>)
tinyscheme_genesi... 230 Loads a DLL declaring foreign procedures. On Unix/Linux, one can make use
tinyscheme_genesi... 231 of the ld.so.conf file or the LD_RUN_PATH system variable in order to place
tinyscheme_genesi... 232 the library in a directory other than the current one. Please refer to the
tinyscheme_genesi... 233 appropriate 'man' page.
tinyscheme_genesi... 234
tinyscheme_genesi... 235 Esoteric procedures
tinyscheme_genesi... 236 (oblist)
tinyscheme_genesi... 237 Returns the oblist, an immutable list of all the symbols.
tinyscheme_genesi... 238
tinyscheme_genesi... 239 (macro-expand <form>)
tinyscheme_genesi... 240 Returns the expanded form of the macro call denoted by the argument
tinyscheme_genesi... 241
tinyscheme_genesi... 242 (define-with-return (<procname> <args>...) <body>)
tinyscheme_genesi... 243 Like plain 'define', but makes the continuation available as 'return'
tinyscheme_genesi... 244 inside the procedure. Handy for imperative programs.
tinyscheme_genesi... 245
tinyscheme_genesi... 246 (new-segment <num>)
tinyscheme_genesi... 247 Allocates more memory segments.
tinyscheme_genesi... 248
tinyscheme_genesi... 249 defined?
tinyscheme_genesi... 250 See "Environments"
tinyscheme_genesi... 251
tinyscheme_genesi... 252 (get-closure-code <closure>)
tinyscheme_genesi... 253 Gets the code as scheme data.
tinyscheme_genesi... 254
tinyscheme_genesi... 255 (make-closure <code> <environment>)
tinyscheme_genesi... 256 Makes a new closure in the given environment.
tinyscheme_genesi... 257
tinyscheme_genesi... 258 Obsolete procedures
tinyscheme_genesi... 259 (print-width <object>)
tinyscheme_genesi... 260
tinyscheme_genesi... 261 Programmer's Reference
tinyscheme_genesi... 262 ----------------------
tinyscheme_genesi... 263
tinyscheme_genesi... 264 The interpreter state is initialized with "scheme_init".
tinyscheme_genesi... 265 Custom memory allocation routines can be installed with an alternate
tinyscheme_genesi... 266 initialization function: "scheme_init_custom_alloc".
tinyscheme_genesi... 267 Files can be loaded with "scheme_load_file". Strings containing Scheme
tinyscheme_genesi... 268 code can be loaded with "scheme_load_string". It is a good idea to
tinyscheme_genesi... 269 "scheme_load" init.scm before anything else.
tinyscheme_genesi... 270
tinyscheme_genesi... 271 External data for keeping external state (of use to foreign functions)
tinyscheme_genesi... 272 can be installed with "scheme_set_external_data".
tinyscheme_genesi... 273 Foreign functions are installed with "assign_foreign". Additional
tinyscheme_genesi... 274 definitions can be added to the interpreter state, with "scheme_define"
tinyscheme_genesi... 275 (this is the way HTTP header data and HTML form data are passed to the
tinyscheme_genesi... 276 Scheme script in the Altera SQL Server). If you wish to define the
tinyscheme_genesi... 277 foreign function in a specific environment (to enhance modularity),
tinyscheme_genesi... 278 use "assign_foreign_env".
tinyscheme_genesi... 279
tinyscheme_genesi... 280 The procedure "scheme_apply0" has been added with persistent scripts in
tinyscheme_genesi... 281 mind. Persistent scripts are loaded once, and every time they are needed
tinyscheme_genesi... 282 to produce HTTP output, appropriate data are passed through global
tinyscheme_genesi... 283 definitions and function "main" is called to do the job. One could
tinyscheme_genesi... 284 add easily "scheme_apply1" etc.
tinyscheme_genesi... 285
tinyscheme_genesi... 286 The interpreter state should be deinitialized with "scheme_deinit".
tinyscheme_genesi... 287
tinyscheme_genesi... 288 DLLs containing foreign functions should define a function named
tinyscheme_genesi... 289 init_<base-name>. E.g. foo.dll should define init_foo, and bar.so
tinyscheme_genesi... 290 should define init_bar. This function should assign_foreign any foreign
tinyscheme_genesi... 291 function contained in the DLL.
tinyscheme_genesi... 292
tinyscheme_genesi... 293 The first dynamically loaded extension available for TinyScheme is
tinyscheme_genesi... 294 a regular expression library. Although it's by no means an
tinyscheme_genesi... 295 established standard, this library is supposed to be installed in
tinyscheme_genesi... 296 a directory mirroring its name under the TinyScheme location.
tinyscheme_genesi... 297
tinyscheme_genesi... 298
tinyscheme_genesi... 299 Foreign Functions
tinyscheme_genesi... 300 -----------------
tinyscheme_genesi... 301
tinyscheme_genesi... 302 The user can add foreign functions in C. For example, a function
tinyscheme_genesi... 303 that squares its argument:
tinyscheme_genesi... 304
tinyscheme_genesi... 305 pointer square(scheme *sc, pointer args) {
tinyscheme_genesi... 306 if(args!=sc->NIL) {
tinyscheme_genesi... 307 if(sc->isnumber(sc->pair_car(args))) {
tinyscheme_genesi... 308 double v=sc->rvalue(sc->pair_car(args));
tinyscheme_genesi... 309 return sc->mk_real(sc,v*v);
tinyscheme_genesi... 310 }
tinyscheme_genesi... 311 }
tinyscheme_genesi... 312 return sc->NIL;
tinyscheme_genesi... 313 }
tinyscheme_genesi... 314
tinyscheme_genesi... 315 Foreign functions are now defined as closures:
tinyscheme_genesi... 316
tinyscheme_genesi... 317 sc->interface->scheme_define(
tinyscheme_genesi... 318 sc,
tinyscheme_genesi... 319 sc->global_env,
tinyscheme_genesi... 320 sc->interface->mk_symbol(sc,"square"),
tinyscheme_genesi... 321 sc->interface->mk_foreign_func(sc, square));
tinyscheme_genesi... 322
tinyscheme_genesi... 323
tinyscheme_genesi... 324 Foreign functions can use the external data in the "scheme" struct
tinyscheme_genesi... 325 to implement any kind of external state.
tinyscheme_genesi... 326
tinyscheme_genesi... 327 External data are set with the following function:
tinyscheme_genesi... 328 void scheme_set_external_data(scheme *sc, void *p);
tinyscheme_genesi... 329
tinyscheme_genesi... 330 As of v.1.17, the canonical way for a foreign function in a DLL to
tinyscheme_genesi... 331 manipulate Scheme data is using the function pointers in sc->interface.
tinyscheme_genesi... 332
tinyscheme_genesi... 333 Standalone
tinyscheme_genesi... 334 ----------
tinyscheme_genesi... 335
tinyscheme_genesi... 336 Usage: tinyscheme -?
tinyscheme_genesi... 337 or: tinyscheme [<file1> <file2> ...]
tinyscheme_genesi... 338 followed by
tinyscheme_genesi... 339 -1 <file> [<arg1> <arg2> ...]
tinyscheme_genesi... 340 -c <Scheme commands> [<arg1> <arg2> ...]
tinyscheme_genesi... 341 assuming that the executable is named tinyscheme.
tinyscheme_genesi... 342
tinyscheme_genesi... 343 Use - in the place of a filename to denote stdin.
tinyscheme_genesi... 344 The -1 flag is meant for #! usage in shell scripts. If you specify
tinyscheme_genesi... 345 #! /somewhere/tinyscheme -1
tinyscheme_genesi... 346 then tinyscheme will be called to process the file. For example, the
tinyscheme_genesi... 347 following script echoes the Scheme list of its arguments.
tinyscheme_genesi... 348
tinyscheme_genesi... 349 #! /somewhere/tinyscheme -1
tinyscheme_genesi... 350 (display *args*)
tinyscheme_genesi... 351
tinyscheme_genesi... 352 The -c flag permits execution of arbitrary Scheme code.
tinyscheme_genesi... 353
tinyscheme_genesi... 354
tinyscheme_genesi... 355 Error Handling
tinyscheme_genesi... 356 --------------
tinyscheme_genesi... 357
tinyscheme_genesi... 358 Errors are recovered from without damage. The user can install his
tinyscheme_genesi... 359 own handler for system errors, by defining *error-hook*. Defining
tinyscheme_genesi... 360 to '() gives the default behavior, which is equivalent to "error".
tinyscheme_genesi... 361 USE_ERROR_HOOK must be defined.
tinyscheme_genesi... 362
tinyscheme_genesi... 363 A simple exception handling mechanism can be found in "init.scm".
tinyscheme_genesi... 364 A new syntactic form is introduced:
tinyscheme_genesi... 365
tinyscheme_genesi... 366 (catch <expr returned exceptionally>
tinyscheme_genesi... 367 <expr1> <expr2> ... <exprN>)
tinyscheme_genesi... 368
tinyscheme_genesi... 369 "Catch" establishes a scope spanning multiple call-frames
tinyscheme_genesi... 370 until another "catch" is encountered.
tinyscheme_genesi... 371
tinyscheme_genesi... 372 Exceptions are thrown with:
tinyscheme_genesi... 373
tinyscheme_genesi... 374 (throw "message")
tinyscheme_genesi... 375
tinyscheme_genesi... 376 If used outside a (catch ...), reverts to (error "message").
tinyscheme_genesi... 377
tinyscheme_genesi... 378 Example of use:
tinyscheme_genesi... 379
tinyscheme_genesi... 380 (define (foo x) (write x) (newline) (/ x 0))
tinyscheme_genesi... 381
tinyscheme_genesi... 382 (catch (begin (display "Error!\n") 0)
tinyscheme_genesi... 383 (write "Before foo ... ")
tinyscheme_genesi... 384 (foo 5)
tinyscheme_genesi... 385 (write "After foo"))
tinyscheme_genesi... 386
tinyscheme_genesi... 387 The exception mechanism can be used even by system errors, by
tinyscheme_genesi... 388
tinyscheme_genesi... 389 (define *error-hook* throw)
tinyscheme_genesi... 390
tinyscheme_genesi... 391 which makes use of the error hook described above.
tinyscheme_genesi... 392
tinyscheme_genesi... 393 If necessary, the user can devise his own exception mechanism with
tinyscheme_genesi... 394 tagged exceptions etc.
tinyscheme_genesi... 395
tinyscheme_genesi... 396
tinyscheme_genesi... 397 Reader extensions
tinyscheme_genesi... 398 -----------------
tinyscheme_genesi... 399
tinyscheme_genesi... 400 When encountering an unknown character after '#', the user-specified
tinyscheme_genesi... 401 procedure *sharp-hook* (if any), is called to read the expression.
tinyscheme_genesi... 402 This can be used to extend the reader to handle user-defined constants
tinyscheme_genesi... 403 or whatever. It should be a procedure without arguments, reading from
tinyscheme_genesi... 404 the current input port (which will be the load-port).
tinyscheme_genesi... 405
tinyscheme_genesi... 406
tinyscheme_genesi... 407 Colon Qualifiers - Packages
tinyscheme_genesi... 408 ---------------------------
tinyscheme_genesi... 409
tinyscheme_genesi... 410 When USE_COLON_HOOK=1:
tinyscheme_genesi... 411 The lexer now recognizes the construction <qualifier>::<symbol> and
tinyscheme_genesi... 412 transforms it in the following manner (T is the transformation function):
tinyscheme_genesi... 413
tinyscheme_genesi... 414 T(<qualifier>::<symbol>) = (*colon-hook* 'T(<symbol>) <qualifier>)
tinyscheme_genesi... 415
tinyscheme_genesi... 416 where <qualifier> is a symbol not containing any double-colons.
tinyscheme_genesi... 417
tinyscheme_genesi... 418 As the definition is recursive, qualifiers can be nested.
tinyscheme_genesi... 419 The user can define his own *colon-hook*, to handle qualified names.
tinyscheme_genesi... 420 By default, "init.scm" defines *colon-hook* as EVAL. Consequently,
tinyscheme_genesi... 421 the qualifier must denote a Scheme environment, such as one returned
tinyscheme_genesi... 422 by (interaction-environment). "Init.scm" defines a new syntantic form,
tinyscheme_genesi... 423 PACKAGE, as a simple example. It is used like this:
tinyscheme_genesi... 424
tinyscheme_genesi... 425 (define toto
tinyscheme_genesi... 426 (package
tinyscheme_genesi... 427 (define foo 1)
tinyscheme_genesi... 428 (define bar +)))
tinyscheme_genesi... 429
tinyscheme_genesi... 430 foo ==> Error, "foo" undefined
tinyscheme_genesi... 431 (eval 'foo) ==> Error, "foo" undefined
tinyscheme_genesi... 432 (eval 'foo toto) ==> 1
tinyscheme_genesi... 433 toto::foo ==> 1
tinyscheme_genesi... 434 ((eval 'bar toto) 2 (eval 'foo toto)) ==> 3
tinyscheme_genesi... 435 (toto::bar 2 toto::foo) ==> 3
tinyscheme_genesi... 436 (eval (bar 2 foo) toto) ==> 3
tinyscheme_genesi... 437
tinyscheme_genesi... 438 If the user installs another package infrastructure, he must define
tinyscheme_genesi... 439 a new 'package' procedure or macro to retain compatibility with supplied
tinyscheme_genesi... 440 code.
tinyscheme_genesi... 441
tinyscheme_genesi... 442 Note: Older versions used ':' as a qualifier. Unfortunately, the use
tinyscheme_genesi... 443 of ':' as a pseudo-qualifier in existing code (i.e. SLIB) essentially
tinyscheme_genesi... 444 precludes its use as a real qualifier.
tinyscheme_genesi... 445
tinyscheme_genesi... 446
tinyscheme_genesi... 447
tinyscheme_genesi... 448
tinyscheme_genesi... 449
tinyscheme_genesi... 450
tinyscheme_genesi... 451
tinyscheme_genesi... 452