views:

104

answers:

2

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.

+4  A: 

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

Marcelo Cantos
As does Guile. :-P
Chris Jester-Young
+4  A: 

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.

eljenso
That makes sense! Thanks for answering. (I still think there _could_ be a promise? predicate that would answer #t whenever you can use force on the object -- even if it always returns true.)
Jay
Wait, what does memoization have to do with the types (force x) and x? Force will always return a value, and x is always a promise, unless I am misunderstanding this.
erjiang