Search code examples
promiseracketr5rs

scheme `promise?` Dr Racket, geiser


Welcome to DrRacket, version 6.0 [3m].
Language: racket; memory limit: 128 MB.
> promise?
#<procedure:promise?>
> (promise? (delay (+ 1 2)))
#t

I need to use R5RS and am working with delayed evaluation... here using geiser in emacs:

racket@> (require r5rs)
racket@> (cons 1 '())
(mcons 1 '()) ;; this is how racket represents a r5rs cons
racket@> (define x (delay (+ 1 2)))
racket@> x
#<promise>
racket@> (promise? x)
#f ;; what is going on here???
racket@> promise?
#<procedure:promise?>

Surely the above code (promise? x) should return #t... I have noticed that when i switch to R5rS in DrRacket (gui) I get the following error. Can someone explain what is going on? I thought promise? was defined for R5RS. Or am I mistaken?

Welcome to DrRacket, version 6.0 [3m].
Language: R5RS; memory limit: 128 MB.
> promise?
. . promise?: undefined;
 cannot reference undefined identifier
> 

Solution

  • There is no promise? in R5RS. The construct delay produces a value representing a promise, but it is up the implementor to decide how to represent promises. Some implementations have chosen to represent them as closures. The R5RS implementation in Racket has chosen to use a struct with the name promise?. That's why you see the promise value printed as #<promise>.

    I suspect something similar is true for R6RS.