-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange.y
More file actions
35 lines (28 loc) · 782 Bytes
/
range.y
File metadata and controls
35 lines (28 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**********************************************************************
AUTHOR: Kenneth Pollick <me@kennethpollick.com>
COPYRIGHT: 2022-2023 Kenneth Pollick
DATE: 2023-08-15
**********************************************************************/
//make sure to switch dt out with a type representing a well ordered set
immutable range: dt sdt
{
dt#0 low;
dt#0 length;
ctor(dt#0 low, dt#0 length)
{
this.low = low;
this.length = length;
}
static dt#0 high() { return this.low + (this.length - 1); }
map_sink((<<dt#0) proc)
{
dt#0 h = this.high();
for (dt#0 c = this.low; c <= h; c++) proc(c);
}
dt#1 array map((dt<<dt#0) proc)
{
dt#0 h = this.high();
dt#1 array[this.length] arr;
for (dt#0 c = this.low; c <= h; c++) arr[c-this.low] = proc(c);
}
}