summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--module/Makefile.am1
-rw-r--r--module/ice-9/curried-definitions.scm37
-rw-r--r--test-suite/Makefile.am1
-rw-r--r--test-suite/tests/curried-definitions.test46
4 files changed, 85 insertions, 0 deletions
diff --git a/module/Makefile.am b/module/Makefile.am
index ca3852417..16013b05f 100644
--- a/module/Makefile.am
+++ b/module/Makefile.am
@@ -179,6 +179,7 @@ ICE_9_SOURCES = \
ice-9/calling.scm \
ice-9/common-list.scm \
ice-9/control.scm \
+ ice-9/curried-definitions.scm \
ice-9/debug.scm \
ice-9/debugger.scm \
ice-9/documentation.scm \
diff --git a/module/ice-9/curried-definitions.scm b/module/ice-9/curried-definitions.scm
new file mode 100644
index 000000000..d7db1f0a8
--- /dev/null
+++ b/module/ice-9/curried-definitions.scm
@@ -0,0 +1,37 @@
+;;; Copyright (C) 2010 Free Software Foundation, Inc.
+;;;
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 3 of the License, or (at your option) any later version.
+;;;;
+;;;; This library is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this library; if not, write to the Free Software
+;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(define-module (ice-9 curried-definitions)
+ #:replace ((cdefine . define)
+ (cdefine* . define*)))
+
+(define-syntax cdefine
+ (syntax-rules ()
+ ((_ ((head . tail) . rest) body body* ...)
+ (cdefine (head . tail)
+ (lambda rest body body* ...)))
+ ((_ (head . rest) body body* ...)
+ (define head
+ (lambda rest body body* ...)))))
+
+(define-syntax cdefine*
+ (syntax-rules ()
+ ((_ ((head . tail) . rest) body body* ...)
+ (cdefine* (head . tail)
+ (lambda* rest body body* ...)))
+ ((_ (head . rest) body body* ...)
+ (define* head
+ (lambda* rest body body* ...)))))
diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am
index bc166c432..006b13107 100644
--- a/test-suite/Makefile.am
+++ b/test-suite/Makefile.am
@@ -35,6 +35,7 @@ SCM_TESTS = tests/00-initial-env.test \
tests/common-list.test \
tests/control.test \
tests/continuations.test \
+ tests/curried-definitions.test \
tests/ecmascript.test \
tests/elisp.test \
tests/elisp-compiler.test \
diff --git a/test-suite/tests/curried-definitions.test b/test-suite/tests/curried-definitions.test
new file mode 100644
index 000000000..650288f5c
--- /dev/null
+++ b/test-suite/tests/curried-definitions.test
@@ -0,0 +1,46 @@
+;;;; curried-definitions.test -*- scheme -*-
+;;;; Copyright (C) 2010 Free Software Foundation, Inc.
+;;;;
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 3 of the License, or (at your option) any later version.
+;;;;
+;;;; This library is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this library; if not, write to the Free Software
+;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(define-module (test-suite test-curried-definitions)
+ #:use-module (test-suite lib)
+ #:use-module (ice-9 curried-definitions))
+
+(with-test-prefix "define"
+ (pass-if "define works as usual"
+ (equal? 34
+ (primitive-eval '(let ()
+ (define (foo)
+ 34)
+ (foo)))))
+ (pass-if "define works as usual (2)"
+ (equal? 134
+ (primitive-eval '(let ()
+ (define (foo x)
+ (+ x 34))
+ (foo 100)))))
+ (pass-if "currying once"
+ (equal? 234
+ (primitive-eval '(let ()
+ (define ((foo) x)
+ (+ x 34))
+ ((foo) 200)))))
+ (pass-if "currying twice"
+ (equal? 334
+ (primitive-eval '(let ()
+ (define (((foo)) x)
+ (+ x 34))
+ (((foo)) 300))))))