File: FactorialMacro.net

package info (click to toggle)
dxsamples 4.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 26,340 kB
  • sloc: ansic: 10,079; sh: 8,445; java: 1,772; makefile: 1,102
file content (86 lines) | stat: -rw-r--r-- 2,855 bytes parent folder | download | duplicates (5)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// time: Wed Feb 12 11:23:22 1997
//
// version: 3.1.1 (format), 3.1.4 (DX Beta)
//
//
// Begin MDF
// MODULE Factorial
// CATEGORY Macros
// DESCRIPTION Computes a factorial
// INPUT input_1; integer; (no default);  
// OUTPUT output_1; value or value list or field;  
// End MDF
//
// comment: This macro computes a factorial, given the number N. A loop is executed over the numbers 1 to N, mutiplying each number in that list by the product so far. GetLocal and SetLocal are used to cache the accumulated product.
// comment: 
// comment: Because we are using GetLocal and SetLocal instead of GetGlobal and SetGlobal, it is not necessary to reset the cache (to the value 1) whenever the loop is re-run; this happens automatically.
// workspace: width = 379, height = 369
// layout: snap = 0, width = 50, height = 50, align = NN
//
macro Factorial(
 input_1
) -> (
 output_1
) {
    // 
    // node GetLocal[1]: x = 173, y = 137, inputs = 3, label = GetLocal
    // input[1]: defaulting = 0, visible = 1, type = 67108863, value = 1
    //
Factorial_GetLocal_1_out_1,
Factorial_GetLocal_1_out_2 = 
    GetLocal(
    1,
    NULL,
    NULL
    ) [instance: 1, cache: 1];
    // 
    // node Input[1]: x = 278, y = 15, inputs = 0, label = Input
    // parameter: position = 1, name = 'input_1', value = '(no default)', descriptive = 1, description = ' ', required = 0, visible = 1
    //
Factorial_Input_1_out_1 = input_1;
    // 
    // node ForEachN[1]: x = 271, y = 83, inputs = 3, label = ForEachN
    // input[1]: defaulting = 0, visible = 1, type = 1, value = 1
    // input[3]: defaulting = 0, visible = 1, type = 1, value = 1
    //
Factorial_ForEachN_1_out_1,
Factorial_ForEachN_1_out_2 = 
    ForEachN(
    1,
    Factorial_Input_1_out_1,
    1
    ) [instance: 1, cache: 1];
    // 
    // node Compute[1]: x = 271, y = 197, inputs = 3, label = Compute
    // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0*$1"
    // expression: value = product*current
    // name[2]: value = product
    // name[3]: value = current
    //
Factorial_Compute_1_out_1 = 
    Compute(
    "$0*$1",
    Factorial_GetLocal_1_out_1,
    Factorial_ForEachN_1_out_1
    ) [instance: 1, cache: 1];
    // 
    // node Output[1]: x = 324, y = 304, inputs = 1, label = Output
    // parameter: position = 1, name = 'output_1', value = ' ', descriptive = 0, description = ' ', required = 0, visible = 1
    //
output_1 = Factorial_Compute_1_out_1;
    // 
    // node SetLocal[1]: x = 204, y = 307, inputs = 3, label = SetLocal
    //
    SetLocal(
    Factorial_Compute_1_out_1,
    Factorial_GetLocal_1_out_2,
    NULL
    ) [instance: 1, cache: 1];
// network: end of macro body
}
Factorial_GetLocal_1_out_1 = NULL;
Factorial_GetLocal_1_out_2 = NULL;
Factorial_Input_1_out_1 = NULL;
Factorial_ForEachN_1_out_1 = NULL;
Factorial_Compute_1_out_1 = NULL;