1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 09:10:22 +02:00

Merge remote-tracking branch 'origin/stable-2.0'

Moved scm_i_struct_hash from struct.c to hash.c and made it static.

The port's alist is now a field of 'scm_t_port'.

Conflicts:
	libguile/arrays.c
	libguile/hash.c
	libguile/ports.c
	libguile/print.h
	libguile/read.c
This commit is contained in:
Mark H Weaver 2012-10-30 23:46:31 -04:00
commit fa980bcc0f
53 changed files with 1677 additions and 531 deletions

View file

@ -62,6 +62,7 @@ guile_TEXINFOS = preface.texi \
web.texi \
expect.texi \
scsh.texi \
curried.texi \
sxml-match.texi \
scheme-scripts.texi \
api-overview.texi \

View file

@ -3152,12 +3152,24 @@ These procedures are useful for similar tasks.
Convert the string @var{str} into a list of characters.
@end deffn
@deffn {Scheme Procedure} string-split str chr
@deffnx {C Function} scm_string_split (str, chr)
@deffn {Scheme Procedure} string-split str char_pred
@deffnx {C Function} scm_string_split (str, char_pred)
Split the string @var{str} into a list of substrings delimited
by appearances of the character @var{chr}. Note that an empty substring
between separator characters will result in an empty string in the
result list.
by appearances of characters that
@itemize @bullet
@item
equal @var{char_pred}, if it is a character,
@item
satisfy the predicate @var{char_pred}, if it is a procedure,
@item
are in the set @var{char_pred}, if it is a character set.
@end itemize
Note that an empty substring between separator characters will result in
an empty string in the result list.
@lisp
(string-split "root:x:0:0:root:/root:/bin/bash" #\:)

View file

@ -254,6 +254,8 @@ Encoding of Source Files}.
@node Case Sensitivity
@subsubsection Case Sensitivity
@cindex fold-case
@cindex no-fold-case
@c FIXME::martin: Review me!
@ -275,9 +277,9 @@ options, @xref{Scheme Read}.
(read-enable 'case-insensitive)
@end lisp
Note that this is seldom a problem, because Scheme programmers tend not
to use uppercase letters in their identifiers anyway.
It is also possible to disable (or enable) case sensitivity within a
single file by placing the reader directives @code{#!fold-case} (or
@code{#!no-fold-case}) within the file itself.
@node Keyword Syntax
@subsubsection Keyword Syntax
@ -315,10 +317,10 @@ its read options.
@cindex options - read
@cindex read options
@deffn {Scheme Procedure} read-options [setting]
Display the current settings of the read options. If @var{setting} is
omitted, only a short form of the current read options is printed.
Otherwise if @var{setting} is the symbol @code{help}, a complete options
description is displayed.
Display the current settings of the global read options. If
@var{setting} is omitted, only a short form of the current read options
is printed. Otherwise if @var{setting} is the symbol @code{help}, a
complete options description is displayed.
@end deffn
The set of available options, and their default values, may be had by
@ -336,8 +338,19 @@ r6rs-hex-escapes no Use R6RS variable-length character and string hex escape
square-brackets yes Treat `[' and `]' as parentheses, for R6RS compatibility.
hungry-eol-escapes no In strings, consume leading whitespace after an
escaped end-of-line.
curly-infix no Support SRFI-105 curly infix expressions.
@end smalllisp
Note that Guile also includes a preliminary mechanism for setting read
options on a per-port basis. For instance, the @code{case-insensitive}
read option is set (or unset) on the port when the reader encounters the
@code{#!fold-case} or @code{#!no-fold-case} reader directives.
Similarly, the @code{#!curly-infix} reader directive sets the
@code{curly-infix} read option on the port, and
@code{#!curly-infix-and-bracket-lists} sets @code{curly-infix} and
unsets @code{square-brackets} on the port (@pxref{SRFI-105}). There is
currently no other way to access or set the per-port read options.
The boolean options may be toggled with @code{read-enable} and
@code{read-disable}. The non-boolean @code{keywords} option must be set
using @code{read-set!}.

View file

@ -390,6 +390,7 @@ r6rs-hex-escapes no Use R6RS variable-length character and string hex escape
square-brackets yes Treat `[' and `]' as parentheses, for R6RS compatibility.
hungry-eol-escapes no In strings, consume leading whitespace after an
escaped end-of-line.
curly-infix no Support SRFI-105 curly infix expressions.
scheme@@(guile-user) [1]> (read-enable 'case-insensitive)
$2 = (square-brackets keywords #f case-insensitive positions)
scheme@@(guile-user) [1]> ,q

View file

@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2009, 2010
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2009, 2010, 2012
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@ -54,11 +54,12 @@ Zero bytes (@code{#\nul}) cannot be used in regex patterns or input
strings, since the underlying C functions treat that as the end of
string. If there's a zero byte an error is thrown.
Patterns and input strings are treated as being in the locale
character set if @code{setlocale} has been called (@pxref{Locales}),
and in a multibyte locale this includes treating multi-byte sequences
as a single character. (Guile strings are currently merely bytes,
though this may change in the future, @xref{Conversion to/from C}.)
Internally, patterns and input strings are converted to the current
locale's encoding, and then passed to the C library's regular expression
routines (@pxref{Regular Expressions,,, libc, The GNU C Library
Reference Manual}). The returned match structures always point to
characters in the strings, not to individual bytes, even in the case of
multi-byte encodings.
@deffn {Scheme Procedure} string-match pattern str [start]
Compile the string @var{pattern} into a regular expression and compare

56
doc/ref/curried.texi Normal file
View file

@ -0,0 +1,56 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
@c Copyright (C) 2012 Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@node Curried Definitions
@section Curried Definitions
The macros in this section are provided by
@lisp
(use-modules (ice-9 curried-definitions))
@end lisp
@noindent
and replace those provided by default.
Prior to Guile 2.0, Guile provided a type of definition known colloquially
as a ``curried definition''. The idea is to extend the syntax of
@code{define} so that you can conveniently define procedures that return
procedures, up to any desired depth.
For example,
@example
(define ((foo x) y)
(list x y))
@end example
is a convenience form of
@example
(define foo
(lambda (x)
(lambda (y)
(list x y))))
@end example
@deffn {Scheme Syntax} define (@dots{} (name args @dots{}) @dots{}) body @dots{}
@deffnx {Scheme Syntax} define* (@dots{} (name args @dots{}) @dots{}) body @dots{}
@deffnx {Scheme Syntax} define-public (@dots{} (name args @dots{}) @dots{}) body @dots{}
Create a top level variable @var{name} bound to the procedure with
parameter list @var{args}. If @var{name} is itself a formal parameter
list, then a higher order procedure is created using that
formal-parameter list, and returning a procedure that has parameter list
@var{args}. This nesting may occur to arbitrary depth.
@code{define*} is similar but the formal parameter lists take additional
options as described in @ref{lambda* and define*}. For example,
@example
(define* ((foo #:keys (bar 'baz) (quux 'zot)) frotz #:rest rest)
(list bar quux frotz rest))
((foo #:quux 'foo) 1 2 3 4 5)
@result{} (baz foo 1 (2 3 4 5))
@end example
@code{define-public} is similar to @code{define} but it also adds
@var{name} to the list of exported bindings of the current module.
@end deffn

View file

@ -370,6 +370,7 @@ available through both Scheme and C interfaces.
* Expect:: Controlling interactive programs with Guile.
* sxml-match:: Pattern matching of SXML.
* The Scheme shell (scsh):: Using scsh interfaces in Guile.
* Curried Definitions:: Extended @code{define} syntax.
@end menu
@include slib.texi
@ -387,6 +388,7 @@ available through both Scheme and C interfaces.
@include sxml-match.texi
@include scsh.texi
@include curried.texi
@node Standard Library
@chapter Standard Library

View file

@ -476,6 +476,11 @@ The corresponding forms of the alternative @code{define} syntax are:
@noindent
For details on how these forms work, see @xref{Lambda}.
Prior to Guile 2.0, Guile provided an extension to @code{define} syntax
that allowed you to nest the previous extension up to an arbitrary
depth. These are no longer provided by default, and instead have been
moved to @ref{Curried Definitions}
(It could be argued that the alternative @code{define} forms are rather
confusing, especially for newcomers to the Scheme language, as they hide
both the role of @code{lambda} and the fact that procedures are values

View file

@ -457,7 +457,7 @@ show a short error printout.
Default values for REPL options may be set using
@code{repl-default-option-set!} from @code{(system repl common)}:
@deffn {Scheme Procedure} repl-set-default-option! key value
@deffn {Scheme Procedure} repl-default-option-set! key value
Set the default value of a REPL option. This function is particularly
useful in a user's init file. @xref{Init File}.
@end deffn

View file

@ -54,6 +54,7 @@ get the relevant SRFI documents from the SRFI home page
* SRFI-69:: Basic hash tables.
* SRFI-88:: Keyword objects.
* SRFI-98:: Accessing environment variables.
* SRFI-105:: Curly-infix expressions.
@end menu
@ -3003,10 +3004,10 @@ with locale decimal point, eg.@: @samp{5.2}
@item @nicode{~z} @tab time zone, RFC-822 style
@item @nicode{~Z} @tab time zone symbol (not currently implemented)
@item @nicode{~1} @tab ISO-8601 date, @samp{~Y-~m-~d}
@item @nicode{~2} @tab ISO-8601 time+zone, @samp{~k:~M:~S~z}
@item @nicode{~3} @tab ISO-8601 time, @samp{~k:~M:~S}
@item @nicode{~4} @tab ISO-8601 date/time+zone, @samp{~Y-~m-~dT~k:~M:~S~z}
@item @nicode{~5} @tab ISO-8601 date/time, @samp{~Y-~m-~dT~k:~M:~S}
@item @nicode{~2} @tab ISO-8601 time+zone, @samp{~H:~M:~S~z}
@item @nicode{~3} @tab ISO-8601 time, @samp{~H:~M:~S}
@item @nicode{~4} @tab ISO-8601 date/time+zone, @samp{~Y-~m-~dT~H:~M:~S~z}
@item @nicode{~5} @tab ISO-8601 date/time, @samp{~Y-~m-~dT~H:~M:~S}
@end multitable
@end defun
@ -4469,6 +4470,56 @@ Returns the names and values of all the environment variables as an
association list in which both the keys and the values are strings.
@end deffn
@node SRFI-105
@subsection SRFI-105 Curly-infix expressions.
@cindex SRFI-105
@cindex curly-infix
@cindex curly-infix-and-bracket-lists
Guile's built-in reader includes support for SRFI-105 curly-infix
expressions. See @uref{http://srfi.schemers.org/srfi-105/srfi-105.html,
the specification of SRFI-105}. Some examples:
@example
@{n <= 5@} @result{} (<= n 5)
@{a + b + c@} @result{} (+ a b c)
@{a * @{b + c@}@} @result{} (* a (+ b c))
@{(- a) / b@} @result{} (/ (- a) b)
@{-(a) / b@} @result{} (/ (- a) b) as well
@{(f a b) + (g h)@} @result{} (+ (f a b) (g h))
@{f(a b) + g(h)@} @result{} (+ (f a b) (g h)) as well
@{f[a b] + g(h)@} @result{} (+ ($bracket-apply$ f a b) (g h))
'@{a + f(b) + x@} @result{} '(+ a (f b) x)
@{length(x) >= 6@} @result{} (>= (length x) 6)
@{n-1 + n-2@} @result{} (+ n-1 n-2)
@{n * factorial@{n - 1@}@} @result{} (* n (factorial (- n 1)))
@{@{a > 0@} and @{b >= 1@}@} @result{} (and (> a 0) (>= b 1))
@{f@{n - 1@}(x)@} @result{} ((f (- n 1)) x)
@{a . z@} @result{} ($nfx$ a . z)
@{a + b - c@} @result{} ($nfx$ a + b - c)
@end example
To enable curly-infix expressions within a file, place the reader
directive @code{#!curly-infix} before the first use of curly-infix
notation. To globally enable curly-infix expressions in Guile's reader,
set the @code{curly-infix} read option.
Guile also implements the following non-standard extension to SRFI-105:
if @code{curly-infix} is enabled and there is no other meaning assigned
to square brackets (i.e. the @code{square-brackets} read option is
turned off), then lists within square brackets are read as normal lists
but with the special symbol @code{$bracket-list$} added to the front.
To enable this combination of read options within a file, use the reader
directive @code{#!curly-infix-and-bracket-lists}. For example:
@example
[a b] @result{} ($bracket-list$ a b)
[a . b] @result{} ($bracket-list$ a . b)
@end example
For more information on reader options, @xref{Scheme Read}.
@c srfi-modules.texi ends here
@c Local Variables:

View file

@ -1,7 +1,7 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2010, 2011
@c Free Software Foundation, Inc.
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2010, 2011,
@c 2012 Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@raisesections
@ -149,7 +149,7 @@ that makes the @code{j0} function available to Scheme code.
SCM
j0_wrapper (SCM x)
@{
return scm_make_real (j0 (scm_num2dbl (x, "j0")));
return scm_from_double (j0 (scm_to_double (x)));
@}
void