1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 22:40:34 +02:00

add (ice-9 curried definitions)

* module/Makefile.am:
* module/ice-9/curried-definitions.scm: New module, implementing
  SICM-style currying.

* test-suite/Makefile.am:
* test-suite/tests/curried-definitions.test: A test.
This commit is contained in:
Andy Wingo 2010-04-08 00:36:53 +02:00
parent 8f44138ac6
commit 9225df3c55
4 changed files with 85 additions and 0 deletions

View file

@ -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 \

View file

@ -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* ...)))))

View file

@ -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 \

View file

@ -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))))))