racket/undefined: remove undefined? and check-not-undefined

The intent is to provide a minimal bridge between the current Racket
and one where `(letrec ([x x]) x)` no longer works.

Merge to v6.0.1
This commit is contained in:
Matthew Flatt 2014-04-08 10:22:15 -06:00
parent e9b97c494c
commit 83a573ccd8
2 changed files with 9 additions and 32 deletions

View File

@ -1,5 +1,6 @@
#lang scribble/doc
@(require "mz.rkt")
@(require "mz.rkt"
(for-label racket/undefined))
@title[#:style 'toc #:tag "data"]{Datatypes}
@ -174,25 +175,14 @@ The @|void-const| value is always @racket[eq?] to itself.
@section[#:tag "undefined"]{Undefined}
The constant @|undefined-const| is used as the initial value for
@racket[letrec] bindings.
@racket[letrec] bindings and in other places where a placeholder value
is needed before a specific value can be assigned. Use
@racket[undefined] (which is bound to @|undefined-const|) as a last resort.
The @|undefined-const| value is always @racket[eq?] to itself.
@note-lib[racket/undefined]
@note-lib-only[racket/undefined]
@defthing[undefined any/c]{The @|undefined-const| constant.}
@history[#:added "6.0.0.6"]
@defproc[(undefined? [v any/c]) boolean?]{Returns @racket[#t] if @racket[v] is the
constant @|undefined-const|, @racket[#f] otherwise.}
@defthing[undefined undefined?]{The @|undefined-const| constant.}
@defproc[(check-not-undefined [v any/c] [sym symbol?]) (and/c any/c (not/c undefined?))]{
Checks whether @racket[v] is @|undefined-const|, and raises
@racket[exn:fail:contract:variable] in that case with an error message
along the lines of ``@racket[sym]: variable used before its definition.''
If @racket[v] is not @|undefined-const|, then @racket[v] is returned.
}

View File

@ -1,21 +1,8 @@
#lang racket/base
(require '#%kernel)
(provide check-not-undefined
undefined
undefined?)
(provide undefined)
;; In a future version of Racket, this `letrec` pattern
;; will not work, but the `racket/undefined` library will
;; still export an `undefined`:
(define undefined (letrec ([x x]) x))
(define (undefined? v) (eq? v undefined))
(define (check-not-undefined v s)
(unless (symbol? s) (raise-argument-error 'check-not-undefined "symbol?" 1 v s))
(if (eq? v undefined)
(raise (make-exn:fail:contract:variable
(format "~a: variable used before its definition" s)
(current-continuation-marks)
s))
v))