GNU bug report logs - #12341
define does not support lambda shorthand notation, define-public does

Previous Next

Package: guile;

Reported by: David Kastrup <dak <at> gnu.org>

Date: Mon, 3 Sep 2012 18:08:01 UTC

Severity: normal

Done: Ian Price <ianprice90 <at> googlemail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12341 in the body.
You can then email your comments to 12341 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Mon, 03 Sep 2012 18:08:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to David Kastrup <dak <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Mon, 03 Sep 2012 18:08:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: David Kastrup <dak <at> gnu.org>
To: bug-guile <at> gnu.org
Subject: define does not support lambda shorthand notation, define-public does
Date: Mon, 03 Sep 2012 20:05:25 +0200
Having this supported in define-public but not in define seems like an
inconsistency:


dak <at> lola:/usr/local/tmp/lilypond$ guile
GNU Guile 2.0.5-deb+1-1
Copyright (C) 1995-2012 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (define-public ((x a) b) a)
scheme@(guile-user)> (define ((x a) b) a)
While compiling expression:
ERROR: Syntax error:
unknown file:2:0: source expression failed to match any pattern in form (define ((x a) b) a)
scheme@(guile-user)> 

The Scheme report does not mention this explicitly, but it would appear
as a recursive application of the rule
(define (a b) ...) -> (define a (lambda (b) ...))

leading first to

(define (x a) (lambda (b) a))

and thence to

(define x (lambda (a) (lambda (b) a)))

And if it is not supposed to be supported, why is it supported with
define-public?

-- 
David Kastrup




Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Mon, 03 Sep 2012 20:32:01 GMT) Full text and rfc822 format available.

Message #8 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: David Kastrup <dak <at> gnu.org>
Cc: 12341 <at> debbugs.gnu.org
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Mon, 03 Sep 2012 22:29:48 +0200
Hi David,

David Kastrup <dak <at> gnu.org> skribis:

> scheme@(guile-user)> (define-public ((x a) b) a)
> scheme@(guile-user)> (define ((x a) b) a)
> While compiling expression:
> ERROR: Syntax error:
> unknown file:2:0: source expression failed to match any pattern in form (define ((x a) b) a)

