1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Eval_product = ->
|
11 | i = 0
|
12 | j = 0
|
13 | k = 0
|
14 |
|
15 |
|
16 | body = cadr(p1)
|
17 |
|
18 |
|
19 | indexVariable = caddr(p1)
|
20 | if (!issymbol(p6))
|
21 | stop("sum: 1st arg?")
|
22 |
|
23 |
|
24 | push(cadddr(p1))
|
25 | Eval()
|
26 | j = pop_integer()
|
27 | if (isNaN(j))
|
28 | push p1
|
29 | return
|
30 |
|
31 |
|
32 | push(caddddr(p1))
|
33 | Eval()
|
34 | k = pop_integer()
|
35 | if (isNaN(k))
|
36 | push p1
|
37 | return
|
38 |
|
39 |
|
40 |
|
41 | oldIndexVariableValue = get_binding(indexVariable)
|
42 |
|
43 | push_integer(1)
|
44 |
|
45 | for i in [j..k]
|
46 | push_integer(i)
|
47 | p5 = pop()
|
48 | set_binding(indexVariable, p5)
|
49 | push(body)
|
50 | Eval()
|
51 | if DEBUG
|
52 | console.log "product - factor 1: " + stack[tos-1].toString()
|
53 | console.log "product - factor 2: " + stack[tos-2].toString()
|
54 | multiply()
|
55 | if DEBUG
|
56 | console.log "product - result: " + stack[tos-1].toString()
|
57 |
|
58 |
|
59 | set_binding(indexVariable, oldIndexVariableValue)
|