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.
There can't be that strong a reason, since MIT/GNU scheme, defines a promise?
function.
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.
精彩评论