[plt-scheme] define/contract/provide ?
Matthew answered the macro issues, but there is a difference between
contracts and types that seems to be tripping you up. Specifically, a
contract always comes with a boundary. The contract governs how the
code inside the boundary interacts with the code outside. This is
unlike types that express facts about the program. For
provide/contract (for example), the boundary is the module; the
contracts govern the values that flow into and out of the module (via
the functions defined in the module).
So, that's something to keep in mind when you are defining your macro:
where is the inside and where is the outside for your contracts?
Robby
On Sat, Mar 20, 2010 at 4:35 PM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> Wrapping my brain around modules and contracts. Coming from C/C++/C# mindset.
>
> Have successfully used define and provide/contract in a module
>
> Just noticed define/contract. I'm thinking, hey, this is how my C-ish
> brain works. Define the function and its types/contract in one swell
> foop.
>
> Small annoyance is now I have to type provide by itself.
>
> So I'm wondering, why isn't there a define/contract/provide? Isn't
> doing all three a common scenario when making a module? Or am I
> carrying baggage from my C background?
>
>
> On a related note, I risked further brain burn by attempting to
> provide (sorry) this myself with define-syntax.
>
> Attempt 1 was this:
>
> (define-syntax-rule (define/contract/provide (id args ...) (contract
> ...) body-expr ...)
> (begin
> (define/contract (id args ...) (contract ...) body-expr ...)
> (provide id)))
>
> But doesn't work because provide doesn't work inside (begin). No error
> making the module, but user of it doesn't see the function since
> provide inside begin (I think?).
>
> Attempt 2 was this:
>
> (define-syntax-rule (define/contract/provide (id args ...) (contract
> ...) body-expr ...)
> (define/contract (id args ...) (contract ...) body-expr ...)
> (provide id))
>
> But that complains:
> define-syntax-rule: too many templates in: ((provide id))
>
>
> Thanks in advance for any help!
>
> Greg
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>