Opened 5 years ago

Closed 5 years ago

#405 closed defect (fixed)

Make promises first-class

Reported by: cowan Owned by: cowan
Priority: major Milestone:
Component: WG1 - Core Keywords:
Cc:

Description (last modified by cowan)

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

Change History (9)

comment:1 Changed 5 years ago by cowan

  • Description modified (diff)

comment:2 Changed 5 years ago by cowan

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

comment:3 Changed 5 years ago by cowan

  • Status changed from new to decided

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

comment:4 Changed 5 years ago by cowan

  • Owner changed from alexshinn to cowan
  • Status changed from decided to writing

comment:5 Changed 5 years ago by cowan

  • Resolution set to fixed
  • Status changed from writing to closed

comment:6 Changed 5 years ago by cowan

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

comment:7 Changed 5 years ago by cowan

  • Status changed from reopened to decided

WG1 decided to retract the above requirement.

comment:8 Changed 5 years ago by cowan

  • Status changed from decided to writing

comment:9 Changed 5 years ago by cowan

  • Resolution set to fixed
  • Status changed from writing to closed
Note: See TracTickets for help on using tickets.