blob: 526996c03cfd0dcc1dac421e55933018ab29668a (
plain) (
blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
class ConsumerList inherits System {
item: IStringConsumer;
next: ConsumerList;
init(value: IStringConsumer, tail: Object) : ConsumerList {{
assert(not (isvoid value), "init", "value argument cannot be void!");
assert(isvoid item, "init", "List has already been initialised!");
item <- value;
if isvoid tail then
void
else
case tail of
cl: ConsumerList => next <- cl;
o: Object => assert(false, "init", "tail argument can be either a ConsumerList or void!");
esac
fi;
self;
}};
push(value: IStringConsumer) : ConsumerList {{
assert(not (isvoid value), "push", "value argument cannot be void!");
if isvoid item
then
item <- value
else if isvoid next
then
next <- (new ConsumerList).init(value, void)
else
next.push(value)
fi
fi;
self;
}};
find(s: String) : Object {{
assert(not (isvoid item), "find", "list isn't initialised!");
if 0 < item.consume(s)
then
item
else if isvoid next
then
void
else
next.find(s)
fi
fi;
}};
};
|