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