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