For the latter, one should use (ice-9 curried-definitions), introduced
in 2.0 (see ‘NEWS’), with code like this:

  (cond-expand (guile-2 (use-modules (ice-9 curried-definitions)))
               (else    #t))  ; Guile 1.8 and earlier supports it

That the former works is indeed inconsistent.  It’s due to the fact that
‘define-public’ is implemented as a macro, whereas ‘define’ is a core
form.

I’m inclined to live with the inconsistency, but I’m open to
suggestions.

Thanks,
Ludo’.

PS: This was also discussed at
    <http://thread.gmane.org/gmane.comp.gnu.lilypond.devel/31461>.




Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Tue, 04 Sep 2012 12:22:02 GMT) Full text and rfc822 format available.

Message #11 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 12341 <at> debbugs.gnu.org, David Kastrup <dak <at> gnu.org>
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Tue, 04 Sep 2012 13:21:39 +0100
[Message part 1 (text/plain, inline)]
ludo <at> gnu.org (Ludovic Court$(D+2(Bs) writes:

> I$B!G(Bm inclined to live with the inconsistency, but I$B!G(Bm open to
> suggestions.
A quick git grep doesn't show any uses of curried define-public in the
guile code base, so the fix is pretty simple. I'm open to better
approaches though, since it does duplicate code, though this code is IMO
trivial.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

[0001-define-public-is-no-a-longer-curried-definition-by-d.patch (text/x-patch, inline)]
From fb23b4a49e9c1f5c15ef0ceb2ee1903ebfddd71a Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90 <at> googlemail.com>
Date: Tue, 4 Sep 2012 13:18:58 +0100
Subject: [PATCH] `define-public' is no a longer curried definition by
 default.

* module/ice-9/boot-9.scm (define-public): Remove currying functionality.
* module/ice-9/curried-definitions.scm (define-public): New export.
---
 module/ice-9/boot-9.scm              |    4 +++-
 module/ice-9/curried-definitions.scm |   14 +++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 5ed543a..cf8252a 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -3321,7 +3321,9 @@ module '(ice-9 q) '(make-q q-length))}."
 (define-syntax define-public
   (syntax-rules ()
     ((_ (name . args) . body)
-     (define-public name (lambda args . body)))
+     (begin
+       (define name (lambda args . body))
+       (export name)))
     ((_ name val)
      (begin
        (define name val)
diff --git a/module/ice-9/curried-definitions.scm b/module/ice-9/curried-definitions.scm
index d55f1fb..8c684a1 100644
--- a/module/ice-9/curried-definitions.scm
+++ b/module/ice-9/curried-definitions.scm
@@ -16,7 +16,8 @@
 
 (define-module (ice-9 curried-definitions)
   #:replace ((cdefine . define)
-             (cdefine* . define*)))
+             (cdefine* . define*)
+             define-public))
 
 (define-syntax cdefine
   (syntax-rules ()
@@ -39,3 +40,14 @@
        (lambda* rest body body* ...)))
     ((_ . rest)
      (define* . rest))))
+
+(define-syntax define-public
+  (syntax-rules ()
+    ((_ (name . args) . body)
+     (begin
+       (cdefine (name . args) . body)
+       (export name)))
+    ((_ name val)
+     (begin
+       (define name val)
+       (export name)))))
-- 
1.7.7.6


Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Tue, 04 Sep 2012 12:37:01 GMT) Full text and rfc822 format available.

Message #14 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: David Kastrup <dak <at> gnu.org>
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 12341 <at> debbugs.gnu.org
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Tue, 04 Sep 2012 14:36:26 +0200
Ian Price <ianprice90 <at> googlemail.com> writes:

> ludo <at> gnu.org (Ludovic Courtès) writes:
>
>> I’m inclined to live with the inconsistency, but I’m open to
>> suggestions.
> A quick git grep doesn't show any uses of curried define-public in the
> guile code base, so the fix is pretty simple. I'm open to better
> approaches though, since it does duplicate code, though this code is IMO
> trivial.

Since this is a change from 1.8 behavior, would it be feasible to place
a cross-reference to (ice-9 curried-definitions) into the manual entry
for define ?  At the current point of time, discoverability of this
change is really bad.  I can't find _any_ reference to it in the Guile
manual (a plain text search for either "curried" or "curry" turns up
nothing), so it seems like this is just a change sprung without notice
or discoverable remedy on Guile users.

I'd have expected a pointer at least somewhere (if not everywhere) among
those links:

<URL:http://www.gnu.org/software/guile/manual/html_node/Definition.html#Definition>

<URL:http://www.gnu.org/software/guile/manual/html_node/Lambda-Alternatives.html#Lambda-Alternatives>

-- 
David Kastrup




Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Tue, 04 Sep 2012 14:39:02 GMT) Full text and rfc822 format available.

Message #17 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: David Kastrup <dak <at> gnu.org>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 12341 <at> debbugs.gnu.org
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Tue, 04 Sep 2012 15:37:50 +0100
[Message part 1 (text/plain, inline)]
David Kastrup <dak <at> gnu.org> writes:

> I'd have expected a pointer at least somewhere (if not everywhere) among
> those links:
>
> <URL:http://www.gnu.org/software/guile/manual/html_node/Definition.html#Definition>
>
> <URL:http://www.gnu.org/software/guile/manual/html_node/Lambda-Alternatives.html#Lambda-Alternatives>

I agree, and have provided some documentation. I'm no texinfo expert so
it probably needs cleanup. In particular, I wasn't sure of how to markup
these curried forms.

Comments kindly requested,

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

[0001-Document-ice-9-curried-definitions.patch (text/x-patch, inline)]
From 6addaedac96ffe919d1b0cb58ed9992fbd240bf7 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90 <at> googlemail.com>
Date: Tue, 4 Sep 2012 15:36:54 +0100
Subject: [PATCH] Document (ice-9 curried definitions)

* doc/ref/Makefile.am(guile_TEXINFOS): Add curried.texi to list
* doc/ref/curried.texi: New file.
* doc/ref/guile.texi(Guile Modules): Add "Curried Definitions" to menu.
* doc/ref/scheme-ideas.texi(Lambda Alternatives): Refer to "Curried Definitions"
  from the `define' section.
---
 doc/ref/Makefile.am       |    1 +
 doc/ref/curried.texi      |   53 +++++++++++++++++++++++++++++++++++++++++++++
 doc/ref/guile.texi        |    2 +
 doc/ref/scheme-ideas.texi |    5 ++++
 4 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 doc/ref/curried.texi

diff --git a/doc/ref/Makefile.am b/doc/ref/Makefile.am
index abe9cb9..201ab6b 100644
--- a/doc/ref/Makefile.am
+++ b/doc/ref/Makefile.am
@@ -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		\
diff --git a/doc/ref/curried.texi b/doc/ref/curried.texi
new file mode 100644
index 0000000..05475bd
--- /dev/null
+++ b/doc/ref/curried.texi
@@ -0,0 +1,53 @@
+@c -*-texinfo-*-
+@c This is part of the GNU Guile Reference Manual.
+@c Copyright (C)  2012
+@c   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, 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 {Syntax} define (@dots{} (name args @dots{}) @dots{}) expression @dots{}
+A curried version of the default @code{define}.
+@end deffn
+
+@deffn {Syntax} define* (@dots{} (name args @dots{}) @dots{}) expression @dots{}
+A curried version of the default @code{define*}. Accepts all the options
+@code{lambda*} does, 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
+@end deffn
+
+@deffn {Syntax} define-public (@dots{} (name args @dots{}) @dots{}) expression @dots{}
+A curried version of the default @code{define-public}.
+@end deffn
diff --git a/doc/ref/guile.texi b/doc/ref/guile.texi
index c3da0c3..a1b3fe6 100644
--- a/doc/ref/guile.texi
+++ b/doc/ref/guile.texi
@@ -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
diff --git a/doc/ref/scheme-ideas.texi b/doc/ref/scheme-ideas.texi
index 53f7b61..49297fd 100644
--- a/doc/ref/scheme-ideas.texi
+++ b/doc/ref/scheme-ideas.texi
@@ -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, 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
-- 
1.7.7.6


Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Wed, 05 Sep 2012 21:17:02 GMT) Full text and rfc822 format available.

Message #20 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 12341 <at> debbugs.gnu.org, David Kastrup <dak <at> gnu.org>
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Wed, 05 Sep 2012 23:16:02 +0200
Hello,

Ian Price <ianprice90 <at> googlemail.com> skribis:

> From fb23b4a49e9c1f5c15ef0ceb2ee1903ebfddd71a Mon Sep 17 00:00:00 2001
> From: Ian Price <ianprice90 <at> googlemail.com>
> Date: Tue, 4 Sep 2012 13:18:58 +0100
> Subject: [PATCH] `define-public' is no a longer curried definition by
>  default.
>
> * module/ice-9/boot-9.scm (define-public): Remove currying functionality.
> * module/ice-9/curried-definitions.scm (define-public): New export.

Looks good to me.

You now have commit access, so you’re welcome to commit it by yourself!
:-)

Please post patches before committing, for a start.  Make sure to always
rebase before committing, to avoid gratuitous merge commits if somebody
else pushed changes in the meantime.  If you have any doubts with Git,
please ask us.

> David Kastrup <dak <at> gnu.org> writes:
>
>> I'd have expected a pointer at least somewhere (if not everywhere) among
>> those links:
>>
>> <URL:http://www.gnu.org/software/guile/manual/html_node/Definition.html#Definition>
>>
>> <URL:http://www.gnu.org/software/guile/manual/html_node/Lambda-Alternatives.html#Lambda-Alternatives>
>
> I agree, and have provided some documentation.

+1.

> I'm no texinfo expert so it probably needs cleanup. In particular, I
> wasn't sure of how to markup these curried forms.
> From 6addaedac96ffe919d1b0cb58ed9992fbd240bf7 Mon Sep 17 00:00:00 2001
> From: Ian Price <ianprice90 <at> googlemail.com>
> Date: Tue, 4 Sep 2012 15:36:54 +0100
> Subject: [PATCH] Document (ice-9 curried definitions)
>
> * doc/ref/Makefile.am(guile_TEXINFOS): Add curried.texi to list
> * doc/ref/curried.texi: New file.
> * doc/ref/guile.texi(Guile Modules): Add "Curried Definitions" to menu.
> * doc/ref/scheme-ideas.texi(Lambda Alternatives): Refer to "Curried Definitions"
>   from the `define' section.

Please leave a space before opening parentheses.

> +++ b/doc/ref/curried.texi
> @@ -0,0 +1,53 @@
> +@c -*-texinfo-*-
> +@c This is part of the GNU Guile Reference Manual.
> +@c Copyright (C)  2012
> +@c   Free Software Foundation, Inc.

No newline.

> +@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, guile provided a type of definition known colloquially

Should be “Guile 2.0”.

> +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 {Syntax} define (@dots{} (name args @dots{}) @dots{}) expression @dots{}

It should be {Scheme Syntax}, for consistency with most of the manual.

Instead of ‘expression’, what about ‘body @dots{}’?

Also, I wonder whether the parentheses should appear at all, since it
also accepts the flat form.  OTOH, the only things worth describing is
the parenthesized form.

> +A curried version of the default @code{define}.
> +@end deffn

Please use a more formal, present-tense description, like “Create a
top-level variable @var{name} bound to the procedure defined by
@var{args}.  @var{args} may be a list of formal parameters, possibly
including nested formal parameter lists, in which case a higher-order
procedure is created, as in the example above.”

> +@deffn {Syntax} define* (@dots{} (name args @dots{}) @dots{}) expression @dots{}

Here ‘deffnx’ could be used instead, like:

  @deffn {Scheme Syntax} define (@dots{} (name args @dots{}) @dots{}) body @dots{}
  @deffnx {Scheme Syntax} define* (@dots{} (name args @dots{}) @dots{}) body @dots{}
  [...]

  @code{define*} works similarly, and accepts all the options that
  @code{lambda*} accepts (@pxref{lambda* and define*}).  For example:

  @example
  [...]
  @end example
  @end deffn
  
> +@deffn {Syntax} define-public (@dots{} (name args @dots{}) @dots{}) expression @dots{}

@deffnx too?

> +Prior to guile 2, guile provided an extension to @code{define} syntax

“Guile 2.0”.

Thanks!

Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Thu, 06 Sep 2012 20:28:01 GMT) Full text and rfc822 format available.

Message #23 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 12341 <at> debbugs.gnu.org, David Kastrup <dak <at> gnu.org>
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Thu, 06 Sep 2012 21:27:31 +0100
[Message part 1 (text/plain, inline)]
ludo <at> gnu.org (Ludovic Court$(D+2(Bs) writes:

> You now have commit access, so you$B!G(Bre welcome to commit it by yourself!
> :-)
I have :-)
>
> Please post patches before committing, for a start.  Make sure to always
> rebase before committing, to avoid gratuitous merge commits if somebody
> else pushed changes in the meantime.  If you have any doubts with Git,
> please ask us.
Rebasing is already standard practice when sending patches, so no
trouble there.

>> * doc/ref/Makefile.am(guile_TEXINFOS): Add curried.texi to list
>> * doc/ref/curried.texi: New file.
>> * doc/ref/guile.texi(Guile Modules): Add "Curried Definitions" to menu.
>> * doc/ref/scheme-ideas.texi(Lambda Alternatives): Refer to "Curried Definitions"
>>   from the `define' section.
>
> Please leave a space before opening parentheses.
Fixed.

>> +++ b/doc/ref/curried.texi
>> @@ -0,0 +1,53 @@
>> +@c -*-texinfo-*-
>> +@c This is part of the GNU Guile Reference Manual.
>> +@c Copyright (C)  2012
>> +@c   Free Software Foundation, Inc.
>
> No newline.
Can you tell I just mimicked the nearest file? Fixed.

>> +Prior to guile 2, guile provided a type of definition known colloquially
>
> Should be $B!H(BGuile 2.0$B!I(B.
Fixed.

>> +@deffn {Syntax} define (@dots{} (name args @dots{}) @dots{}) expression @dots{}
>
> It should be {Scheme Syntax}, for consistency with most of the manual.
Fixed.

> Instead of $B!F(Bexpression$B!G(B, what about $B!F(Bbody @dots{}$B!G(B?
Fixed.

> Also, I wonder whether the parentheses should appear at all, since it
> also accepts the flat form.  OTOH, the only things worth describing is
> the parenthesized form.
That was my thinking.

>> +A curried version of the default @code{define}.
>> +@end deffn
>
> Please use a more formal, present-tense description, like $B!H(BCreate a
> top-level variable @var{name} bound to the procedure defined by
> @var{args}.  @var{args} may be a list of formal parameters, possibly
> including nested formal parameter lists, in which case a higher-order
> procedure is created, as in the example above.$B!I(B
I was having a hard time adequately describing it, and thought it was
better to show by example than give a bad formal description. Anyway, I
hope I've met your expectations with this one.

>> +@deffn {Syntax} define* (@dots{} (name args @dots{}) @dots{}) expression @dots{}
>
> Here $B!F(Bdeffnx$B!G(B could be used instead, like:
I was not aware of that options, done.

>> +Prior to guile 2, guile provided an extension to @code{define} syntax
>
> $B!H(BGuile 2.0$B!I(B.
Fixed.

David,
How about you, any feedback on this documentation?

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

[0001-Document-ice-9-curried-definitions.patch (text/x-patch, inline)]
From 4f4783096d1052e6e7532acfed21616556c9c456 Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90 <at> googlemail.com>
Date: Thu, 6 Sep 2012 21:21:47 +0100
Subject: [PATCH] Document (ice-9 curried definitions)

* doc/ref/Makefile.am (guile_TEXINFOS): Add curried.texi to list
* doc/ref/curried.texi: New file.
* doc/ref/guile.texi (Guile Modules): Add "Curried Definitions" to menu.
* doc/ref/scheme-ideas.texi (Lambda Alternatives): Refer to "Curried Definitions"
  from the `define' section.
---
 doc/ref/Makefile.am       |    1 +
 doc/ref/curried.texi      |   56 +++++++++++++++++++++++++++++++++++++++++++++
 doc/ref/guile.texi        |    2 +
 doc/ref/scheme-ideas.texi |    5 ++++
 4 files changed, 64 insertions(+), 0 deletions(-)
 create mode 100644 doc/ref/curried.texi

diff --git a/doc/ref/Makefile.am b/doc/ref/Makefile.am
index abe9cb9..201ab6b 100644
--- a/doc/ref/Makefile.am
+++ b/doc/ref/Makefile.am
@@ -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		\
diff --git a/doc/ref/curried.texi b/doc/ref/curried.texi
new file mode 100644
index 0000000..f12907e
--- /dev/null
+++ b/doc/ref/curried.texi
@@ -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
diff --git a/doc/ref/guile.texi b/doc/ref/guile.texi
index c3da0c3..a1b3fe6 100644
--- a/doc/ref/guile.texi
+++ b/doc/ref/guile.texi
@@ -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
diff --git a/doc/ref/scheme-ideas.texi b/doc/ref/scheme-ideas.texi
index 53f7b61..cbf1a5c 100644
--- a/doc/ref/scheme-ideas.texi
+++ b/doc/ref/scheme-ideas.texi
@@ -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
-- 
1.7.7.6


Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Thu, 06 Sep 2012 20:38:02 GMT) Full text and rfc822 format available.

Message #26 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 12341 <at> debbugs.gnu.org, David Kastrup <dak <at> gnu.org>
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Thu, 06 Sep 2012 22:37:10 +0200
Hi!

Ian Price <ianprice90 <at> googlemail.com> skribis:

> ludo <at> gnu.org (Ludovic Courtès) writes:
>
>> You now have commit access, so you’re welcome to commit it by yourself!
>> :-)
> I have :-)

Great, thanks!

>> Please post patches before committing, for a start.  Make sure to always
>> rebase before committing, to avoid gratuitous merge commits if somebody
>> else pushed changes in the meantime.  If you have any doubts with Git,
>> please ask us.
> Rebasing is already standard practice when sending patches, so no
> trouble there.

Yeah, that’s what I suspected anyway.  ;-)

