[plt-scheme] Writing interfaces

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Feb 9 23:08:52 EST 2009

Here is the stack module and its interface:

> #lang scheme
>
> (define empty-stack '())
>
> (define (push-stack stack item) (cons item stack))
>
> (define (pop-stack stack) (cdr stack))
>
> (define (empty-stack? stack) (null? stack))
>
> ;; --- interface ---
>
> (require scheme/contract)
>
> (define stack/c (listof any/c))
>
> (provide/contract
>  ;; the empty stack
>  [empty-stack  stack/c]
>  ;; add an item to the top of this stack
>  [push-stack   (-> stack/c any/c stack/c)]
>  ;; remove an item from the top of this stack
>  [pop-stack    (-> stack/c stack/c)]
>  ;; is this stack empty?
>  [empty-stack? (-> stack/c boolean?)])

Here is the client:

> #lang scheme
>
> (require "stack.ss")
>
> (define s1 empty-stack)
> (define s2 (push-stack s1 1))
> (define s3 (pop-stack s2))
> (empty-stack? s3)




On Feb 9, 2009, at 10:34 PM, aditya shukla wrote:

> How should i approach to write interfaces for abstract data types  
> in scheme eg . if the data type is stack of values and the  
> operations are push , pop , top and empty-stack?
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.