1#!/bin/bash
2
3. common.bash
4
5#------------------------------------------------------------------------------
6#------------------------------------------------------------------------------
7
8echo "<< Testing if explicit variables are killed when their box is closed:"
9rm -f $ERRORS
10
11#------------------------------------------------------------------------------
12test_next
13echo "testing untyped boxes, explicit variables without value"
14$BOX << EOF  >$BOXOUT 2>&1
15  [a = Char]
16  a = Int
17EOF
18check_noerr
19
20#------------------------------------------------------------------------------
21test_next
22echo "testing again with complex expressions"
23$BOX << EOF  >$BOXOUT 2>&1
24  pi = 3.1415926
25  x = pi/2.0
26  [x2 = x*x, x3 = x2*x, x5 =x3*x2, x7=x5*x2
27  f3=6.0, f5=f3*4.0*5.0, f7=f5*6.0*7.0
28  y::=x-x3/f3+x5/f5-x7/f7]
29  Print["answer=", y]
30  x2=1, x3=1, x5=6, x7=9
31  f3='a', f5='b', f7='r'
32EOF
33check_noerr
34check_answer 0.999843
35
36#------------------------------------------------------------------------------
37test_next
38echo "testing untyped boxes, explicit variables with value"
39$BOX << EOF  >$BOXOUT 2>&1
40  [a = 1.234]
41  a = Char
42EOF
43check_noerr
44
45#------------------------------------------------------------------------------
46test_next
47echo "testing typed boxes, explicit variables"
48$BOX << EOF  >$BOXOUT 2>&1
49  Print[a = 1.234]
50  a = Char
51EOF
52check_noerr
53
54#------------------------------------------------------------------------------
55test_next
56echo "testing again with complex expressions"
57$BOX << EOF  >$BOXOUT 2>&1
58  pi = 3.1415926
59  x = pi/2.0
60  Print[x2 = x*x, x3 = x2*x, x5 =x3*x2, x7=x5*x2
61  f3=6.0, f5=f3*4.0*5.0, f7=f5*6.0*7.0
62  "answer=", x-x3/f3+x5/f5-x7/f7]
63  x2=1, x3=1, x5=6, x7=9
64  f3='a', f5='b', f7='r'
65EOF
66check_noerr
67check_answer 0.999843
68
69#------------------------------------------------------------------------------
70test_next
71echo "testing scoping and unnamed-prefixes of explicit symbols"
72$BOX << EOF  >$BOXOUT 2>&1
73Print[
74  a = 1.23
75  [
76    Print[
77      a: = 4.56
78      Print[
79        b = a::
80        c = a::::
81        Print["answer=", b, ',', c, '\n']
82      ]
83    ]
84  ]
85]
86EOF
87check_noerr
88check_answer 4.56,1.23
89
90#------------------------------------------------------------------------------
91test_next
92echo "testing scoping and named-prefixes of explicit symbols"
93$BOX << EOF  >$BOXOUT 2>&1
94Print[
95  a = 1.23
96  [
97    Print[
98      a: = 4.56
99      Print[
100        b = a:Print
101        c = a:Print:Print
102        Print["answer=", b, ',', c, '\n']
103      ]
104    ]
105  ]
106]
107EOF
108check_noerr
109check_answer 4.56,1.23
110
111#------------------------------------------------------------------------------
112test_next
113echo "testing scoping of procedure definitions: 1"
114$BOX << EOF  >$BOXOUT 2>&1
115X = Void
116[Int@X[Print["answer=X"]], X[1]]
117[Int@X[Print["Y";]], X[1]]
118EOF
119check_noerr
120check_answer XY
121
122#------------------------------------------------------------------------------
123#------------------------------------------------------------------------------
124echo ">>"
125check_final
126