[r6rs-discuss] Re: [Formal] Allow compilers to reject obvious violations
On Sun, 25 Feb 2007, Per Bothner wrote:
> Hm. Now you lost me. You seem to preclude a compiler complaining
> about this expression:
> (lambda (k) ((lambda () 12) (k 17)))
> This seems to me an expression that cannot possibly be useful
> or correct or what the writer intended. Thus it would seem
> useful that a compiler complain.
The correctness of this code depends on the value of k.
If k is a procedure that does not return (and scheme
allows the creation of such with call/cc), then this
is perfectly correct because the function of zero arguments
which returns 12 will never be called. It is in fact
dead code, and an optimizing compiler could theoretically
reduce the whole expression to something like:
;; implementation of assert and continuation? are left as
;; an exercise for the reader.
(lambda (k)
(begin
(assert (continuation? k) "arity mismatch - 1 arg given to 0-arg function")
(k 17)))
Of course, the same magical optimizing compiler could have
reduced the original expression (where the above is provided
as an argument to call/cc) to just the number 17 by partial
evaluation, and then we wouldn't be having a discussion about
how funny-looking it was.
Bear
Received on Sun Mar 11 2007 - 13:28:50 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC