This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home.

Ticket 405: Make promises first-class

2012-10-07 04:36:15
WG1 - Core
cowan
major
cowan
fixed
source
closed
2012-06-12 04:08:03
defect

Currently there is no way to inspect an object to see if it's a promise. This proposal makes promises first-class by adding a promise? predicate. It also requires that if the argument to make-promise is a promise, it is returned without rewrapping it, and that if force is given a non-promise argument, it returns it unchanged. (These things cannot be provided by the user without a promise? predicate, and are trivial to provide with it.)

descriptionCurrently there is no way to inspect an object to see if it's a promise. This proposal makes promises first-class by adding a `promise?` predicate. It also requires that if the argument to `make-promise` is a promise, it is returned without rewrapping it.Currently there is no way to inspect an object to see if it's a promise. This proposal makes promises first-class by adding a `promise?` predicate. It also requires that if the argument to `make-promise` is a promise, it is returned without rewrapping it, and that if `force` is given a non-promise argument, it returns it unchanged. (These things cannot be provided by the user without a `promise?` predicate, and are trivial to provide with it.)

Programmers can do the second two items themselves if the implementation provides promise?, but they are simple and worth having. Combined with auto-forcing (with or without insta-forcing of constants), they provide what Per spoke of: laziness is explicit, eagerness is implicit, but the user has full control.

On the other hand, since auto-forcing is not required, there is only trivial cost to implementations who don't wish to provide it, namely the cost of making sure promises are a disjoint type and not just a special case of procedures.

I ran tests against the usual suite of Schemes:

Promises are not thunks, force returns any non-promise unchanged : Racket, Gauche, Gambit, Chicken, Chibi, STklos, RScheme, XLisp, UMB, Oaklisp, SXM

Promises are not thunks but can be invoked anyway, force returns any non-promise unchanged: TinyScheme

Promises are not thunks, force rejects anything but a promise: Guile, SCM, SigScheme, Elk, VX, Spark

Promises are thunks, force rejects anything else (presumably because it just invokes its argument): Scheme48/scsh, SISC, Chez, Vicare, Larceny, Ypsilon, Mosh, IronScheme, Scheme 9, Dream, BDC, Schemik, Sizzle, Inlab

No force/delay support: KSi, Shoe, Scheme 7, Rep, Llava, Femtolisp, Dfsch

statusnewdecided

WG1 voted to add the promise? procedure without requiring promises to be disjoint.

owneralexshinncowan
statusdecidedwriting
resolutionfixed
statuswritingclosed
resolutionfixed
statusclosedreopened

Reopening part of the ticket to retract this requirement: "If force is given a non-promise argument, it returns it unchanged", because it conflicts with R6RS, which requires an error to be signalled.

statusreopeneddecided

WG1 decided to retract the above requirement.

statusdecidedwriting
resolutionfixed
statuswritingclosed