Move identity' from unstable/function' into `racket/function'.

This commit is contained in:
Eli Barzilay 2011-06-06 11:36:56 -04:00
parent 2eb0a94677
commit a70ef57f02
6 changed files with 14 additions and 15 deletions

View File

@ -1,6 +1,8 @@
#lang scheme/base #lang scheme/base
(provide const negate curry curryr) (provide identity const negate curry curryr)
(define (identity x) x)
(define (const c) (define (const c)
(define (const . _) c) (define (const . _) c)

View File

@ -482,6 +482,10 @@ applied.}
@(define fun-eval (make-base-eval)) @(define fun-eval (make-base-eval))
@(interaction-eval #:eval fun-eval (require racket/function)) @(interaction-eval #:eval fun-eval (require racket/function))
@defproc[(identity [v any/c]) any/c]{
Returns @scheme[v].
}
@defproc[(const [v any]) procedure?]{ @defproc[(const [v any]) procedure?]{
Returns a procedure that accepts any arguments and returns @scheme[v]. Returns a procedure that accepts any arguments and returns @scheme[v].

View File

@ -43,6 +43,13 @@
(test 'f object-name (rec f (lambda (x) x))) (test 'f object-name (rec f (lambda (x) x)))
(test (list 2) (rec (f . x) (if (= (car x) 3) (f 2) x)) 3)) (test (list 2) (rec (f . x) (if (= (car x) 3) (f 2) x)) 3))
;; ---------- identity ----------
(let ()
(test 'foo identity 'foo)
(test 1 identity 1)
(err/rt-test (identity 1 2))
(err/rt-test (identity)))
;; ---------- const ---------- ;; ---------- const ----------
(let () (let ()
(test 'foo (const 'foo)) (test 'foo (const 'foo))

View File

@ -9,11 +9,6 @@
(test-suite "Simple Functions" (test-suite "Simple Functions"
(test-suite "identity"
(test-case "unique symbol"
(let* ([sym (gensym)])
(check-eq? (identity sym) sym))))
(test-suite "thunk" (test-suite "thunk"
(test-case "unique symbol" (test-case "unique symbol"
(let* ([count 0] (let* ([count 0]

View File

@ -91,8 +91,6 @@
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (identity x) x)
(define-syntax (thunk stx) (define-syntax (thunk stx)
(syntax-case stx () (syntax-case stx ()
[(thunk body ...) [(thunk body ...)
@ -365,7 +363,6 @@
(provide (provide
;; functions ;; functions
identity
thunk thunk
conjoin disjoin conjoin disjoin
curryn currynr papply papplyr call curryn currynr papply papplyr call

View File

@ -14,12 +14,6 @@ This module provides tools for higher-order programming and creating functions.
@section{Simple Functions} @section{Simple Functions}
@defproc[(identity [x any/c]) (one-of/c x)]{
Returns @scheme[x].
}
@defform[(thunk body ...)]{ @defform[(thunk body ...)]{
Creates a function that ignores its inputs and evaluates the given body. Useful Creates a function that ignores its inputs and evaluates the given body. Useful