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