succ_stream.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- Successor stream
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: succ_stream.sa,v 1.1 1996/07/13 06:48:51 gomes Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.


abstract class $SUCC_STREAM{NTP}

abstract class $SUCC_STREAM{NTP} is -- An abstraction that specifies a generator of successive -- unique values of type NTP next: NTP; -- Return the next unique value end;

class INT_STREAM < $SUCC_STREAM{INT}

class INT_STREAM < $SUCC_STREAM{INT} is -- Yield a stream of successive integers private attr val: INT; create(start_val: INT): SAME is -- Return a new integer stream whose next yielded -- value will be "start_val" res ::= new; res.val := start_val; return res; end; next: INT is -- Yield the next integer in this stream -- Wrap around is not permitted in this kind of integer stream res ::= val; assert val /= INT::maxint; val := val+1; return res; end; next!: INT is -- Keep yielding successive integers. -- Will quit at maxint - 1 if val = INT::maxint then quit end; yield next; end; end;