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