_SystemEnum.dcl 2.07 KB
Newer Older
1 2
definition module _SystemEnum

Camil Staps's avatar
Camil Staps committed
3 4
/**
 * The underlying functions for dotdot expressions.
Camil Staps's avatar
Camil Staps committed
5 6 7 8 9 10 11 12
 *
 * This module must be imported if dotdot expressions are used.
 * Then, the following constructs can be used:
 *
 * - `[from .. ]`         -> `{{_from}} from`
 * - `[from .. to]`       -> `{{_from_to}} from to`
 * - `[from, then .. ]`   -> `{{_from_then}} from then`
 * - `[from, then .. to]` -> `{{_from_then_to}} from then to`
Camil Staps's avatar
Camil Staps committed
13 14
 */

15 16 17 18 19 20 21 22 23
// ****************************************************************************************
//	Concurrent Clean Standard Library Module Version 2.0
//	Copyright 1998 University of Nijmegen
// ****************************************************************************************

from StdClass import class Enum (..), class IncDec (..), class Ord (..),<=,inc,dec
from StdBool import not 
import StdInt,StdChar

Camil Staps's avatar
Camil Staps committed
24 25 26 27 28 29 30
/**
 * Generate a list of all values from a starting point.
 * Instead of `_from x`, you can use `[x..]`.
 *
 * @param The starting point
 * @result [x, x + one, x + one + one, x + one + one + one, ...]
 */
31
_from			::  a		-> .[a] | IncDec , Ord a	special a=Int; a=Char
Camil Staps's avatar
Camil Staps committed
32 33 34 35 36 37 38 39 40

/**
 * Generate a list of all values from a starting point to an endpoint.
 * Instead of `_from_to x y`, you can use `[x..y]`.
 *
 * @param The starting point
 * @param The endpoint
 * @result [x, inc x, inc (inc x), inc (inc (inc x)), ..., E] where E <= y
 */
41
_from_to		:: !a !a	-> .[a] | Enum a			special a=Int; a=Char
Camil Staps's avatar
Camil Staps committed
42 43 44 45 46 47 48 49 50

/**
 * Generate a list of all values from a starting point with a certain interval.
 * Instead of `_from_then x y`, you can use `[x,y..]`.
 *
 * @param The starting point
 * @param The next point
 * @result [x, y, x + (y - x) + (y - x), ...]
 */
51
_from_then		::  a  a	-> .[a] | Enum a			special a=Int; a=Char
Camil Staps's avatar
Camil Staps committed
52 53 54 55 56 57 58 59 60 61 62

/**
 * Generate a list of all values from a starting point to an endpoint with a
 * certain interval.
 * Instead of `_from_then_to x y z`, you can use `[x,y..z]`.
 *
 * @param The starting point
 * @param The next point
 * @param The endpoint
 * @result [x, y, x + (y - x) + (y - x), ..., E] where E <= z
 */
63
_from_then_to	:: !a !a !a	-> .[a] | Enum a			special a=Int; a=Char