> +Prior to guile 2.0, guile provided a type of definition known colloquially

Should really be “Guile 2.0” and “Guile”, with a capital ‘G’, when
talking about the package.

Other than that, looks good to me.

Thank you!

Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#12341; Package guile. (Thu, 06 Sep 2012 21:38:01 GMT) Full text and rfc822 format available.

Message #29 received at 12341 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 12341 <at> debbugs.gnu.org, David Kastrup <dak <at> gnu.org>,
	12341-done <at> debbugs.gnu.org
Subject: Re: bug#12341: define does not support lambda shorthand notation,
	define-public does
Date: Thu, 06 Sep 2012 22:37:23 +0100
ludo <at> gnu.org (Ludovic Court$(D+2(Bs) writes:

> Should really be $B!H(BGuile 2.0$B!I(B and $B!H(BGuile$B!I(B, with a capital $B!F(BG$B!G(B, when
> talking about the package.

Ah, of course. Fixed and Pushed.

Thanks David for the report, I'm marking this as done.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




Reply sent to Ian Price <ianprice90 <at> googlemail.com>:
You have taken responsibility. (Thu, 06 Sep 2012 21:38:02 GMT) Full text and rfc822 format available.

Notification sent to David Kastrup <dak <at> gnu.org>:
bug acknowledged by developer. (Thu, 06 Sep 2012 21:38:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 05 Oct 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 321 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.