Commit | Line | Data |
---|---|---|
f7b47737 | 1 | Guile NEWS --- history of user-visible changes. -*- text -*- |
d21ffe26 | 2 | Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. |
5c54da76 JB |
3 | See the end for copying conditions. |
4 | ||
e1b6c710 | 5 | Please send Guile bug reports to bug-guile@gnu.org. |
5c54da76 | 6 | \f |
43fa9a05 JB |
7 | Changes since Guile 1.3.2: |
8 | ||
0fdcbcaa MD |
9 | * Changes to the stand-alone interpreter |
10 | ||
11 | ** Debugger | |
12 | ||
13 | An initial version of the Guile debugger written by Chris Hanson has | |
14 | been added. The debugger is still under development but is included | |
15 | in the distribution anyway since it is already quite useful. | |
16 | ||
17 | Type | |
18 | ||
19 | (debug) | |
20 | ||
21 | after an error to enter the debugger. Type `help' inside the debugger | |
22 | for a description of available commands. | |
23 | ||
24 | If you prefer to have stack frames numbered and printed in | |
25 | anti-chronological order and prefer up in the stack to be down on the | |
26 | screen as is the case in gdb, you can put | |
27 | ||
28 | (debug-enable 'backwards) | |
29 | ||
30 | in your .guile startup file. (However, this means that Guile can't | |
31 | use indentation to indicate stack level.) | |
32 | ||
33 | The debugger is autoloaded into Guile at the first use. | |
34 | ||
35 | ** Further enhancements to backtraces | |
36 | ||
37 | There is a new debug option `width' which controls the maximum width | |
38 | on the screen of printed stack frames. Fancy printing parameters | |
39 | ("level" and "length" as in Common LISP) are adaptively adjusted for | |
40 | each stack frame to give maximum information while still fitting | |
41 | within the bounds. If the stack frame can't be made to fit by | |
42 | adjusting parameters, it is simply cut off at the end. This is marked | |
43 | with a `$'. | |
44 | ||
45 | ** Some modules are now only loaded when the repl is started | |
46 | ||
47 | The modules (ice-9 debug), (ice-9 session), (ice-9 threads) and (ice-9 | |
48 | regex) are now loaded into (guile-user) only if the repl has been | |
49 | started. The effect is that the startup time for scripts has been | |
50 | reduced to 30% of what it was previously. | |
51 | ||
52 | Correctly written scripts load the modules they require at the top of | |
53 | the file and should not be affected by this change. | |
54 | ||
ece41168 MD |
55 | ** Hooks are now represented as smobs |
56 | ||
6822fe53 MD |
57 | * Changes to Scheme functions and syntax |
58 | ||
0ce204b0 MV |
59 | ** Readline support has changed again. |
60 | ||
61 | The old (readline-activator) module is gone. Use (ice-9 readline) | |
62 | instead, which now contains all readline functionality. So the code | |
63 | to activate readline is now | |
64 | ||
65 | (use-modules (ice-9 readline)) | |
66 | (activate-readline) | |
67 | ||
68 | This should work at any time, including from the guile prompt. | |
69 | ||
25b0654e JB |
70 | ** regexp-substitute/global has changed slightly, but incompatibly. |
71 | ||
72 | If you include a function in the item list, the string of the match | |
73 | object it receives is the same string passed to | |
74 | regexp-substitute/global, not some suffix of that string. | |
75 | Correspondingly, the match's positions are relative to the entire | |
76 | string, not the suffix. | |
77 | ||
78 | If the regexp can match the empty string, the way matches are chosen | |
79 | from the string has changed. regexp-substitute/global recognizes the | |
80 | same set of matches that list-matches does; see below. | |
81 | ||
82 | ** New function: list-matches REGEXP STRING [FLAGS] | |
83 | ||
84 | Return a list of match objects, one for every non-overlapping, maximal | |
85 | match of REGEXP in STRING. The matches appear in left-to-right order. | |
86 | list-matches only reports matches of the empty string if there are no | |
87 | other matches which begin on, end at, or include the empty match's | |
88 | position. | |
89 | ||
90 | If present, FLAGS is passed as the FLAGS argument to regexp-exec. | |
91 | ||
92 | ** New function: fold-matches REGEXP STRING INIT PROC [FLAGS] | |
93 | ||
94 | For each match of REGEXP in STRING, apply PROC to the match object, | |
95 | and the last value PROC returned, or INIT for the first call. Return | |
96 | the last value returned by PROC. We apply PROC to the matches as they | |
97 | appear from left to right. | |
98 | ||
99 | This function recognizes matches according to the same criteria as | |
100 | list-matches. | |
101 | ||
102 | Thus, you could define list-matches like this: | |
103 | ||
104 | (define (list-matches regexp string . flags) | |
105 | (reverse! (apply fold-matches regexp string '() cons flags))) | |
106 | ||
107 | If present, FLAGS is passed as the FLAGS argument to regexp-exec. | |
108 | ||
bc848f7f MD |
109 | ** Hooks |
110 | ||
111 | *** New function: hook? OBJ | |
112 | ||
113 | Return #t if OBJ is a hook, otherwise #f. | |
114 | ||
ece41168 MD |
115 | *** New function: make-hook-with-name NAME [ARITY] |
116 | ||
117 | Return a hook with name NAME and arity ARITY. The default value for | |
118 | ARITY is 0. The only effect of NAME is that it will appear when the | |
119 | hook object is printed to ease debugging. | |
120 | ||
bc848f7f MD |
121 | *** New function: hook-empty? HOOK |
122 | ||
123 | Return #t if HOOK doesn't contain any procedures, otherwise #f. | |
124 | ||
125 | *** New function: hook->list HOOK | |
126 | ||
127 | Return a list of the procedures that are called when run-hook is | |
128 | applied to HOOK. | |
129 | ||
b074884f JB |
130 | ** `map' signals an error if its argument lists are not all the same length. |
131 | ||
132 | This is the behavior required by R5RS, so this change is really a bug | |
133 | fix. But it seems to affect a lot of people's code, so we're | |
134 | mentioning it here anyway. | |
135 | ||
6822fe53 MD |
136 | ** Print-state handling has been made more transparent |
137 | ||
138 | Under certain circumstances, ports are represented as a port with an | |
139 | associated print state. Earlier, this pair was represented as a pair | |
140 | (see "Some magic has been added to the printer" below). It is now | |
141 | indistinguishable (almost; see `get-print-state') from a port on the | |
142 | user level. | |
143 | ||
144 | *** New function: port-with-print-state OUTPUT-PORT PRINT-STATE | |
145 | ||
146 | Return a new port with the associated print state PRINT-STATE. | |
147 | ||
148 | *** New function: get-print-state OUTPUT-PORT | |
149 | ||
150 | Return the print state associated with this port if it exists, | |
151 | otherwise return #f. | |
152 | ||
340a8770 | 153 | *** New function: directory-stream? OBJECT |
77242ff9 | 154 | |
340a8770 | 155 | Returns true iff OBJECT is a directory stream --- the sort of object |
77242ff9 GH |
156 | returned by `opendir'. |
157 | ||
0fdcbcaa MD |
158 | ** New function: using-readline? |
159 | ||
160 | Return #t if readline is in use in the current repl. | |
161 | ||
49199eaa MD |
162 | * Changes to the scm_ interface |
163 | ||
164 | ** The internal representation of subr's has changed | |
165 | ||
166 | Instead of giving a hint to the subr name, the CAR field of the subr | |
167 | now contains an index to a subr entry in scm_subr_table. | |
168 | ||
169 | *** New variable: scm_subr_table | |
170 | ||
171 | An array of subr entries. A subr entry contains the name, properties | |
172 | and documentation associated with the subr. The properties and | |
173 | documentation slots are not yet used. | |
174 | ||
175 | ** A new scheme for "forwarding" calls to a builtin to a generic function | |
176 | ||
177 | It is now possible to extend the functionality of some Guile | |
178 | primitives by letting them defer a call to a GOOPS generic function on | |
179 | argument mismatch. This functionality is enabled with the GOOPS | |
180 | primitive | |
181 | ||
182 | enable-primitive-generic! PRIMITIVE ... | |
183 | ||
184 | It is then possible to extend the primitive(s) by defining methods for | |
185 | them without loss of efficiency in normal evaluation. | |
186 | ||
187 | Example: | |
188 | ||
189 | (use-modules (oop goops)) | |
190 | (enable-primitive-generic! +) | |
191 | (define-method + ((x <string>) (y <string>)) | |
192 | (string-append x y)) | |
193 | ||
194 | + will still be as efficient as usual in numerical calculations, but | |
195 | can also be used for concatenating strings. | |
196 | ||
197 | Who will be the first one to extend Guile's numerical tower to | |
198 | rationals? :) | |
199 | ||
200 | *** New snarf macros for defining primitives: SCM_GPROC, SCM_GPROC1 | |
201 | ||
202 | New macro: SCM_GPROC (CNAME, SNAME, REQ, OPT, VAR, CFUNC, GENERIC) | |
203 | ||
204 | New macro: SCM_GPROC1 (CNAME, SNAME, TYPE, CFUNC, GENERIC) | |
205 | ||
d02cafe7 | 206 | These do the same job as SCM_PROC and SCM_PROC1, but they also define |
49199eaa MD |
207 | a variable GENERIC which can be used by the dispatch macros below. |
208 | ||
209 | [This is experimental code which may change soon.] | |
210 | ||
211 | *** New macros for forwarding control to a generic on arg type error | |
212 | ||
213 | New macro: SCM_WTA_DISPATCH_1 (GENERIC, ARG1, POS, SUBR) | |
214 | ||
215 | New macro: SCM_WTA_DISPATCH_2 (GENERIC, ARG1, ARG2, POS, SUBR) | |
216 | ||
217 | These correspond to the scm_wta function call, and have the same | |
218 | behaviour until the user has called the GOOPS primitive | |
219 | `enable-primitive-generic!'. After that, these macros will apply the | |
220 | generic function GENERIC to the argument(s) instead of calling | |
221 | scm_wta. | |
222 | ||
223 | [This is experimental code which may change soon.] | |
224 | ||
225 | *** New macros for argument testing with generic dispatch | |
226 | ||
227 | New macro: SCM_GASSERT1 (COND, GENERIC, ARG1, POS, SUBR) | |
228 | ||
229 | New macro: SCM_GASSERT2 (COND, GENERIC, ARG1, ARG2, POS, SUBR) | |
230 | ||
231 | These correspond to the SCM_ASSERT macro, but will defer control to | |
232 | GENERIC on error after `enable-primitive-generic!' has been called. | |
233 | ||
234 | [This is experimental code which may change soon.] | |
235 | ||
236 | ** New function: SCM scm_eval_body (SCM body, SCM env) | |
237 | ||
238 | Evaluates the body of a special form. | |
239 | ||
240 | ** The internal representation of struct's has changed | |
241 | ||
242 | Previously, four slots were allocated for the procedure(s) of entities | |
243 | and operators. The motivation for this representation had to do with | |
244 | the structure of the evaluator, the wish to support tail-recursive | |
245 | generic functions, and efficiency. Since the generic function | |
246 | dispatch mechanism has changed, there is no longer a need for such an | |
247 | expensive representation, and the representation has been simplified. | |
248 | ||
249 | This should not make any difference for most users. | |
250 | ||
251 | ** GOOPS support has been cleaned up. | |
252 | ||
253 | Some code has been moved from eval.c to objects.c and code in both of | |
254 | these compilation units has been cleaned up and better structured. | |
255 | ||
256 | *** New functions for applying generic functions | |
257 | ||
258 | New function: SCM scm_apply_generic (GENERIC, ARGS) | |
259 | New function: SCM scm_call_generic_0 (GENERIC) | |
260 | New function: SCM scm_call_generic_1 (GENERIC, ARG1) | |
261 | New function: SCM scm_call_generic_2 (GENERIC, ARG1, ARG2) | |
262 | New function: SCM scm_call_generic_3 (GENERIC, ARG1, ARG2, ARG3) | |
263 | ||
ece41168 MD |
264 | ** Deprecated function: scm_make_named_hook |
265 | ||
266 | It is now replaced by: | |
267 | ||
268 | ** New function: SCM scm_create_hook (const char *name, int arity) | |
269 | ||
270 | Creates a hook in the same way as make-hook above but also | |
271 | binds a variable named NAME to it. | |
272 | ||
273 | This is the typical way of creating a hook from C code. | |
274 | ||
275 | Currently, the variable is created in the "current" module. | |
276 | This might change when we get the new module system. | |
277 | ||
278 | [The behaviour is identical to scm_make_named_hook.] | |
279 | ||
280 | ||
43fa9a05 | 281 | \f |
f3227c7a JB |
282 | Changes since Guile 1.3: |
283 | ||
6ca345f3 JB |
284 | * Changes to mailing lists |
285 | ||
286 | ** Some of the Guile mailing lists have moved to sourceware.cygnus.com. | |
287 | ||
288 | See the README file to find current addresses for all the Guile | |
289 | mailing lists. | |
290 | ||
d77fb593 JB |
291 | * Changes to the distribution |
292 | ||
1d335863 JB |
293 | ** Readline support is no longer included with Guile by default. |
294 | ||
295 | Based on the different license terms of Guile and Readline, we | |
296 | concluded that Guile should not *by default* cause the linking of | |
297 | Readline into an application program. Readline support is now offered | |
298 | as a separate module, which is linked into an application only when | |
299 | you explicitly specify it. | |
300 | ||
301 | Although Guile is GNU software, its distribution terms add a special | |
302 | exception to the usual GNU General Public License (GPL). Guile's | |
303 | license includes a clause that allows you to link Guile with non-free | |
304 | programs. We add this exception so as not to put Guile at a | |
305 | disadvantage vis-a-vis other extensibility packages that support other | |
306 | languages. | |
307 | ||
308 | In contrast, the GNU Readline library is distributed under the GNU | |
309 | General Public License pure and simple. This means that you may not | |
310 | link Readline, even dynamically, into an application unless it is | |
311 | distributed under a free software license that is compatible the GPL. | |
312 | ||
313 | Because of this difference in distribution terms, an application that | |
314 | can use Guile may not be able to use Readline. Now users will be | |
315 | explicitly offered two independent decisions about the use of these | |
316 | two packages. | |
d77fb593 | 317 | |
0e8a8468 MV |
318 | You can activate the readline support by issuing |
319 | ||
320 | (use-modules (readline-activator)) | |
321 | (activate-readline) | |
322 | ||
323 | from your ".guile" file, for example. | |
324 | ||
e4eae9b1 MD |
325 | * Changes to the stand-alone interpreter |
326 | ||
67ad463a MD |
327 | ** All builtins now print as primitives. |
328 | Previously builtin procedures not belonging to the fundamental subr | |
329 | types printed as #<compiled closure #<primitive-procedure gsubr-apply>>. | |
330 | Now, they print as #<primitive-procedure NAME>. | |
331 | ||
332 | ** Backtraces slightly more intelligible. | |
333 | gsubr-apply and macro transformer application frames no longer appear | |
334 | in backtraces. | |
335 | ||
69c6acbb JB |
336 | * Changes to Scheme functions and syntax |
337 | ||
2a52b429 MD |
338 | ** Guile now correctly handles internal defines by rewriting them into |
339 | their equivalent letrec. Previously, internal defines would | |
340 | incrementally add to the innermost environment, without checking | |
341 | whether the restrictions specified in RnRS were met. This lead to the | |
342 | correct behaviour when these restriction actually were met, but didn't | |
343 | catch all illegal uses. Such an illegal use could lead to crashes of | |
344 | the Guile interpreter or or other unwanted results. An example of | |
345 | incorrect internal defines that made Guile behave erratically: | |
346 | ||
347 | (let () | |
348 | (define a 1) | |
349 | (define (b) a) | |
350 | (define c (1+ (b))) | |
351 | (define d 3) | |
352 | ||
353 | (b)) | |
354 | ||
355 | => 2 | |
356 | ||
357 | The problem with this example is that the definition of `c' uses the | |
358 | value of `b' directly. This confuses the meoization machine of Guile | |
359 | so that the second call of `b' (this time in a larger environment that | |
360 | also contains bindings for `c' and `d') refers to the binding of `c' | |
361 | instead of `a'. You could also make Guile crash with a variation on | |
362 | this theme: | |
363 | ||
364 | (define (foo flag) | |
365 | (define a 1) | |
366 | (define (b flag) (if flag a 1)) | |
367 | (define c (1+ (b flag))) | |
368 | (define d 3) | |
369 | ||
370 | (b #t)) | |
371 | ||
372 | (foo #f) | |
373 | (foo #t) | |
374 | ||
375 | From now on, Guile will issue an `Unbound variable: b' error message | |
376 | for both examples. | |
377 | ||
36d3d540 MD |
378 | ** Hooks |
379 | ||
380 | A hook contains a list of functions which should be called on | |
381 | particular occasions in an existing program. Hooks are used for | |
382 | customization. | |
383 | ||
384 | A window manager might have a hook before-window-map-hook. The window | |
385 | manager uses the function run-hooks to call all functions stored in | |
386 | before-window-map-hook each time a window is mapped. The user can | |
387 | store functions in the hook using add-hook!. | |
388 | ||
389 | In Guile, hooks are first class objects. | |
390 | ||
391 | *** New function: make-hook [N_ARGS] | |
392 | ||
393 | Return a hook for hook functions which can take N_ARGS arguments. | |
394 | The default value for N_ARGS is 0. | |
395 | ||
ad91d6c3 MD |
396 | (See also scm_make_named_hook below.) |
397 | ||
36d3d540 MD |
398 | *** New function: add-hook! HOOK PROC [APPEND_P] |
399 | ||
400 | Put PROC at the beginning of the list of functions stored in HOOK. | |
401 | If APPEND_P is supplied, and non-false, put PROC at the end instead. | |
402 | ||
403 | PROC must be able to take the number of arguments specified when the | |
404 | hook was created. | |
405 | ||
406 | If PROC already exists in HOOK, then remove it first. | |
407 | ||
408 | *** New function: remove-hook! HOOK PROC | |
409 | ||
410 | Remove PROC from the list of functions in HOOK. | |
411 | ||
412 | *** New function: reset-hook! HOOK | |
413 | ||
414 | Clear the list of hook functions stored in HOOK. | |
415 | ||
416 | *** New function: run-hook HOOK ARG1 ... | |
417 | ||
418 | Run all hook functions stored in HOOK with arguments ARG1 ... . | |
419 | The number of arguments supplied must correspond to the number given | |
420 | when the hook was created. | |
421 | ||
56a19408 MV |
422 | ** The function `dynamic-link' now takes optional keyword arguments. |
423 | The only keyword argument that is currently defined is `:global | |
424 | BOOL'. With it, you can control whether the shared library will be | |
425 | linked in global mode or not. In global mode, the symbols from the | |
426 | linked library can be used to resolve references from other | |
427 | dynamically linked libraries. In non-global mode, the linked | |
428 | library is essentially invisible and can only be accessed via | |
429 | `dynamic-func', etc. The default is now to link in global mode. | |
430 | Previously, the default has been non-global mode. | |
431 | ||
432 | The `#:global' keyword is only effective on platforms that support | |
433 | the dlopen family of functions. | |
434 | ||
ad226f25 | 435 | ** New function `provided?' |
b7e13f65 JB |
436 | |
437 | - Function: provided? FEATURE | |
438 | Return true iff FEATURE is supported by this installation of | |
439 | Guile. FEATURE must be a symbol naming a feature; the global | |
440 | variable `*features*' is a list of available features. | |
441 | ||
ad226f25 JB |
442 | ** Changes to the module (ice-9 expect): |
443 | ||
444 | *** The expect-strings macro now matches `$' in a regular expression | |
445 | only at a line-break or end-of-file by default. Previously it would | |
ab711359 JB |
446 | match the end of the string accumulated so far. The old behaviour |
447 | can be obtained by setting the variable `expect-strings-exec-flags' | |
448 | to 0. | |
ad226f25 JB |
449 | |
450 | *** The expect-strings macro now uses a variable `expect-strings-exec-flags' | |
451 | for the regexp-exec flags. If `regexp/noteol' is included, then `$' | |
452 | in a regular expression will still match before a line-break or | |
453 | end-of-file. The default is `regexp/noteol'. | |
454 | ||
455 | *** The expect-strings macro now uses a variable | |
456 | `expect-strings-compile-flags' for the flags to be supplied to | |
457 | `make-regexp'. The default is `regexp/newline', which was previously | |
458 | hard-coded. | |
459 | ||
460 | *** The expect macro now supplies two arguments to a match procedure: | |
ab711359 JB |
461 | the current accumulated string and a flag to indicate whether |
462 | end-of-file has been reached. Previously only the string was supplied. | |
463 | If end-of-file is reached, the match procedure will be called an | |
464 | additional time with the same accumulated string as the previous call | |
465 | but with the flag set. | |
ad226f25 | 466 | |
b7e13f65 JB |
467 | ** New module (ice-9 format), implementing the Common Lisp `format' function. |
468 | ||
469 | This code, and the documentation for it that appears here, was | |
470 | borrowed from SLIB, with minor adaptations for Guile. | |
471 | ||
472 | - Function: format DESTINATION FORMAT-STRING . ARGUMENTS | |
473 | An almost complete implementation of Common LISP format description | |
474 | according to the CL reference book `Common LISP' from Guy L. | |
475 | Steele, Digital Press. Backward compatible to most of the | |
476 | available Scheme format implementations. | |
477 | ||
478 | Returns `#t', `#f' or a string; has side effect of printing | |
479 | according to FORMAT-STRING. If DESTINATION is `#t', the output is | |
480 | to the current output port and `#t' is returned. If DESTINATION | |
481 | is `#f', a formatted string is returned as the result of the call. | |
482 | NEW: If DESTINATION is a string, DESTINATION is regarded as the | |
483 | format string; FORMAT-STRING is then the first argument and the | |
484 | output is returned as a string. If DESTINATION is a number, the | |
485 | output is to the current error port if available by the | |
486 | implementation. Otherwise DESTINATION must be an output port and | |
487 | `#t' is returned. | |
488 | ||
489 | FORMAT-STRING must be a string. In case of a formatting error | |
490 | format returns `#f' and prints a message on the current output or | |
491 | error port. Characters are output as if the string were output by | |
492 | the `display' function with the exception of those prefixed by a | |
493 | tilde (~). For a detailed description of the FORMAT-STRING syntax | |
494 | please consult a Common LISP format reference manual. For a test | |
495 | suite to verify this format implementation load `formatst.scm'. | |
496 | Please send bug reports to `lutzeb@cs.tu-berlin.de'. | |
497 | ||
498 | Note: `format' is not reentrant, i.e. only one `format'-call may | |
499 | be executed at a time. | |
500 | ||
501 | ||
502 | *** Format Specification (Format version 3.0) | |
503 | ||
504 | Please consult a Common LISP format reference manual for a detailed | |
505 | description of the format string syntax. For a demonstration of the | |
506 | implemented directives see `formatst.scm'. | |
507 | ||
508 | This implementation supports directive parameters and modifiers (`:' | |
509 | and `@' characters). Multiple parameters must be separated by a comma | |
510 | (`,'). Parameters can be numerical parameters (positive or negative), | |
511 | character parameters (prefixed by a quote character (`''), variable | |
512 | parameters (`v'), number of rest arguments parameter (`#'), empty and | |
513 | default parameters. Directive characters are case independent. The | |
514 | general form of a directive is: | |
515 | ||
516 | DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER | |
517 | ||
518 | DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ] | |
519 | ||
520 | *** Implemented CL Format Control Directives | |
521 | ||
522 | Documentation syntax: Uppercase characters represent the | |
523 | corresponding control directive characters. Lowercase characters | |
524 | represent control directive parameter descriptions. | |
525 | ||
526 | `~A' | |
527 | Any (print as `display' does). | |
528 | `~@A' | |
529 | left pad. | |
530 | ||
531 | `~MINCOL,COLINC,MINPAD,PADCHARA' | |
532 | full padding. | |
533 | ||
534 | `~S' | |
535 | S-expression (print as `write' does). | |
536 | `~@S' | |
537 | left pad. | |
538 | ||
539 | `~MINCOL,COLINC,MINPAD,PADCHARS' | |
540 | full padding. | |
541 | ||
542 | `~D' | |
543 | Decimal. | |
544 | `~@D' | |
545 | print number sign always. | |
546 | ||
547 | `~:D' | |
548 | print comma separated. | |
549 | ||
550 | `~MINCOL,PADCHAR,COMMACHARD' | |
551 | padding. | |
552 | ||
553 | `~X' | |
554 | Hexadecimal. | |
555 | `~@X' | |
556 | print number sign always. | |
557 | ||
558 | `~:X' | |
559 | print comma separated. | |
560 | ||
561 | `~MINCOL,PADCHAR,COMMACHARX' | |
562 | padding. | |
563 | ||
564 | `~O' | |
565 | Octal. | |
566 | `~@O' | |
567 | print number sign always. | |
568 | ||
569 | `~:O' | |
570 | print comma separated. | |
571 | ||
572 | `~MINCOL,PADCHAR,COMMACHARO' | |
573 | padding. | |
574 | ||
575 | `~B' | |
576 | Binary. | |
577 | `~@B' | |
578 | print number sign always. | |
579 | ||
580 | `~:B' | |
581 | print comma separated. | |
582 | ||
583 | `~MINCOL,PADCHAR,COMMACHARB' | |
584 | padding. | |
585 | ||
586 | `~NR' | |
587 | Radix N. | |
588 | `~N,MINCOL,PADCHAR,COMMACHARR' | |
589 | padding. | |
590 | ||
591 | `~@R' | |
592 | print a number as a Roman numeral. | |
593 | ||
594 | `~:@R' | |
595 | print a number as an "old fashioned" Roman numeral. | |
596 | ||
597 | `~:R' | |
598 | print a number as an ordinal English number. | |
599 | ||
600 | `~:@R' | |
601 | print a number as a cardinal English number. | |
602 | ||
603 | `~P' | |
604 | Plural. | |
605 | `~@P' | |
606 | prints `y' and `ies'. | |
607 | ||
608 | `~:P' | |
609 | as `~P but jumps 1 argument backward.' | |
610 | ||
611 | `~:@P' | |
612 | as `~@P but jumps 1 argument backward.' | |
613 | ||
614 | `~C' | |
615 | Character. | |
616 | `~@C' | |
617 | prints a character as the reader can understand it (i.e. `#\' | |
618 | prefixing). | |
619 | ||
620 | `~:C' | |
621 | prints a character as emacs does (eg. `^C' for ASCII 03). | |
622 | ||
623 | `~F' | |
624 | Fixed-format floating-point (prints a flonum like MMM.NNN). | |
625 | `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF' | |
626 | `~@F' | |
627 | If the number is positive a plus sign is printed. | |
628 | ||
629 | `~E' | |
630 | Exponential floating-point (prints a flonum like MMM.NNN`E'EE). | |
631 | `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE' | |
632 | `~@E' | |
633 | If the number is positive a plus sign is printed. | |
634 | ||
635 | `~G' | |
636 | General floating-point (prints a flonum either fixed or | |
637 | exponential). | |
638 | `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG' | |
639 | `~@G' | |
640 | If the number is positive a plus sign is printed. | |
641 | ||
642 | `~$' | |
643 | Dollars floating-point (prints a flonum in fixed with signs | |
644 | separated). | |
645 | `~DIGITS,SCALE,WIDTH,PADCHAR$' | |
646 | `~@$' | |
647 | If the number is positive a plus sign is printed. | |
648 | ||
649 | `~:@$' | |
650 | A sign is always printed and appears before the padding. | |
651 | ||
652 | `~:$' | |
653 | The sign appears before the padding. | |
654 | ||
655 | `~%' | |
656 | Newline. | |
657 | `~N%' | |
658 | print N newlines. | |
659 | ||
660 | `~&' | |
661 | print newline if not at the beginning of the output line. | |
662 | `~N&' | |
663 | prints `~&' and then N-1 newlines. | |
664 | ||
665 | `~|' | |
666 | Page Separator. | |
667 | `~N|' | |
668 | print N page separators. | |
669 | ||
670 | `~~' | |
671 | Tilde. | |
672 | `~N~' | |
673 | print N tildes. | |
674 | ||
675 | `~'<newline> | |
676 | Continuation Line. | |
677 | `~:'<newline> | |
678 | newline is ignored, white space left. | |
679 | ||
680 | `~@'<newline> | |
681 | newline is left, white space ignored. | |
682 | ||
683 | `~T' | |
684 | Tabulation. | |
685 | `~@T' | |
686 | relative tabulation. | |
687 | ||
688 | `~COLNUM,COLINCT' | |
689 | full tabulation. | |
690 | ||
691 | `~?' | |
692 | Indirection (expects indirect arguments as a list). | |
693 | `~@?' | |
694 | extracts indirect arguments from format arguments. | |
695 | ||
696 | `~(STR~)' | |
697 | Case conversion (converts by `string-downcase'). | |
698 | `~:(STR~)' | |
699 | converts by `string-capitalize'. | |
700 | ||
701 | `~@(STR~)' | |
702 | converts by `string-capitalize-first'. | |
703 | ||
704 | `~:@(STR~)' | |
705 | converts by `string-upcase'. | |
706 | ||
707 | `~*' | |
708 | Argument Jumping (jumps 1 argument forward). | |
709 | `~N*' | |
710 | jumps N arguments forward. | |
711 | ||
712 | `~:*' | |
713 | jumps 1 argument backward. | |
714 | ||
715 | `~N:*' | |
716 | jumps N arguments backward. | |
717 | ||
718 | `~@*' | |
719 | jumps to the 0th argument. | |
720 | ||
721 | `~N@*' | |
722 | jumps to the Nth argument (beginning from 0) | |
723 | ||
724 | `~[STR0~;STR1~;...~;STRN~]' | |
725 | Conditional Expression (numerical clause conditional). | |
726 | `~N[' | |
727 | take argument from N. | |
728 | ||
729 | `~@[' | |
730 | true test conditional. | |
731 | ||
732 | `~:[' | |
733 | if-else-then conditional. | |
734 | ||
735 | `~;' | |
736 | clause separator. | |
737 | ||
738 | `~:;' | |
739 | default clause follows. | |
740 | ||
741 | `~{STR~}' | |
742 | Iteration (args come from the next argument (a list)). | |
743 | `~N{' | |
744 | at most N iterations. | |
745 | ||
746 | `~:{' | |
747 | args from next arg (a list of lists). | |
748 | ||
749 | `~@{' | |
750 | args from the rest of arguments. | |
751 | ||
752 | `~:@{' | |
753 | args from the rest args (lists). | |
754 | ||
755 | `~^' | |
756 | Up and out. | |
757 | `~N^' | |
758 | aborts if N = 0 | |
759 | ||
760 | `~N,M^' | |
761 | aborts if N = M | |
762 | ||
763 | `~N,M,K^' | |
764 | aborts if N <= M <= K | |
765 | ||
766 | *** Not Implemented CL Format Control Directives | |
767 | ||
768 | `~:A' | |
769 | print `#f' as an empty list (see below). | |
770 | ||
771 | `~:S' | |
772 | print `#f' as an empty list (see below). | |
773 | ||
774 | `~<~>' | |
775 | Justification. | |
776 | ||
777 | `~:^' | |
778 | (sorry I don't understand its semantics completely) | |
779 | ||
780 | *** Extended, Replaced and Additional Control Directives | |
781 | ||
782 | `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD' | |
783 | `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX' | |
784 | `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO' | |
785 | `~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB' | |
786 | `~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR' | |
787 | COMMAWIDTH is the number of characters between two comma | |
788 | characters. | |
789 | ||
790 | `~I' | |
791 | print a R4RS complex number as `~F~@Fi' with passed parameters for | |
792 | `~F'. | |
793 | ||
794 | `~Y' | |
795 | Pretty print formatting of an argument for scheme code lists. | |
796 | ||
797 | `~K' | |
798 | Same as `~?.' | |
799 | ||
800 | `~!' | |
801 | Flushes the output if format DESTINATION is a port. | |
802 | ||
803 | `~_' | |
804 | Print a `#\space' character | |
805 | `~N_' | |
806 | print N `#\space' characters. | |
807 | ||
808 | `~/' | |
809 | Print a `#\tab' character | |
810 | `~N/' | |
811 | print N `#\tab' characters. | |
812 | ||
813 | `~NC' | |
814 | Takes N as an integer representation for a character. No arguments | |
815 | are consumed. N is converted to a character by `integer->char'. N | |
816 | must be a positive decimal number. | |
817 | ||
818 | `~:S' | |
819 | Print out readproof. Prints out internal objects represented as | |
820 | `#<...>' as strings `"#<...>"' so that the format output can always | |
821 | be processed by `read'. | |
822 | ||
823 | `~:A' | |
824 | Print out readproof. Prints out internal objects represented as | |
825 | `#<...>' as strings `"#<...>"' so that the format output can always | |
826 | be processed by `read'. | |
827 | ||
828 | `~Q' | |
829 | Prints information and a copyright notice on the format | |
830 | implementation. | |
831 | `~:Q' | |
832 | prints format version. | |
833 | ||
834 | `~F, ~E, ~G, ~$' | |
835 | may also print number strings, i.e. passing a number as a string | |
836 | and format it accordingly. | |
837 | ||
838 | *** Configuration Variables | |
839 | ||
840 | The format module exports some configuration variables to suit the | |
841 | systems and users needs. There should be no modification necessary for | |
842 | the configuration that comes with Guile. Format detects automatically | |
843 | if the running scheme system implements floating point numbers and | |
844 | complex numbers. | |
845 | ||
846 | format:symbol-case-conv | |
847 | Symbols are converted by `symbol->string' so the case type of the | |
848 | printed symbols is implementation dependent. | |
849 | `format:symbol-case-conv' is a one arg closure which is either | |
850 | `#f' (no conversion), `string-upcase', `string-downcase' or | |
851 | `string-capitalize'. (default `#f') | |
852 | ||
853 | format:iobj-case-conv | |
854 | As FORMAT:SYMBOL-CASE-CONV but applies for the representation of | |
855 | implementation internal objects. (default `#f') | |
856 | ||
857 | format:expch | |
858 | The character prefixing the exponent value in `~E' printing. | |
859 | (default `#\E') | |
860 | ||
861 | *** Compatibility With Other Format Implementations | |
862 | ||
863 | SLIB format 2.x: | |
864 | See `format.doc'. | |
865 | ||
866 | SLIB format 1.4: | |
867 | Downward compatible except for padding support and `~A', `~S', | |
868 | `~P', `~X' uppercase printing. SLIB format 1.4 uses C-style | |
869 | `printf' padding support which is completely replaced by the CL | |
870 | `format' padding style. | |
871 | ||
872 | MIT C-Scheme 7.1: | |
873 | Downward compatible except for `~', which is not documented | |
874 | (ignores all characters inside the format string up to a newline | |
875 | character). (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%', | |
876 | numerical and variable parameters and `:/@' modifiers in the CL | |
877 | sense). | |
878 | ||
879 | Elk 1.5/2.0: | |
880 | Downward compatible except for `~A' and `~S' which print in | |
881 | uppercase. (Elk implements `~a', `~s', `~~', and `~%' (no | |
882 | directive parameters or modifiers)). | |
883 | ||
884 | Scheme->C 01nov91: | |
885 | Downward compatible except for an optional destination parameter: | |
886 | S2C accepts a format call without a destination which returns a | |
887 | formatted string. This is equivalent to a #f destination in S2C. | |
888 | (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive | |
889 | parameters or modifiers)). | |
890 | ||
891 | ||
e7d37b0a | 892 | ** Changes to string-handling functions. |
b7e13f65 | 893 | |
e7d37b0a | 894 | These functions were added to support the (ice-9 format) module, above. |
b7e13f65 | 895 | |
e7d37b0a JB |
896 | *** New function: string-upcase STRING |
897 | *** New function: string-downcase STRING | |
b7e13f65 | 898 | |
e7d37b0a JB |
899 | These are non-destructive versions of the existing string-upcase! and |
900 | string-downcase! functions. | |
b7e13f65 | 901 | |
e7d37b0a JB |
902 | *** New function: string-capitalize! STRING |
903 | *** New function: string-capitalize STRING | |
904 | ||
905 | These functions convert the first letter of each word in the string to | |
906 | upper case. Thus: | |
907 | ||
908 | (string-capitalize "howdy there") | |
909 | => "Howdy There" | |
910 | ||
911 | As with the other functions, string-capitalize! modifies the string in | |
912 | place, while string-capitalize returns a modified copy of its argument. | |
913 | ||
914 | *** New function: string-ci->symbol STRING | |
915 | ||
916 | Return a symbol whose name is STRING, but having the same case as if | |
917 | the symbol had be read by `read'. | |
918 | ||
919 | Guile can be configured to be sensitive or insensitive to case | |
920 | differences in Scheme identifiers. If Guile is case-insensitive, all | |
921 | symbols are converted to lower case on input. The `string-ci->symbol' | |
922 | function returns a symbol whose name in STRING, transformed as Guile | |
923 | would if STRING were input. | |
924 | ||
925 | *** New function: substring-move! STRING1 START END STRING2 START | |
926 | ||
927 | Copy the substring of STRING1 from START (inclusive) to END | |
928 | (exclusive) to STRING2 at START. STRING1 and STRING2 may be the same | |
929 | string, and the source and destination areas may overlap; in all | |
930 | cases, the function behaves as if all the characters were copied | |
931 | simultanously. | |
932 | ||
933 | *** Extended functions: substring-move-left! substring-move-right! | |
934 | ||
935 | These functions now correctly copy arbitrarily overlapping substrings; | |
936 | they are both synonyms for substring-move!. | |
b7e13f65 | 937 | |
b7e13f65 | 938 | |
deaceb4e JB |
939 | ** New module (ice-9 getopt-long), with the function `getopt-long'. |
940 | ||
941 | getopt-long is a function for parsing command-line arguments in a | |
942 | manner consistent with other GNU programs. | |
943 | ||
944 | (getopt-long ARGS GRAMMAR) | |
945 | Parse the arguments ARGS according to the argument list grammar GRAMMAR. | |
946 | ||
947 | ARGS should be a list of strings. Its first element should be the | |
948 | name of the program; subsequent elements should be the arguments | |
949 | that were passed to the program on the command line. The | |
950 | `program-arguments' procedure returns a list of this form. | |
951 | ||
952 | GRAMMAR is a list of the form: | |
953 | ((OPTION (PROPERTY VALUE) ...) ...) | |
954 | ||
955 | Each OPTION should be a symbol. `getopt-long' will accept a | |
956 | command-line option named `--OPTION'. | |
957 | Each option can have the following (PROPERTY VALUE) pairs: | |
958 | ||
959 | (single-char CHAR) --- Accept `-CHAR' as a single-character | |
960 | equivalent to `--OPTION'. This is how to specify traditional | |
961 | Unix-style flags. | |
962 | (required? BOOL) --- If BOOL is true, the option is required. | |
963 | getopt-long will raise an error if it is not found in ARGS. | |
964 | (value BOOL) --- If BOOL is #t, the option accepts a value; if | |
965 | it is #f, it does not; and if it is the symbol | |
966 | `optional', the option may appear in ARGS with or | |
967 | without a value. | |
968 | (predicate FUNC) --- If the option accepts a value (i.e. you | |
969 | specified `(value #t)' for this option), then getopt | |
970 | will apply FUNC to the value, and throw an exception | |
971 | if it returns #f. FUNC should be a procedure which | |
972 | accepts a string and returns a boolean value; you may | |
973 | need to use quasiquotes to get it into GRAMMAR. | |
974 | ||
975 | The (PROPERTY VALUE) pairs may occur in any order, but each | |
976 | property may occur only once. By default, options do not have | |
977 | single-character equivalents, are not required, and do not take | |
978 | values. | |
979 | ||
980 | In ARGS, single-character options may be combined, in the usual | |
981 | Unix fashion: ("-x" "-y") is equivalent to ("-xy"). If an option | |
982 | accepts values, then it must be the last option in the | |
983 | combination; the value is the next argument. So, for example, using | |
984 | the following grammar: | |
985 | ((apples (single-char #\a)) | |
986 | (blimps (single-char #\b) (value #t)) | |
987 | (catalexis (single-char #\c) (value #t))) | |
988 | the following argument lists would be acceptable: | |
989 | ("-a" "-b" "bang" "-c" "couth") ("bang" and "couth" are the values | |
990 | for "blimps" and "catalexis") | |
991 | ("-ab" "bang" "-c" "couth") (same) | |
992 | ("-ac" "couth" "-b" "bang") (same) | |
993 | ("-abc" "couth" "bang") (an error, since `-b' is not the | |
994 | last option in its combination) | |
995 | ||
996 | If an option's value is optional, then `getopt-long' decides | |
997 | whether it has a value by looking at what follows it in ARGS. If | |
998 | the next element is a string, and it does not appear to be an | |
999 | option itself, then that string is the option's value. | |
1000 | ||
1001 | The value of a long option can appear as the next element in ARGS, | |
1002 | or it can follow the option name, separated by an `=' character. | |
1003 | Thus, using the same grammar as above, the following argument lists | |
1004 | are equivalent: | |
1005 | ("--apples" "Braeburn" "--blimps" "Goodyear") | |
1006 | ("--apples=Braeburn" "--blimps" "Goodyear") | |
1007 | ("--blimps" "Goodyear" "--apples=Braeburn") | |
1008 | ||
1009 | If the option "--" appears in ARGS, argument parsing stops there; | |
1010 | subsequent arguments are returned as ordinary arguments, even if | |
1011 | they resemble options. So, in the argument list: | |
1012 | ("--apples" "Granny Smith" "--" "--blimp" "Goodyear") | |
1013 | `getopt-long' will recognize the `apples' option as having the | |
1014 | value "Granny Smith", but it will not recognize the `blimp' | |
1015 | option; it will return the strings "--blimp" and "Goodyear" as | |
1016 | ordinary argument strings. | |
1017 | ||
1018 | The `getopt-long' function returns the parsed argument list as an | |
1019 | assocation list, mapping option names --- the symbols from GRAMMAR | |
1020 | --- onto their values, or #t if the option does not accept a value. | |
1021 | Unused options do not appear in the alist. | |
1022 | ||
1023 | All arguments that are not the value of any option are returned | |
1024 | as a list, associated with the empty list. | |
1025 | ||
1026 | `getopt-long' throws an exception if: | |
1027 | - it finds an unrecognized option in ARGS | |
1028 | - a required option is omitted | |
1029 | - an option that requires an argument doesn't get one | |
1030 | - an option that doesn't accept an argument does get one (this can | |
1031 | only happen using the long option `--opt=value' syntax) | |
1032 | - an option predicate fails | |
1033 | ||
1034 | So, for example: | |
1035 | ||
1036 | (define grammar | |
1037 | `((lockfile-dir (required? #t) | |
1038 | (value #t) | |
1039 | (single-char #\k) | |
1040 | (predicate ,file-is-directory?)) | |
1041 | (verbose (required? #f) | |
1042 | (single-char #\v) | |
1043 | (value #f)) | |
1044 | (x-includes (single-char #\x)) | |
1045 | (rnet-server (single-char #\y) | |
1046 | (predicate ,string?)))) | |
1047 | ||
1048 | (getopt-long '("my-prog" "-vk" "/tmp" "foo1" "--x-includes=/usr/include" | |
1049 | "--rnet-server=lamprod" "--" "-fred" "foo2" "foo3") | |
1050 | grammar) | |
1051 | => ((() "foo1" "-fred" "foo2" "foo3") | |
1052 | (rnet-server . "lamprod") | |
1053 | (x-includes . "/usr/include") | |
1054 | (lockfile-dir . "/tmp") | |
1055 | (verbose . #t)) | |
1056 | ||
1057 | ** The (ice-9 getopt-gnu-style) module is obsolete; use (ice-9 getopt-long). | |
1058 | ||
1059 | It will be removed in a few releases. | |
1060 | ||
08394899 MS |
1061 | ** New syntax: lambda* |
1062 | ** New syntax: define* | |
1063 | ** New syntax: define*-public | |
1064 | ** New syntax: defmacro* | |
1065 | ** New syntax: defmacro*-public | |
1066 | Guile now supports optional arguments. | |
1067 | ||
1068 | `lambda*', `define*', `define*-public', `defmacro*' and | |
1069 | `defmacro*-public' are identical to the non-* versions except that | |
1070 | they use an extended type of parameter list that has the following BNF | |
1071 | syntax (parentheses are literal, square brackets indicate grouping, | |
1072 | and `*', `+' and `?' have the usual meaning): | |
1073 | ||
1074 | ext-param-list ::= ( [identifier]* [#&optional [ext-var-decl]+]? | |
1075 | [#&key [ext-var-decl]+ [#&allow-other-keys]?]? | |
1076 | [[#&rest identifier]|[. identifier]]? ) | [identifier] | |
1077 | ||
1078 | ext-var-decl ::= identifier | ( identifier expression ) | |
1079 | ||
1080 | The semantics are best illustrated with the following documentation | |
1081 | and examples for `lambda*': | |
1082 | ||
1083 | lambda* args . body | |
1084 | lambda extended for optional and keyword arguments | |
1085 | ||
1086 | lambda* creates a procedure that takes optional arguments. These | |
1087 | are specified by putting them inside brackets at the end of the | |
1088 | paramater list, but before any dotted rest argument. For example, | |
1089 | (lambda* (a b #&optional c d . e) '()) | |
1090 | creates a procedure with fixed arguments a and b, optional arguments c | |
1091 | and d, and rest argument e. If the optional arguments are omitted | |
1092 | in a call, the variables for them are unbound in the procedure. This | |
1093 | can be checked with the bound? macro. | |
1094 | ||
1095 | lambda* can also take keyword arguments. For example, a procedure | |
1096 | defined like this: | |
1097 | (lambda* (#&key xyzzy larch) '()) | |
1098 | can be called with any of the argument lists (#:xyzzy 11) | |
1099 | (#:larch 13) (#:larch 42 #:xyzzy 19) (). Whichever arguments | |
1100 | are given as keywords are bound to values. | |
1101 | ||
1102 | Optional and keyword arguments can also be given default values | |
1103 | which they take on when they are not present in a call, by giving a | |
1104 | two-item list in place of an optional argument, for example in: | |
1105 | (lambda* (foo #&optional (bar 42) #&key (baz 73)) (list foo bar baz)) | |
1106 | foo is a fixed argument, bar is an optional argument with default | |
1107 | value 42, and baz is a keyword argument with default value 73. | |
1108 | Default value expressions are not evaluated unless they are needed | |
1109 | and until the procedure is called. | |
1110 | ||
1111 | lambda* now supports two more special parameter list keywords. | |
1112 | ||
1113 | lambda*-defined procedures now throw an error by default if a | |
1114 | keyword other than one of those specified is found in the actual | |
1115 | passed arguments. However, specifying #&allow-other-keys | |
1116 | immediately after the kyword argument declarations restores the | |
1117 | previous behavior of ignoring unknown keywords. lambda* also now | |
1118 | guarantees that if the same keyword is passed more than once, the | |
1119 | last one passed is the one that takes effect. For example, | |
1120 | ((lambda* (#&key (heads 0) (tails 0)) (display (list heads tails))) | |
1121 | #:heads 37 #:tails 42 #:heads 99) | |
1122 | would result in (99 47) being displayed. | |
1123 | ||
1124 | #&rest is also now provided as a synonym for the dotted syntax rest | |
1125 | argument. The argument lists (a . b) and (a #&rest b) are equivalent in | |
1126 | all respects to lambda*. This is provided for more similarity to DSSSL, | |
1127 | MIT-Scheme and Kawa among others, as well as for refugees from other | |
1128 | Lisp dialects. | |
1129 | ||
1130 | Further documentation may be found in the optargs.scm file itself. | |
1131 | ||
1132 | The optional argument module also exports the macros `let-optional', | |
1133 | `let-optional*', `let-keywords', `let-keywords*' and `bound?'. These | |
1134 | are not documented here because they may be removed in the future, but | |
1135 | full documentation is still available in optargs.scm. | |
1136 | ||
2e132553 JB |
1137 | ** New syntax: and-let* |
1138 | Guile now supports the `and-let*' form, described in the draft SRFI-2. | |
1139 | ||
1140 | Syntax: (land* (<clause> ...) <body> ...) | |
1141 | Each <clause> should have one of the following forms: | |
1142 | (<variable> <expression>) | |
1143 | (<expression>) | |
1144 | <bound-variable> | |
1145 | Each <variable> or <bound-variable> should be an identifier. Each | |
1146 | <expression> should be a valid expression. The <body> should be a | |
1147 | possibly empty sequence of expressions, like the <body> of a | |
1148 | lambda form. | |
1149 | ||
1150 | Semantics: A LAND* expression is evaluated by evaluating the | |
1151 | <expression> or <bound-variable> of each of the <clause>s from | |
1152 | left to right. The value of the first <expression> or | |
1153 | <bound-variable> that evaluates to a false value is returned; the | |
1154 | remaining <expression>s and <bound-variable>s are not evaluated. | |
1155 | The <body> forms are evaluated iff all the <expression>s and | |
1156 | <bound-variable>s evaluate to true values. | |
1157 | ||
1158 | The <expression>s and the <body> are evaluated in an environment | |
1159 | binding each <variable> of the preceding (<variable> <expression>) | |
1160 | clauses to the value of the <expression>. Later bindings | |
1161 | shadow earlier bindings. | |
1162 | ||
1163 | Guile's and-let* macro was contributed by Michael Livshin. | |
1164 | ||
36d3d540 MD |
1165 | ** New sorting functions |
1166 | ||
1167 | *** New function: sorted? SEQUENCE LESS? | |
ed8c8636 MD |
1168 | Returns `#t' when the sequence argument is in non-decreasing order |
1169 | according to LESS? (that is, there is no adjacent pair `... x y | |
1170 | ...' for which `(less? y x)'). | |
1171 | ||
1172 | Returns `#f' when the sequence contains at least one out-of-order | |
1173 | pair. It is an error if the sequence is neither a list nor a | |
1174 | vector. | |
1175 | ||
36d3d540 | 1176 | *** New function: merge LIST1 LIST2 LESS? |
ed8c8636 MD |
1177 | LIST1 and LIST2 are sorted lists. |
1178 | Returns the sorted list of all elements in LIST1 and LIST2. | |
1179 | ||
1180 | Assume that the elements a and b1 in LIST1 and b2 in LIST2 are "equal" | |
1181 | in the sense that (LESS? x y) --> #f for x, y in {a, b1, b2}, | |
1182 | and that a < b1 in LIST1. Then a < b1 < b2 in the result. | |
1183 | (Here "<" should read "comes before".) | |
1184 | ||
36d3d540 | 1185 | *** New procedure: merge! LIST1 LIST2 LESS? |
ed8c8636 MD |
1186 | Merges two lists, re-using the pairs of LIST1 and LIST2 to build |
1187 | the result. If the code is compiled, and LESS? constructs no new | |
1188 | pairs, no pairs at all will be allocated. The first pair of the | |
1189 | result will be either the first pair of LIST1 or the first pair of | |
1190 | LIST2. | |
1191 | ||
36d3d540 | 1192 | *** New function: sort SEQUENCE LESS? |
ed8c8636 MD |
1193 | Accepts either a list or a vector, and returns a new sequence |
1194 | which is sorted. The new sequence is the same type as the input. | |
1195 | Always `(sorted? (sort sequence less?) less?)'. The original | |
1196 | sequence is not altered in any way. The new sequence shares its | |
1197 | elements with the old one; no elements are copied. | |
1198 | ||
36d3d540 | 1199 | *** New procedure: sort! SEQUENCE LESS |
ed8c8636 MD |
1200 | Returns its sorted result in the original boxes. No new storage is |
1201 | allocated at all. Proper usage: (set! slist (sort! slist <)) | |
1202 | ||
36d3d540 | 1203 | *** New function: stable-sort SEQUENCE LESS? |
ed8c8636 MD |
1204 | Similar to `sort' but stable. That is, if "equal" elements are |
1205 | ordered a < b in the original sequence, they will have the same order | |
1206 | in the result. | |
1207 | ||
36d3d540 | 1208 | *** New function: stable-sort! SEQUENCE LESS? |
ed8c8636 MD |
1209 | Similar to `sort!' but stable. |
1210 | Uses temporary storage when sorting vectors. | |
1211 | ||
36d3d540 | 1212 | *** New functions: sort-list, sort-list! |
ed8c8636 MD |
1213 | Added for compatibility with scsh. |
1214 | ||
36d3d540 MD |
1215 | ** New built-in random number support |
1216 | ||
1217 | *** New function: random N [STATE] | |
3e8370c3 MD |
1218 | Accepts a positive integer or real N and returns a number of the |
1219 | same type between zero (inclusive) and N (exclusive). The values | |
1220 | returned have a uniform distribution. | |
1221 | ||
1222 | The optional argument STATE must be of the type produced by | |
416075f1 MD |
1223 | `copy-random-state' or `seed->random-state'. It defaults to the value |
1224 | of the variable `*random-state*'. This object is used to maintain the | |
1225 | state of the pseudo-random-number generator and is altered as a side | |
1226 | effect of the `random' operation. | |
3e8370c3 | 1227 | |
36d3d540 | 1228 | *** New variable: *random-state* |
3e8370c3 MD |
1229 | Holds a data structure that encodes the internal state of the |
1230 | random-number generator that `random' uses by default. The nature | |
1231 | of this data structure is implementation-dependent. It may be | |
1232 | printed out and successfully read back in, but may or may not | |
1233 | function correctly as a random-number state object in another | |
1234 | implementation. | |
1235 | ||
36d3d540 | 1236 | *** New function: copy-random-state [STATE] |
3e8370c3 MD |
1237 | Returns a new object of type suitable for use as the value of the |
1238 | variable `*random-state*' and as a second argument to `random'. | |
1239 | If argument STATE is given, a copy of it is returned. Otherwise a | |
1240 | copy of `*random-state*' is returned. | |
416075f1 | 1241 | |
36d3d540 | 1242 | *** New function: seed->random-state SEED |
416075f1 MD |
1243 | Returns a new object of type suitable for use as the value of the |
1244 | variable `*random-state*' and as a second argument to `random'. | |
1245 | SEED is a string or a number. A new state is generated and | |
1246 | initialized using SEED. | |
3e8370c3 | 1247 | |
36d3d540 | 1248 | *** New function: random:uniform [STATE] |
3e8370c3 MD |
1249 | Returns an uniformly distributed inexact real random number in the |
1250 | range between 0 and 1. | |
1251 | ||
36d3d540 | 1252 | *** New procedure: random:solid-sphere! VECT [STATE] |
3e8370c3 MD |
1253 | Fills VECT with inexact real random numbers the sum of whose |
1254 | squares is less than 1.0. Thinking of VECT as coordinates in | |
1255 | space of dimension N = `(vector-length VECT)', the coordinates are | |
1256 | uniformly distributed within the unit N-shere. The sum of the | |
1257 | squares of the numbers is returned. VECT can be either a vector | |
1258 | or a uniform vector of doubles. | |
1259 | ||
36d3d540 | 1260 | *** New procedure: random:hollow-sphere! VECT [STATE] |
3e8370c3 MD |
1261 | Fills VECT with inexact real random numbers the sum of whose squares |
1262 | is equal to 1.0. Thinking of VECT as coordinates in space of | |
1263 | dimension n = `(vector-length VECT)', the coordinates are uniformly | |
1264 | distributed over the surface of the unit n-shere. VECT can be either | |
1265 | a vector or a uniform vector of doubles. | |
1266 | ||
36d3d540 | 1267 | *** New function: random:normal [STATE] |
3e8370c3 MD |
1268 | Returns an inexact real in a normal distribution with mean 0 and |
1269 | standard deviation 1. For a normal distribution with mean M and | |
1270 | standard deviation D use `(+ M (* D (random:normal)))'. | |
1271 | ||
36d3d540 | 1272 | *** New procedure: random:normal-vector! VECT [STATE] |
3e8370c3 MD |
1273 | Fills VECT with inexact real random numbers which are independent and |
1274 | standard normally distributed (i.e., with mean 0 and variance 1). | |
1275 | VECT can be either a vector or a uniform vector of doubles. | |
1276 | ||
36d3d540 | 1277 | *** New function: random:exp STATE |
3e8370c3 MD |
1278 | Returns an inexact real in an exponential distribution with mean 1. |
1279 | For an exponential distribution with mean U use (* U (random:exp)). | |
1280 | ||
69c6acbb JB |
1281 | ** The range of logand, logior, logxor, logtest, and logbit? have changed. |
1282 | ||
1283 | These functions now operate on numbers in the range of a C unsigned | |
1284 | long. | |
1285 | ||
1286 | These functions used to operate on numbers in the range of a C signed | |
1287 | long; however, this seems inappropriate, because Guile integers don't | |
1288 | overflow. | |
1289 | ||
ba4ee0d6 MD |
1290 | ** New function: make-guardian |
1291 | This is an implementation of guardians as described in | |
1292 | R. Kent Dybvig, Carl Bruggeman, and David Eby (1993) "Guardians in a | |
1293 | Generation-Based Garbage Collector" ACM SIGPLAN Conference on | |
1294 | Programming Language Design and Implementation, June 1993 | |
1295 | ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/pubs/guardians.ps.gz | |
1296 | ||
88ceea5c MD |
1297 | ** New functions: delq1!, delv1!, delete1! |
1298 | These procedures behave similar to delq! and friends but delete only | |
1299 | one object if at all. | |
1300 | ||
55254a6a MD |
1301 | ** New function: unread-string STRING PORT |
1302 | Unread STRING to PORT, that is, push it back onto the port so that | |
1303 | next read operation will work on the pushed back characters. | |
1304 | ||
1305 | ** unread-char can now be called multiple times | |
1306 | If unread-char is called multiple times, the unread characters will be | |
1307 | read again in last-in first-out order. | |
1308 | ||
9e97c52d GH |
1309 | ** the procedures uniform-array-read! and uniform-array-write! now |
1310 | work on any kind of port, not just ports which are open on a file. | |
1311 | ||
b074884f | 1312 | ** Now 'l' in a port mode requests line buffering. |
9e97c52d | 1313 | |
69bc9ff3 GH |
1314 | ** The procedure truncate-file now works on string ports as well |
1315 | as file ports. If the size argument is omitted, the current | |
1b9c3dae | 1316 | file position is used. |
9e97c52d | 1317 | |
c94577b4 | 1318 | ** new procedure: seek PORT/FDES OFFSET WHENCE |
9e97c52d GH |
1319 | The arguments are the same as for the old fseek procedure, but it |
1320 | works on string ports as well as random-access file ports. | |
1321 | ||
1322 | ** the fseek procedure now works on string ports, since it has been | |
c94577b4 | 1323 | redefined using seek. |
9e97c52d GH |
1324 | |
1325 | ** the setvbuf procedure now uses a default size if mode is _IOFBF and | |
1326 | size is not supplied. | |
1327 | ||
1328 | ** the newline procedure no longer flushes the port if it's not | |
1329 | line-buffered: previously it did if it was the current output port. | |
1330 | ||
1331 | ** open-pipe and close-pipe are no longer primitive procedures, but | |
1332 | an emulation can be obtained using `(use-modules (ice-9 popen))'. | |
1333 | ||
1334 | ** the freopen procedure has been removed. | |
1335 | ||
1336 | ** new procedure: drain-input PORT | |
1337 | Drains PORT's read buffers (including any pushed-back characters) | |
1338 | and returns the contents as a single string. | |
1339 | ||
67ad463a | 1340 | ** New function: map-in-order PROC LIST1 LIST2 ... |
d41b3904 MD |
1341 | Version of `map' which guarantees that the procedure is applied to the |
1342 | lists in serial order. | |
1343 | ||
67ad463a MD |
1344 | ** Renamed `serial-array-copy!' and `serial-array-map!' to |
1345 | `array-copy-in-order!' and `array-map-in-order!'. The old names are | |
1346 | now obsolete and will go away in release 1.5. | |
1347 | ||
cf7132b3 | 1348 | ** New syntax: collect BODY1 ... |
d41b3904 MD |
1349 | Version of `begin' which returns a list of the results of the body |
1350 | forms instead of the result of the last body form. In contrast to | |
cf7132b3 | 1351 | `begin', `collect' allows an empty body. |
d41b3904 | 1352 | |
e4eae9b1 MD |
1353 | ** New functions: read-history FILENAME, write-history FILENAME |
1354 | Read/write command line history from/to file. Returns #t on success | |
1355 | and #f if an error occured. | |
1356 | ||
d21ffe26 JB |
1357 | ** `ls' and `lls' in module (ice-9 ls) now handle no arguments. |
1358 | ||
1359 | These procedures return a list of definitions available in the specified | |
1360 | argument, a relative module reference. In the case of no argument, | |
1361 | `(current-module)' is now consulted for definitions to return, instead | |
1362 | of simply returning #f, the former behavior. | |
1363 | ||
f8c9d497 JB |
1364 | ** The #/ syntax for lists is no longer supported. |
1365 | ||
1366 | Earlier versions of Scheme accepted this syntax, but printed a | |
1367 | warning. | |
1368 | ||
1369 | ** Guile no longer consults the SCHEME_LOAD_PATH environment variable. | |
1370 | ||
1371 | Instead, you should set GUILE_LOAD_PATH to tell Guile where to find | |
1372 | modules. | |
1373 | ||
3ffc7a36 MD |
1374 | * Changes to the gh_ interface |
1375 | ||
1376 | ** gh_scm2doubles | |
1377 | ||
1378 | Now takes a second argument which is the result array. If this | |
1379 | pointer is NULL, a new array is malloced (the old behaviour). | |
1380 | ||
1381 | ** gh_chars2byvect, gh_shorts2svect, gh_floats2fvect, gh_scm2chars, | |
1382 | gh_scm2shorts, gh_scm2longs, gh_scm2floats | |
1383 | ||
1384 | New functions. | |
1385 | ||
3e8370c3 MD |
1386 | * Changes to the scm_ interface |
1387 | ||
ad91d6c3 MD |
1388 | ** Function: scm_make_named_hook (char* name, int n_args) |
1389 | ||
1390 | Creates a hook in the same way as make-hook above but also | |
1391 | binds a variable named NAME to it. | |
1392 | ||
1393 | This is the typical way of creating a hook from C code. | |
1394 | ||
ece41168 MD |
1395 | Currently, the variable is created in the "current" module. This |
1396 | might change when we get the new module system. | |
ad91d6c3 | 1397 | |
16a5a9a4 MD |
1398 | ** The smob interface |
1399 | ||
1400 | The interface for creating smobs has changed. For documentation, see | |
1401 | data-rep.info (made from guile-core/doc/data-rep.texi). | |
1402 | ||
1403 | *** Deprecated function: SCM scm_newsmob (scm_smobfuns *) | |
1404 | ||
1405 | >>> This function will be removed in 1.3.4. <<< | |
1406 | ||
1407 | It is replaced by: | |
1408 | ||
1409 | *** Function: SCM scm_make_smob_type (const char *name, scm_sizet size) | |
1410 | This function adds a new smob type, named NAME, with instance size | |
1411 | SIZE to the system. The return value is a tag that is used in | |
1412 | creating instances of the type. If SIZE is 0, then no memory will | |
1413 | be allocated when instances of the smob are created, and nothing | |
1414 | will be freed by the default free function. | |
1415 | ||
1416 | *** Function: void scm_set_smob_mark (long tc, SCM (*mark) (SCM)) | |
1417 | This function sets the smob marking procedure for the smob type | |
1418 | specified by the tag TC. TC is the tag returned by | |
1419 | `scm_make_smob_type'. | |
1420 | ||
1421 | *** Function: void scm_set_smob_free (long tc, SCM (*mark) (SCM)) | |
1422 | This function sets the smob freeing procedure for the smob type | |
1423 | specified by the tag TC. TC is the tag returned by | |
1424 | `scm_make_smob_type'. | |
1425 | ||
1426 | *** Function: void scm_set_smob_print (tc, print) | |
1427 | ||
1428 | - Function: void scm_set_smob_print (long tc, | |
1429 | scm_sizet (*print) (SCM, | |
1430 | SCM, | |
1431 | scm_print_state *)) | |
1432 | ||
1433 | This function sets the smob printing procedure for the smob type | |
1434 | specified by the tag TC. TC is the tag returned by | |
1435 | `scm_make_smob_type'. | |
1436 | ||
1437 | *** Function: void scm_set_smob_equalp (long tc, SCM (*equalp) (SCM, SCM)) | |
1438 | This function sets the smob equality-testing predicate for the | |
1439 | smob type specified by the tag TC. TC is the tag returned by | |
1440 | `scm_make_smob_type'. | |
1441 | ||
1442 | *** Macro: void SCM_NEWSMOB (SCM var, long tc, void *data) | |
1443 | Make VALUE contain a smob instance of the type with type code TC and | |
1444 | smob data DATA. VALUE must be previously declared as C type `SCM'. | |
1445 | ||
1446 | *** Macro: fn_returns SCM_RETURN_NEWSMOB (long tc, void *data) | |
1447 | This macro expands to a block of code that creates a smob instance | |
1448 | of the type with type code TC and smob data DATA, and returns that | |
1449 | `SCM' value. It should be the last piece of code in a block. | |
1450 | ||
9e97c52d GH |
1451 | ** The interfaces for using I/O ports and implementing port types |
1452 | (ptobs) have changed significantly. The new interface is based on | |
1453 | shared access to buffers and a new set of ptob procedures. | |
1454 | ||
16a5a9a4 MD |
1455 | *** scm_newptob has been removed |
1456 | ||
1457 | It is replaced by: | |
1458 | ||
1459 | *** Function: SCM scm_make_port_type (type_name, fill_buffer, write_flush) | |
1460 | ||
1461 | - Function: SCM scm_make_port_type (char *type_name, | |
1462 | int (*fill_buffer) (SCM port), | |
1463 | void (*write_flush) (SCM port)); | |
1464 | ||
1465 | Similarly to the new smob interface, there is a set of function | |
1466 | setters by which the user can customize the behaviour of his port | |
544e9093 | 1467 | type. See ports.h (scm_set_port_XXX). |
16a5a9a4 | 1468 | |
9e97c52d GH |
1469 | ** scm_strport_to_string: New function: creates a new string from |
1470 | a string port's buffer. | |
1471 | ||
3e8370c3 MD |
1472 | ** Plug in interface for random number generators |
1473 | The variable `scm_the_rng' in random.c contains a value and three | |
1474 | function pointers which together define the current random number | |
1475 | generator being used by the Scheme level interface and the random | |
1476 | number library functions. | |
1477 | ||
1478 | The user is free to replace the default generator with the generator | |
1479 | of his own choice. | |
1480 | ||
1481 | *** Variable: size_t scm_the_rng.rstate_size | |
1482 | The size of the random state type used by the current RNG | |
1483 | measured in chars. | |
1484 | ||
1485 | *** Function: unsigned long scm_the_rng.random_bits (scm_rstate *STATE) | |
1486 | Given the random STATE, return 32 random bits. | |
1487 | ||
1488 | *** Function: void scm_the_rng.init_rstate (scm_rstate *STATE, chars *S, int N) | |
1489 | Seed random state STATE using string S of length N. | |
1490 | ||
1491 | *** Function: scm_rstate *scm_the_rng.copy_rstate (scm_rstate *STATE) | |
1492 | Given random state STATE, return a malloced copy. | |
1493 | ||
1494 | ** Default RNG | |
1495 | The default RNG is the MWC (Multiply With Carry) random number | |
1496 | generator described by George Marsaglia at the Department of | |
1497 | Statistics and Supercomputer Computations Research Institute, The | |
1498 | Florida State University (http://stat.fsu.edu/~geo). | |
1499 | ||
1500 | It uses 64 bits, has a period of 4578426017172946943 (4.6e18), and | |
1501 | passes all tests in the DIEHARD test suite | |
1502 | (http://stat.fsu.edu/~geo/diehard.html). The generation of 32 bits | |
1503 | costs one multiply and one add on platforms which either supports long | |
1504 | longs (gcc does this on most systems) or have 64 bit longs. The cost | |
1505 | is four multiply on other systems but this can be optimized by writing | |
1506 | scm_i_uniform32 in assembler. | |
1507 | ||
1508 | These functions are provided through the scm_the_rng interface for use | |
1509 | by libguile and the application. | |
1510 | ||
1511 | *** Function: unsigned long scm_i_uniform32 (scm_i_rstate *STATE) | |
1512 | Given the random STATE, return 32 random bits. | |
1513 | Don't use this function directly. Instead go through the plugin | |
1514 | interface (see "Plug in interface" above). | |
1515 | ||
1516 | *** Function: void scm_i_init_rstate (scm_i_rstate *STATE, char *SEED, int N) | |
1517 | Initialize STATE using SEED of length N. | |
1518 | ||
1519 | *** Function: scm_i_rstate *scm_i_copy_rstate (scm_i_rstate *STATE) | |
1520 | Return a malloc:ed copy of STATE. This function can easily be re-used | |
1521 | in the interfaces to other RNGs. | |
1522 | ||
1523 | ** Random number library functions | |
1524 | These functions use the current RNG through the scm_the_rng interface. | |
1525 | It might be a good idea to use these functions from your C code so | |
1526 | that only one random generator is used by all code in your program. | |
1527 | ||
259529f2 | 1528 | The default random state is stored in: |
3e8370c3 MD |
1529 | |
1530 | *** Variable: SCM scm_var_random_state | |
1531 | Contains the vcell of the Scheme variable "*random-state*" which is | |
1532 | used as default state by all random number functions in the Scheme | |
1533 | level interface. | |
1534 | ||
1535 | Example: | |
1536 | ||
259529f2 | 1537 | double x = scm_c_uniform01 (SCM_RSTATE (SCM_CDR (scm_var_random_state))); |
3e8370c3 | 1538 | |
259529f2 MD |
1539 | *** Function: scm_rstate *scm_c_default_rstate (void) |
1540 | This is a convenience function which returns the value of | |
1541 | scm_var_random_state. An error message is generated if this value | |
1542 | isn't a random state. | |
1543 | ||
1544 | *** Function: scm_rstate *scm_c_make_rstate (char *SEED, int LENGTH) | |
1545 | Make a new random state from the string SEED of length LENGTH. | |
1546 | ||
1547 | It is generally not a good idea to use multiple random states in a | |
1548 | program. While subsequent random numbers generated from one random | |
1549 | state are guaranteed to be reasonably independent, there is no such | |
1550 | guarantee for numbers generated from different random states. | |
1551 | ||
1552 | *** Macro: unsigned long scm_c_uniform32 (scm_rstate *STATE) | |
1553 | Return 32 random bits. | |
1554 | ||
1555 | *** Function: double scm_c_uniform01 (scm_rstate *STATE) | |
3e8370c3 MD |
1556 | Return a sample from the uniform(0,1) distribution. |
1557 | ||
259529f2 | 1558 | *** Function: double scm_c_normal01 (scm_rstate *STATE) |
3e8370c3 MD |
1559 | Return a sample from the normal(0,1) distribution. |
1560 | ||
259529f2 | 1561 | *** Function: double scm_c_exp1 (scm_rstate *STATE) |
3e8370c3 MD |
1562 | Return a sample from the exp(1) distribution. |
1563 | ||
259529f2 MD |
1564 | *** Function: unsigned long scm_c_random (scm_rstate *STATE, unsigned long M) |
1565 | Return a sample from the discrete uniform(0,M) distribution. | |
1566 | ||
1567 | *** Function: SCM scm_c_random_bignum (scm_rstate *STATE, SCM M) | |
3e8370c3 | 1568 | Return a sample from the discrete uniform(0,M) distribution. |
259529f2 | 1569 | M must be a bignum object. The returned value may be an INUM. |
3e8370c3 | 1570 | |
9e97c52d | 1571 | |
f3227c7a | 1572 | \f |
d23bbf3e | 1573 | Changes in Guile 1.3 (released Monday, October 19, 1998): |
c484bf7f JB |
1574 | |
1575 | * Changes to the distribution | |
1576 | ||
e2d6569c JB |
1577 | ** We renamed the SCHEME_LOAD_PATH environment variable to GUILE_LOAD_PATH. |
1578 | To avoid conflicts, programs should name environment variables after | |
1579 | themselves, except when there's a common practice establishing some | |
1580 | other convention. | |
1581 | ||
1582 | For now, Guile supports both GUILE_LOAD_PATH and SCHEME_LOAD_PATH, | |
1583 | giving the former precedence, and printing a warning message if the | |
1584 | latter is set. Guile 1.4 will not recognize SCHEME_LOAD_PATH at all. | |
1585 | ||
1586 | ** The header files related to multi-byte characters have been removed. | |
1587 | They were: libguile/extchrs.h and libguile/mbstrings.h. Any C code | |
1588 | which referred to these explicitly will probably need to be rewritten, | |
1589 | since the support for the variant string types has been removed; see | |
1590 | below. | |
1591 | ||
1592 | ** The header files append.h and sequences.h have been removed. These | |
1593 | files implemented non-R4RS operations which would encourage | |
1594 | non-portable programming style and less easy-to-read code. | |
3a97e020 | 1595 | |
c484bf7f JB |
1596 | * Changes to the stand-alone interpreter |
1597 | ||
2e368582 | 1598 | ** New procedures have been added to implement a "batch mode": |
ec4ab4fd | 1599 | |
2e368582 | 1600 | *** Function: batch-mode? |
ec4ab4fd GH |
1601 | |
1602 | Returns a boolean indicating whether the interpreter is in batch | |
1603 | mode. | |
1604 | ||
2e368582 | 1605 | *** Function: set-batch-mode?! ARG |
ec4ab4fd GH |
1606 | |
1607 | If ARG is true, switches the interpreter to batch mode. The `#f' | |
1608 | case has not been implemented. | |
1609 | ||
2e368582 JB |
1610 | ** Guile now provides full command-line editing, when run interactively. |
1611 | To use this feature, you must have the readline library installed. | |
1612 | The Guile build process will notice it, and automatically include | |
1613 | support for it. | |
1614 | ||
1615 | The readline library is available via anonymous FTP from any GNU | |
1616 | mirror site; the canonical location is "ftp://prep.ai.mit.edu/pub/gnu". | |
1617 | ||
a5d6d578 MD |
1618 | ** the-last-stack is now a fluid. |
1619 | ||
c484bf7f JB |
1620 | * Changes to the procedure for linking libguile with your programs |
1621 | ||
71f20534 | 1622 | ** You can now use the `guile-config' utility to build programs that use Guile. |
2e368582 | 1623 | |
2adfe1c0 | 1624 | Guile now includes a command-line utility called `guile-config', which |
71f20534 JB |
1625 | can provide information about how to compile and link programs that |
1626 | use Guile. | |
1627 | ||
1628 | *** `guile-config compile' prints any C compiler flags needed to use Guile. | |
1629 | You should include this command's output on the command line you use | |
1630 | to compile C or C++ code that #includes the Guile header files. It's | |
1631 | usually just a `-I' flag to help the compiler find the Guile headers. | |
1632 | ||
1633 | ||
1634 | *** `guile-config link' prints any linker flags necessary to link with Guile. | |
8aa5c148 | 1635 | |
71f20534 | 1636 | This command writes to its standard output a list of flags which you |
8aa5c148 JB |
1637 | must pass to the linker to link your code against the Guile library. |
1638 | The flags include '-lguile' itself, any other libraries the Guile | |
1639 | library depends upon, and any `-L' flags needed to help the linker | |
1640 | find those libraries. | |
2e368582 JB |
1641 | |
1642 | For example, here is a Makefile rule that builds a program named 'foo' | |
1643 | from the object files ${FOO_OBJECTS}, and links them against Guile: | |
1644 | ||
1645 | foo: ${FOO_OBJECTS} | |
2adfe1c0 | 1646 | ${CC} ${CFLAGS} ${FOO_OBJECTS} `guile-config link` -o foo |
2e368582 | 1647 | |
e2d6569c JB |
1648 | Previous Guile releases recommended that you use autoconf to detect |
1649 | which of a predefined set of libraries were present on your system. | |
2adfe1c0 | 1650 | It is more robust to use `guile-config', since it records exactly which |
e2d6569c JB |
1651 | libraries the installed Guile library requires. |
1652 | ||
2adfe1c0 JB |
1653 | This was originally called `build-guile', but was renamed to |
1654 | `guile-config' before Guile 1.3 was released, to be consistent with | |
1655 | the analogous script for the GTK+ GUI toolkit, which is called | |
1656 | `gtk-config'. | |
1657 | ||
2e368582 | 1658 | |
8aa5c148 JB |
1659 | ** Use the GUILE_FLAGS macro in your configure.in file to find Guile. |
1660 | ||
1661 | If you are using the GNU autoconf package to configure your program, | |
1662 | you can use the GUILE_FLAGS autoconf macro to call `guile-config' | |
1663 | (described above) and gather the necessary values for use in your | |
1664 | Makefiles. | |
1665 | ||
1666 | The GUILE_FLAGS macro expands to configure script code which runs the | |
1667 | `guile-config' script, to find out where Guile's header files and | |
1668 | libraries are installed. It sets two variables, marked for | |
1669 | substitution, as by AC_SUBST. | |
1670 | ||
1671 | GUILE_CFLAGS --- flags to pass to a C or C++ compiler to build | |
1672 | code that uses Guile header files. This is almost always just a | |
1673 | -I flag. | |
1674 | ||
1675 | GUILE_LDFLAGS --- flags to pass to the linker to link a | |
1676 | program against Guile. This includes `-lguile' for the Guile | |
1677 | library itself, any libraries that Guile itself requires (like | |
1678 | -lqthreads), and so on. It may also include a -L flag to tell the | |
1679 | compiler where to find the libraries. | |
1680 | ||
1681 | GUILE_FLAGS is defined in the file guile.m4, in the top-level | |
1682 | directory of the Guile distribution. You can copy it into your | |
1683 | package's aclocal.m4 file, and then use it in your configure.in file. | |
1684 | ||
1685 | If you are using the `aclocal' program, distributed with GNU automake, | |
1686 | to maintain your aclocal.m4 file, the Guile installation process | |
1687 | installs guile.m4 where aclocal will find it. All you need to do is | |
1688 | use GUILE_FLAGS in your configure.in file, and then run `aclocal'; | |
1689 | this will copy the definition of GUILE_FLAGS into your aclocal.m4 | |
1690 | file. | |
1691 | ||
1692 | ||
c484bf7f | 1693 | * Changes to Scheme functions and syntax |
7ad3c1e7 | 1694 | |
02755d59 | 1695 | ** Multi-byte strings have been removed, as have multi-byte and wide |
e2d6569c JB |
1696 | ports. We felt that these were the wrong approach to |
1697 | internationalization support. | |
02755d59 | 1698 | |
2e368582 JB |
1699 | ** New function: readline [PROMPT] |
1700 | Read a line from the terminal, and allow the user to edit it, | |
1701 | prompting with PROMPT. READLINE provides a large set of Emacs-like | |
1702 | editing commands, lets the user recall previously typed lines, and | |
1703 | works on almost every kind of terminal, including dumb terminals. | |
1704 | ||
1705 | READLINE assumes that the cursor is at the beginning of the line when | |
1706 | it is invoked. Thus, you can't print a prompt yourself, and then call | |
1707 | READLINE; you need to package up your prompt as a string, pass it to | |
1708 | the function, and let READLINE print the prompt itself. This is | |
1709 | because READLINE needs to know the prompt's screen width. | |
1710 | ||
8cd57bd0 JB |
1711 | For Guile to provide this function, you must have the readline |
1712 | library, version 2.1 or later, installed on your system. Readline is | |
1713 | available via anonymous FTP from prep.ai.mit.edu in pub/gnu, or from | |
1714 | any GNU mirror site. | |
2e368582 JB |
1715 | |
1716 | See also ADD-HISTORY function. | |
1717 | ||
1718 | ** New function: add-history STRING | |
1719 | Add STRING as the most recent line in the history used by the READLINE | |
1720 | command. READLINE does not add lines to the history itself; you must | |
1721 | call ADD-HISTORY to make previous input available to the user. | |
1722 | ||
8cd57bd0 JB |
1723 | ** The behavior of the read-line function has changed. |
1724 | ||
1725 | This function now uses standard C library functions to read the line, | |
1726 | for speed. This means that it doesn not respect the value of | |
1727 | scm-line-incrementors; it assumes that lines are delimited with | |
1728 | #\newline. | |
1729 | ||
1730 | (Note that this is read-line, the function that reads a line of text | |
1731 | from a port, not readline, the function that reads a line from a | |
1732 | terminal, providing full editing capabilities.) | |
1733 | ||
1a0106ef JB |
1734 | ** New module (ice-9 getopt-gnu-style): Parse command-line arguments. |
1735 | ||
1736 | This module provides some simple argument parsing. It exports one | |
1737 | function: | |
1738 | ||
1739 | Function: getopt-gnu-style ARG-LS | |
1740 | Parse a list of program arguments into an alist of option | |
1741 | descriptions. | |
1742 | ||
1743 | Each item in the list of program arguments is examined to see if | |
1744 | it meets the syntax of a GNU long-named option. An argument like | |
1745 | `--MUMBLE' produces an element of the form (MUMBLE . #t) in the | |
1746 | returned alist, where MUMBLE is a keyword object with the same | |
1747 | name as the argument. An argument like `--MUMBLE=FROB' produces | |
1748 | an element of the form (MUMBLE . FROB), where FROB is a string. | |
1749 | ||
1750 | As a special case, the returned alist also contains a pair whose | |
1751 | car is the symbol `rest'. The cdr of this pair is a list | |
1752 | containing all the items in the argument list that are not options | |
1753 | of the form mentioned above. | |
1754 | ||
1755 | The argument `--' is treated specially: all items in the argument | |
1756 | list appearing after such an argument are not examined, and are | |
1757 | returned in the special `rest' list. | |
1758 | ||
1759 | This function does not parse normal single-character switches. | |
1760 | You will need to parse them out of the `rest' list yourself. | |
1761 | ||
8cd57bd0 JB |
1762 | ** The read syntax for byte vectors and short vectors has changed. |
1763 | ||
1764 | Instead of #bytes(...), write #y(...). | |
1765 | ||
1766 | Instead of #short(...), write #h(...). | |
1767 | ||
1768 | This may seem nutty, but, like the other uniform vectors, byte vectors | |
1769 | and short vectors want to have the same print and read syntax (and, | |
1770 | more basic, want to have read syntax!). Changing the read syntax to | |
1771 | use multiple characters after the hash sign breaks with the | |
1772 | conventions used in R5RS and the conventions used for the other | |
1773 | uniform vectors. It also introduces complexity in the current reader, | |
1774 | both on the C and Scheme levels. (The Right solution is probably to | |
1775 | change the syntax and prototypes for uniform vectors entirely.) | |
1776 | ||
1777 | ||
1778 | ** The new module (ice-9 session) provides useful interactive functions. | |
1779 | ||
1780 | *** New procedure: (apropos REGEXP OPTION ...) | |
1781 | ||
1782 | Display a list of top-level variables whose names match REGEXP, and | |
1783 | the modules they are imported from. Each OPTION should be one of the | |
1784 | following symbols: | |
1785 | ||
1786 | value --- Show the value of each matching variable. | |
1787 | shadow --- Show bindings shadowed by subsequently imported modules. | |
1788 | full --- Same as both `shadow' and `value'. | |
1789 | ||
1790 | For example: | |
1791 | ||
1792 | guile> (apropos "trace" 'full) | |
1793 | debug: trace #<procedure trace args> | |
1794 | debug: untrace #<procedure untrace args> | |
1795 | the-scm-module: display-backtrace #<compiled-closure #<primitive-procedure gsubr-apply>> | |
1796 | the-scm-module: before-backtrace-hook () | |
1797 | the-scm-module: backtrace #<primitive-procedure backtrace> | |
1798 | the-scm-module: after-backtrace-hook () | |
1799 | the-scm-module: has-shown-backtrace-hint? #f | |
1800 | guile> | |
1801 | ||
1802 | ** There are new functions and syntax for working with macros. | |
1803 | ||
1804 | Guile implements macros as a special object type. Any variable whose | |
1805 | top-level binding is a macro object acts as a macro. The macro object | |
1806 | specifies how the expression should be transformed before evaluation. | |
1807 | ||
1808 | *** Macro objects now print in a reasonable way, resembling procedures. | |
1809 | ||
1810 | *** New function: (macro? OBJ) | |
1811 | True iff OBJ is a macro object. | |
1812 | ||
1813 | *** New function: (primitive-macro? OBJ) | |
1814 | Like (macro? OBJ), but true only if OBJ is one of the Guile primitive | |
1815 | macro transformers, implemented in eval.c rather than Scheme code. | |
1816 | ||
dbdd0c16 JB |
1817 | Why do we have this function? |
1818 | - For symmetry with procedure? and primitive-procedure?, | |
1819 | - to allow custom print procedures to tell whether a macro is | |
1820 | primitive, and display it differently, and | |
1821 | - to allow compilers and user-written evaluators to distinguish | |
1822 | builtin special forms from user-defined ones, which could be | |
1823 | compiled. | |
1824 | ||
8cd57bd0 JB |
1825 | *** New function: (macro-type OBJ) |
1826 | Return a value indicating what kind of macro OBJ is. Possible return | |
1827 | values are: | |
1828 | ||
1829 | The symbol `syntax' --- a macro created by procedure->syntax. | |
1830 | The symbol `macro' --- a macro created by procedure->macro. | |
1831 | The symbol `macro!' --- a macro created by procedure->memoizing-macro. | |
1832 | The boolean #f --- if OBJ is not a macro object. | |
1833 | ||
1834 | *** New function: (macro-name MACRO) | |
1835 | Return the name of the macro object MACRO's procedure, as returned by | |
1836 | procedure-name. | |
1837 | ||
1838 | *** New function: (macro-transformer MACRO) | |
1839 | Return the transformer procedure for MACRO. | |
1840 | ||
1841 | *** New syntax: (use-syntax MODULE ... TRANSFORMER) | |
1842 | ||
1843 | Specify a new macro expander to use in the current module. Each | |
1844 | MODULE is a module name, with the same meaning as in the `use-modules' | |
1845 | form; each named module's exported bindings are added to the current | |
1846 | top-level environment. TRANSFORMER is an expression evaluated in the | |
1847 | resulting environment which must yield a procedure to use as the | |
1848 | module's eval transformer: every expression evaluated in this module | |
1849 | is passed to this function, and the result passed to the Guile | |
1850 | interpreter. | |
1851 | ||
1852 | *** macro-eval! is removed. Use local-eval instead. | |
29521173 | 1853 | |
8d9dcb3c MV |
1854 | ** Some magic has been added to the printer to better handle user |
1855 | written printing routines (like record printers, closure printers). | |
1856 | ||
1857 | The problem is that these user written routines must have access to | |
7fbd77df | 1858 | the current `print-state' to be able to handle fancy things like |
8d9dcb3c MV |
1859 | detection of circular references. These print-states have to be |
1860 | passed to the builtin printing routines (display, write, etc) to | |
1861 | properly continue the print chain. | |
1862 | ||
1863 | We didn't want to change all existing print code so that it | |
8cd57bd0 | 1864 | explicitly passes thru a print state in addition to a port. Instead, |
8d9dcb3c MV |
1865 | we extented the possible values that the builtin printing routines |
1866 | accept as a `port'. In addition to a normal port, they now also take | |
1867 | a pair of a normal port and a print-state. Printing will go to the | |
1868 | port and the print-state will be used to control the detection of | |
1869 | circular references, etc. If the builtin function does not care for a | |
1870 | print-state, it is simply ignored. | |
1871 | ||
1872 | User written callbacks are now called with such a pair as their | |
1873 | `port', but because every function now accepts this pair as a PORT | |
1874 | argument, you don't have to worry about that. In fact, it is probably | |
1875 | safest to not check for these pairs. | |
1876 | ||
1877 | However, it is sometimes necessary to continue a print chain on a | |
1878 | different port, for example to get a intermediate string | |
1879 | representation of the printed value, mangle that string somehow, and | |
1880 | then to finally print the mangled string. Use the new function | |
1881 | ||
1882 | inherit-print-state OLD-PORT NEW-PORT | |
1883 | ||
1884 | for this. It constructs a new `port' that prints to NEW-PORT but | |
1885 | inherits the print-state of OLD-PORT. | |
1886 | ||
ef1ea498 MD |
1887 | ** struct-vtable-offset renamed to vtable-offset-user |
1888 | ||
1889 | ** New constants: vtable-index-layout, vtable-index-vtable, vtable-index-printer | |
1890 | ||
1891 | ** There is now a fourth (optional) argument to make-vtable-vtable and | |
1892 | make-struct when constructing new types (vtables). This argument | |
1893 | initializes field vtable-index-printer of the vtable. | |
1894 | ||
4851dc57 MV |
1895 | ** The detection of circular references has been extended to structs. |
1896 | That is, a structure that -- in the process of being printed -- prints | |
1897 | itself does not lead to infinite recursion. | |
1898 | ||
1899 | ** There is now some basic support for fluids. Please read | |
1900 | "libguile/fluid.h" to find out more. It is accessible from Scheme with | |
1901 | the following functions and macros: | |
1902 | ||
9c3fb66f MV |
1903 | Function: make-fluid |
1904 | ||
1905 | Create a new fluid object. Fluids are not special variables or | |
1906 | some other extension to the semantics of Scheme, but rather | |
1907 | ordinary Scheme objects. You can store them into variables (that | |
1908 | are still lexically scoped, of course) or into any other place you | |
1909 | like. Every fluid has a initial value of `#f'. | |
04c76b58 | 1910 | |
9c3fb66f | 1911 | Function: fluid? OBJ |
04c76b58 | 1912 | |
9c3fb66f | 1913 | Test whether OBJ is a fluid. |
04c76b58 | 1914 | |
9c3fb66f MV |
1915 | Function: fluid-ref FLUID |
1916 | Function: fluid-set! FLUID VAL | |
04c76b58 MV |
1917 | |
1918 | Access/modify the fluid FLUID. Modifications are only visible | |
1919 | within the current dynamic root (that includes threads). | |
1920 | ||
9c3fb66f MV |
1921 | Function: with-fluids* FLUIDS VALUES THUNK |
1922 | ||
1923 | FLUIDS is a list of fluids and VALUES a corresponding list of | |
1924 | values for these fluids. Before THUNK gets called the values are | |
1925 | installed in the fluids and the old values of the fluids are | |
1926 | saved in the VALUES list. When the flow of control leaves THUNK | |
1927 | or reenters it, the values get swapped again. You might think of | |
1928 | this as a `safe-fluid-excursion'. Note that the VALUES list is | |
1929 | modified by `with-fluids*'. | |
1930 | ||
1931 | Macro: with-fluids ((FLUID VALUE) ...) FORM ... | |
1932 | ||
1933 | The same as `with-fluids*' but with a different syntax. It looks | |
1934 | just like `let', but both FLUID and VALUE are evaluated. Remember, | |
1935 | fluids are not special variables but ordinary objects. FLUID | |
1936 | should evaluate to a fluid. | |
04c76b58 | 1937 | |
e2d6569c | 1938 | ** Changes to system call interfaces: |
64d01d13 | 1939 | |
e2d6569c | 1940 | *** close-port, close-input-port and close-output-port now return a |
64d01d13 GH |
1941 | boolean instead of an `unspecified' object. #t means that the port |
1942 | was successfully closed, while #f means it was already closed. It is | |
1943 | also now possible for these procedures to raise an exception if an | |
1944 | error occurs (some errors from write can be delayed until close.) | |
1945 | ||
e2d6569c | 1946 | *** the first argument to chmod, fcntl, ftell and fseek can now be a |
6afcd3b2 GH |
1947 | file descriptor. |
1948 | ||
e2d6569c | 1949 | *** the third argument to fcntl is now optional. |
6afcd3b2 | 1950 | |
e2d6569c | 1951 | *** the first argument to chown can now be a file descriptor or a port. |
6afcd3b2 | 1952 | |
e2d6569c | 1953 | *** the argument to stat can now be a port. |
6afcd3b2 | 1954 | |
e2d6569c | 1955 | *** The following new procedures have been added (most use scsh |
64d01d13 GH |
1956 | interfaces): |
1957 | ||
e2d6569c | 1958 | *** procedure: close PORT/FD |
ec4ab4fd GH |
1959 | Similar to close-port (*note close-port: Closing Ports.), but also |
1960 | works on file descriptors. A side effect of closing a file | |
1961 | descriptor is that any ports using that file descriptor are moved | |
1962 | to a different file descriptor and have their revealed counts set | |
1963 | to zero. | |
1964 | ||
e2d6569c | 1965 | *** procedure: port->fdes PORT |
ec4ab4fd GH |
1966 | Returns the integer file descriptor underlying PORT. As a side |
1967 | effect the revealed count of PORT is incremented. | |
1968 | ||
e2d6569c | 1969 | *** procedure: fdes->ports FDES |
ec4ab4fd GH |
1970 | Returns a list of existing ports which have FDES as an underlying |
1971 | file descriptor, without changing their revealed counts. | |
1972 | ||
e2d6569c | 1973 | *** procedure: fdes->inport FDES |
ec4ab4fd GH |
1974 | Returns an existing input port which has FDES as its underlying |
1975 | file descriptor, if one exists, and increments its revealed count. | |
1976 | Otherwise, returns a new input port with a revealed count of 1. | |
1977 | ||
e2d6569c | 1978 | *** procedure: fdes->outport FDES |
ec4ab4fd GH |
1979 | Returns an existing output port which has FDES as its underlying |
1980 | file descriptor, if one exists, and increments its revealed count. | |
1981 | Otherwise, returns a new output port with a revealed count of 1. | |
1982 | ||
1983 | The next group of procedures perform a `dup2' system call, if NEWFD | |
1984 | (an integer) is supplied, otherwise a `dup'. The file descriptor to be | |
1985 | duplicated can be supplied as an integer or contained in a port. The | |
64d01d13 GH |
1986 | type of value returned varies depending on which procedure is used. |
1987 | ||
ec4ab4fd GH |
1988 | All procedures also have the side effect when performing `dup2' that |
1989 | any ports using NEWFD are moved to a different file descriptor and have | |
64d01d13 GH |
1990 | their revealed counts set to zero. |
1991 | ||
e2d6569c | 1992 | *** procedure: dup->fdes PORT/FD [NEWFD] |
ec4ab4fd | 1993 | Returns an integer file descriptor. |
64d01d13 | 1994 | |
e2d6569c | 1995 | *** procedure: dup->inport PORT/FD [NEWFD] |
ec4ab4fd | 1996 | Returns a new input port using the new file descriptor. |
64d01d13 | 1997 | |
e2d6569c | 1998 | *** procedure: dup->outport PORT/FD [NEWFD] |
ec4ab4fd | 1999 | Returns a new output port using the new file descriptor. |
64d01d13 | 2000 | |
e2d6569c | 2001 | *** procedure: dup PORT/FD [NEWFD] |
ec4ab4fd GH |
2002 | Returns a new port if PORT/FD is a port, with the same mode as the |
2003 | supplied port, otherwise returns an integer file descriptor. | |
64d01d13 | 2004 | |
e2d6569c | 2005 | *** procedure: dup->port PORT/FD MODE [NEWFD] |
ec4ab4fd GH |
2006 | Returns a new port using the new file descriptor. MODE supplies a |
2007 | mode string for the port (*note open-file: File Ports.). | |
64d01d13 | 2008 | |
e2d6569c | 2009 | *** procedure: setenv NAME VALUE |
ec4ab4fd GH |
2010 | Modifies the environment of the current process, which is also the |
2011 | default environment inherited by child processes. | |
64d01d13 | 2012 | |
ec4ab4fd GH |
2013 | If VALUE is `#f', then NAME is removed from the environment. |
2014 | Otherwise, the string NAME=VALUE is added to the environment, | |
2015 | replacing any existing string with name matching NAME. | |
64d01d13 | 2016 | |
ec4ab4fd | 2017 | The return value is unspecified. |
956055a9 | 2018 | |
e2d6569c | 2019 | *** procedure: truncate-file OBJ SIZE |
6afcd3b2 GH |
2020 | Truncates the file referred to by OBJ to at most SIZE bytes. OBJ |
2021 | can be a string containing a file name or an integer file | |
2022 | descriptor or port open for output on the file. The underlying | |
2023 | system calls are `truncate' and `ftruncate'. | |
2024 | ||
2025 | The return value is unspecified. | |
2026 | ||
e2d6569c | 2027 | *** procedure: setvbuf PORT MODE [SIZE] |
7a6f1ffa GH |
2028 | Set the buffering mode for PORT. MODE can be: |
2029 | `_IONBF' | |
2030 | non-buffered | |
2031 | ||
2032 | `_IOLBF' | |
2033 | line buffered | |
2034 | ||
2035 | `_IOFBF' | |
2036 | block buffered, using a newly allocated buffer of SIZE bytes. | |
2037 | However if SIZE is zero or unspecified, the port will be made | |
2038 | non-buffered. | |
2039 | ||
2040 | This procedure should not be used after I/O has been performed with | |
2041 | the port. | |
2042 | ||
2043 | Ports are usually block buffered by default, with a default buffer | |
2044 | size. Procedures e.g., *Note open-file: File Ports, which accept a | |
2045 | mode string allow `0' to be added to request an unbuffered port. | |
2046 | ||
e2d6569c | 2047 | *** procedure: fsync PORT/FD |
6afcd3b2 GH |
2048 | Copies any unwritten data for the specified output file descriptor |
2049 | to disk. If PORT/FD is a port, its buffer is flushed before the | |
2050 | underlying file descriptor is fsync'd. The return value is | |
2051 | unspecified. | |
2052 | ||
e2d6569c | 2053 | *** procedure: open-fdes PATH FLAGS [MODES] |
6afcd3b2 GH |
2054 | Similar to `open' but returns a file descriptor instead of a port. |
2055 | ||
e2d6569c | 2056 | *** procedure: execle PATH ENV [ARG] ... |
6afcd3b2 GH |
2057 | Similar to `execl', but the environment of the new process is |
2058 | specified by ENV, which must be a list of strings as returned by | |
2059 | the `environ' procedure. | |
2060 | ||
2061 | This procedure is currently implemented using the `execve' system | |
2062 | call, but we call it `execle' because of its Scheme calling | |
2063 | interface. | |
2064 | ||
e2d6569c | 2065 | *** procedure: strerror ERRNO |
ec4ab4fd GH |
2066 | Returns the Unix error message corresponding to ERRNO, an integer. |
2067 | ||
e2d6569c | 2068 | *** procedure: primitive-exit [STATUS] |
6afcd3b2 GH |
2069 | Terminate the current process without unwinding the Scheme stack. |
2070 | This is would typically be useful after a fork. The exit status | |
2071 | is STATUS if supplied, otherwise zero. | |
2072 | ||
e2d6569c | 2073 | *** procedure: times |
6afcd3b2 GH |
2074 | Returns an object with information about real and processor time. |
2075 | The following procedures accept such an object as an argument and | |
2076 | return a selected component: | |
2077 | ||
2078 | `tms:clock' | |
2079 | The current real time, expressed as time units relative to an | |
2080 | arbitrary base. | |
2081 | ||
2082 | `tms:utime' | |
2083 | The CPU time units used by the calling process. | |
2084 | ||
2085 | `tms:stime' | |
2086 | The CPU time units used by the system on behalf of the | |
2087 | calling process. | |
2088 | ||
2089 | `tms:cutime' | |
2090 | The CPU time units used by terminated child processes of the | |
2091 | calling process, whose status has been collected (e.g., using | |
2092 | `waitpid'). | |
2093 | ||
2094 | `tms:cstime' | |
2095 | Similarly, the CPU times units used by the system on behalf of | |
2096 | terminated child processes. | |
7ad3c1e7 | 2097 | |
e2d6569c JB |
2098 | ** Removed: list-length |
2099 | ** Removed: list-append, list-append! | |
2100 | ** Removed: list-reverse, list-reverse! | |
2101 | ||
2102 | ** array-map renamed to array-map! | |
2103 | ||
2104 | ** serial-array-map renamed to serial-array-map! | |
2105 | ||
660f41fa MD |
2106 | ** catch doesn't take #f as first argument any longer |
2107 | ||
2108 | Previously, it was possible to pass #f instead of a key to `catch'. | |
2109 | That would cause `catch' to pass a jump buffer object to the procedure | |
2110 | passed as second argument. The procedure could then use this jump | |
2111 | buffer objekt as an argument to throw. | |
2112 | ||
2113 | This mechanism has been removed since its utility doesn't motivate the | |
2114 | extra complexity it introduces. | |
2115 | ||
332d00f6 JB |
2116 | ** The `#/' notation for lists now provokes a warning message from Guile. |
2117 | This syntax will be removed from Guile in the near future. | |
2118 | ||
2119 | To disable the warning message, set the GUILE_HUSH environment | |
2120 | variable to any non-empty value. | |
2121 | ||
8cd57bd0 JB |
2122 | ** The newline character now prints as `#\newline', following the |
2123 | normal Scheme notation, not `#\nl'. | |
2124 | ||
c484bf7f JB |
2125 | * Changes to the gh_ interface |
2126 | ||
8986901b JB |
2127 | ** The gh_enter function now takes care of loading the Guile startup files. |
2128 | gh_enter works by calling scm_boot_guile; see the remarks below. | |
2129 | ||
5424b4f7 MD |
2130 | ** Function: void gh_write (SCM x) |
2131 | ||
2132 | Write the printed representation of the scheme object x to the current | |
2133 | output port. Corresponds to the scheme level `write'. | |
2134 | ||
3a97e020 MD |
2135 | ** gh_list_length renamed to gh_length. |
2136 | ||
8d6787b6 MG |
2137 | ** vector handling routines |
2138 | ||
2139 | Several major changes. In particular, gh_vector() now resembles | |
2140 | (vector ...) (with a caveat -- see manual), and gh_make_vector() now | |
956328d2 MG |
2141 | exists and behaves like (make-vector ...). gh_vset() and gh_vref() |
2142 | have been renamed gh_vector_set_x() and gh_vector_ref(). Some missing | |
8d6787b6 MG |
2143 | vector-related gh_ functions have been implemented. |
2144 | ||
7fee59bd MG |
2145 | ** pair and list routines |
2146 | ||
2147 | Implemented several of the R4RS pair and list functions that were | |
2148 | missing. | |
2149 | ||
171422a9 MD |
2150 | ** gh_scm2doubles, gh_doubles2scm, gh_doubles2dvect |
2151 | ||
2152 | New function. Converts double arrays back and forth between Scheme | |
2153 | and C. | |
2154 | ||
c484bf7f JB |
2155 | * Changes to the scm_ interface |
2156 | ||
8986901b JB |
2157 | ** The function scm_boot_guile now takes care of loading the startup files. |
2158 | ||
2159 | Guile's primary initialization function, scm_boot_guile, now takes | |
2160 | care of loading `boot-9.scm', in the `ice-9' module, to initialize | |
2161 | Guile, define the module system, and put together some standard | |
2162 | bindings. It also loads `init.scm', which is intended to hold | |
2163 | site-specific initialization code. | |
2164 | ||
2165 | Since Guile cannot operate properly until boot-9.scm is loaded, there | |
2166 | is no reason to separate loading boot-9.scm from Guile's other | |
2167 | initialization processes. | |
2168 | ||
2169 | This job used to be done by scm_compile_shell_switches, which didn't | |
2170 | make much sense; in particular, it meant that people using Guile for | |
2171 | non-shell-like applications had to jump through hoops to get Guile | |
2172 | initialized properly. | |
2173 | ||
2174 | ** The function scm_compile_shell_switches no longer loads the startup files. | |
2175 | Now, Guile always loads the startup files, whenever it is initialized; | |
2176 | see the notes above for scm_boot_guile and scm_load_startup_files. | |
2177 | ||
2178 | ** Function: scm_load_startup_files | |
2179 | This new function takes care of loading Guile's initialization file | |
2180 | (`boot-9.scm'), and the site initialization file, `init.scm'. Since | |
2181 | this is always called by the Guile initialization process, it's | |
2182 | probably not too useful to call this yourself, but it's there anyway. | |
2183 | ||
87148d9e JB |
2184 | ** The semantics of smob marking have changed slightly. |
2185 | ||
2186 | The smob marking function (the `mark' member of the scm_smobfuns | |
2187 | structure) is no longer responsible for setting the mark bit on the | |
2188 | smob. The generic smob handling code in the garbage collector will | |
2189 | set this bit. The mark function need only ensure that any other | |
2190 | objects the smob refers to get marked. | |
2191 | ||
2192 | Note that this change means that the smob's GC8MARK bit is typically | |
2193 | already set upon entry to the mark function. Thus, marking functions | |
2194 | which look like this: | |
2195 | ||
2196 | { | |
2197 | if (SCM_GC8MARKP (ptr)) | |
2198 | return SCM_BOOL_F; | |
2199 | SCM_SETGC8MARK (ptr); | |
2200 | ... mark objects to which the smob refers ... | |
2201 | } | |
2202 | ||
2203 | are now incorrect, since they will return early, and fail to mark any | |
2204 | other objects the smob refers to. Some code in the Guile library used | |
2205 | to work this way. | |
2206 | ||
1cf84ea5 JB |
2207 | ** The semantics of the I/O port functions in scm_ptobfuns have changed. |
2208 | ||
2209 | If you have implemented your own I/O port type, by writing the | |
2210 | functions required by the scm_ptobfuns and then calling scm_newptob, | |
2211 | you will need to change your functions slightly. | |
2212 | ||
2213 | The functions in a scm_ptobfuns structure now expect the port itself | |
2214 | as their argument; they used to expect the `stream' member of the | |
2215 | port's scm_port_table structure. This allows functions in an | |
2216 | scm_ptobfuns structure to easily access the port's cell (and any flags | |
2217 | it its CAR), and the port's scm_port_table structure. | |
2218 | ||
2219 | Guile now passes the I/O port itself as the `port' argument in the | |
2220 | following scm_ptobfuns functions: | |
2221 | ||
2222 | int (*free) (SCM port); | |
2223 | int (*fputc) (int, SCM port); | |
2224 | int (*fputs) (char *, SCM port); | |
2225 | scm_sizet (*fwrite) SCM_P ((char *ptr, | |
2226 | scm_sizet size, | |
2227 | scm_sizet nitems, | |
2228 | SCM port)); | |
2229 | int (*fflush) (SCM port); | |
2230 | int (*fgetc) (SCM port); | |
2231 | int (*fclose) (SCM port); | |
2232 | ||
2233 | The interfaces to the `mark', `print', `equalp', and `fgets' methods | |
2234 | are unchanged. | |
2235 | ||
2236 | If you have existing code which defines its own port types, it is easy | |
2237 | to convert your code to the new interface; simply apply SCM_STREAM to | |
2238 | the port argument to yield the value you code used to expect. | |
2239 | ||
2240 | Note that since both the port and the stream have the same type in the | |
2241 | C code --- they are both SCM values --- the C compiler will not remind | |
2242 | you if you forget to update your scm_ptobfuns functions. | |
2243 | ||
2244 | ||
933a7411 MD |
2245 | ** Function: int scm_internal_select (int fds, |
2246 | SELECT_TYPE *rfds, | |
2247 | SELECT_TYPE *wfds, | |
2248 | SELECT_TYPE *efds, | |
2249 | struct timeval *timeout); | |
2250 | ||
2251 | This is a replacement for the `select' function provided by the OS. | |
2252 | It enables I/O blocking and sleeping to happen for one cooperative | |
2253 | thread without blocking other threads. It also avoids busy-loops in | |
2254 | these situations. It is intended that all I/O blocking and sleeping | |
2255 | will finally go through this function. Currently, this function is | |
2256 | only available on systems providing `gettimeofday' and `select'. | |
2257 | ||
5424b4f7 MD |
2258 | ** Function: SCM scm_internal_stack_catch (SCM tag, |
2259 | scm_catch_body_t body, | |
2260 | void *body_data, | |
2261 | scm_catch_handler_t handler, | |
2262 | void *handler_data) | |
2263 | ||
2264 | A new sibling to the other two C level `catch' functions | |
2265 | scm_internal_catch and scm_internal_lazy_catch. Use it if you want | |
2266 | the stack to be saved automatically into the variable `the-last-stack' | |
2267 | (scm_the_last_stack_var) on error. This is necessary if you want to | |
2268 | use advanced error reporting, such as calling scm_display_error and | |
2269 | scm_display_backtrace. (They both take a stack object as argument.) | |
2270 | ||
df366c26 MD |
2271 | ** Function: SCM scm_spawn_thread (scm_catch_body_t body, |
2272 | void *body_data, | |
2273 | scm_catch_handler_t handler, | |
2274 | void *handler_data) | |
2275 | ||
2276 | Spawns a new thread. It does a job similar to | |
2277 | scm_call_with_new_thread but takes arguments more suitable when | |
2278 | spawning threads from application C code. | |
2279 | ||
88482b31 MD |
2280 | ** The hook scm_error_callback has been removed. It was originally |
2281 | intended as a way for the user to install his own error handler. But | |
2282 | that method works badly since it intervenes between throw and catch, | |
2283 | thereby changing the semantics of expressions like (catch #t ...). | |
2284 | The correct way to do it is to use one of the C level catch functions | |
2285 | in throw.c: scm_internal_catch/lazy_catch/stack_catch. | |
2286 | ||
3a97e020 MD |
2287 | ** Removed functions: |
2288 | ||
2289 | scm_obj_length, scm_list_length, scm_list_append, scm_list_append_x, | |
2290 | scm_list_reverse, scm_list_reverse_x | |
2291 | ||
2292 | ** New macros: SCM_LISTn where n is one of the integers 0-9. | |
2293 | ||
2294 | These can be used for pretty list creation from C. The idea is taken | |
2295 | from Erick Gallesio's STk. | |
2296 | ||
298aa6e3 MD |
2297 | ** scm_array_map renamed to scm_array_map_x |
2298 | ||
527da704 MD |
2299 | ** mbstrings are now removed |
2300 | ||
2301 | This means that the type codes scm_tc7_mb_string and | |
2302 | scm_tc7_mb_substring has been removed. | |
2303 | ||
8cd57bd0 JB |
2304 | ** scm_gen_putc, scm_gen_puts, scm_gen_write, and scm_gen_getc have changed. |
2305 | ||
2306 | Since we no longer support multi-byte strings, these I/O functions | |
2307 | have been simplified, and renamed. Here are their old names, and | |
2308 | their new names and arguments: | |
2309 | ||
2310 | scm_gen_putc -> void scm_putc (int c, SCM port); | |
2311 | scm_gen_puts -> void scm_puts (char *s, SCM port); | |
2312 | scm_gen_write -> void scm_lfwrite (char *ptr, scm_sizet size, SCM port); | |
2313 | scm_gen_getc -> void scm_getc (SCM port); | |
2314 | ||
2315 | ||
527da704 MD |
2316 | ** The macros SCM_TYP7D and SCM_TYP7SD has been removed. |
2317 | ||
2318 | ** The macro SCM_TYP7S has taken the role of the old SCM_TYP7D | |
2319 | ||
2320 | SCM_TYP7S now masks away the bit which distinguishes substrings from | |
2321 | strings. | |
2322 | ||
660f41fa MD |
2323 | ** scm_catch_body_t: Backward incompatible change! |
2324 | ||
2325 | Body functions to scm_internal_catch and friends do not any longer | |
2326 | take a second argument. This is because it is no longer possible to | |
2327 | pass a #f arg to catch. | |
2328 | ||
a8e05009 JB |
2329 | ** Calls to scm_protect_object and scm_unprotect now nest properly. |
2330 | ||
2331 | The function scm_protect_object protects its argument from being freed | |
2332 | by the garbage collector. scm_unprotect_object removes that | |
2333 | protection. | |
2334 | ||
2335 | These functions now nest properly. That is, for every object O, there | |
2336 | is a counter which scm_protect_object(O) increments and | |
2337 | scm_unprotect_object(O) decrements, if the counter is greater than | |
2338 | zero. Every object's counter is zero when it is first created. If an | |
2339 | object's counter is greater than zero, the garbage collector will not | |
2340 | reclaim its storage. | |
2341 | ||
2342 | This allows you to use scm_protect_object in your code without | |
2343 | worrying that some other function you call will call | |
2344 | scm_unprotect_object, and allow it to be freed. Assuming that the | |
2345 | functions you call are well-behaved, and unprotect only those objects | |
2346 | they protect, you can follow the same rule and have confidence that | |
2347 | objects will be freed only at appropriate times. | |
2348 | ||
c484bf7f JB |
2349 | \f |
2350 | Changes in Guile 1.2 (released Tuesday, June 24 1997): | |
cf78e9e8 | 2351 | |
737c9113 JB |
2352 | * Changes to the distribution |
2353 | ||
832b09ed JB |
2354 | ** Nightly snapshots are now available from ftp.red-bean.com. |
2355 | The old server, ftp.cyclic.com, has been relinquished to its rightful | |
2356 | owner. | |
2357 | ||
2358 | Nightly snapshots of the Guile development sources are now available via | |
2359 | anonymous FTP from ftp.red-bean.com, as /pub/guile/guile-snap.tar.gz. | |
2360 | ||
2361 | Via the web, that's: ftp://ftp.red-bean.com/pub/guile/guile-snap.tar.gz | |
2362 | For getit, that's: ftp.red-bean.com:/pub/guile/guile-snap.tar.gz | |
2363 | ||
0fcab5ed JB |
2364 | ** To run Guile without installing it, the procedure has changed a bit. |
2365 | ||
2366 | If you used a separate build directory to compile Guile, you'll need | |
2367 | to include the build directory in SCHEME_LOAD_PATH, as well as the | |
2368 | source directory. See the `INSTALL' file for examples. | |
2369 | ||
737c9113 JB |
2370 | * Changes to the procedure for linking libguile with your programs |
2371 | ||
94982a4e JB |
2372 | ** The standard Guile load path for Scheme code now includes |
2373 | $(datadir)/guile (usually /usr/local/share/guile). This means that | |
2374 | you can install your own Scheme files there, and Guile will find them. | |
2375 | (Previous versions of Guile only checked a directory whose name | |
2376 | contained the Guile version number, so you had to re-install or move | |
2377 | your Scheme sources each time you installed a fresh version of Guile.) | |
2378 | ||
2379 | The load path also includes $(datadir)/guile/site; we recommend | |
2380 | putting individual Scheme files there. If you want to install a | |
2381 | package with multiple source files, create a directory for them under | |
2382 | $(datadir)/guile. | |
2383 | ||
2384 | ** Guile 1.2 will now use the Rx regular expression library, if it is | |
2385 | installed on your system. When you are linking libguile into your own | |
2386 | programs, this means you will have to link against -lguile, -lqt (if | |
2387 | you configured Guile with thread support), and -lrx. | |
27590f82 JB |
2388 | |
2389 | If you are using autoconf to generate configuration scripts for your | |
2390 | application, the following lines should suffice to add the appropriate | |
2391 | libraries to your link command: | |
2392 | ||
2393 | ### Find Rx, quickthreads and libguile. | |
2394 | AC_CHECK_LIB(rx, main) | |
2395 | AC_CHECK_LIB(qt, main) | |
2396 | AC_CHECK_LIB(guile, scm_shell) | |
2397 | ||
94982a4e JB |
2398 | The Guile 1.2 distribution does not contain sources for the Rx |
2399 | library, as Guile 1.0 did. If you want to use Rx, you'll need to | |
2400 | retrieve it from a GNU FTP site and install it separately. | |
2401 | ||
b83b8bee JB |
2402 | * Changes to Scheme functions and syntax |
2403 | ||
e035e7e6 MV |
2404 | ** The dynamic linking features of Guile are now enabled by default. |
2405 | You can disable them by giving the `--disable-dynamic-linking' option | |
2406 | to configure. | |
2407 | ||
e035e7e6 MV |
2408 | (dynamic-link FILENAME) |
2409 | ||
2410 | Find the object file denoted by FILENAME (a string) and link it | |
2411 | into the running Guile application. When everything works out, | |
2412 | return a Scheme object suitable for representing the linked object | |
2413 | file. Otherwise an error is thrown. How object files are | |
2414 | searched is system dependent. | |
2415 | ||
2416 | (dynamic-object? VAL) | |
2417 | ||
2418 | Determine whether VAL represents a dynamically linked object file. | |
2419 | ||
2420 | (dynamic-unlink DYNOBJ) | |
2421 | ||
2422 | Unlink the indicated object file from the application. DYNOBJ | |
2423 | should be one of the values returned by `dynamic-link'. | |
2424 | ||
2425 | (dynamic-func FUNCTION DYNOBJ) | |
2426 | ||
2427 | Search the C function indicated by FUNCTION (a string or symbol) | |
2428 | in DYNOBJ and return some Scheme object that can later be used | |
2429 | with `dynamic-call' to actually call this function. Right now, | |
2430 | these Scheme objects are formed by casting the address of the | |
2431 | function to `long' and converting this number to its Scheme | |
2432 | representation. | |
2433 | ||
2434 | (dynamic-call FUNCTION DYNOBJ) | |
2435 | ||
2436 | Call the C function indicated by FUNCTION and DYNOBJ. The | |
2437 | function is passed no arguments and its return value is ignored. | |
2438 | When FUNCTION is something returned by `dynamic-func', call that | |
2439 | function and ignore DYNOBJ. When FUNCTION is a string (or symbol, | |
2440 | etc.), look it up in DYNOBJ; this is equivalent to | |
2441 | ||
2442 | (dynamic-call (dynamic-func FUNCTION DYNOBJ) #f) | |
2443 | ||
2444 | Interrupts are deferred while the C function is executing (with | |
2445 | SCM_DEFER_INTS/SCM_ALLOW_INTS). | |
2446 | ||
2447 | (dynamic-args-call FUNCTION DYNOBJ ARGS) | |
2448 | ||
2449 | Call the C function indicated by FUNCTION and DYNOBJ, but pass it | |
2450 | some arguments and return its return value. The C function is | |
2451 | expected to take two arguments and return an `int', just like | |
2452 | `main': | |
2453 | ||
2454 | int c_func (int argc, char **argv); | |
2455 | ||
2456 | ARGS must be a list of strings and is converted into an array of | |
2457 | `char *'. The array is passed in ARGV and its size in ARGC. The | |
2458 | return value is converted to a Scheme number and returned from the | |
2459 | call to `dynamic-args-call'. | |
2460 | ||
0fcab5ed JB |
2461 | When dynamic linking is disabled or not supported on your system, |
2462 | the above functions throw errors, but they are still available. | |
2463 | ||
e035e7e6 MV |
2464 | Here is a small example that works on GNU/Linux: |
2465 | ||
2466 | (define libc-obj (dynamic-link "libc.so")) | |
2467 | (dynamic-args-call 'rand libc-obj '()) | |
2468 | ||
2469 | See the file `libguile/DYNAMIC-LINKING' for additional comments. | |
2470 | ||
27590f82 JB |
2471 | ** The #/ syntax for module names is depreciated, and will be removed |
2472 | in a future version of Guile. Instead of | |
2473 | ||
2474 | #/foo/bar/baz | |
2475 | ||
2476 | instead write | |
2477 | ||
2478 | (foo bar baz) | |
2479 | ||
2480 | The latter syntax is more consistent with existing Lisp practice. | |
2481 | ||
5dade857 MV |
2482 | ** Guile now does fancier printing of structures. Structures are the |
2483 | underlying implementation for records, which in turn are used to | |
2484 | implement modules, so all of these object now print differently and in | |
2485 | a more informative way. | |
2486 | ||
161029df JB |
2487 | The Scheme printer will examine the builtin variable *struct-printer* |
2488 | whenever it needs to print a structure object. When this variable is | |
2489 | not `#f' it is deemed to be a procedure and will be applied to the | |
2490 | structure object and the output port. When *struct-printer* is `#f' | |
2491 | or the procedure return `#f' the structure object will be printed in | |
2492 | the boring #<struct 80458270> form. | |
5dade857 MV |
2493 | |
2494 | This hook is used by some routines in ice-9/boot-9.scm to implement | |
2495 | type specific printing routines. Please read the comments there about | |
2496 | "printing structs". | |
2497 | ||
2498 | One of the more specific uses of structs are records. The printing | |
2499 | procedure that could be passed to MAKE-RECORD-TYPE is now actually | |
2500 | called. It should behave like a *struct-printer* procedure (described | |
2501 | above). | |
2502 | ||
b83b8bee JB |
2503 | ** Guile now supports a new R4RS-compliant syntax for keywords. A |
2504 | token of the form #:NAME, where NAME has the same syntax as a Scheme | |
2505 | symbol, is the external representation of the keyword named NAME. | |
2506 | Keyword objects print using this syntax as well, so values containing | |
1e5afba0 JB |
2507 | keyword objects can be read back into Guile. When used in an |
2508 | expression, keywords are self-quoting objects. | |
b83b8bee JB |
2509 | |
2510 | Guile suports this read syntax, and uses this print syntax, regardless | |
2511 | of the current setting of the `keyword' read option. The `keyword' | |
2512 | read option only controls whether Guile recognizes the `:NAME' syntax, | |
2513 | which is incompatible with R4RS. (R4RS says such token represent | |
2514 | symbols.) | |
737c9113 JB |
2515 | |
2516 | ** Guile has regular expression support again. Guile 1.0 included | |
2517 | functions for matching regular expressions, based on the Rx library. | |
2518 | In Guile 1.1, the Guile/Rx interface was removed to simplify the | |
2519 | distribution, and thus Guile had no regular expression support. Guile | |
94982a4e JB |
2520 | 1.2 again supports the most commonly used functions, and supports all |
2521 | of SCSH's regular expression functions. | |
2409cdfa | 2522 | |
94982a4e JB |
2523 | If your system does not include a POSIX regular expression library, |
2524 | and you have not linked Guile with a third-party regexp library such as | |
2525 | Rx, these functions will not be available. You can tell whether your | |
2526 | Guile installation includes regular expression support by checking | |
2527 | whether the `*features*' list includes the `regex' symbol. | |
737c9113 | 2528 | |
94982a4e | 2529 | *** regexp functions |
161029df | 2530 | |
94982a4e JB |
2531 | By default, Guile supports POSIX extended regular expressions. That |
2532 | means that the characters `(', `)', `+' and `?' are special, and must | |
2533 | be escaped if you wish to match the literal characters. | |
e1a191a8 | 2534 | |
94982a4e JB |
2535 | This regular expression interface was modeled after that implemented |
2536 | by SCSH, the Scheme Shell. It is intended to be upwardly compatible | |
2537 | with SCSH regular expressions. | |
2538 | ||
2539 | **** Function: string-match PATTERN STR [START] | |
2540 | Compile the string PATTERN into a regular expression and compare | |
2541 | it with STR. The optional numeric argument START specifies the | |
2542 | position of STR at which to begin matching. | |
2543 | ||
2544 | `string-match' returns a "match structure" which describes what, | |
2545 | if anything, was matched by the regular expression. *Note Match | |
2546 | Structures::. If STR does not match PATTERN at all, | |
2547 | `string-match' returns `#f'. | |
2548 | ||
2549 | Each time `string-match' is called, it must compile its PATTERN | |
2550 | argument into a regular expression structure. This operation is | |
2551 | expensive, which makes `string-match' inefficient if the same regular | |
2552 | expression is used several times (for example, in a loop). For better | |
2553 | performance, you can compile a regular expression in advance and then | |
2554 | match strings against the compiled regexp. | |
2555 | ||
2556 | **** Function: make-regexp STR [FLAGS] | |
2557 | Compile the regular expression described by STR, and return the | |
2558 | compiled regexp structure. If STR does not describe a legal | |
2559 | regular expression, `make-regexp' throws a | |
2560 | `regular-expression-syntax' error. | |
2561 | ||
2562 | FLAGS may be the bitwise-or of one or more of the following: | |
2563 | ||
2564 | **** Constant: regexp/extended | |
2565 | Use POSIX Extended Regular Expression syntax when interpreting | |
2566 | STR. If not set, POSIX Basic Regular Expression syntax is used. | |
2567 | If the FLAGS argument is omitted, we assume regexp/extended. | |
2568 | ||
2569 | **** Constant: regexp/icase | |
2570 | Do not differentiate case. Subsequent searches using the | |
2571 | returned regular expression will be case insensitive. | |
2572 | ||
2573 | **** Constant: regexp/newline | |
2574 | Match-any-character operators don't match a newline. | |
2575 | ||
2576 | A non-matching list ([^...]) not containing a newline matches a | |
2577 | newline. | |
2578 | ||
2579 | Match-beginning-of-line operator (^) matches the empty string | |
2580 | immediately after a newline, regardless of whether the FLAGS | |
2581 | passed to regexp-exec contain regexp/notbol. | |
2582 | ||
2583 | Match-end-of-line operator ($) matches the empty string | |
2584 | immediately before a newline, regardless of whether the FLAGS | |
2585 | passed to regexp-exec contain regexp/noteol. | |
2586 | ||
2587 | **** Function: regexp-exec REGEXP STR [START [FLAGS]] | |
2588 | Match the compiled regular expression REGEXP against `str'. If | |
2589 | the optional integer START argument is provided, begin matching | |
2590 | from that position in the string. Return a match structure | |
2591 | describing the results of the match, or `#f' if no match could be | |
2592 | found. | |
2593 | ||
2594 | FLAGS may be the bitwise-or of one or more of the following: | |
2595 | ||
2596 | **** Constant: regexp/notbol | |
2597 | The match-beginning-of-line operator always fails to match (but | |
2598 | see the compilation flag regexp/newline above) This flag may be | |
2599 | used when different portions of a string are passed to | |
2600 | regexp-exec and the beginning of the string should not be | |
2601 | interpreted as the beginning of the line. | |
2602 | ||
2603 | **** Constant: regexp/noteol | |
2604 | The match-end-of-line operator always fails to match (but see the | |
2605 | compilation flag regexp/newline above) | |
2606 | ||
2607 | **** Function: regexp? OBJ | |
2608 | Return `#t' if OBJ is a compiled regular expression, or `#f' | |
2609 | otherwise. | |
2610 | ||
2611 | Regular expressions are commonly used to find patterns in one string | |
2612 | and replace them with the contents of another string. | |
2613 | ||
2614 | **** Function: regexp-substitute PORT MATCH [ITEM...] | |
2615 | Write to the output port PORT selected contents of the match | |
2616 | structure MATCH. Each ITEM specifies what should be written, and | |
2617 | may be one of the following arguments: | |
2618 | ||
2619 | * A string. String arguments are written out verbatim. | |
2620 | ||
2621 | * An integer. The submatch with that number is written. | |
2622 | ||
2623 | * The symbol `pre'. The portion of the matched string preceding | |
2624 | the regexp match is written. | |
2625 | ||
2626 | * The symbol `post'. The portion of the matched string | |
2627 | following the regexp match is written. | |
2628 | ||
2629 | PORT may be `#f', in which case nothing is written; instead, | |
2630 | `regexp-substitute' constructs a string from the specified ITEMs | |
2631 | and returns that. | |
2632 | ||
2633 | **** Function: regexp-substitute/global PORT REGEXP TARGET [ITEM...] | |
2634 | Similar to `regexp-substitute', but can be used to perform global | |
2635 | substitutions on STR. Instead of taking a match structure as an | |
2636 | argument, `regexp-substitute/global' takes two string arguments: a | |
2637 | REGEXP string describing a regular expression, and a TARGET string | |
2638 | which should be matched against this regular expression. | |
2639 | ||
2640 | Each ITEM behaves as in REGEXP-SUBSTITUTE, with the following | |
2641 | exceptions: | |
2642 | ||
2643 | * A function may be supplied. When this function is called, it | |
2644 | will be passed one argument: a match structure for a given | |
2645 | regular expression match. It should return a string to be | |
2646 | written out to PORT. | |
2647 | ||
2648 | * The `post' symbol causes `regexp-substitute/global' to recurse | |
2649 | on the unmatched portion of STR. This *must* be supplied in | |
2650 | order to perform global search-and-replace on STR; if it is | |
2651 | not present among the ITEMs, then `regexp-substitute/global' | |
2652 | will return after processing a single match. | |
2653 | ||
2654 | *** Match Structures | |
2655 | ||
2656 | A "match structure" is the object returned by `string-match' and | |
2657 | `regexp-exec'. It describes which portion of a string, if any, matched | |
2658 | the given regular expression. Match structures include: a reference to | |
2659 | the string that was checked for matches; the starting and ending | |
2660 | positions of the regexp match; and, if the regexp included any | |
2661 | parenthesized subexpressions, the starting and ending positions of each | |
2662 | submatch. | |
2663 | ||
2664 | In each of the regexp match functions described below, the `match' | |
2665 | argument must be a match structure returned by a previous call to | |
2666 | `string-match' or `regexp-exec'. Most of these functions return some | |
2667 | information about the original target string that was matched against a | |
2668 | regular expression; we will call that string TARGET for easy reference. | |
2669 | ||
2670 | **** Function: regexp-match? OBJ | |
2671 | Return `#t' if OBJ is a match structure returned by a previous | |
2672 | call to `regexp-exec', or `#f' otherwise. | |
2673 | ||
2674 | **** Function: match:substring MATCH [N] | |
2675 | Return the portion of TARGET matched by subexpression number N. | |
2676 | Submatch 0 (the default) represents the entire regexp match. If | |
2677 | the regular expression as a whole matched, but the subexpression | |
2678 | number N did not match, return `#f'. | |
2679 | ||
2680 | **** Function: match:start MATCH [N] | |
2681 | Return the starting position of submatch number N. | |
2682 | ||
2683 | **** Function: match:end MATCH [N] | |
2684 | Return the ending position of submatch number N. | |
2685 | ||
2686 | **** Function: match:prefix MATCH | |
2687 | Return the unmatched portion of TARGET preceding the regexp match. | |
2688 | ||
2689 | **** Function: match:suffix MATCH | |
2690 | Return the unmatched portion of TARGET following the regexp match. | |
2691 | ||
2692 | **** Function: match:count MATCH | |
2693 | Return the number of parenthesized subexpressions from MATCH. | |
2694 | Note that the entire regular expression match itself counts as a | |
2695 | subexpression, and failed submatches are included in the count. | |
2696 | ||
2697 | **** Function: match:string MATCH | |
2698 | Return the original TARGET string. | |
2699 | ||
2700 | *** Backslash Escapes | |
2701 | ||
2702 | Sometimes you will want a regexp to match characters like `*' or `$' | |
2703 | exactly. For example, to check whether a particular string represents | |
2704 | a menu entry from an Info node, it would be useful to match it against | |
2705 | a regexp like `^* [^:]*::'. However, this won't work; because the | |
2706 | asterisk is a metacharacter, it won't match the `*' at the beginning of | |
2707 | the string. In this case, we want to make the first asterisk un-magic. | |
2708 | ||
2709 | You can do this by preceding the metacharacter with a backslash | |
2710 | character `\'. (This is also called "quoting" the metacharacter, and | |
2711 | is known as a "backslash escape".) When Guile sees a backslash in a | |
2712 | regular expression, it considers the following glyph to be an ordinary | |
2713 | character, no matter what special meaning it would ordinarily have. | |
2714 | Therefore, we can make the above example work by changing the regexp to | |
2715 | `^\* [^:]*::'. The `\*' sequence tells the regular expression engine | |
2716 | to match only a single asterisk in the target string. | |
2717 | ||
2718 | Since the backslash is itself a metacharacter, you may force a | |
2719 | regexp to match a backslash in the target string by preceding the | |
2720 | backslash with itself. For example, to find variable references in a | |
2721 | TeX program, you might want to find occurrences of the string `\let\' | |
2722 | followed by any number of alphabetic characters. The regular expression | |
2723 | `\\let\\[A-Za-z]*' would do this: the double backslashes in the regexp | |
2724 | each match a single backslash in the target string. | |
2725 | ||
2726 | **** Function: regexp-quote STR | |
2727 | Quote each special character found in STR with a backslash, and | |
2728 | return the resulting string. | |
2729 | ||
2730 | *Very important:* Using backslash escapes in Guile source code (as | |
2731 | in Emacs Lisp or C) can be tricky, because the backslash character has | |
2732 | special meaning for the Guile reader. For example, if Guile encounters | |
2733 | the character sequence `\n' in the middle of a string while processing | |
2734 | Scheme code, it replaces those characters with a newline character. | |
2735 | Similarly, the character sequence `\t' is replaced by a horizontal tab. | |
2736 | Several of these "escape sequences" are processed by the Guile reader | |
2737 | before your code is executed. Unrecognized escape sequences are | |
2738 | ignored: if the characters `\*' appear in a string, they will be | |
2739 | translated to the single character `*'. | |
2740 | ||
2741 | This translation is obviously undesirable for regular expressions, | |
2742 | since we want to be able to include backslashes in a string in order to | |
2743 | escape regexp metacharacters. Therefore, to make sure that a backslash | |
2744 | is preserved in a string in your Guile program, you must use *two* | |
2745 | consecutive backslashes: | |
2746 | ||
2747 | (define Info-menu-entry-pattern (make-regexp "^\\* [^:]*")) | |
2748 | ||
2749 | The string in this example is preprocessed by the Guile reader before | |
2750 | any code is executed. The resulting argument to `make-regexp' is the | |
2751 | string `^\* [^:]*', which is what we really want. | |
2752 | ||
2753 | This also means that in order to write a regular expression that | |
2754 | matches a single backslash character, the regular expression string in | |
2755 | the source code must include *four* backslashes. Each consecutive pair | |
2756 | of backslashes gets translated by the Guile reader to a single | |
2757 | backslash, and the resulting double-backslash is interpreted by the | |
2758 | regexp engine as matching a single backslash character. Hence: | |
2759 | ||
2760 | (define tex-variable-pattern (make-regexp "\\\\let\\\\=[A-Za-z]*")) | |
2761 | ||
2762 | The reason for the unwieldiness of this syntax is historical. Both | |
2763 | regular expression pattern matchers and Unix string processing systems | |
2764 | have traditionally used backslashes with the special meanings described | |
2765 | above. The POSIX regular expression specification and ANSI C standard | |
2766 | both require these semantics. Attempting to abandon either convention | |
2767 | would cause other kinds of compatibility problems, possibly more severe | |
2768 | ones. Therefore, without extending the Scheme reader to support | |
2769 | strings with different quoting conventions (an ungainly and confusing | |
2770 | extension when implemented in other languages), we must adhere to this | |
2771 | cumbersome escape syntax. | |
2772 | ||
7ad3c1e7 GH |
2773 | * Changes to the gh_ interface |
2774 | ||
2775 | * Changes to the scm_ interface | |
2776 | ||
2777 | * Changes to system call interfaces: | |
94982a4e | 2778 | |
7ad3c1e7 | 2779 | ** The value returned by `raise' is now unspecified. It throws an exception |
e1a191a8 GH |
2780 | if an error occurs. |
2781 | ||
94982a4e | 2782 | *** A new procedure `sigaction' can be used to install signal handlers |
115b09a5 GH |
2783 | |
2784 | (sigaction signum [action] [flags]) | |
2785 | ||
2786 | signum is the signal number, which can be specified using the value | |
2787 | of SIGINT etc. | |
2788 | ||
2789 | If action is omitted, sigaction returns a pair: the CAR is the current | |
2790 | signal hander, which will be either an integer with the value SIG_DFL | |
2791 | (default action) or SIG_IGN (ignore), or the Scheme procedure which | |
2792 | handles the signal, or #f if a non-Scheme procedure handles the | |
2793 | signal. The CDR contains the current sigaction flags for the handler. | |
2794 | ||
2795 | If action is provided, it is installed as the new handler for signum. | |
2796 | action can be a Scheme procedure taking one argument, or the value of | |
2797 | SIG_DFL (default action) or SIG_IGN (ignore), or #f to restore | |
2798 | whatever signal handler was installed before sigaction was first used. | |
2799 | Flags can optionally be specified for the new handler (SA_RESTART is | |
2800 | always used if the system provides it, so need not be specified.) The | |
2801 | return value is a pair with information about the old handler as | |
2802 | described above. | |
2803 | ||
2804 | This interface does not provide access to the "signal blocking" | |
2805 | facility. Maybe this is not needed, since the thread support may | |
2806 | provide solutions to the problem of consistent access to data | |
2807 | structures. | |
e1a191a8 | 2808 | |
94982a4e | 2809 | *** A new procedure `flush-all-ports' is equivalent to running |
89ea5b7c GH |
2810 | `force-output' on every port open for output. |
2811 | ||
94982a4e JB |
2812 | ** Guile now provides information on how it was built, via the new |
2813 | global variable, %guile-build-info. This variable records the values | |
2814 | of the standard GNU makefile directory variables as an assocation | |
2815 | list, mapping variable names (symbols) onto directory paths (strings). | |
2816 | For example, to find out where the Guile link libraries were | |
2817 | installed, you can say: | |
2818 | ||
2819 | guile -c "(display (assq-ref %guile-build-info 'libdir)) (newline)" | |
2820 | ||
2821 | ||
2822 | * Changes to the scm_ interface | |
2823 | ||
2824 | ** The new function scm_handle_by_message_noexit is just like the | |
2825 | existing scm_handle_by_message function, except that it doesn't call | |
2826 | exit to terminate the process. Instead, it prints a message and just | |
2827 | returns #f. This might be a more appropriate catch-all handler for | |
2828 | new dynamic roots and threads. | |
2829 | ||
cf78e9e8 | 2830 | \f |
c484bf7f | 2831 | Changes in Guile 1.1 (released Friday, May 16 1997): |
f3b1485f JB |
2832 | |
2833 | * Changes to the distribution. | |
2834 | ||
2835 | The Guile 1.0 distribution has been split up into several smaller | |
2836 | pieces: | |
2837 | guile-core --- the Guile interpreter itself. | |
2838 | guile-tcltk --- the interface between the Guile interpreter and | |
2839 | Tcl/Tk; Tcl is an interpreter for a stringy language, and Tk | |
2840 | is a toolkit for building graphical user interfaces. | |
2841 | guile-rgx-ctax --- the interface between Guile and the Rx regular | |
2842 | expression matcher, and the translator for the Ctax | |
2843 | programming language. These are packaged together because the | |
2844 | Ctax translator uses Rx to parse Ctax source code. | |
2845 | ||
095936d2 JB |
2846 | This NEWS file describes the changes made to guile-core since the 1.0 |
2847 | release. | |
2848 | ||
48d224d7 JB |
2849 | We no longer distribute the documentation, since it was either out of |
2850 | date, or incomplete. As soon as we have current documentation, we | |
2851 | will distribute it. | |
2852 | ||
0fcab5ed JB |
2853 | |
2854 | ||
f3b1485f JB |
2855 | * Changes to the stand-alone interpreter |
2856 | ||
48d224d7 JB |
2857 | ** guile now accepts command-line arguments compatible with SCSH, Olin |
2858 | Shivers' Scheme Shell. | |
2859 | ||
2860 | In general, arguments are evaluated from left to right, but there are | |
2861 | exceptions. The following switches stop argument processing, and | |
2862 | stash all remaining command-line arguments as the value returned by | |
2863 | the (command-line) function. | |
2864 | -s SCRIPT load Scheme source code from FILE, and exit | |
2865 | -c EXPR evalute Scheme expression EXPR, and exit | |
2866 | -- stop scanning arguments; run interactively | |
2867 | ||
2868 | The switches below are processed as they are encountered. | |
2869 | -l FILE load Scheme source code from FILE | |
2870 | -e FUNCTION after reading script, apply FUNCTION to | |
2871 | command line arguments | |
2872 | -ds do -s script at this point | |
2873 | --emacs enable Emacs protocol (experimental) | |
2874 | -h, --help display this help and exit | |
2875 | -v, --version display version information and exit | |
2876 | \ read arguments from following script lines | |
2877 | ||
2878 | So, for example, here is a Guile script named `ekko' (thanks, Olin) | |
2879 | which re-implements the traditional "echo" command: | |
2880 | ||
2881 | #!/usr/local/bin/guile -s | |
2882 | !# | |
2883 | (define (main args) | |
2884 | (map (lambda (arg) (display arg) (display " ")) | |
2885 | (cdr args)) | |
2886 | (newline)) | |
2887 | ||
2888 | (main (command-line)) | |
2889 | ||
2890 | Suppose we invoke this script as follows: | |
2891 | ||
2892 | ekko a speckled gecko | |
2893 | ||
2894 | Through the magic of Unix script processing (triggered by the `#!' | |
2895 | token at the top of the file), /usr/local/bin/guile receives the | |
2896 | following list of command-line arguments: | |
2897 | ||
2898 | ("-s" "./ekko" "a" "speckled" "gecko") | |
2899 | ||
2900 | Unix inserts the name of the script after the argument specified on | |
2901 | the first line of the file (in this case, "-s"), and then follows that | |
2902 | with the arguments given to the script. Guile loads the script, which | |
2903 | defines the `main' function, and then applies it to the list of | |
2904 | remaining command-line arguments, ("a" "speckled" "gecko"). | |
2905 | ||
095936d2 JB |
2906 | In Unix, the first line of a script file must take the following form: |
2907 | ||
2908 | #!INTERPRETER ARGUMENT | |
2909 | ||
2910 | where INTERPRETER is the absolute filename of the interpreter | |
2911 | executable, and ARGUMENT is a single command-line argument to pass to | |
2912 | the interpreter. | |
2913 | ||
2914 | You may only pass one argument to the interpreter, and its length is | |
2915 | limited. These restrictions can be annoying to work around, so Guile | |
2916 | provides a general mechanism (borrowed from, and compatible with, | |
2917 | SCSH) for circumventing them. | |
2918 | ||
2919 | If the ARGUMENT in a Guile script is a single backslash character, | |
2920 | `\', Guile will open the script file, parse arguments from its second | |
2921 | and subsequent lines, and replace the `\' with them. So, for example, | |
2922 | here is another implementation of the `ekko' script: | |
2923 | ||
2924 | #!/usr/local/bin/guile \ | |
2925 | -e main -s | |
2926 | !# | |
2927 | (define (main args) | |
2928 | (for-each (lambda (arg) (display arg) (display " ")) | |
2929 | (cdr args)) | |
2930 | (newline)) | |
2931 | ||
2932 | If the user invokes this script as follows: | |
2933 | ||
2934 | ekko a speckled gecko | |
2935 | ||
2936 | Unix expands this into | |
2937 | ||
2938 | /usr/local/bin/guile \ ekko a speckled gecko | |
2939 | ||
2940 | When Guile sees the `\' argument, it replaces it with the arguments | |
2941 | read from the second line of the script, producing: | |
2942 | ||
2943 | /usr/local/bin/guile -e main -s ekko a speckled gecko | |
2944 | ||
2945 | This tells Guile to load the `ekko' script, and apply the function | |
2946 | `main' to the argument list ("a" "speckled" "gecko"). | |
2947 | ||
2948 | Here is how Guile parses the command-line arguments: | |
2949 | - Each space character terminates an argument. This means that two | |
2950 | spaces in a row introduce an empty-string argument. | |
2951 | - The tab character is not permitted (unless you quote it with the | |
2952 | backslash character, as described below), to avoid confusion. | |
2953 | - The newline character terminates the sequence of arguments, and will | |
2954 | also terminate a final non-empty argument. (However, a newline | |
2955 | following a space will not introduce a final empty-string argument; | |
2956 | it only terminates the argument list.) | |
2957 | - The backslash character is the escape character. It escapes | |
2958 | backslash, space, tab, and newline. The ANSI C escape sequences | |
2959 | like \n and \t are also supported. These produce argument | |
2960 | constituents; the two-character combination \n doesn't act like a | |
2961 | terminating newline. The escape sequence \NNN for exactly three | |
2962 | octal digits reads as the character whose ASCII code is NNN. As | |
2963 | above, characters produced this way are argument constituents. | |
2964 | Backslash followed by other characters is not allowed. | |
2965 | ||
48d224d7 JB |
2966 | * Changes to the procedure for linking libguile with your programs |
2967 | ||
2968 | ** Guile now builds and installs a shared guile library, if your | |
2969 | system support shared libraries. (It still builds a static library on | |
2970 | all systems.) Guile automatically detects whether your system | |
2971 | supports shared libraries. To prevent Guile from buildisg shared | |
2972 | libraries, pass the `--disable-shared' flag to the configure script. | |
2973 | ||
2974 | Guile takes longer to compile when it builds shared libraries, because | |
2975 | it must compile every file twice --- once to produce position- | |
2976 | independent object code, and once to produce normal object code. | |
2977 | ||
2978 | ** The libthreads library has been merged into libguile. | |
2979 | ||
2980 | To link a program against Guile, you now need only link against | |
2981 | -lguile and -lqt; -lthreads is no longer needed. If you are using | |
2982 | autoconf to generate configuration scripts for your application, the | |
2983 | following lines should suffice to add the appropriate libraries to | |
2984 | your link command: | |
2985 | ||
2986 | ### Find quickthreads and libguile. | |
2987 | AC_CHECK_LIB(qt, main) | |
2988 | AC_CHECK_LIB(guile, scm_shell) | |
f3b1485f JB |
2989 | |
2990 | * Changes to Scheme functions | |
2991 | ||
095936d2 JB |
2992 | ** Guile Scheme's special syntax for keyword objects is now optional, |
2993 | and disabled by default. | |
2994 | ||
2995 | The syntax variation from R4RS made it difficult to port some | |
2996 | interesting packages to Guile. The routines which accepted keyword | |
2997 | arguments (mostly in the module system) have been modified to also | |
2998 | accept symbols whose names begin with `:'. | |
2999 | ||
3000 | To change the keyword syntax, you must first import the (ice-9 debug) | |
3001 | module: | |
3002 | (use-modules (ice-9 debug)) | |
3003 | ||
3004 | Then you can enable the keyword syntax as follows: | |
3005 | (read-set! keywords 'prefix) | |
3006 | ||
3007 | To disable keyword syntax, do this: | |
3008 | (read-set! keywords #f) | |
3009 | ||
3010 | ** Many more primitive functions accept shared substrings as | |
3011 | arguments. In the past, these functions required normal, mutable | |
3012 | strings as arguments, although they never made use of this | |
3013 | restriction. | |
3014 | ||
3015 | ** The uniform array functions now operate on byte vectors. These | |
3016 | functions are `array-fill!', `serial-array-copy!', `array-copy!', | |
3017 | `serial-array-map', `array-map', `array-for-each', and | |
3018 | `array-index-map!'. | |
3019 | ||
3020 | ** The new functions `trace' and `untrace' implement simple debugging | |
3021 | support for Scheme functions. | |
3022 | ||
3023 | The `trace' function accepts any number of procedures as arguments, | |
3024 | and tells the Guile interpreter to display each procedure's name and | |
3025 | arguments each time the procedure is invoked. When invoked with no | |
3026 | arguments, `trace' returns the list of procedures currently being | |
3027 | traced. | |
3028 | ||
3029 | The `untrace' function accepts any number of procedures as arguments, | |
3030 | and tells the Guile interpreter not to trace them any more. When | |
3031 | invoked with no arguments, `untrace' untraces all curretly traced | |
3032 | procedures. | |
3033 | ||
3034 | The tracing in Guile has an advantage over most other systems: we | |
3035 | don't create new procedure objects, but mark the procedure objects | |
3036 | themselves. This means that anonymous and internal procedures can be | |
3037 | traced. | |
3038 | ||
3039 | ** The function `assert-repl-prompt' has been renamed to | |
3040 | `set-repl-prompt!'. It takes one argument, PROMPT. | |
3041 | - If PROMPT is #f, the Guile read-eval-print loop will not prompt. | |
3042 | - If PROMPT is a string, we use it as a prompt. | |
3043 | - If PROMPT is a procedure accepting no arguments, we call it, and | |
3044 | display the result as a prompt. | |
3045 | - Otherwise, we display "> ". | |
3046 | ||
3047 | ** The new function `eval-string' reads Scheme expressions from a | |
3048 | string and evaluates them, returning the value of the last expression | |
3049 | in the string. If the string contains no expressions, it returns an | |
3050 | unspecified value. | |
3051 | ||
3052 | ** The new function `thunk?' returns true iff its argument is a | |
3053 | procedure of zero arguments. | |
3054 | ||
3055 | ** `defined?' is now a builtin function, instead of syntax. This | |
3056 | means that its argument should be quoted. It returns #t iff its | |
3057 | argument is bound in the current module. | |
3058 | ||
3059 | ** The new syntax `use-modules' allows you to add new modules to your | |
3060 | environment without re-typing a complete `define-module' form. It | |
3061 | accepts any number of module names as arguments, and imports their | |
3062 | public bindings into the current module. | |
3063 | ||
3064 | ** The new function (module-defined? NAME MODULE) returns true iff | |
3065 | NAME, a symbol, is defined in MODULE, a module object. | |
3066 | ||
3067 | ** The new function `builtin-bindings' creates and returns a hash | |
3068 | table containing copies of all the root module's bindings. | |
3069 | ||
3070 | ** The new function `builtin-weak-bindings' does the same as | |
3071 | `builtin-bindings', but creates a doubly-weak hash table. | |
3072 | ||
3073 | ** The `equal?' function now considers variable objects to be | |
3074 | equivalent if they have the same name and the same value. | |
3075 | ||
3076 | ** The new function `command-line' returns the command-line arguments | |
3077 | given to Guile, as a list of strings. | |
3078 | ||
3079 | When using guile as a script interpreter, `command-line' returns the | |
3080 | script's arguments; those processed by the interpreter (like `-s' or | |
3081 | `-c') are omitted. (In other words, you get the normal, expected | |
3082 | behavior.) Any application that uses scm_shell to process its | |
3083 | command-line arguments gets this behavior as well. | |
3084 | ||
3085 | ** The new function `load-user-init' looks for a file called `.guile' | |
3086 | in the user's home directory, and loads it if it exists. This is | |
3087 | mostly for use by the code generated by scm_compile_shell_switches, | |
3088 | but we thought it might also be useful in other circumstances. | |
3089 | ||
3090 | ** The new function `log10' returns the base-10 logarithm of its | |
3091 | argument. | |
3092 | ||
3093 | ** Changes to I/O functions | |
3094 | ||
3095 | *** The functions `read', `primitive-load', `read-and-eval!', and | |
3096 | `primitive-load-path' no longer take optional arguments controlling | |
3097 | case insensitivity and a `#' parser. | |
3098 | ||
3099 | Case sensitivity is now controlled by a read option called | |
3100 | `case-insensitive'. The user can add new `#' syntaxes with the | |
3101 | `read-hash-extend' function (see below). | |
3102 | ||
3103 | *** The new function `read-hash-extend' allows the user to change the | |
3104 | syntax of Guile Scheme in a somewhat controlled way. | |
3105 | ||
3106 | (read-hash-extend CHAR PROC) | |
3107 | When parsing S-expressions, if we read a `#' character followed by | |
3108 | the character CHAR, use PROC to parse an object from the stream. | |
3109 | If PROC is #f, remove any parsing procedure registered for CHAR. | |
3110 | ||
3111 | The reader applies PROC to two arguments: CHAR and an input port. | |
3112 | ||
3113 | *** The new functions read-delimited and read-delimited! provide a | |
3114 | general mechanism for doing delimited input on streams. | |
3115 | ||
3116 | (read-delimited DELIMS [PORT HANDLE-DELIM]) | |
3117 | Read until we encounter one of the characters in DELIMS (a string), | |
3118 | or end-of-file. PORT is the input port to read from; it defaults to | |
3119 | the current input port. The HANDLE-DELIM parameter determines how | |
3120 | the terminating character is handled; it should be one of the | |
3121 | following symbols: | |
3122 | ||
3123 | 'trim omit delimiter from result | |
3124 | 'peek leave delimiter character in input stream | |
3125 | 'concat append delimiter character to returned value | |
3126 | 'split return a pair: (RESULT . TERMINATOR) | |
3127 | ||
3128 | HANDLE-DELIM defaults to 'peek. | |
3129 | ||
3130 | (read-delimited! DELIMS BUF [PORT HANDLE-DELIM START END]) | |
3131 | A side-effecting variant of `read-delimited'. | |
3132 | ||
3133 | The data is written into the string BUF at the indices in the | |
3134 | half-open interval [START, END); the default interval is the whole | |
3135 | string: START = 0 and END = (string-length BUF). The values of | |
3136 | START and END must specify a well-defined interval in BUF, i.e. | |
3137 | 0 <= START <= END <= (string-length BUF). | |
3138 | ||
3139 | It returns NBYTES, the number of bytes read. If the buffer filled | |
3140 | up without a delimiter character being found, it returns #f. If the | |
3141 | port is at EOF when the read starts, it returns the EOF object. | |
3142 | ||
3143 | If an integer is returned (i.e., the read is successfully terminated | |
3144 | by reading a delimiter character), then the HANDLE-DELIM parameter | |
3145 | determines how to handle the terminating character. It is described | |
3146 | above, and defaults to 'peek. | |
3147 | ||
3148 | (The descriptions of these functions were borrowed from the SCSH | |
3149 | manual, by Olin Shivers and Brian Carlstrom.) | |
3150 | ||
3151 | *** The `%read-delimited!' function is the primitive used to implement | |
3152 | `read-delimited' and `read-delimited!'. | |
3153 | ||
3154 | (%read-delimited! DELIMS BUF GOBBLE? [PORT START END]) | |
3155 | ||
3156 | This returns a pair of values: (TERMINATOR . NUM-READ). | |
3157 | - TERMINATOR describes why the read was terminated. If it is a | |
3158 | character or the eof object, then that is the value that terminated | |
3159 | the read. If it is #f, the function filled the buffer without finding | |
3160 | a delimiting character. | |
3161 | - NUM-READ is the number of characters read into BUF. | |
3162 | ||
3163 | If the read is successfully terminated by reading a delimiter | |
3164 | character, then the gobble? parameter determines what to do with the | |
3165 | terminating character. If true, the character is removed from the | |
3166 | input stream; if false, the character is left in the input stream | |
3167 | where a subsequent read operation will retrieve it. In either case, | |
3168 | the character is also the first value returned by the procedure call. | |
3169 | ||
3170 | (The descriptions of this function was borrowed from the SCSH manual, | |
3171 | by Olin Shivers and Brian Carlstrom.) | |
3172 | ||
3173 | *** The `read-line' and `read-line!' functions have changed; they now | |
3174 | trim the terminator by default; previously they appended it to the | |
3175 | returned string. For the old behavior, use (read-line PORT 'concat). | |
3176 | ||
3177 | *** The functions `uniform-array-read!' and `uniform-array-write!' now | |
3178 | take new optional START and END arguments, specifying the region of | |
3179 | the array to read and write. | |
3180 | ||
f348c807 JB |
3181 | *** The `ungetc-char-ready?' function has been removed. We feel it's |
3182 | inappropriate for an interface to expose implementation details this | |
3183 | way. | |
095936d2 JB |
3184 | |
3185 | ** Changes to the Unix library and system call interface | |
3186 | ||
3187 | *** The new fcntl function provides access to the Unix `fcntl' system | |
3188 | call. | |
3189 | ||
3190 | (fcntl PORT COMMAND VALUE) | |
3191 | Apply COMMAND to PORT's file descriptor, with VALUE as an argument. | |
3192 | Values for COMMAND are: | |
3193 | ||
3194 | F_DUPFD duplicate a file descriptor | |
3195 | F_GETFD read the descriptor's close-on-exec flag | |
3196 | F_SETFD set the descriptor's close-on-exec flag to VALUE | |
3197 | F_GETFL read the descriptor's flags, as set on open | |
3198 | F_SETFL set the descriptor's flags, as set on open to VALUE | |
3199 | F_GETOWN return the process ID of a socket's owner, for SIGIO | |
3200 | F_SETOWN set the process that owns a socket to VALUE, for SIGIO | |
3201 | FD_CLOEXEC not sure what this is | |
3202 | ||
3203 | For details, see the documentation for the fcntl system call. | |
3204 | ||
3205 | *** The arguments to `select' have changed, for compatibility with | |
3206 | SCSH. The TIMEOUT parameter may now be non-integral, yielding the | |
3207 | expected behavior. The MILLISECONDS parameter has been changed to | |
3208 | MICROSECONDS, to more closely resemble the underlying system call. | |
3209 | The RVEC, WVEC, and EVEC arguments can now be vectors; the type of the | |
3210 | corresponding return set will be the same. | |
3211 | ||
3212 | *** The arguments to the `mknod' system call have changed. They are | |
3213 | now: | |
3214 | ||
3215 | (mknod PATH TYPE PERMS DEV) | |
3216 | Create a new file (`node') in the file system. PATH is the name of | |
3217 | the file to create. TYPE is the kind of file to create; it should | |
3218 | be 'fifo, 'block-special, or 'char-special. PERMS specifies the | |
3219 | permission bits to give the newly created file. If TYPE is | |
3220 | 'block-special or 'char-special, DEV specifies which device the | |
3221 | special file refers to; its interpretation depends on the kind of | |
3222 | special file being created. | |
3223 | ||
3224 | *** The `fork' function has been renamed to `primitive-fork', to avoid | |
3225 | clashing with various SCSH forks. | |
3226 | ||
3227 | *** The `recv' and `recvfrom' functions have been renamed to `recv!' | |
3228 | and `recvfrom!'. They no longer accept a size for a second argument; | |
3229 | you must pass a string to hold the received value. They no longer | |
3230 | return the buffer. Instead, `recv' returns the length of the message | |
3231 | received, and `recvfrom' returns a pair containing the packet's length | |
3232 | and originating address. | |
3233 | ||
3234 | *** The file descriptor datatype has been removed, as have the | |
3235 | `read-fd', `write-fd', `close', `lseek', and `dup' functions. | |
3236 | We plan to replace these functions with a SCSH-compatible interface. | |
3237 | ||
3238 | *** The `create' function has been removed; it's just a special case | |
3239 | of `open'. | |
3240 | ||
3241 | *** There are new functions to break down process termination status | |
3242 | values. In the descriptions below, STATUS is a value returned by | |
3243 | `waitpid'. | |
3244 | ||
3245 | (status:exit-val STATUS) | |
3246 | If the child process exited normally, this function returns the exit | |
3247 | code for the child process (i.e., the value passed to exit, or | |
3248 | returned from main). If the child process did not exit normally, | |
3249 | this function returns #f. | |
3250 | ||
3251 | (status:stop-sig STATUS) | |
3252 | If the child process was suspended by a signal, this function | |
3253 | returns the signal that suspended the child. Otherwise, it returns | |
3254 | #f. | |
3255 | ||
3256 | (status:term-sig STATUS) | |
3257 | If the child process terminated abnormally, this function returns | |
3258 | the signal that terminated the child. Otherwise, this function | |
3259 | returns false. | |
3260 | ||
3261 | POSIX promises that exactly one of these functions will return true on | |
3262 | a valid STATUS value. | |
3263 | ||
3264 | These functions are compatible with SCSH. | |
3265 | ||
3266 | *** There are new accessors and setters for the broken-out time vectors | |
48d224d7 JB |
3267 | returned by `localtime', `gmtime', and that ilk. They are: |
3268 | ||
3269 | Component Accessor Setter | |
3270 | ========================= ============ ============ | |
3271 | seconds tm:sec set-tm:sec | |
3272 | minutes tm:min set-tm:min | |
3273 | hours tm:hour set-tm:hour | |
3274 | day of the month tm:mday set-tm:mday | |
3275 | month tm:mon set-tm:mon | |
3276 | year tm:year set-tm:year | |
3277 | day of the week tm:wday set-tm:wday | |
3278 | day in the year tm:yday set-tm:yday | |
3279 | daylight saving time tm:isdst set-tm:isdst | |
3280 | GMT offset, seconds tm:gmtoff set-tm:gmtoff | |
3281 | name of time zone tm:zone set-tm:zone | |
3282 | ||
095936d2 JB |
3283 | *** There are new accessors for the vectors returned by `uname', |
3284 | describing the host system: | |
48d224d7 JB |
3285 | |
3286 | Component Accessor | |
3287 | ============================================== ================ | |
3288 | name of the operating system implementation utsname:sysname | |
3289 | network name of this machine utsname:nodename | |
3290 | release level of the operating system utsname:release | |
3291 | version level of the operating system utsname:version | |
3292 | machine hardware platform utsname:machine | |
3293 | ||
095936d2 JB |
3294 | *** There are new accessors for the vectors returned by `getpw', |
3295 | `getpwnam', `getpwuid', and `getpwent', describing entries from the | |
3296 | system's user database: | |
3297 | ||
3298 | Component Accessor | |
3299 | ====================== ================= | |
3300 | user name passwd:name | |
3301 | user password passwd:passwd | |
3302 | user id passwd:uid | |
3303 | group id passwd:gid | |
3304 | real name passwd:gecos | |
3305 | home directory passwd:dir | |
3306 | shell program passwd:shell | |
3307 | ||
3308 | *** There are new accessors for the vectors returned by `getgr', | |
3309 | `getgrnam', `getgrgid', and `getgrent', describing entries from the | |
3310 | system's group database: | |
3311 | ||
3312 | Component Accessor | |
3313 | ======================= ============ | |
3314 | group name group:name | |
3315 | group password group:passwd | |
3316 | group id group:gid | |
3317 | group members group:mem | |
3318 | ||
3319 | *** There are new accessors for the vectors returned by `gethost', | |
3320 | `gethostbyaddr', `gethostbyname', and `gethostent', describing | |
3321 | internet hosts: | |
3322 | ||
3323 | Component Accessor | |
3324 | ========================= =============== | |
3325 | official name of host hostent:name | |
3326 | alias list hostent:aliases | |
3327 | host address type hostent:addrtype | |
3328 | length of address hostent:length | |
3329 | list of addresses hostent:addr-list | |
3330 | ||
3331 | *** There are new accessors for the vectors returned by `getnet', | |
3332 | `getnetbyaddr', `getnetbyname', and `getnetent', describing internet | |
3333 | networks: | |
3334 | ||
3335 | Component Accessor | |
3336 | ========================= =============== | |
3337 | official name of net netent:name | |
3338 | alias list netent:aliases | |
3339 | net number type netent:addrtype | |
3340 | net number netent:net | |
3341 | ||
3342 | *** There are new accessors for the vectors returned by `getproto', | |
3343 | `getprotobyname', `getprotobynumber', and `getprotoent', describing | |
3344 | internet protocols: | |
3345 | ||
3346 | Component Accessor | |
3347 | ========================= =============== | |
3348 | official protocol name protoent:name | |
3349 | alias list protoent:aliases | |
3350 | protocol number protoent:proto | |
3351 | ||
3352 | *** There are new accessors for the vectors returned by `getserv', | |
3353 | `getservbyname', `getservbyport', and `getservent', describing | |
3354 | internet protocols: | |
3355 | ||
3356 | Component Accessor | |
3357 | ========================= =============== | |
3358 | official service name servent:name | |
3359 | alias list servent:aliases | |
3360 | port number servent:port | |
3361 | protocol to use servent:proto | |
3362 | ||
3363 | *** There are new accessors for the sockaddr structures returned by | |
3364 | `accept', `getsockname', `getpeername', `recvfrom!': | |
3365 | ||
3366 | Component Accessor | |
3367 | ======================================== =============== | |
3368 | address format (`family') sockaddr:fam | |
3369 | path, for file domain addresses sockaddr:path | |
3370 | address, for internet domain addresses sockaddr:addr | |
3371 | TCP or UDP port, for internet sockaddr:port | |
3372 | ||
3373 | *** The `getpwent', `getgrent', `gethostent', `getnetent', | |
3374 | `getprotoent', and `getservent' functions now return #f at the end of | |
3375 | the user database. (They used to throw an exception.) | |
3376 | ||
3377 | Note that calling MUMBLEent function is equivalent to calling the | |
3378 | corresponding MUMBLE function with no arguments. | |
3379 | ||
3380 | *** The `setpwent', `setgrent', `sethostent', `setnetent', | |
3381 | `setprotoent', and `setservent' routines now take no arguments. | |
3382 | ||
3383 | *** The `gethost', `getproto', `getnet', and `getserv' functions now | |
3384 | provide more useful information when they throw an exception. | |
3385 | ||
3386 | *** The `lnaof' function has been renamed to `inet-lnaof'. | |
3387 | ||
3388 | *** Guile now claims to have the `current-time' feature. | |
3389 | ||
3390 | *** The `mktime' function now takes an optional second argument ZONE, | |
3391 | giving the time zone to use for the conversion. ZONE should be a | |
3392 | string, in the same format as expected for the "TZ" environment variable. | |
3393 | ||
3394 | *** The `strptime' function now returns a pair (TIME . COUNT), where | |
3395 | TIME is the parsed time as a vector, and COUNT is the number of | |
3396 | characters from the string left unparsed. This function used to | |
3397 | return the remaining characters as a string. | |
3398 | ||
3399 | *** The `gettimeofday' function has replaced the old `time+ticks' function. | |
3400 | The return value is now (SECONDS . MICROSECONDS); the fractional | |
3401 | component is no longer expressed in "ticks". | |
3402 | ||
3403 | *** The `ticks/sec' constant has been removed, in light of the above change. | |
6685dc83 | 3404 | |
ea00ecba MG |
3405 | * Changes to the gh_ interface |
3406 | ||
3407 | ** gh_eval_str() now returns an SCM object which is the result of the | |
3408 | evaluation | |
3409 | ||
aaef0d2a MG |
3410 | ** gh_scm2str() now copies the Scheme data to a caller-provided C |
3411 | array | |
3412 | ||
3413 | ** gh_scm2newstr() now makes a C array, copies the Scheme data to it, | |
3414 | and returns the array | |
3415 | ||
3416 | ** gh_scm2str0() is gone: there is no need to distinguish | |
3417 | null-terminated from non-null-terminated, since gh_scm2newstr() allows | |
3418 | the user to interpret the data both ways. | |
3419 | ||
f3b1485f JB |
3420 | * Changes to the scm_ interface |
3421 | ||
095936d2 JB |
3422 | ** The new function scm_symbol_value0 provides an easy way to get a |
3423 | symbol's value from C code: | |
3424 | ||
3425 | SCM scm_symbol_value0 (char *NAME) | |
3426 | Return the value of the symbol named by the null-terminated string | |
3427 | NAME in the current module. If the symbol named NAME is unbound in | |
3428 | the current module, return SCM_UNDEFINED. | |
3429 | ||
3430 | ** The new function scm_sysintern0 creates new top-level variables, | |
3431 | without assigning them a value. | |
3432 | ||
3433 | SCM scm_sysintern0 (char *NAME) | |
3434 | Create a new Scheme top-level variable named NAME. NAME is a | |
3435 | null-terminated string. Return the variable's value cell. | |
3436 | ||
3437 | ** The function scm_internal_catch is the guts of catch. It handles | |
3438 | all the mechanics of setting up a catch target, invoking the catch | |
3439 | body, and perhaps invoking the handler if the body does a throw. | |
3440 | ||
3441 | The function is designed to be usable from C code, but is general | |
3442 | enough to implement all the semantics Guile Scheme expects from throw. | |
3443 | ||
3444 | TAG is the catch tag. Typically, this is a symbol, but this function | |
3445 | doesn't actually care about that. | |
3446 | ||
3447 | BODY is a pointer to a C function which runs the body of the catch; | |
3448 | this is the code you can throw from. We call it like this: | |
3449 | BODY (BODY_DATA, JMPBUF) | |
3450 | where: | |
3451 | BODY_DATA is just the BODY_DATA argument we received; we pass it | |
3452 | through to BODY as its first argument. The caller can make | |
3453 | BODY_DATA point to anything useful that BODY might need. | |
3454 | JMPBUF is the Scheme jmpbuf object corresponding to this catch, | |
3455 | which we have just created and initialized. | |
3456 | ||
3457 | HANDLER is a pointer to a C function to deal with a throw to TAG, | |
3458 | should one occur. We call it like this: | |
3459 | HANDLER (HANDLER_DATA, THROWN_TAG, THROW_ARGS) | |
3460 | where | |
3461 | HANDLER_DATA is the HANDLER_DATA argument we recevied; it's the | |
3462 | same idea as BODY_DATA above. | |
3463 | THROWN_TAG is the tag that the user threw to; usually this is | |
3464 | TAG, but it could be something else if TAG was #t (i.e., a | |
3465 | catch-all), or the user threw to a jmpbuf. | |
3466 | THROW_ARGS is the list of arguments the user passed to the THROW | |
3467 | function. | |
3468 | ||
3469 | BODY_DATA is just a pointer we pass through to BODY. HANDLER_DATA | |
3470 | is just a pointer we pass through to HANDLER. We don't actually | |
3471 | use either of those pointers otherwise ourselves. The idea is | |
3472 | that, if our caller wants to communicate something to BODY or | |
3473 | HANDLER, it can pass a pointer to it as MUMBLE_DATA, which BODY and | |
3474 | HANDLER can then use. Think of it as a way to make BODY and | |
3475 | HANDLER closures, not just functions; MUMBLE_DATA points to the | |
3476 | enclosed variables. | |
3477 | ||
3478 | Of course, it's up to the caller to make sure that any data a | |
3479 | MUMBLE_DATA needs is protected from GC. A common way to do this is | |
3480 | to make MUMBLE_DATA a pointer to data stored in an automatic | |
3481 | structure variable; since the collector must scan the stack for | |
3482 | references anyway, this assures that any references in MUMBLE_DATA | |
3483 | will be found. | |
3484 | ||
3485 | ** The new function scm_internal_lazy_catch is exactly like | |
3486 | scm_internal_catch, except: | |
3487 | ||
3488 | - It does not unwind the stack (this is the major difference). | |
3489 | - If handler returns, its value is returned from the throw. | |
3490 | - BODY always receives #f as its JMPBUF argument (since there's no | |
3491 | jmpbuf associated with a lazy catch, because we don't unwind the | |
3492 | stack.) | |
3493 | ||
3494 | ** scm_body_thunk is a new body function you can pass to | |
3495 | scm_internal_catch if you want the body to be like Scheme's `catch' | |
3496 | --- a thunk, or a function of one argument if the tag is #f. | |
3497 | ||
3498 | BODY_DATA is a pointer to a scm_body_thunk_data structure, which | |
3499 | contains the Scheme procedure to invoke as the body, and the tag | |
3500 | we're catching. If the tag is #f, then we pass JMPBUF (created by | |
3501 | scm_internal_catch) to the body procedure; otherwise, the body gets | |
3502 | no arguments. | |
3503 | ||
3504 | ** scm_handle_by_proc is a new handler function you can pass to | |
3505 | scm_internal_catch if you want the handler to act like Scheme's catch | |
3506 | --- call a procedure with the tag and the throw arguments. | |
3507 | ||
3508 | If the user does a throw to this catch, this function runs a handler | |
3509 | procedure written in Scheme. HANDLER_DATA is a pointer to an SCM | |
3510 | variable holding the Scheme procedure object to invoke. It ought to | |
3511 | be a pointer to an automatic variable (i.e., one living on the stack), | |
3512 | or the procedure object should be otherwise protected from GC. | |
3513 | ||
3514 | ** scm_handle_by_message is a new handler function to use with | |
3515 | `scm_internal_catch' if you want Guile to print a message and die. | |
3516 | It's useful for dealing with throws to uncaught keys at the top level. | |
3517 | ||
3518 | HANDLER_DATA, if non-zero, is assumed to be a char * pointing to a | |
3519 | message header to print; if zero, we use "guile" instead. That | |
3520 | text is followed by a colon, then the message described by ARGS. | |
3521 | ||
3522 | ** The return type of scm_boot_guile is now void; the function does | |
3523 | not return a value, and indeed, never returns at all. | |
3524 | ||
f3b1485f JB |
3525 | ** The new function scm_shell makes it easy for user applications to |
3526 | process command-line arguments in a way that is compatible with the | |
3527 | stand-alone guile interpreter (which is in turn compatible with SCSH, | |
3528 | the Scheme shell). | |
3529 | ||
3530 | To use the scm_shell function, first initialize any guile modules | |
3531 | linked into your application, and then call scm_shell with the values | |
7ed46dc8 | 3532 | of ARGC and ARGV your `main' function received. scm_shell will add |
f3b1485f JB |
3533 | any SCSH-style meta-arguments from the top of the script file to the |
3534 | argument vector, and then process the command-line arguments. This | |
3535 | generally means loading a script file or starting up an interactive | |
3536 | command interpreter. For details, see "Changes to the stand-alone | |
3537 | interpreter" above. | |
3538 | ||
095936d2 JB |
3539 | ** The new functions scm_get_meta_args and scm_count_argv help you |
3540 | implement the SCSH-style meta-argument, `\'. | |
3541 | ||
3542 | char **scm_get_meta_args (int ARGC, char **ARGV) | |
3543 | If the second element of ARGV is a string consisting of a single | |
3544 | backslash character (i.e. "\\" in Scheme notation), open the file | |
3545 | named by the following argument, parse arguments from it, and return | |
3546 | the spliced command line. The returned array is terminated by a | |
3547 | null pointer. | |
3548 | ||
3549 | For details of argument parsing, see above, under "guile now accepts | |
3550 | command-line arguments compatible with SCSH..." | |
3551 | ||
3552 | int scm_count_argv (char **ARGV) | |
3553 | Count the arguments in ARGV, assuming it is terminated by a null | |
3554 | pointer. | |
3555 | ||
3556 | For an example of how these functions might be used, see the source | |
3557 | code for the function scm_shell in libguile/script.c. | |
3558 | ||
3559 | You will usually want to use scm_shell instead of calling this | |
3560 | function yourself. | |
3561 | ||
3562 | ** The new function scm_compile_shell_switches turns an array of | |
3563 | command-line arguments into Scheme code to carry out the actions they | |
3564 | describe. Given ARGC and ARGV, it returns a Scheme expression to | |
3565 | evaluate, and calls scm_set_program_arguments to make any remaining | |
3566 | command-line arguments available to the Scheme code. For example, | |
3567 | given the following arguments: | |
3568 | ||
3569 | -e main -s ekko a speckled gecko | |
3570 | ||
3571 | scm_set_program_arguments will return the following expression: | |
3572 | ||
3573 | (begin (load "ekko") (main (command-line)) (quit)) | |
3574 | ||
3575 | You will usually want to use scm_shell instead of calling this | |
3576 | function yourself. | |
3577 | ||
3578 | ** The function scm_shell_usage prints a usage message appropriate for | |
3579 | an interpreter that uses scm_compile_shell_switches to handle its | |
3580 | command-line arguments. | |
3581 | ||
3582 | void scm_shell_usage (int FATAL, char *MESSAGE) | |
3583 | Print a usage message to the standard error output. If MESSAGE is | |
3584 | non-zero, write it before the usage message, followed by a newline. | |
3585 | If FATAL is non-zero, exit the process, using FATAL as the | |
3586 | termination status. (If you want to be compatible with Guile, | |
3587 | always use 1 as the exit status when terminating due to command-line | |
3588 | usage problems.) | |
3589 | ||
3590 | You will usually want to use scm_shell instead of calling this | |
3591 | function yourself. | |
48d224d7 JB |
3592 | |
3593 | ** scm_eval_0str now returns SCM_UNSPECIFIED if the string contains no | |
095936d2 JB |
3594 | expressions. It used to return SCM_EOL. Earth-shattering. |
3595 | ||
3596 | ** The macros for declaring scheme objects in C code have been | |
3597 | rearranged slightly. They are now: | |
3598 | ||
3599 | SCM_SYMBOL (C_NAME, SCHEME_NAME) | |
3600 | Declare a static SCM variable named C_NAME, and initialize it to | |
3601 | point to the Scheme symbol whose name is SCHEME_NAME. C_NAME should | |
3602 | be a C identifier, and SCHEME_NAME should be a C string. | |
3603 | ||
3604 | SCM_GLOBAL_SYMBOL (C_NAME, SCHEME_NAME) | |
3605 | Just like SCM_SYMBOL, but make C_NAME globally visible. | |
3606 | ||
3607 | SCM_VCELL (C_NAME, SCHEME_NAME) | |
3608 | Create a global variable at the Scheme level named SCHEME_NAME. | |
3609 | Declare a static SCM variable named C_NAME, and initialize it to | |
3610 | point to the Scheme variable's value cell. | |
3611 | ||
3612 | SCM_GLOBAL_VCELL (C_NAME, SCHEME_NAME) | |
3613 | Just like SCM_VCELL, but make C_NAME globally visible. | |
3614 | ||
3615 | The `guile-snarf' script writes initialization code for these macros | |
3616 | to its standard output, given C source code as input. | |
3617 | ||
3618 | The SCM_GLOBAL macro is gone. | |
3619 | ||
3620 | ** The scm_read_line and scm_read_line_x functions have been replaced | |
3621 | by Scheme code based on the %read-delimited! procedure (known to C | |
3622 | code as scm_read_delimited_x). See its description above for more | |
3623 | information. | |
48d224d7 | 3624 | |
095936d2 JB |
3625 | ** The function scm_sys_open has been renamed to scm_open. It now |
3626 | returns a port instead of an FD object. | |
ea00ecba | 3627 | |
095936d2 JB |
3628 | * The dynamic linking support has changed. For more information, see |
3629 | libguile/DYNAMIC-LINKING. | |
ea00ecba | 3630 | |
f7b47737 JB |
3631 | \f |
3632 | Guile 1.0b3 | |
3065a62a | 3633 | |
f3b1485f JB |
3634 | User-visible changes from Thursday, September 5, 1996 until Guile 1.0 |
3635 | (Sun 5 Jan 1997): | |
3065a62a | 3636 | |
4b521edb | 3637 | * Changes to the 'guile' program: |
3065a62a | 3638 | |
4b521edb JB |
3639 | ** Guile now loads some new files when it starts up. Guile first |
3640 | searches the load path for init.scm, and loads it if found. Then, if | |
3641 | Guile is not being used to execute a script, and the user's home | |
3642 | directory contains a file named `.guile', Guile loads that. | |
c6486f8a | 3643 | |
4b521edb | 3644 | ** You can now use Guile as a shell script interpreter. |
3065a62a JB |
3645 | |
3646 | To paraphrase the SCSH manual: | |
3647 | ||
3648 | When Unix tries to execute an executable file whose first two | |
3649 | characters are the `#!', it treats the file not as machine code to | |
3650 | be directly executed by the native processor, but as source code | |
3651 | to be executed by some interpreter. The interpreter to use is | |
3652 | specified immediately after the #! sequence on the first line of | |
3653 | the source file. The kernel reads in the name of the interpreter, | |
3654 | and executes that instead. It passes the interpreter the source | |
3655 | filename as its first argument, with the original arguments | |
3656 | following. Consult the Unix man page for the `exec' system call | |
3657 | for more information. | |
3658 | ||
1a1945be JB |
3659 | Now you can use Guile as an interpreter, using a mechanism which is a |
3660 | compatible subset of that provided by SCSH. | |
3661 | ||
3065a62a JB |
3662 | Guile now recognizes a '-s' command line switch, whose argument is the |
3663 | name of a file of Scheme code to load. It also treats the two | |
3664 | characters `#!' as the start of a comment, terminated by `!#'. Thus, | |
3665 | to make a file of Scheme code directly executable by Unix, insert the | |
3666 | following two lines at the top of the file: | |
3667 | ||
3668 | #!/usr/local/bin/guile -s | |
3669 | !# | |
3670 | ||
3671 | Guile treats the argument of the `-s' command-line switch as the name | |
3672 | of a file of Scheme code to load, and treats the sequence `#!' as the | |
3673 | start of a block comment, terminated by `!#'. | |
3674 | ||
3675 | For example, here's a version of 'echo' written in Scheme: | |
3676 | ||
3677 | #!/usr/local/bin/guile -s | |
3678 | !# | |
3679 | (let loop ((args (cdr (program-arguments)))) | |
3680 | (if (pair? args) | |
3681 | (begin | |
3682 | (display (car args)) | |
3683 | (if (pair? (cdr args)) | |
3684 | (display " ")) | |
3685 | (loop (cdr args))))) | |
3686 | (newline) | |
3687 | ||
3688 | Why does `#!' start a block comment terminated by `!#', instead of the | |
3689 | end of the line? That is the notation SCSH uses, and although we | |
3690 | don't yet support the other SCSH features that motivate that choice, | |
3691 | we would like to be backward-compatible with any existing Guile | |
3763761c JB |
3692 | scripts once we do. Furthermore, if the path to Guile on your system |
3693 | is too long for your kernel, you can start the script with this | |
3694 | horrible hack: | |
3695 | ||
3696 | #!/bin/sh | |
3697 | exec /really/long/path/to/guile -s "$0" ${1+"$@"} | |
3698 | !# | |
3065a62a JB |
3699 | |
3700 | Note that some very old Unix systems don't support the `#!' syntax. | |
3701 | ||
c6486f8a | 3702 | |
4b521edb | 3703 | ** You can now run Guile without installing it. |
6685dc83 JB |
3704 | |
3705 | Previous versions of the interactive Guile interpreter (`guile') | |
3706 | couldn't start up unless Guile's Scheme library had been installed; | |
3707 | they used the value of the environment variable `SCHEME_LOAD_PATH' | |
3708 | later on in the startup process, but not to find the startup code | |
3709 | itself. Now Guile uses `SCHEME_LOAD_PATH' in all searches for Scheme | |
3710 | code. | |
3711 | ||
3712 | To run Guile without installing it, build it in the normal way, and | |
3713 | then set the environment variable `SCHEME_LOAD_PATH' to a | |
3714 | colon-separated list of directories, including the top-level directory | |
3715 | of the Guile sources. For example, if you unpacked Guile so that the | |
3716 | full filename of this NEWS file is /home/jimb/guile-1.0b3/NEWS, then | |
3717 | you might say | |
3718 | ||
3719 | export SCHEME_LOAD_PATH=/home/jimb/my-scheme:/home/jimb/guile-1.0b3 | |
3720 | ||
c6486f8a | 3721 | |
4b521edb JB |
3722 | ** Guile's read-eval-print loop no longer prints #<unspecified> |
3723 | results. If the user wants to see this, she can evaluate the | |
3724 | expression (assert-repl-print-unspecified #t), perhaps in her startup | |
48d224d7 | 3725 | file. |
6685dc83 | 3726 | |
4b521edb JB |
3727 | ** Guile no longer shows backtraces by default when an error occurs; |
3728 | however, it does display a message saying how to get one, and how to | |
3729 | request that they be displayed by default. After an error, evaluate | |
3730 | (backtrace) | |
3731 | to see a backtrace, and | |
3732 | (debug-enable 'backtrace) | |
3733 | to see them by default. | |
6685dc83 | 3734 | |
6685dc83 | 3735 | |
d9fb83d9 | 3736 | |
4b521edb JB |
3737 | * Changes to Guile Scheme: |
3738 | ||
3739 | ** Guile now distinguishes between #f and the empty list. | |
3740 | ||
3741 | This is for compatibility with the IEEE standard, the (possibly) | |
3742 | upcoming Revised^5 Report on Scheme, and many extant Scheme | |
3743 | implementations. | |
3744 | ||
3745 | Guile used to have #f and '() denote the same object, to make Scheme's | |
3746 | type system more compatible with Emacs Lisp's. However, the change | |
3747 | caused too much trouble for Scheme programmers, and we found another | |
3748 | way to reconcile Emacs Lisp with Scheme that didn't require this. | |
3749 | ||
3750 | ||
3751 | ** Guile's delq, delv, delete functions, and their destructive | |
c6486f8a JB |
3752 | counterparts, delq!, delv!, and delete!, now remove all matching |
3753 | elements from the list, not just the first. This matches the behavior | |
3754 | of the corresponding Emacs Lisp functions, and (I believe) the Maclisp | |
3755 | functions which inspired them. | |
3756 | ||
3757 | I recognize that this change may break code in subtle ways, but it | |
3758 | seems best to make the change before the FSF's first Guile release, | |
3759 | rather than after. | |
3760 | ||
3761 | ||
4b521edb | 3762 | ** The compiled-library-path function has been deleted from libguile. |
6685dc83 | 3763 | |
4b521edb | 3764 | ** The facilities for loading Scheme source files have changed. |
c6486f8a | 3765 | |
4b521edb | 3766 | *** The variable %load-path now tells Guile which directories to search |
6685dc83 JB |
3767 | for Scheme code. Its value is a list of strings, each of which names |
3768 | a directory. | |
3769 | ||
4b521edb JB |
3770 | *** The variable %load-extensions now tells Guile which extensions to |
3771 | try appending to a filename when searching the load path. Its value | |
3772 | is a list of strings. Its default value is ("" ".scm"). | |
3773 | ||
3774 | *** (%search-load-path FILENAME) searches the directories listed in the | |
3775 | value of the %load-path variable for a Scheme file named FILENAME, | |
3776 | with all the extensions listed in %load-extensions. If it finds a | |
3777 | match, then it returns its full filename. If FILENAME is absolute, it | |
3778 | returns it unchanged. Otherwise, it returns #f. | |
6685dc83 | 3779 | |
4b521edb JB |
3780 | %search-load-path will not return matches that refer to directories. |
3781 | ||
3782 | *** (primitive-load FILENAME :optional CASE-INSENSITIVE-P SHARP) | |
3783 | uses %seach-load-path to find a file named FILENAME, and loads it if | |
3784 | it finds it. If it can't read FILENAME for any reason, it throws an | |
3785 | error. | |
6685dc83 JB |
3786 | |
3787 | The arguments CASE-INSENSITIVE-P and SHARP are interpreted as by the | |
4b521edb JB |
3788 | `read' function. |
3789 | ||
3790 | *** load uses the same searching semantics as primitive-load. | |
3791 | ||
3792 | *** The functions %try-load, try-load-with-path, %load, load-with-path, | |
3793 | basic-try-load-with-path, basic-load-with-path, try-load-module-with- | |
3794 | path, and load-module-with-path have been deleted. The functions | |
3795 | above should serve their purposes. | |
3796 | ||
3797 | *** If the value of the variable %load-hook is a procedure, | |
3798 | `primitive-load' applies its value to the name of the file being | |
3799 | loaded (without the load path directory name prepended). If its value | |
3800 | is #f, it is ignored. Otherwise, an error occurs. | |
3801 | ||
3802 | This is mostly useful for printing load notification messages. | |
3803 | ||
3804 | ||
3805 | ** The function `eval!' is no longer accessible from the scheme level. | |
3806 | We can't allow operations which introduce glocs into the scheme level, | |
3807 | because Guile's type system can't handle these as data. Use `eval' or | |
3808 | `read-and-eval!' (see below) as replacement. | |
3809 | ||
3810 | ** The new function read-and-eval! reads an expression from PORT, | |
3811 | evaluates it, and returns the result. This is more efficient than | |
3812 | simply calling `read' and `eval', since it is not necessary to make a | |
3813 | copy of the expression for the evaluator to munge. | |
3814 | ||
3815 | Its optional arguments CASE_INSENSITIVE_P and SHARP are interpreted as | |
3816 | for the `read' function. | |
3817 | ||
3818 | ||
3819 | ** The function `int?' has been removed; its definition was identical | |
3820 | to that of `integer?'. | |
3821 | ||
3822 | ** The functions `<?', `<?', `<=?', `=?', `>?', and `>=?'. Code should | |
3823 | use the R4RS names for these functions. | |
3824 | ||
3825 | ** The function object-properties no longer returns the hash handle; | |
3826 | it simply returns the object's property list. | |
3827 | ||
3828 | ** Many functions have been changed to throw errors, instead of | |
3829 | returning #f on failure. The point of providing exception handling in | |
3830 | the language is to simplify the logic of user code, but this is less | |
3831 | useful if Guile's primitives don't throw exceptions. | |
3832 | ||
3833 | ** The function `fileno' has been renamed from `%fileno'. | |
3834 | ||
3835 | ** The function primitive-mode->fdes returns #t or #f now, not 1 or 0. | |
3836 | ||
3837 | ||
3838 | * Changes to Guile's C interface: | |
3839 | ||
3840 | ** The library's initialization procedure has been simplified. | |
3841 | scm_boot_guile now has the prototype: | |
3842 | ||
3843 | void scm_boot_guile (int ARGC, | |
3844 | char **ARGV, | |
3845 | void (*main_func) (), | |
3846 | void *closure); | |
3847 | ||
3848 | scm_boot_guile calls MAIN_FUNC, passing it CLOSURE, ARGC, and ARGV. | |
3849 | MAIN_FUNC should do all the work of the program (initializing other | |
3850 | packages, reading user input, etc.) before returning. When MAIN_FUNC | |
3851 | returns, call exit (0); this function never returns. If you want some | |
3852 | other exit value, MAIN_FUNC may call exit itself. | |
3853 | ||
3854 | scm_boot_guile arranges for program-arguments to return the strings | |
3855 | given by ARGC and ARGV. If MAIN_FUNC modifies ARGC/ARGV, should call | |
3856 | scm_set_program_arguments with the final list, so Scheme code will | |
3857 | know which arguments have been processed. | |
3858 | ||
3859 | scm_boot_guile establishes a catch-all catch handler which prints an | |
3860 | error message and exits the process. This means that Guile exits in a | |
3861 | coherent way when system errors occur and the user isn't prepared to | |
3862 | handle it. If the user doesn't like this behavior, they can establish | |
3863 | their own universal catcher in MAIN_FUNC to shadow this one. | |
3864 | ||
3865 | Why must the caller do all the real work from MAIN_FUNC? The garbage | |
3866 | collector assumes that all local variables of type SCM will be above | |
3867 | scm_boot_guile's stack frame on the stack. If you try to manipulate | |
3868 | SCM values after this function returns, it's the luck of the draw | |
3869 | whether the GC will be able to find the objects you allocate. So, | |
3870 | scm_boot_guile function exits, rather than returning, to discourage | |
3871 | people from making that mistake. | |
3872 | ||
3873 | The IN, OUT, and ERR arguments were removed; there are other | |
3874 | convenient ways to override these when desired. | |
3875 | ||
3876 | The RESULT argument was deleted; this function should never return. | |
3877 | ||
3878 | The BOOT_CMD argument was deleted; the MAIN_FUNC argument is more | |
3879 | general. | |
3880 | ||
3881 | ||
3882 | ** Guile's header files should no longer conflict with your system's | |
3883 | header files. | |
3884 | ||
3885 | In order to compile code which #included <libguile.h>, previous | |
3886 | versions of Guile required you to add a directory containing all the | |
3887 | Guile header files to your #include path. This was a problem, since | |
3888 | Guile's header files have names which conflict with many systems' | |
3889 | header files. | |
3890 | ||
3891 | Now only <libguile.h> need appear in your #include path; you must | |
3892 | refer to all Guile's other header files as <libguile/mumble.h>. | |
3893 | Guile's installation procedure puts libguile.h in $(includedir), and | |
3894 | the rest in $(includedir)/libguile. | |
3895 | ||
3896 | ||
3897 | ** Two new C functions, scm_protect_object and scm_unprotect_object, | |
3898 | have been added to the Guile library. | |
3899 | ||
3900 | scm_protect_object (OBJ) protects OBJ from the garbage collector. | |
3901 | OBJ will not be freed, even if all other references are dropped, | |
3902 | until someone does scm_unprotect_object (OBJ). Both functions | |
3903 | return OBJ. | |
3904 | ||
3905 | Note that calls to scm_protect_object do not nest. You can call | |
3906 | scm_protect_object any number of times on a given object, and the | |
3907 | next call to scm_unprotect_object will unprotect it completely. | |
3908 | ||
3909 | Basically, scm_protect_object and scm_unprotect_object just | |
3910 | maintain a list of references to things. Since the GC knows about | |
3911 | this list, all objects it mentions stay alive. scm_protect_object | |
3912 | adds its argument to the list; scm_unprotect_object remove its | |
3913 | argument from the list. | |
3914 | ||
3915 | ||
3916 | ** scm_eval_0str now returns the value of the last expression | |
3917 | evaluated. | |
3918 | ||
3919 | ** The new function scm_read_0str reads an s-expression from a | |
3920 | null-terminated string, and returns it. | |
3921 | ||
3922 | ** The new function `scm_stdio_to_port' converts a STDIO file pointer | |
3923 | to a Scheme port object. | |
3924 | ||
3925 | ** The new function `scm_set_program_arguments' allows C code to set | |
e80c8fea | 3926 | the value returned by the Scheme `program-arguments' function. |
6685dc83 | 3927 | |
6685dc83 | 3928 | \f |
1a1945be JB |
3929 | Older changes: |
3930 | ||
3931 | * Guile no longer includes sophisticated Tcl/Tk support. | |
3932 | ||
3933 | The old Tcl/Tk support was unsatisfying to us, because it required the | |
3934 | user to link against the Tcl library, as well as Tk and Guile. The | |
3935 | interface was also un-lispy, in that it preserved Tcl/Tk's practice of | |
3936 | referring to widgets by names, rather than exporting widgets to Scheme | |
3937 | code as a special datatype. | |
3938 | ||
3939 | In the Usenix Tk Developer's Workshop held in July 1996, the Tcl/Tk | |
3940 | maintainers described some very interesting changes in progress to the | |
3941 | Tcl/Tk internals, which would facilitate clean interfaces between lone | |
3942 | Tk and other interpreters --- even for garbage-collected languages | |
3943 | like Scheme. They expected the new Tk to be publicly available in the | |
3944 | fall of 1996. | |
3945 | ||
3946 | Since it seems that Guile might soon have a new, cleaner interface to | |
3947 | lone Tk, and that the old Guile/Tk glue code would probably need to be | |
3948 | completely rewritten, we (Jim Blandy and Richard Stallman) have | |
3949 | decided not to support the old code. We'll spend the time instead on | |
3950 | a good interface to the newer Tk, as soon as it is available. | |
5c54da76 | 3951 | |
8512dea6 | 3952 | Until then, gtcltk-lib provides trivial, low-maintenance functionality. |
deb95d71 | 3953 | |
5c54da76 JB |
3954 | \f |
3955 | Copyright information: | |
3956 | ||
ea00ecba | 3957 | Copyright (C) 1996,1997 Free Software Foundation, Inc. |
5c54da76 JB |
3958 | |
3959 | Permission is granted to anyone to make or distribute verbatim copies | |
3960 | of this document as received, in any medium, provided that the | |
3961 | copyright notice and this permission notice are preserved, | |
3962 | thus giving the recipient permission to redistribute in turn. | |
3963 | ||
3964 | Permission is granted to distribute modified versions | |
3965 | of this document, or of portions of it, | |
3966 | under the above conditions, provided also that they | |
3967 | carry prominent notices stating who last changed them. | |
3968 | ||
48d224d7 JB |
3969 | \f |
3970 | Local variables: | |
3971 | mode: outline | |
3972 | paragraph-separate: "[ \f]*$" | |
3973 | end: | |
3974 |