-
Notifications
You must be signed in to change notification settings - Fork 9
/
pick.ast
48 lines (39 loc) · 1.2 KB
/
pick.ast
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
------------------------------------------------------------------
-- pick.ast
--
-- this module implements the Pick structure
--
-- (c) Lutz Hamel, University of Rhode Island
------------------------------------------------------------------
load system random.
------------------------------------------------------------------
structure Pick
------------------------------------------------------------------
-- A pick object holds a list of items that
-- we can randomly pick from with the 'pickitems'
-- member function
with
data items.
function pickitems
with none do
let ix = random @randint(0, this @items @length()-1).
return this @items @ix.
with n:%integer do
let l = [].
for i in 1 to n do
let ix = random @randint(0, this @items @length()-1).
l @append(this @items @ix).
end
return l.
end
--make sure that we only pass lists into the constructor
function __init__ with l:%list do
let this @items = l.
end
end -- Pick
------------------------------------------------------------------
function pick
------------------------------------------------------------------
with l:%list do
return Pick(l).
end