Re: ADTs

From: Robert STRANDH (strandh_at_labri.fr)
Date: 03/05/04

  • Next message: Richard Heathfield: "Re: Dijkstra gets it wrong [was: Re: D gets it right]"
    Date: 05 Mar 2004 07:46:17 +0100
    
    

    Michael Mendelsohn <keine.Werbung.1300@michael.mendelsohn.de> writes:

    > The ADT List
    > ------------------
    >
    > 1. Constructors
    >
    > Empty() : List;
    > constructs an empty list.
    > Cons(I : InfoType ; L : List) : List;
    > inserts item I at the head of the list L.
    >
    > 2. Predicates
    >
    > IsEmpty(L : List) : Boolean;
    > checks the list to determine whether it is empty
    >
    > 3. Selectors
    >
    > Head (L : List) : Infotype;
    > returns the item at the head of the list
    > Tail (L : List) : List;
    > returns the list which results from removing the head

    It is interesting to observe as well that this set of operations is
    identical to that defining a stack :

    1. Constructors

     Empty() : Stack;
        constructs an empty stack.
     Push(I : InfoType ; S : Stack) : Stack;
        inserts item I at the top of the stack S.

    2. Predicates

     IsEmpty(S : Stack) : Boolean;
        checks the stack to determine whether it is empty

    3. Selectors
     
     Top (S : Stack) : Infotype;
        returns the item at the top of the stack
     Pop (S : Stack) : Stack;
        returns the stack which results from removing the top

    -- 
    Robert Strandh
    ---------------------------------------------------------------------
    Greenspun's Tenth Rule of Programming: any sufficiently complicated C
    or Fortran program contains an ad hoc informally-specified bug-ridden
    slow implementation of half of Common Lisp.
    ---------------------------------------------------------------------
    

  • Next message: Richard Heathfield: "Re: Dijkstra gets it wrong [was: Re: D gets it right]"

    Relevant Pages

    • Re: DOLIST with empty list?
      ... To decide to return the empty list, ... But this fundamentally redefines DOLIST/DOSUBS in a manner ... any new results on the stack, you get a list of those ... and I replace each by recalling the variable's contents, ...
      (comp.sys.hp48)
    • Re: LIFO in C, need your suggestions
      ... printf(" stack is not empty yet, ... interpretation will be stack_remove() will remove the stack and stack_free ... if(sfree!= NULL) ... the memory held by 100 elements. ...
      (comp.lang.c)
    • Re: Beat Toudai
      ... of empty pdf pages. ... KPDF got empty little, and empty big, pages. ... But still it and evince ... Execution stack: ...
      (sci.lang.japan)
    • Re: Python from Wise Guys Viewpoint
      ... introduce constructors, which also serve as inspectors for pattern matching. ... Node Empty Empty -- Creates a node that doesn't have leaves ... mapTree f (Leaf foo) = Leaf f foo ...
      (comp.lang.python)
    • Re: Python from Wise Guys Viewpoint
      ... introduce constructors, which also serve as inspectors for pattern matching. ... Node Empty Empty -- Creates a node that doesn't have leaves ... mapTree f (Leaf foo) = Leaf f foo ...
      (comp.lang.lisp)