[plt-scheme] Contracts with keywords -- opaque error message

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue May 25 12:25:12 EDT 2010


I'm having difficulty understanding why the following is producing the error message it is.

The provided contract on NEW-STATEMENT appears to follow the syntax of '->*' as described in section 7.2 of the manual, but the error, while strictly accurate, is rather ... discreet about what I've done wrong.  There is indeed a call to MEMBER  on line 1509 of arrow.ss, but that doesn't give much away, either.

Am I horribly misusing MAKE-KEYWORD-PROCEDURE? (I suspect not, since the error does appear to be in the contract handling)

% cat src/contract-try.ss     
#lang scheme

(define (statement? s)
  (and (string? s)
       (> (string-length s) 3)))
(define statement/c (flat-contract statement?))

(define new-statement
   (λ (kws kw-args . statement)
     (format "kws=~s  kw-args=~s  statement=~s" kws kw-args statement))))
(provide/contract (new-statement
                   (->* (statement/c)
                        (#:s string?)
% mzscheme -t src/contract-try.ss
member: not a proper list: #f

 === context ===
/Data/LocalApplications/PLT Scheme/PLT Scheme v4.2.5/collects/scheme/contract/private/arrow.ss:1509:17
/Data/LocalApplications/PLT Scheme/PLT Scheme v4.2.5/collects/scheme/contract/private/arrow.ss:1476:0: check-procedure
/checkouts/me/code/plt-librdf/src/contract-try.ss: [running body]


The contract

(provide/contract (new-statement
                   (->* ()
                        (statement/c #:s string?)

(which is what I'm actually looking for) produces the same mysterious error.

Incidentally, the contract

(provide/contract (new-statement
                   (->* ()

allows me to call this function as 

(new-statement "hello" #:s "there")

That surprised me, since I thought that contract was forbidding all keywords, since it didn't mention any.  But it makes some sense if the contract only controls the types of the keyword arguments, not the existence of keywords.  Is that correct?

Thanks for any pointers,


Norman Gray  :  http://nxg.me.uk

Posted on the users mailing list.