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