[plt-scheme] optional arguments in function contracts
That contract is one that requires the second argument (none/c used
like that means "you must supply a value, but I won't accept it"
roughly, so isn't what you want).
This is the relevant section of the guide that explains optional arguments:
http://docs.plt-scheme.org/guide/contracts-general-functions.html#(part._contracts-optional)
and this is the relevant section of the reference manual (for all the details):
http://docs.plt-scheme.org/reference/Function_Contracts.html
Robby
On Fri, Jun 27, 2008 at 4:52 AM, Stephen De Gabrielle
<spdegabrielle at gmail.com> wrote:
> HI,
>
> I'm trying to do a contract with an optional argument, but I'm stuck
> (and can't find an example in the doc's, tests or 'plt-full' code)
> my provide/contract is;
> ;; write-email accepts an email and optionally an output-port (2 or one args)
> (provide/contract
> (write-email (email? (or/c none/c output-port?) . -> . any))
> )
>
>
> and my function is
> ;; write-email : message [output-port] -> void
> (define write-email
> (lambda (message (out-port (current-output-port)))
> (printf "~V:~V~N" message out-port)
> )
> )
>
> but calling it I get the error; procedure write-email: expects 2
> arguments, given 1:
>
> Forgive me if this is a dumb question but I feel I'm missing something
> fundamental about how I'm specifying the contract?
>
>
> Cheers,
>
> Stephen
>
> --
> Stephen De Gabrielle
> s.degabrielle at cs.ucl.ac.uk
> Telephone +44 (0)20 7679 0693 (x30693)
> Mobile 079 851 890 45
> Project: Making Sense of Information (MaSI)
> http://www.uclic.ucl.ac.uk/annb/MaSI.html
>
> UCL Interaction Centre
> MPEB 8th floor
> University College London
> Gower Street
> London WC1E 6BT
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>