[plt-scheme] optional arguments in function contracts
Thank you both,
I think I have solved my problems;
(I am working on mail-parser in planet)
I was importing mzlib/contract [to replace (lib "contract.ss")] as
the code used opt-> and union, and this seemed to be causing
unfortunate interactions.
I have removed mzlib/contract and it seems to be fixed now.
I'd advise against anyone using mzlib/contract.
Thanks again,
Stephen
On Fri, Jun 27, 2008 at 1:03 PM, Robby Findler <robby at cs.uchicago.edu> wrote:
> 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
>>
>>
>
--
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