* boot-9.scm (setenv): new procedure, scsh compatible.
[bpt/guile.git] / NEWS
CommitLineData
f7b47737
JB
1Guile NEWS --- history of user-visible changes. -*- text -*-
2Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5c54da76
JB
3See the end for copying conditions.
4
16f2ebea 5Please send Guile bug reports to bug-guile@prep.ai.mit.edu.
5c54da76 6\f
c484bf7f
JB
7Changes since Guile 1.2:
8
9* Changes to the distribution
10
11* Changes to the stand-alone interpreter
12
13* Changes to the procedure for linking libguile with your programs
14
15* Changes to Scheme functions and syntax
7ad3c1e7 16
04c76b58
MV
17** There is now some basic support for fluids. Please read
18"libguile/fluid.h" to find out more. It is accessible from Scheme with
19the following builtin procedures:
20
21 (make-fluid)
22
23 Create a new fluid object.
24
25 (fluid-ref FLUID)
26 (fluid-set! FLUID VAL)
27
28 Access/modify the fluid FLUID. Modifications are only visible
29 within the current dynamic root (that includes threads).
30
31There is no `fluid-let' yet.
32
64d01d13
GH
33* Changes to system call interfaces:
34
35** close-port, close-input-port and close-output-port now return a
36boolean instead of an `unspecified' object. #t means that the port
37was successfully closed, while #f means it was already closed. It is
38also now possible for these procedures to raise an exception if an
39error occurs (some errors from write can be delayed until close.)
40
41** The following new procedures have been added (most use scsh
42interfaces):
43
44** close PORT/FD
45Similar to close-port, but also works on file descriptors. A side
46effect of closing a file descriptor is that any ports using that file
47descriptor are moved to a different file descriptor and have
48their revealed counts set to zero.
49
50The next five procedures perform a dup2 system call, if NEWFD (an
51integer) is supplied, otherwise a dup. The file descriptor to be
52duplicated can be supplied as an integer or wrapped in a port. The
53type of value returned varies depending on which procedure is used.
54
55All procedures also have the side effect when performing dup2 that any
56ports using NEWFD are moved to a different file descriptor and have
57their revealed counts set to zero.
58
59** dup->fdes PORT/FD [NEWFD]
60Returns an integer file descriptor.
61
62** dup->inport PORT/FD [NEWFD]
63Returns a new input port using the new file descriptor.
64
65** dup->outport PORT/FD [NEWFD]
66Returns a new output port using the new file descriptor.
67
68** dup PORT/FD [NEWFD]
69Returns a new port if PORT/FD is a port, with the same mode as the
70supplied port, otherwise returns an integer file descriptor.
71
72** dup->port PORT/FD MODE [NEWFD]
73Returns a new port using the new file descriptor. MODE supplies a
74mode string for the port (as for `open-file').
75
76** primitive-dup PORT/FD
77Performs a dup system call on the file descriptor FD, or the file
78descriptor underlying PORT and returns a new integer file descriptor.
79
80** primitive-dup2 PORT/FD NEWFD
81
82Performs a dup2 system call on the file descriptor FD, or the file
83descriptor underlying PORT, using NEWFD (an integer) as the target
84file descriptor. Any ports using NEWFD are moved to a different file
85descriptor and have their revealed counts set to zero. The value
86returned is NEWFD.
87
88** port->fdes PORT
89Returns the integer file descriptor underlying PORT. As a
90side effect the revealed count of PORT is incremented.
91
92** fdes->inport FDES
93Returns an existing input port which has FDES as its underlying file
94descriptor, if one exists, and increments its revealed count.
95Otherwise, returns a new input port with a revealed count of 1.
96
97** fdes->outport FDES
98Returns an existing output port which has FDES as its underlying file
99descriptor, if one exists, and increments its revealed count.
100Otherwise, returns a new output port with a revealed count of 1.
101
956055a9
GH
102** setenv [NAME] [VALUE]
103If VALUE is `#f', removes NAME from the environment. Otherwise
104adds the string NAME=VALUE to the environment, replacing any previous
105value for NAME.
106
64d01d13
GH
107** primitive-exit [STATUS]
108Terminates the current process without unwinding the Scheme stack.
109This would usually be used after a fork.
7ad3c1e7 110
c484bf7f
JB
111* Changes to the gh_ interface
112
113* Changes to the scm_ interface
114
115\f
116Changes in Guile 1.2 (released Tuesday, June 24 1997):
cf78e9e8 117
737c9113
JB
118* Changes to the distribution
119
832b09ed
JB
120** Nightly snapshots are now available from ftp.red-bean.com.
121The old server, ftp.cyclic.com, has been relinquished to its rightful
122owner.
123
124Nightly snapshots of the Guile development sources are now available via
125anonymous FTP from ftp.red-bean.com, as /pub/guile/guile-snap.tar.gz.
126
127Via the web, that's: ftp://ftp.red-bean.com/pub/guile/guile-snap.tar.gz
128For getit, that's: ftp.red-bean.com:/pub/guile/guile-snap.tar.gz
129
0fcab5ed
JB
130** To run Guile without installing it, the procedure has changed a bit.
131
132If you used a separate build directory to compile Guile, you'll need
133to include the build directory in SCHEME_LOAD_PATH, as well as the
134source directory. See the `INSTALL' file for examples.
135
737c9113
JB
136* Changes to the procedure for linking libguile with your programs
137
94982a4e
JB
138** The standard Guile load path for Scheme code now includes
139$(datadir)/guile (usually /usr/local/share/guile). This means that
140you can install your own Scheme files there, and Guile will find them.
141(Previous versions of Guile only checked a directory whose name
142contained the Guile version number, so you had to re-install or move
143your Scheme sources each time you installed a fresh version of Guile.)
144
145The load path also includes $(datadir)/guile/site; we recommend
146putting individual Scheme files there. If you want to install a
147package with multiple source files, create a directory for them under
148$(datadir)/guile.
149
150** Guile 1.2 will now use the Rx regular expression library, if it is
151installed on your system. When you are linking libguile into your own
152programs, this means you will have to link against -lguile, -lqt (if
153you configured Guile with thread support), and -lrx.
27590f82
JB
154
155If you are using autoconf to generate configuration scripts for your
156application, the following lines should suffice to add the appropriate
157libraries to your link command:
158
159### Find Rx, quickthreads and libguile.
160AC_CHECK_LIB(rx, main)
161AC_CHECK_LIB(qt, main)
162AC_CHECK_LIB(guile, scm_shell)
163
94982a4e
JB
164The Guile 1.2 distribution does not contain sources for the Rx
165library, as Guile 1.0 did. If you want to use Rx, you'll need to
166retrieve it from a GNU FTP site and install it separately.
167
b83b8bee
JB
168* Changes to Scheme functions and syntax
169
e035e7e6
MV
170** The dynamic linking features of Guile are now enabled by default.
171You can disable them by giving the `--disable-dynamic-linking' option
172to configure.
173
e035e7e6
MV
174 (dynamic-link FILENAME)
175
176 Find the object file denoted by FILENAME (a string) and link it
177 into the running Guile application. When everything works out,
178 return a Scheme object suitable for representing the linked object
179 file. Otherwise an error is thrown. How object files are
180 searched is system dependent.
181
182 (dynamic-object? VAL)
183
184 Determine whether VAL represents a dynamically linked object file.
185
186 (dynamic-unlink DYNOBJ)
187
188 Unlink the indicated object file from the application. DYNOBJ
189 should be one of the values returned by `dynamic-link'.
190
191 (dynamic-func FUNCTION DYNOBJ)
192
193 Search the C function indicated by FUNCTION (a string or symbol)
194 in DYNOBJ and return some Scheme object that can later be used
195 with `dynamic-call' to actually call this function. Right now,
196 these Scheme objects are formed by casting the address of the
197 function to `long' and converting this number to its Scheme
198 representation.
199
200 (dynamic-call FUNCTION DYNOBJ)
201
202 Call the C function indicated by FUNCTION and DYNOBJ. The
203 function is passed no arguments and its return value is ignored.
204 When FUNCTION is something returned by `dynamic-func', call that
205 function and ignore DYNOBJ. When FUNCTION is a string (or symbol,
206 etc.), look it up in DYNOBJ; this is equivalent to
207
208 (dynamic-call (dynamic-func FUNCTION DYNOBJ) #f)
209
210 Interrupts are deferred while the C function is executing (with
211 SCM_DEFER_INTS/SCM_ALLOW_INTS).
212
213 (dynamic-args-call FUNCTION DYNOBJ ARGS)
214
215 Call the C function indicated by FUNCTION and DYNOBJ, but pass it
216 some arguments and return its return value. The C function is
217 expected to take two arguments and return an `int', just like
218 `main':
219
220 int c_func (int argc, char **argv);
221
222 ARGS must be a list of strings and is converted into an array of
223 `char *'. The array is passed in ARGV and its size in ARGC. The
224 return value is converted to a Scheme number and returned from the
225 call to `dynamic-args-call'.
226
0fcab5ed
JB
227When dynamic linking is disabled or not supported on your system,
228the above functions throw errors, but they are still available.
229
e035e7e6
MV
230Here is a small example that works on GNU/Linux:
231
232 (define libc-obj (dynamic-link "libc.so"))
233 (dynamic-args-call 'rand libc-obj '())
234
235See the file `libguile/DYNAMIC-LINKING' for additional comments.
236
27590f82
JB
237** The #/ syntax for module names is depreciated, and will be removed
238in a future version of Guile. Instead of
239
240 #/foo/bar/baz
241
242instead write
243
244 (foo bar baz)
245
246The latter syntax is more consistent with existing Lisp practice.
247
5dade857
MV
248** Guile now does fancier printing of structures. Structures are the
249underlying implementation for records, which in turn are used to
250implement modules, so all of these object now print differently and in
251a more informative way.
252
161029df
JB
253The Scheme printer will examine the builtin variable *struct-printer*
254whenever it needs to print a structure object. When this variable is
255not `#f' it is deemed to be a procedure and will be applied to the
256structure object and the output port. When *struct-printer* is `#f'
257or the procedure return `#f' the structure object will be printed in
258the boring #<struct 80458270> form.
5dade857
MV
259
260This hook is used by some routines in ice-9/boot-9.scm to implement
261type specific printing routines. Please read the comments there about
262"printing structs".
263
264One of the more specific uses of structs are records. The printing
265procedure that could be passed to MAKE-RECORD-TYPE is now actually
266called. It should behave like a *struct-printer* procedure (described
267above).
268
b83b8bee
JB
269** Guile now supports a new R4RS-compliant syntax for keywords. A
270token of the form #:NAME, where NAME has the same syntax as a Scheme
271symbol, is the external representation of the keyword named NAME.
272Keyword objects print using this syntax as well, so values containing
1e5afba0
JB
273keyword objects can be read back into Guile. When used in an
274expression, keywords are self-quoting objects.
b83b8bee
JB
275
276Guile suports this read syntax, and uses this print syntax, regardless
277of the current setting of the `keyword' read option. The `keyword'
278read option only controls whether Guile recognizes the `:NAME' syntax,
279which is incompatible with R4RS. (R4RS says such token represent
280symbols.)
737c9113
JB
281
282** Guile has regular expression support again. Guile 1.0 included
283functions for matching regular expressions, based on the Rx library.
284In Guile 1.1, the Guile/Rx interface was removed to simplify the
285distribution, and thus Guile had no regular expression support. Guile
94982a4e
JB
2861.2 again supports the most commonly used functions, and supports all
287of SCSH's regular expression functions.
2409cdfa 288
94982a4e
JB
289If your system does not include a POSIX regular expression library,
290and you have not linked Guile with a third-party regexp library such as
291Rx, these functions will not be available. You can tell whether your
292Guile installation includes regular expression support by checking
293whether the `*features*' list includes the `regex' symbol.
737c9113 294
94982a4e 295*** regexp functions
161029df 296
94982a4e
JB
297By default, Guile supports POSIX extended regular expressions. That
298means that the characters `(', `)', `+' and `?' are special, and must
299be escaped if you wish to match the literal characters.
e1a191a8 300
94982a4e
JB
301This regular expression interface was modeled after that implemented
302by SCSH, the Scheme Shell. It is intended to be upwardly compatible
303with SCSH regular expressions.
304
305**** Function: string-match PATTERN STR [START]
306 Compile the string PATTERN into a regular expression and compare
307 it with STR. The optional numeric argument START specifies the
308 position of STR at which to begin matching.
309
310 `string-match' returns a "match structure" which describes what,
311 if anything, was matched by the regular expression. *Note Match
312 Structures::. If STR does not match PATTERN at all,
313 `string-match' returns `#f'.
314
315 Each time `string-match' is called, it must compile its PATTERN
316argument into a regular expression structure. This operation is
317expensive, which makes `string-match' inefficient if the same regular
318expression is used several times (for example, in a loop). For better
319performance, you can compile a regular expression in advance and then
320match strings against the compiled regexp.
321
322**** Function: make-regexp STR [FLAGS]
323 Compile the regular expression described by STR, and return the
324 compiled regexp structure. If STR does not describe a legal
325 regular expression, `make-regexp' throws a
326 `regular-expression-syntax' error.
327
328 FLAGS may be the bitwise-or of one or more of the following:
329
330**** Constant: regexp/extended
331 Use POSIX Extended Regular Expression syntax when interpreting
332 STR. If not set, POSIX Basic Regular Expression syntax is used.
333 If the FLAGS argument is omitted, we assume regexp/extended.
334
335**** Constant: regexp/icase
336 Do not differentiate case. Subsequent searches using the
337 returned regular expression will be case insensitive.
338
339**** Constant: regexp/newline
340 Match-any-character operators don't match a newline.
341
342 A non-matching list ([^...]) not containing a newline matches a
343 newline.
344
345 Match-beginning-of-line operator (^) matches the empty string
346 immediately after a newline, regardless of whether the FLAGS
347 passed to regexp-exec contain regexp/notbol.
348
349 Match-end-of-line operator ($) matches the empty string
350 immediately before a newline, regardless of whether the FLAGS
351 passed to regexp-exec contain regexp/noteol.
352
353**** Function: regexp-exec REGEXP STR [START [FLAGS]]
354 Match the compiled regular expression REGEXP against `str'. If
355 the optional integer START argument is provided, begin matching
356 from that position in the string. Return a match structure
357 describing the results of the match, or `#f' if no match could be
358 found.
359
360 FLAGS may be the bitwise-or of one or more of the following:
361
362**** Constant: regexp/notbol
363 The match-beginning-of-line operator always fails to match (but
364 see the compilation flag regexp/newline above) This flag may be
365 used when different portions of a string are passed to
366 regexp-exec and the beginning of the string should not be
367 interpreted as the beginning of the line.
368
369**** Constant: regexp/noteol
370 The match-end-of-line operator always fails to match (but see the
371 compilation flag regexp/newline above)
372
373**** Function: regexp? OBJ
374 Return `#t' if OBJ is a compiled regular expression, or `#f'
375 otherwise.
376
377 Regular expressions are commonly used to find patterns in one string
378and replace them with the contents of another string.
379
380**** Function: regexp-substitute PORT MATCH [ITEM...]
381 Write to the output port PORT selected contents of the match
382 structure MATCH. Each ITEM specifies what should be written, and
383 may be one of the following arguments:
384
385 * A string. String arguments are written out verbatim.
386
387 * An integer. The submatch with that number is written.
388
389 * The symbol `pre'. The portion of the matched string preceding
390 the regexp match is written.
391
392 * The symbol `post'. The portion of the matched string
393 following the regexp match is written.
394
395 PORT may be `#f', in which case nothing is written; instead,
396 `regexp-substitute' constructs a string from the specified ITEMs
397 and returns that.
398
399**** Function: regexp-substitute/global PORT REGEXP TARGET [ITEM...]
400 Similar to `regexp-substitute', but can be used to perform global
401 substitutions on STR. Instead of taking a match structure as an
402 argument, `regexp-substitute/global' takes two string arguments: a
403 REGEXP string describing a regular expression, and a TARGET string
404 which should be matched against this regular expression.
405
406 Each ITEM behaves as in REGEXP-SUBSTITUTE, with the following
407 exceptions:
408
409 * A function may be supplied. When this function is called, it
410 will be passed one argument: a match structure for a given
411 regular expression match. It should return a string to be
412 written out to PORT.
413
414 * The `post' symbol causes `regexp-substitute/global' to recurse
415 on the unmatched portion of STR. This *must* be supplied in
416 order to perform global search-and-replace on STR; if it is
417 not present among the ITEMs, then `regexp-substitute/global'
418 will return after processing a single match.
419
420*** Match Structures
421
422 A "match structure" is the object returned by `string-match' and
423`regexp-exec'. It describes which portion of a string, if any, matched
424the given regular expression. Match structures include: a reference to
425the string that was checked for matches; the starting and ending
426positions of the regexp match; and, if the regexp included any
427parenthesized subexpressions, the starting and ending positions of each
428submatch.
429
430 In each of the regexp match functions described below, the `match'
431argument must be a match structure returned by a previous call to
432`string-match' or `regexp-exec'. Most of these functions return some
433information about the original target string that was matched against a
434regular expression; we will call that string TARGET for easy reference.
435
436**** Function: regexp-match? OBJ
437 Return `#t' if OBJ is a match structure returned by a previous
438 call to `regexp-exec', or `#f' otherwise.
439
440**** Function: match:substring MATCH [N]
441 Return the portion of TARGET matched by subexpression number N.
442 Submatch 0 (the default) represents the entire regexp match. If
443 the regular expression as a whole matched, but the subexpression
444 number N did not match, return `#f'.
445
446**** Function: match:start MATCH [N]
447 Return the starting position of submatch number N.
448
449**** Function: match:end MATCH [N]
450 Return the ending position of submatch number N.
451
452**** Function: match:prefix MATCH
453 Return the unmatched portion of TARGET preceding the regexp match.
454
455**** Function: match:suffix MATCH
456 Return the unmatched portion of TARGET following the regexp match.
457
458**** Function: match:count MATCH
459 Return the number of parenthesized subexpressions from MATCH.
460 Note that the entire regular expression match itself counts as a
461 subexpression, and failed submatches are included in the count.
462
463**** Function: match:string MATCH
464 Return the original TARGET string.
465
466*** Backslash Escapes
467
468 Sometimes you will want a regexp to match characters like `*' or `$'
469exactly. For example, to check whether a particular string represents
470a menu entry from an Info node, it would be useful to match it against
471a regexp like `^* [^:]*::'. However, this won't work; because the
472asterisk is a metacharacter, it won't match the `*' at the beginning of
473the string. In this case, we want to make the first asterisk un-magic.
474
475 You can do this by preceding the metacharacter with a backslash
476character `\'. (This is also called "quoting" the metacharacter, and
477is known as a "backslash escape".) When Guile sees a backslash in a
478regular expression, it considers the following glyph to be an ordinary
479character, no matter what special meaning it would ordinarily have.
480Therefore, we can make the above example work by changing the regexp to
481`^\* [^:]*::'. The `\*' sequence tells the regular expression engine
482to match only a single asterisk in the target string.
483
484 Since the backslash is itself a metacharacter, you may force a
485regexp to match a backslash in the target string by preceding the
486backslash with itself. For example, to find variable references in a
487TeX program, you might want to find occurrences of the string `\let\'
488followed by any number of alphabetic characters. The regular expression
489`\\let\\[A-Za-z]*' would do this: the double backslashes in the regexp
490each match a single backslash in the target string.
491
492**** Function: regexp-quote STR
493 Quote each special character found in STR with a backslash, and
494 return the resulting string.
495
496 *Very important:* Using backslash escapes in Guile source code (as
497in Emacs Lisp or C) can be tricky, because the backslash character has
498special meaning for the Guile reader. For example, if Guile encounters
499the character sequence `\n' in the middle of a string while processing
500Scheme code, it replaces those characters with a newline character.
501Similarly, the character sequence `\t' is replaced by a horizontal tab.
502Several of these "escape sequences" are processed by the Guile reader
503before your code is executed. Unrecognized escape sequences are
504ignored: if the characters `\*' appear in a string, they will be
505translated to the single character `*'.
506
507 This translation is obviously undesirable for regular expressions,
508since we want to be able to include backslashes in a string in order to
509escape regexp metacharacters. Therefore, to make sure that a backslash
510is preserved in a string in your Guile program, you must use *two*
511consecutive backslashes:
512
513 (define Info-menu-entry-pattern (make-regexp "^\\* [^:]*"))
514
515 The string in this example is preprocessed by the Guile reader before
516any code is executed. The resulting argument to `make-regexp' is the
517string `^\* [^:]*', which is what we really want.
518
519 This also means that in order to write a regular expression that
520matches a single backslash character, the regular expression string in
521the source code must include *four* backslashes. Each consecutive pair
522of backslashes gets translated by the Guile reader to a single
523backslash, and the resulting double-backslash is interpreted by the
524regexp engine as matching a single backslash character. Hence:
525
526 (define tex-variable-pattern (make-regexp "\\\\let\\\\=[A-Za-z]*"))
527
528 The reason for the unwieldiness of this syntax is historical. Both
529regular expression pattern matchers and Unix string processing systems
530have traditionally used backslashes with the special meanings described
531above. The POSIX regular expression specification and ANSI C standard
532both require these semantics. Attempting to abandon either convention
533would cause other kinds of compatibility problems, possibly more severe
534ones. Therefore, without extending the Scheme reader to support
535strings with different quoting conventions (an ungainly and confusing
536extension when implemented in other languages), we must adhere to this
537cumbersome escape syntax.
538
7ad3c1e7
GH
539* Changes to the gh_ interface
540
541* Changes to the scm_ interface
542
543* Changes to system call interfaces:
94982a4e 544
7ad3c1e7 545** The value returned by `raise' is now unspecified. It throws an exception
e1a191a8
GH
546if an error occurs.
547
94982a4e 548*** A new procedure `sigaction' can be used to install signal handlers
115b09a5
GH
549
550(sigaction signum [action] [flags])
551
552signum is the signal number, which can be specified using the value
553of SIGINT etc.
554
555If action is omitted, sigaction returns a pair: the CAR is the current
556signal hander, which will be either an integer with the value SIG_DFL
557(default action) or SIG_IGN (ignore), or the Scheme procedure which
558handles the signal, or #f if a non-Scheme procedure handles the
559signal. The CDR contains the current sigaction flags for the handler.
560
561If action is provided, it is installed as the new handler for signum.
562action can be a Scheme procedure taking one argument, or the value of
563SIG_DFL (default action) or SIG_IGN (ignore), or #f to restore
564whatever signal handler was installed before sigaction was first used.
565Flags can optionally be specified for the new handler (SA_RESTART is
566always used if the system provides it, so need not be specified.) The
567return value is a pair with information about the old handler as
568described above.
569
570This interface does not provide access to the "signal blocking"
571facility. Maybe this is not needed, since the thread support may
572provide solutions to the problem of consistent access to data
573structures.
e1a191a8 574
94982a4e 575*** A new procedure `flush-all-ports' is equivalent to running
89ea5b7c
GH
576`force-output' on every port open for output.
577
94982a4e
JB
578** Guile now provides information on how it was built, via the new
579global variable, %guile-build-info. This variable records the values
580of the standard GNU makefile directory variables as an assocation
581list, mapping variable names (symbols) onto directory paths (strings).
582For example, to find out where the Guile link libraries were
583installed, you can say:
584
585guile -c "(display (assq-ref %guile-build-info 'libdir)) (newline)"
586
587
588* Changes to the scm_ interface
589
590** The new function scm_handle_by_message_noexit is just like the
591existing scm_handle_by_message function, except that it doesn't call
592exit to terminate the process. Instead, it prints a message and just
593returns #f. This might be a more appropriate catch-all handler for
594new dynamic roots and threads.
595
cf78e9e8 596\f
c484bf7f 597Changes in Guile 1.1 (released Friday, May 16 1997):
f3b1485f
JB
598
599* Changes to the distribution.
600
601The Guile 1.0 distribution has been split up into several smaller
602pieces:
603guile-core --- the Guile interpreter itself.
604guile-tcltk --- the interface between the Guile interpreter and
605 Tcl/Tk; Tcl is an interpreter for a stringy language, and Tk
606 is a toolkit for building graphical user interfaces.
607guile-rgx-ctax --- the interface between Guile and the Rx regular
608 expression matcher, and the translator for the Ctax
609 programming language. These are packaged together because the
610 Ctax translator uses Rx to parse Ctax source code.
611
095936d2
JB
612This NEWS file describes the changes made to guile-core since the 1.0
613release.
614
48d224d7
JB
615We no longer distribute the documentation, since it was either out of
616date, or incomplete. As soon as we have current documentation, we
617will distribute it.
618
0fcab5ed
JB
619
620
f3b1485f
JB
621* Changes to the stand-alone interpreter
622
48d224d7
JB
623** guile now accepts command-line arguments compatible with SCSH, Olin
624Shivers' Scheme Shell.
625
626In general, arguments are evaluated from left to right, but there are
627exceptions. The following switches stop argument processing, and
628stash all remaining command-line arguments as the value returned by
629the (command-line) function.
630 -s SCRIPT load Scheme source code from FILE, and exit
631 -c EXPR evalute Scheme expression EXPR, and exit
632 -- stop scanning arguments; run interactively
633
634The switches below are processed as they are encountered.
635 -l FILE load Scheme source code from FILE
636 -e FUNCTION after reading script, apply FUNCTION to
637 command line arguments
638 -ds do -s script at this point
639 --emacs enable Emacs protocol (experimental)
640 -h, --help display this help and exit
641 -v, --version display version information and exit
642 \ read arguments from following script lines
643
644So, for example, here is a Guile script named `ekko' (thanks, Olin)
645which re-implements the traditional "echo" command:
646
647#!/usr/local/bin/guile -s
648!#
649(define (main args)
650 (map (lambda (arg) (display arg) (display " "))
651 (cdr args))
652 (newline))
653
654(main (command-line))
655
656Suppose we invoke this script as follows:
657
658 ekko a speckled gecko
659
660Through the magic of Unix script processing (triggered by the `#!'
661token at the top of the file), /usr/local/bin/guile receives the
662following list of command-line arguments:
663
664 ("-s" "./ekko" "a" "speckled" "gecko")
665
666Unix inserts the name of the script after the argument specified on
667the first line of the file (in this case, "-s"), and then follows that
668with the arguments given to the script. Guile loads the script, which
669defines the `main' function, and then applies it to the list of
670remaining command-line arguments, ("a" "speckled" "gecko").
671
095936d2
JB
672In Unix, the first line of a script file must take the following form:
673
674#!INTERPRETER ARGUMENT
675
676where INTERPRETER is the absolute filename of the interpreter
677executable, and ARGUMENT is a single command-line argument to pass to
678the interpreter.
679
680You may only pass one argument to the interpreter, and its length is
681limited. These restrictions can be annoying to work around, so Guile
682provides a general mechanism (borrowed from, and compatible with,
683SCSH) for circumventing them.
684
685If the ARGUMENT in a Guile script is a single backslash character,
686`\', Guile will open the script file, parse arguments from its second
687and subsequent lines, and replace the `\' with them. So, for example,
688here is another implementation of the `ekko' script:
689
690#!/usr/local/bin/guile \
691-e main -s
692!#
693(define (main args)
694 (for-each (lambda (arg) (display arg) (display " "))
695 (cdr args))
696 (newline))
697
698If the user invokes this script as follows:
699
700 ekko a speckled gecko
701
702Unix expands this into
703
704 /usr/local/bin/guile \ ekko a speckled gecko
705
706When Guile sees the `\' argument, it replaces it with the arguments
707read from the second line of the script, producing:
708
709 /usr/local/bin/guile -e main -s ekko a speckled gecko
710
711This tells Guile to load the `ekko' script, and apply the function
712`main' to the argument list ("a" "speckled" "gecko").
713
714Here is how Guile parses the command-line arguments:
715- Each space character terminates an argument. This means that two
716 spaces in a row introduce an empty-string argument.
717- The tab character is not permitted (unless you quote it with the
718 backslash character, as described below), to avoid confusion.
719- The newline character terminates the sequence of arguments, and will
720 also terminate a final non-empty argument. (However, a newline
721 following a space will not introduce a final empty-string argument;
722 it only terminates the argument list.)
723- The backslash character is the escape character. It escapes
724 backslash, space, tab, and newline. The ANSI C escape sequences
725 like \n and \t are also supported. These produce argument
726 constituents; the two-character combination \n doesn't act like a
727 terminating newline. The escape sequence \NNN for exactly three
728 octal digits reads as the character whose ASCII code is NNN. As
729 above, characters produced this way are argument constituents.
730 Backslash followed by other characters is not allowed.
731
48d224d7
JB
732* Changes to the procedure for linking libguile with your programs
733
734** Guile now builds and installs a shared guile library, if your
735system support shared libraries. (It still builds a static library on
736all systems.) Guile automatically detects whether your system
737supports shared libraries. To prevent Guile from buildisg shared
738libraries, pass the `--disable-shared' flag to the configure script.
739
740Guile takes longer to compile when it builds shared libraries, because
741it must compile every file twice --- once to produce position-
742independent object code, and once to produce normal object code.
743
744** The libthreads library has been merged into libguile.
745
746To link a program against Guile, you now need only link against
747-lguile and -lqt; -lthreads is no longer needed. If you are using
748autoconf to generate configuration scripts for your application, the
749following lines should suffice to add the appropriate libraries to
750your link command:
751
752### Find quickthreads and libguile.
753AC_CHECK_LIB(qt, main)
754AC_CHECK_LIB(guile, scm_shell)
f3b1485f
JB
755
756* Changes to Scheme functions
757
095936d2
JB
758** Guile Scheme's special syntax for keyword objects is now optional,
759and disabled by default.
760
761The syntax variation from R4RS made it difficult to port some
762interesting packages to Guile. The routines which accepted keyword
763arguments (mostly in the module system) have been modified to also
764accept symbols whose names begin with `:'.
765
766To change the keyword syntax, you must first import the (ice-9 debug)
767module:
768 (use-modules (ice-9 debug))
769
770Then you can enable the keyword syntax as follows:
771 (read-set! keywords 'prefix)
772
773To disable keyword syntax, do this:
774 (read-set! keywords #f)
775
776** Many more primitive functions accept shared substrings as
777arguments. In the past, these functions required normal, mutable
778strings as arguments, although they never made use of this
779restriction.
780
781** The uniform array functions now operate on byte vectors. These
782functions are `array-fill!', `serial-array-copy!', `array-copy!',
783`serial-array-map', `array-map', `array-for-each', and
784`array-index-map!'.
785
786** The new functions `trace' and `untrace' implement simple debugging
787support for Scheme functions.
788
789The `trace' function accepts any number of procedures as arguments,
790and tells the Guile interpreter to display each procedure's name and
791arguments each time the procedure is invoked. When invoked with no
792arguments, `trace' returns the list of procedures currently being
793traced.
794
795The `untrace' function accepts any number of procedures as arguments,
796and tells the Guile interpreter not to trace them any more. When
797invoked with no arguments, `untrace' untraces all curretly traced
798procedures.
799
800The tracing in Guile has an advantage over most other systems: we
801don't create new procedure objects, but mark the procedure objects
802themselves. This means that anonymous and internal procedures can be
803traced.
804
805** The function `assert-repl-prompt' has been renamed to
806`set-repl-prompt!'. It takes one argument, PROMPT.
807- If PROMPT is #f, the Guile read-eval-print loop will not prompt.
808- If PROMPT is a string, we use it as a prompt.
809- If PROMPT is a procedure accepting no arguments, we call it, and
810 display the result as a prompt.
811- Otherwise, we display "> ".
812
813** The new function `eval-string' reads Scheme expressions from a
814string and evaluates them, returning the value of the last expression
815in the string. If the string contains no expressions, it returns an
816unspecified value.
817
818** The new function `thunk?' returns true iff its argument is a
819procedure of zero arguments.
820
821** `defined?' is now a builtin function, instead of syntax. This
822means that its argument should be quoted. It returns #t iff its
823argument is bound in the current module.
824
825** The new syntax `use-modules' allows you to add new modules to your
826environment without re-typing a complete `define-module' form. It
827accepts any number of module names as arguments, and imports their
828public bindings into the current module.
829
830** The new function (module-defined? NAME MODULE) returns true iff
831NAME, a symbol, is defined in MODULE, a module object.
832
833** The new function `builtin-bindings' creates and returns a hash
834table containing copies of all the root module's bindings.
835
836** The new function `builtin-weak-bindings' does the same as
837`builtin-bindings', but creates a doubly-weak hash table.
838
839** The `equal?' function now considers variable objects to be
840equivalent if they have the same name and the same value.
841
842** The new function `command-line' returns the command-line arguments
843given to Guile, as a list of strings.
844
845When using guile as a script interpreter, `command-line' returns the
846script's arguments; those processed by the interpreter (like `-s' or
847`-c') are omitted. (In other words, you get the normal, expected
848behavior.) Any application that uses scm_shell to process its
849command-line arguments gets this behavior as well.
850
851** The new function `load-user-init' looks for a file called `.guile'
852in the user's home directory, and loads it if it exists. This is
853mostly for use by the code generated by scm_compile_shell_switches,
854but we thought it might also be useful in other circumstances.
855
856** The new function `log10' returns the base-10 logarithm of its
857argument.
858
859** Changes to I/O functions
860
861*** The functions `read', `primitive-load', `read-and-eval!', and
862`primitive-load-path' no longer take optional arguments controlling
863case insensitivity and a `#' parser.
864
865Case sensitivity is now controlled by a read option called
866`case-insensitive'. The user can add new `#' syntaxes with the
867`read-hash-extend' function (see below).
868
869*** The new function `read-hash-extend' allows the user to change the
870syntax of Guile Scheme in a somewhat controlled way.
871
872(read-hash-extend CHAR PROC)
873 When parsing S-expressions, if we read a `#' character followed by
874 the character CHAR, use PROC to parse an object from the stream.
875 If PROC is #f, remove any parsing procedure registered for CHAR.
876
877 The reader applies PROC to two arguments: CHAR and an input port.
878
879*** The new functions read-delimited and read-delimited! provide a
880general mechanism for doing delimited input on streams.
881
882(read-delimited DELIMS [PORT HANDLE-DELIM])
883 Read until we encounter one of the characters in DELIMS (a string),
884 or end-of-file. PORT is the input port to read from; it defaults to
885 the current input port. The HANDLE-DELIM parameter determines how
886 the terminating character is handled; it should be one of the
887 following symbols:
888
889 'trim omit delimiter from result
890 'peek leave delimiter character in input stream
891 'concat append delimiter character to returned value
892 'split return a pair: (RESULT . TERMINATOR)
893
894 HANDLE-DELIM defaults to 'peek.
895
896(read-delimited! DELIMS BUF [PORT HANDLE-DELIM START END])
897 A side-effecting variant of `read-delimited'.
898
899 The data is written into the string BUF at the indices in the
900 half-open interval [START, END); the default interval is the whole
901 string: START = 0 and END = (string-length BUF). The values of
902 START and END must specify a well-defined interval in BUF, i.e.
903 0 <= START <= END <= (string-length BUF).
904
905 It returns NBYTES, the number of bytes read. If the buffer filled
906 up without a delimiter character being found, it returns #f. If the
907 port is at EOF when the read starts, it returns the EOF object.
908
909 If an integer is returned (i.e., the read is successfully terminated
910 by reading a delimiter character), then the HANDLE-DELIM parameter
911 determines how to handle the terminating character. It is described
912 above, and defaults to 'peek.
913
914(The descriptions of these functions were borrowed from the SCSH
915manual, by Olin Shivers and Brian Carlstrom.)
916
917*** The `%read-delimited!' function is the primitive used to implement
918`read-delimited' and `read-delimited!'.
919
920(%read-delimited! DELIMS BUF GOBBLE? [PORT START END])
921
922This returns a pair of values: (TERMINATOR . NUM-READ).
923- TERMINATOR describes why the read was terminated. If it is a
924 character or the eof object, then that is the value that terminated
925 the read. If it is #f, the function filled the buffer without finding
926 a delimiting character.
927- NUM-READ is the number of characters read into BUF.
928
929If the read is successfully terminated by reading a delimiter
930character, then the gobble? parameter determines what to do with the
931terminating character. If true, the character is removed from the
932input stream; if false, the character is left in the input stream
933where a subsequent read operation will retrieve it. In either case,
934the character is also the first value returned by the procedure call.
935
936(The descriptions of this function was borrowed from the SCSH manual,
937by Olin Shivers and Brian Carlstrom.)
938
939*** The `read-line' and `read-line!' functions have changed; they now
940trim the terminator by default; previously they appended it to the
941returned string. For the old behavior, use (read-line PORT 'concat).
942
943*** The functions `uniform-array-read!' and `uniform-array-write!' now
944take new optional START and END arguments, specifying the region of
945the array to read and write.
946
f348c807
JB
947*** The `ungetc-char-ready?' function has been removed. We feel it's
948inappropriate for an interface to expose implementation details this
949way.
095936d2
JB
950
951** Changes to the Unix library and system call interface
952
953*** The new fcntl function provides access to the Unix `fcntl' system
954call.
955
956(fcntl PORT COMMAND VALUE)
957 Apply COMMAND to PORT's file descriptor, with VALUE as an argument.
958 Values for COMMAND are:
959
960 F_DUPFD duplicate a file descriptor
961 F_GETFD read the descriptor's close-on-exec flag
962 F_SETFD set the descriptor's close-on-exec flag to VALUE
963 F_GETFL read the descriptor's flags, as set on open
964 F_SETFL set the descriptor's flags, as set on open to VALUE
965 F_GETOWN return the process ID of a socket's owner, for SIGIO
966 F_SETOWN set the process that owns a socket to VALUE, for SIGIO
967 FD_CLOEXEC not sure what this is
968
969For details, see the documentation for the fcntl system call.
970
971*** The arguments to `select' have changed, for compatibility with
972SCSH. The TIMEOUT parameter may now be non-integral, yielding the
973expected behavior. The MILLISECONDS parameter has been changed to
974MICROSECONDS, to more closely resemble the underlying system call.
975The RVEC, WVEC, and EVEC arguments can now be vectors; the type of the
976corresponding return set will be the same.
977
978*** The arguments to the `mknod' system call have changed. They are
979now:
980
981(mknod PATH TYPE PERMS DEV)
982 Create a new file (`node') in the file system. PATH is the name of
983 the file to create. TYPE is the kind of file to create; it should
984 be 'fifo, 'block-special, or 'char-special. PERMS specifies the
985 permission bits to give the newly created file. If TYPE is
986 'block-special or 'char-special, DEV specifies which device the
987 special file refers to; its interpretation depends on the kind of
988 special file being created.
989
990*** The `fork' function has been renamed to `primitive-fork', to avoid
991clashing with various SCSH forks.
992
993*** The `recv' and `recvfrom' functions have been renamed to `recv!'
994and `recvfrom!'. They no longer accept a size for a second argument;
995you must pass a string to hold the received value. They no longer
996return the buffer. Instead, `recv' returns the length of the message
997received, and `recvfrom' returns a pair containing the packet's length
998and originating address.
999
1000*** The file descriptor datatype has been removed, as have the
1001`read-fd', `write-fd', `close', `lseek', and `dup' functions.
1002We plan to replace these functions with a SCSH-compatible interface.
1003
1004*** The `create' function has been removed; it's just a special case
1005of `open'.
1006
1007*** There are new functions to break down process termination status
1008values. In the descriptions below, STATUS is a value returned by
1009`waitpid'.
1010
1011(status:exit-val STATUS)
1012 If the child process exited normally, this function returns the exit
1013 code for the child process (i.e., the value passed to exit, or
1014 returned from main). If the child process did not exit normally,
1015 this function returns #f.
1016
1017(status:stop-sig STATUS)
1018 If the child process was suspended by a signal, this function
1019 returns the signal that suspended the child. Otherwise, it returns
1020 #f.
1021
1022(status:term-sig STATUS)
1023 If the child process terminated abnormally, this function returns
1024 the signal that terminated the child. Otherwise, this function
1025 returns false.
1026
1027POSIX promises that exactly one of these functions will return true on
1028a valid STATUS value.
1029
1030These functions are compatible with SCSH.
1031
1032*** There are new accessors and setters for the broken-out time vectors
48d224d7
JB
1033returned by `localtime', `gmtime', and that ilk. They are:
1034
1035 Component Accessor Setter
1036 ========================= ============ ============
1037 seconds tm:sec set-tm:sec
1038 minutes tm:min set-tm:min
1039 hours tm:hour set-tm:hour
1040 day of the month tm:mday set-tm:mday
1041 month tm:mon set-tm:mon
1042 year tm:year set-tm:year
1043 day of the week tm:wday set-tm:wday
1044 day in the year tm:yday set-tm:yday
1045 daylight saving time tm:isdst set-tm:isdst
1046 GMT offset, seconds tm:gmtoff set-tm:gmtoff
1047 name of time zone tm:zone set-tm:zone
1048
095936d2
JB
1049*** There are new accessors for the vectors returned by `uname',
1050describing the host system:
48d224d7
JB
1051
1052 Component Accessor
1053 ============================================== ================
1054 name of the operating system implementation utsname:sysname
1055 network name of this machine utsname:nodename
1056 release level of the operating system utsname:release
1057 version level of the operating system utsname:version
1058 machine hardware platform utsname:machine
1059
095936d2
JB
1060*** There are new accessors for the vectors returned by `getpw',
1061`getpwnam', `getpwuid', and `getpwent', describing entries from the
1062system's user database:
1063
1064 Component Accessor
1065 ====================== =================
1066 user name passwd:name
1067 user password passwd:passwd
1068 user id passwd:uid
1069 group id passwd:gid
1070 real name passwd:gecos
1071 home directory passwd:dir
1072 shell program passwd:shell
1073
1074*** There are new accessors for the vectors returned by `getgr',
1075`getgrnam', `getgrgid', and `getgrent', describing entries from the
1076system's group database:
1077
1078 Component Accessor
1079 ======================= ============
1080 group name group:name
1081 group password group:passwd
1082 group id group:gid
1083 group members group:mem
1084
1085*** There are new accessors for the vectors returned by `gethost',
1086`gethostbyaddr', `gethostbyname', and `gethostent', describing
1087internet hosts:
1088
1089 Component Accessor
1090 ========================= ===============
1091 official name of host hostent:name
1092 alias list hostent:aliases
1093 host address type hostent:addrtype
1094 length of address hostent:length
1095 list of addresses hostent:addr-list
1096
1097*** There are new accessors for the vectors returned by `getnet',
1098`getnetbyaddr', `getnetbyname', and `getnetent', describing internet
1099networks:
1100
1101 Component Accessor
1102 ========================= ===============
1103 official name of net netent:name
1104 alias list netent:aliases
1105 net number type netent:addrtype
1106 net number netent:net
1107
1108*** There are new accessors for the vectors returned by `getproto',
1109`getprotobyname', `getprotobynumber', and `getprotoent', describing
1110internet protocols:
1111
1112 Component Accessor
1113 ========================= ===============
1114 official protocol name protoent:name
1115 alias list protoent:aliases
1116 protocol number protoent:proto
1117
1118*** There are new accessors for the vectors returned by `getserv',
1119`getservbyname', `getservbyport', and `getservent', describing
1120internet protocols:
1121
1122 Component Accessor
1123 ========================= ===============
1124 official service name servent:name
1125 alias list servent:aliases
1126 port number servent:port
1127 protocol to use servent:proto
1128
1129*** There are new accessors for the sockaddr structures returned by
1130`accept', `getsockname', `getpeername', `recvfrom!':
1131
1132 Component Accessor
1133 ======================================== ===============
1134 address format (`family') sockaddr:fam
1135 path, for file domain addresses sockaddr:path
1136 address, for internet domain addresses sockaddr:addr
1137 TCP or UDP port, for internet sockaddr:port
1138
1139*** The `getpwent', `getgrent', `gethostent', `getnetent',
1140`getprotoent', and `getservent' functions now return #f at the end of
1141the user database. (They used to throw an exception.)
1142
1143Note that calling MUMBLEent function is equivalent to calling the
1144corresponding MUMBLE function with no arguments.
1145
1146*** The `setpwent', `setgrent', `sethostent', `setnetent',
1147`setprotoent', and `setservent' routines now take no arguments.
1148
1149*** The `gethost', `getproto', `getnet', and `getserv' functions now
1150provide more useful information when they throw an exception.
1151
1152*** The `lnaof' function has been renamed to `inet-lnaof'.
1153
1154*** Guile now claims to have the `current-time' feature.
1155
1156*** The `mktime' function now takes an optional second argument ZONE,
1157giving the time zone to use for the conversion. ZONE should be a
1158string, in the same format as expected for the "TZ" environment variable.
1159
1160*** The `strptime' function now returns a pair (TIME . COUNT), where
1161TIME is the parsed time as a vector, and COUNT is the number of
1162characters from the string left unparsed. This function used to
1163return the remaining characters as a string.
1164
1165*** The `gettimeofday' function has replaced the old `time+ticks' function.
1166The return value is now (SECONDS . MICROSECONDS); the fractional
1167component is no longer expressed in "ticks".
1168
1169*** The `ticks/sec' constant has been removed, in light of the above change.
6685dc83 1170
ea00ecba
MG
1171* Changes to the gh_ interface
1172
1173** gh_eval_str() now returns an SCM object which is the result of the
1174evaluation
1175
aaef0d2a
MG
1176** gh_scm2str() now copies the Scheme data to a caller-provided C
1177array
1178
1179** gh_scm2newstr() now makes a C array, copies the Scheme data to it,
1180and returns the array
1181
1182** gh_scm2str0() is gone: there is no need to distinguish
1183null-terminated from non-null-terminated, since gh_scm2newstr() allows
1184the user to interpret the data both ways.
1185
f3b1485f
JB
1186* Changes to the scm_ interface
1187
095936d2
JB
1188** The new function scm_symbol_value0 provides an easy way to get a
1189symbol's value from C code:
1190
1191SCM scm_symbol_value0 (char *NAME)
1192 Return the value of the symbol named by the null-terminated string
1193 NAME in the current module. If the symbol named NAME is unbound in
1194 the current module, return SCM_UNDEFINED.
1195
1196** The new function scm_sysintern0 creates new top-level variables,
1197without assigning them a value.
1198
1199SCM scm_sysintern0 (char *NAME)
1200 Create a new Scheme top-level variable named NAME. NAME is a
1201 null-terminated string. Return the variable's value cell.
1202
1203** The function scm_internal_catch is the guts of catch. It handles
1204all the mechanics of setting up a catch target, invoking the catch
1205body, and perhaps invoking the handler if the body does a throw.
1206
1207The function is designed to be usable from C code, but is general
1208enough to implement all the semantics Guile Scheme expects from throw.
1209
1210TAG is the catch tag. Typically, this is a symbol, but this function
1211doesn't actually care about that.
1212
1213BODY is a pointer to a C function which runs the body of the catch;
1214this is the code you can throw from. We call it like this:
1215 BODY (BODY_DATA, JMPBUF)
1216where:
1217 BODY_DATA is just the BODY_DATA argument we received; we pass it
1218 through to BODY as its first argument. The caller can make
1219 BODY_DATA point to anything useful that BODY might need.
1220 JMPBUF is the Scheme jmpbuf object corresponding to this catch,
1221 which we have just created and initialized.
1222
1223HANDLER is a pointer to a C function to deal with a throw to TAG,
1224should one occur. We call it like this:
1225 HANDLER (HANDLER_DATA, THROWN_TAG, THROW_ARGS)
1226where
1227 HANDLER_DATA is the HANDLER_DATA argument we recevied; it's the
1228 same idea as BODY_DATA above.
1229 THROWN_TAG is the tag that the user threw to; usually this is
1230 TAG, but it could be something else if TAG was #t (i.e., a
1231 catch-all), or the user threw to a jmpbuf.
1232 THROW_ARGS is the list of arguments the user passed to the THROW
1233 function.
1234
1235BODY_DATA is just a pointer we pass through to BODY. HANDLER_DATA
1236is just a pointer we pass through to HANDLER. We don't actually
1237use either of those pointers otherwise ourselves. The idea is
1238that, if our caller wants to communicate something to BODY or
1239HANDLER, it can pass a pointer to it as MUMBLE_DATA, which BODY and
1240HANDLER can then use. Think of it as a way to make BODY and
1241HANDLER closures, not just functions; MUMBLE_DATA points to the
1242enclosed variables.
1243
1244Of course, it's up to the caller to make sure that any data a
1245MUMBLE_DATA needs is protected from GC. A common way to do this is
1246to make MUMBLE_DATA a pointer to data stored in an automatic
1247structure variable; since the collector must scan the stack for
1248references anyway, this assures that any references in MUMBLE_DATA
1249will be found.
1250
1251** The new function scm_internal_lazy_catch is exactly like
1252scm_internal_catch, except:
1253
1254- It does not unwind the stack (this is the major difference).
1255- If handler returns, its value is returned from the throw.
1256- BODY always receives #f as its JMPBUF argument (since there's no
1257 jmpbuf associated with a lazy catch, because we don't unwind the
1258 stack.)
1259
1260** scm_body_thunk is a new body function you can pass to
1261scm_internal_catch if you want the body to be like Scheme's `catch'
1262--- a thunk, or a function of one argument if the tag is #f.
1263
1264BODY_DATA is a pointer to a scm_body_thunk_data structure, which
1265contains the Scheme procedure to invoke as the body, and the tag
1266we're catching. If the tag is #f, then we pass JMPBUF (created by
1267scm_internal_catch) to the body procedure; otherwise, the body gets
1268no arguments.
1269
1270** scm_handle_by_proc is a new handler function you can pass to
1271scm_internal_catch if you want the handler to act like Scheme's catch
1272--- call a procedure with the tag and the throw arguments.
1273
1274If the user does a throw to this catch, this function runs a handler
1275procedure written in Scheme. HANDLER_DATA is a pointer to an SCM
1276variable holding the Scheme procedure object to invoke. It ought to
1277be a pointer to an automatic variable (i.e., one living on the stack),
1278or the procedure object should be otherwise protected from GC.
1279
1280** scm_handle_by_message is a new handler function to use with
1281`scm_internal_catch' if you want Guile to print a message and die.
1282It's useful for dealing with throws to uncaught keys at the top level.
1283
1284HANDLER_DATA, if non-zero, is assumed to be a char * pointing to a
1285message header to print; if zero, we use "guile" instead. That
1286text is followed by a colon, then the message described by ARGS.
1287
1288** The return type of scm_boot_guile is now void; the function does
1289not return a value, and indeed, never returns at all.
1290
f3b1485f
JB
1291** The new function scm_shell makes it easy for user applications to
1292process command-line arguments in a way that is compatible with the
1293stand-alone guile interpreter (which is in turn compatible with SCSH,
1294the Scheme shell).
1295
1296To use the scm_shell function, first initialize any guile modules
1297linked into your application, and then call scm_shell with the values
1298of ARGC and ARGV your `main' function received. scm_shell will adding
1299any SCSH-style meta-arguments from the top of the script file to the
1300argument vector, and then process the command-line arguments. This
1301generally means loading a script file or starting up an interactive
1302command interpreter. For details, see "Changes to the stand-alone
1303interpreter" above.
1304
095936d2
JB
1305** The new functions scm_get_meta_args and scm_count_argv help you
1306implement the SCSH-style meta-argument, `\'.
1307
1308char **scm_get_meta_args (int ARGC, char **ARGV)
1309 If the second element of ARGV is a string consisting of a single
1310 backslash character (i.e. "\\" in Scheme notation), open the file
1311 named by the following argument, parse arguments from it, and return
1312 the spliced command line. The returned array is terminated by a
1313 null pointer.
1314
1315 For details of argument parsing, see above, under "guile now accepts
1316 command-line arguments compatible with SCSH..."
1317
1318int scm_count_argv (char **ARGV)
1319 Count the arguments in ARGV, assuming it is terminated by a null
1320 pointer.
1321
1322For an example of how these functions might be used, see the source
1323code for the function scm_shell in libguile/script.c.
1324
1325You will usually want to use scm_shell instead of calling this
1326function yourself.
1327
1328** The new function scm_compile_shell_switches turns an array of
1329command-line arguments into Scheme code to carry out the actions they
1330describe. Given ARGC and ARGV, it returns a Scheme expression to
1331evaluate, and calls scm_set_program_arguments to make any remaining
1332command-line arguments available to the Scheme code. For example,
1333given the following arguments:
1334
1335 -e main -s ekko a speckled gecko
1336
1337scm_set_program_arguments will return the following expression:
1338
1339 (begin (load "ekko") (main (command-line)) (quit))
1340
1341You will usually want to use scm_shell instead of calling this
1342function yourself.
1343
1344** The function scm_shell_usage prints a usage message appropriate for
1345an interpreter that uses scm_compile_shell_switches to handle its
1346command-line arguments.
1347
1348void scm_shell_usage (int FATAL, char *MESSAGE)
1349 Print a usage message to the standard error output. If MESSAGE is
1350 non-zero, write it before the usage message, followed by a newline.
1351 If FATAL is non-zero, exit the process, using FATAL as the
1352 termination status. (If you want to be compatible with Guile,
1353 always use 1 as the exit status when terminating due to command-line
1354 usage problems.)
1355
1356You will usually want to use scm_shell instead of calling this
1357function yourself.
48d224d7
JB
1358
1359** scm_eval_0str now returns SCM_UNSPECIFIED if the string contains no
095936d2
JB
1360expressions. It used to return SCM_EOL. Earth-shattering.
1361
1362** The macros for declaring scheme objects in C code have been
1363rearranged slightly. They are now:
1364
1365SCM_SYMBOL (C_NAME, SCHEME_NAME)
1366 Declare a static SCM variable named C_NAME, and initialize it to
1367 point to the Scheme symbol whose name is SCHEME_NAME. C_NAME should
1368 be a C identifier, and SCHEME_NAME should be a C string.
1369
1370SCM_GLOBAL_SYMBOL (C_NAME, SCHEME_NAME)
1371 Just like SCM_SYMBOL, but make C_NAME globally visible.
1372
1373SCM_VCELL (C_NAME, SCHEME_NAME)
1374 Create a global variable at the Scheme level named SCHEME_NAME.
1375 Declare a static SCM variable named C_NAME, and initialize it to
1376 point to the Scheme variable's value cell.
1377
1378SCM_GLOBAL_VCELL (C_NAME, SCHEME_NAME)
1379 Just like SCM_VCELL, but make C_NAME globally visible.
1380
1381The `guile-snarf' script writes initialization code for these macros
1382to its standard output, given C source code as input.
1383
1384The SCM_GLOBAL macro is gone.
1385
1386** The scm_read_line and scm_read_line_x functions have been replaced
1387by Scheme code based on the %read-delimited! procedure (known to C
1388code as scm_read_delimited_x). See its description above for more
1389information.
48d224d7 1390
095936d2
JB
1391** The function scm_sys_open has been renamed to scm_open. It now
1392returns a port instead of an FD object.
ea00ecba 1393
095936d2
JB
1394* The dynamic linking support has changed. For more information, see
1395libguile/DYNAMIC-LINKING.
ea00ecba 1396
f7b47737
JB
1397\f
1398Guile 1.0b3
3065a62a 1399
f3b1485f
JB
1400User-visible changes from Thursday, September 5, 1996 until Guile 1.0
1401(Sun 5 Jan 1997):
3065a62a 1402
4b521edb 1403* Changes to the 'guile' program:
3065a62a 1404
4b521edb
JB
1405** Guile now loads some new files when it starts up. Guile first
1406searches the load path for init.scm, and loads it if found. Then, if
1407Guile is not being used to execute a script, and the user's home
1408directory contains a file named `.guile', Guile loads that.
c6486f8a 1409
4b521edb 1410** You can now use Guile as a shell script interpreter.
3065a62a
JB
1411
1412To paraphrase the SCSH manual:
1413
1414 When Unix tries to execute an executable file whose first two
1415 characters are the `#!', it treats the file not as machine code to
1416 be directly executed by the native processor, but as source code
1417 to be executed by some interpreter. The interpreter to use is
1418 specified immediately after the #! sequence on the first line of
1419 the source file. The kernel reads in the name of the interpreter,
1420 and executes that instead. It passes the interpreter the source
1421 filename as its first argument, with the original arguments
1422 following. Consult the Unix man page for the `exec' system call
1423 for more information.
1424
1a1945be
JB
1425Now you can use Guile as an interpreter, using a mechanism which is a
1426compatible subset of that provided by SCSH.
1427
3065a62a
JB
1428Guile now recognizes a '-s' command line switch, whose argument is the
1429name of a file of Scheme code to load. It also treats the two
1430characters `#!' as the start of a comment, terminated by `!#'. Thus,
1431to make a file of Scheme code directly executable by Unix, insert the
1432following two lines at the top of the file:
1433
1434#!/usr/local/bin/guile -s
1435!#
1436
1437Guile treats the argument of the `-s' command-line switch as the name
1438of a file of Scheme code to load, and treats the sequence `#!' as the
1439start of a block comment, terminated by `!#'.
1440
1441For example, here's a version of 'echo' written in Scheme:
1442
1443#!/usr/local/bin/guile -s
1444!#
1445(let loop ((args (cdr (program-arguments))))
1446 (if (pair? args)
1447 (begin
1448 (display (car args))
1449 (if (pair? (cdr args))
1450 (display " "))
1451 (loop (cdr args)))))
1452(newline)
1453
1454Why does `#!' start a block comment terminated by `!#', instead of the
1455end of the line? That is the notation SCSH uses, and although we
1456don't yet support the other SCSH features that motivate that choice,
1457we would like to be backward-compatible with any existing Guile
3763761c
JB
1458scripts once we do. Furthermore, if the path to Guile on your system
1459is too long for your kernel, you can start the script with this
1460horrible hack:
1461
1462#!/bin/sh
1463exec /really/long/path/to/guile -s "$0" ${1+"$@"}
1464!#
3065a62a
JB
1465
1466Note that some very old Unix systems don't support the `#!' syntax.
1467
c6486f8a 1468
4b521edb 1469** You can now run Guile without installing it.
6685dc83
JB
1470
1471Previous versions of the interactive Guile interpreter (`guile')
1472couldn't start up unless Guile's Scheme library had been installed;
1473they used the value of the environment variable `SCHEME_LOAD_PATH'
1474later on in the startup process, but not to find the startup code
1475itself. Now Guile uses `SCHEME_LOAD_PATH' in all searches for Scheme
1476code.
1477
1478To run Guile without installing it, build it in the normal way, and
1479then set the environment variable `SCHEME_LOAD_PATH' to a
1480colon-separated list of directories, including the top-level directory
1481of the Guile sources. For example, if you unpacked Guile so that the
1482full filename of this NEWS file is /home/jimb/guile-1.0b3/NEWS, then
1483you might say
1484
1485 export SCHEME_LOAD_PATH=/home/jimb/my-scheme:/home/jimb/guile-1.0b3
1486
c6486f8a 1487
4b521edb
JB
1488** Guile's read-eval-print loop no longer prints #<unspecified>
1489results. If the user wants to see this, she can evaluate the
1490expression (assert-repl-print-unspecified #t), perhaps in her startup
48d224d7 1491file.
6685dc83 1492
4b521edb
JB
1493** Guile no longer shows backtraces by default when an error occurs;
1494however, it does display a message saying how to get one, and how to
1495request that they be displayed by default. After an error, evaluate
1496 (backtrace)
1497to see a backtrace, and
1498 (debug-enable 'backtrace)
1499to see them by default.
6685dc83 1500
6685dc83 1501
d9fb83d9 1502
4b521edb
JB
1503* Changes to Guile Scheme:
1504
1505** Guile now distinguishes between #f and the empty list.
1506
1507This is for compatibility with the IEEE standard, the (possibly)
1508upcoming Revised^5 Report on Scheme, and many extant Scheme
1509implementations.
1510
1511Guile used to have #f and '() denote the same object, to make Scheme's
1512type system more compatible with Emacs Lisp's. However, the change
1513caused too much trouble for Scheme programmers, and we found another
1514way to reconcile Emacs Lisp with Scheme that didn't require this.
1515
1516
1517** Guile's delq, delv, delete functions, and their destructive
c6486f8a
JB
1518counterparts, delq!, delv!, and delete!, now remove all matching
1519elements from the list, not just the first. This matches the behavior
1520of the corresponding Emacs Lisp functions, and (I believe) the Maclisp
1521functions which inspired them.
1522
1523I recognize that this change may break code in subtle ways, but it
1524seems best to make the change before the FSF's first Guile release,
1525rather than after.
1526
1527
4b521edb 1528** The compiled-library-path function has been deleted from libguile.
6685dc83 1529
4b521edb 1530** The facilities for loading Scheme source files have changed.
c6486f8a 1531
4b521edb 1532*** The variable %load-path now tells Guile which directories to search
6685dc83
JB
1533for Scheme code. Its value is a list of strings, each of which names
1534a directory.
1535
4b521edb
JB
1536*** The variable %load-extensions now tells Guile which extensions to
1537try appending to a filename when searching the load path. Its value
1538is a list of strings. Its default value is ("" ".scm").
1539
1540*** (%search-load-path FILENAME) searches the directories listed in the
1541value of the %load-path variable for a Scheme file named FILENAME,
1542with all the extensions listed in %load-extensions. If it finds a
1543match, then it returns its full filename. If FILENAME is absolute, it
1544returns it unchanged. Otherwise, it returns #f.
6685dc83 1545
4b521edb
JB
1546%search-load-path will not return matches that refer to directories.
1547
1548*** (primitive-load FILENAME :optional CASE-INSENSITIVE-P SHARP)
1549uses %seach-load-path to find a file named FILENAME, and loads it if
1550it finds it. If it can't read FILENAME for any reason, it throws an
1551error.
6685dc83
JB
1552
1553The arguments CASE-INSENSITIVE-P and SHARP are interpreted as by the
4b521edb
JB
1554`read' function.
1555
1556*** load uses the same searching semantics as primitive-load.
1557
1558*** The functions %try-load, try-load-with-path, %load, load-with-path,
1559basic-try-load-with-path, basic-load-with-path, try-load-module-with-
1560path, and load-module-with-path have been deleted. The functions
1561above should serve their purposes.
1562
1563*** If the value of the variable %load-hook is a procedure,
1564`primitive-load' applies its value to the name of the file being
1565loaded (without the load path directory name prepended). If its value
1566is #f, it is ignored. Otherwise, an error occurs.
1567
1568This is mostly useful for printing load notification messages.
1569
1570
1571** The function `eval!' is no longer accessible from the scheme level.
1572We can't allow operations which introduce glocs into the scheme level,
1573because Guile's type system can't handle these as data. Use `eval' or
1574`read-and-eval!' (see below) as replacement.
1575
1576** The new function read-and-eval! reads an expression from PORT,
1577evaluates it, and returns the result. This is more efficient than
1578simply calling `read' and `eval', since it is not necessary to make a
1579copy of the expression for the evaluator to munge.
1580
1581Its optional arguments CASE_INSENSITIVE_P and SHARP are interpreted as
1582for the `read' function.
1583
1584
1585** The function `int?' has been removed; its definition was identical
1586to that of `integer?'.
1587
1588** The functions `<?', `<?', `<=?', `=?', `>?', and `>=?'. Code should
1589use the R4RS names for these functions.
1590
1591** The function object-properties no longer returns the hash handle;
1592it simply returns the object's property list.
1593
1594** Many functions have been changed to throw errors, instead of
1595returning #f on failure. The point of providing exception handling in
1596the language is to simplify the logic of user code, but this is less
1597useful if Guile's primitives don't throw exceptions.
1598
1599** The function `fileno' has been renamed from `%fileno'.
1600
1601** The function primitive-mode->fdes returns #t or #f now, not 1 or 0.
1602
1603
1604* Changes to Guile's C interface:
1605
1606** The library's initialization procedure has been simplified.
1607scm_boot_guile now has the prototype:
1608
1609void scm_boot_guile (int ARGC,
1610 char **ARGV,
1611 void (*main_func) (),
1612 void *closure);
1613
1614scm_boot_guile calls MAIN_FUNC, passing it CLOSURE, ARGC, and ARGV.
1615MAIN_FUNC should do all the work of the program (initializing other
1616packages, reading user input, etc.) before returning. When MAIN_FUNC
1617returns, call exit (0); this function never returns. If you want some
1618other exit value, MAIN_FUNC may call exit itself.
1619
1620scm_boot_guile arranges for program-arguments to return the strings
1621given by ARGC and ARGV. If MAIN_FUNC modifies ARGC/ARGV, should call
1622scm_set_program_arguments with the final list, so Scheme code will
1623know which arguments have been processed.
1624
1625scm_boot_guile establishes a catch-all catch handler which prints an
1626error message and exits the process. This means that Guile exits in a
1627coherent way when system errors occur and the user isn't prepared to
1628handle it. If the user doesn't like this behavior, they can establish
1629their own universal catcher in MAIN_FUNC to shadow this one.
1630
1631Why must the caller do all the real work from MAIN_FUNC? The garbage
1632collector assumes that all local variables of type SCM will be above
1633scm_boot_guile's stack frame on the stack. If you try to manipulate
1634SCM values after this function returns, it's the luck of the draw
1635whether the GC will be able to find the objects you allocate. So,
1636scm_boot_guile function exits, rather than returning, to discourage
1637people from making that mistake.
1638
1639The IN, OUT, and ERR arguments were removed; there are other
1640convenient ways to override these when desired.
1641
1642The RESULT argument was deleted; this function should never return.
1643
1644The BOOT_CMD argument was deleted; the MAIN_FUNC argument is more
1645general.
1646
1647
1648** Guile's header files should no longer conflict with your system's
1649header files.
1650
1651In order to compile code which #included <libguile.h>, previous
1652versions of Guile required you to add a directory containing all the
1653Guile header files to your #include path. This was a problem, since
1654Guile's header files have names which conflict with many systems'
1655header files.
1656
1657Now only <libguile.h> need appear in your #include path; you must
1658refer to all Guile's other header files as <libguile/mumble.h>.
1659Guile's installation procedure puts libguile.h in $(includedir), and
1660the rest in $(includedir)/libguile.
1661
1662
1663** Two new C functions, scm_protect_object and scm_unprotect_object,
1664have been added to the Guile library.
1665
1666scm_protect_object (OBJ) protects OBJ from the garbage collector.
1667OBJ will not be freed, even if all other references are dropped,
1668until someone does scm_unprotect_object (OBJ). Both functions
1669return OBJ.
1670
1671Note that calls to scm_protect_object do not nest. You can call
1672scm_protect_object any number of times on a given object, and the
1673next call to scm_unprotect_object will unprotect it completely.
1674
1675Basically, scm_protect_object and scm_unprotect_object just
1676maintain a list of references to things. Since the GC knows about
1677this list, all objects it mentions stay alive. scm_protect_object
1678adds its argument to the list; scm_unprotect_object remove its
1679argument from the list.
1680
1681
1682** scm_eval_0str now returns the value of the last expression
1683evaluated.
1684
1685** The new function scm_read_0str reads an s-expression from a
1686null-terminated string, and returns it.
1687
1688** The new function `scm_stdio_to_port' converts a STDIO file pointer
1689to a Scheme port object.
1690
1691** The new function `scm_set_program_arguments' allows C code to set
1692the value teruturned by the Scheme `program-arguments' function.
6685dc83 1693
6685dc83 1694\f
1a1945be
JB
1695Older changes:
1696
1697* Guile no longer includes sophisticated Tcl/Tk support.
1698
1699The old Tcl/Tk support was unsatisfying to us, because it required the
1700user to link against the Tcl library, as well as Tk and Guile. The
1701interface was also un-lispy, in that it preserved Tcl/Tk's practice of
1702referring to widgets by names, rather than exporting widgets to Scheme
1703code as a special datatype.
1704
1705In the Usenix Tk Developer's Workshop held in July 1996, the Tcl/Tk
1706maintainers described some very interesting changes in progress to the
1707Tcl/Tk internals, which would facilitate clean interfaces between lone
1708Tk and other interpreters --- even for garbage-collected languages
1709like Scheme. They expected the new Tk to be publicly available in the
1710fall of 1996.
1711
1712Since it seems that Guile might soon have a new, cleaner interface to
1713lone Tk, and that the old Guile/Tk glue code would probably need to be
1714completely rewritten, we (Jim Blandy and Richard Stallman) have
1715decided not to support the old code. We'll spend the time instead on
1716a good interface to the newer Tk, as soon as it is available.
5c54da76 1717
8512dea6 1718Until then, gtcltk-lib provides trivial, low-maintenance functionality.
deb95d71 1719
5c54da76
JB
1720\f
1721Copyright information:
1722
ea00ecba 1723Copyright (C) 1996,1997 Free Software Foundation, Inc.
5c54da76
JB
1724
1725 Permission is granted to anyone to make or distribute verbatim copies
1726 of this document as received, in any medium, provided that the
1727 copyright notice and this permission notice are preserved,
1728 thus giving the recipient permission to redistribute in turn.
1729
1730 Permission is granted to distribute modified versions
1731 of this document, or of portions of it,
1732 under the above conditions, provided also that they
1733 carry prominent notices stating who last changed them.
1734
48d224d7
JB
1735\f
1736Local variables:
1737mode: outline
1738paragraph-separate: "[ \f]*$"
1739end:
1740