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