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