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