Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't promise a data type in Scheme?

The object returned by delay in Scheme is "a promise", but promises are not considered to be a type (so there is no promise? procedure, and it's not listed as a type in R5RS or R6RS).

Is there a strong reson why this is so? It would seem quite natural to me to do something like (if (promise? x) (force x) x), for example. (And I see that some implementations will let me force non-promises, and others will not). Also, if I can store something in a variale and pass it around, I feel like it should have a type.

like image 870
Jay Avatar asked Sep 23 '10 10:09

Jay


2 Answers

There can't be that strong a reason, since MIT/GNU scheme, defines a promise? function.

like image 59
Marcelo Cantos Avatar answered Oct 20 '22 07:10

Marcelo Cantos


I think it allows for a more optimized implementation of delay/force. The fact that the forced value can be memoized (so that a promise is really forced only once and the resulting value is returned on subsequent force calls) blurs the distinction between a promise and its resulting value. If you have promise? you cannot substitute a forced promise by its value everywhere it is needed. Therefore, depending on the implementation, a promise can be indistinguishable from any other Scheme value.

like image 25
eljenso Avatar answered Oct 20 '22 07:10

eljenso