[plt-scheme] Re: command-line, parameters, contracts

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri May 21 09:56:30 EDT 2010

On Wed, May 19, 2010 at 12:43 PM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> P.S. Some of the functions in 7.6 turn out to be un-provided. And the
> rest don't work as I expect/guess.  Transcript:
>
> Welcome to DrScheme, version 4.2.4 [3m].
> Language: Module; memory limit: 1024 megabytes.
>> (define/contract (f x) (integer? . -> . integer?) x)
>
>> (has-contract? f)
> . . reference to an identifier before its definition: has-contract?
>
>> (value-contract? f)
> . . reference to an identifier before its definition: value-contract?

I believe these were added in version 4.2.5; you are using 4.2.4.

>> (flat-contract-predicate? f)
> . . reference to an identifier before its definition: flat-contract-predicate?

You added a question mark that is not part of the name.

>> (contract? f)
> #t    ; comment: I would have guessed f HAS-a contract if I could call
> has-contract?. But it IS-a contract?
>
>> (flat-contract? f)
> #t

Section 7 defines contracts as a datatype that includes all unary
functions.  Every unary function can be interpreted as a flat contract
as follows: apply the function to a value; if it produces #f, raise a
contract error, otherwise pass the value through unchanged.  Hence f
is a (flat) contract, completely independently of the fact that a
contract has been applied to it.

>> (contract-first-order-passes? (flat-contract-predicate f) 1)
> #t
>
>> (contract-first-order-passes? (flat-contract-predicate f) null)
> #t   ; shouldn't this be #f because (integer? null) is #f?

I'm kind of surprised you don't get a contract error here about
applying f to an invalid argument.  This might be a bug.

--Carl


Posted on the users mailing list.