-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVariables.pi
More file actions
39 lines (31 loc) · 727 Bytes
/
Variables.pi
File metadata and controls
39 lines (31 loc) · 727 Bytes
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
// Test file for Pi language variables and scoping
// First clear any leftover stack items
clear
// Test basic variable assignment and retrieval
42 'answer #
answer 42 == assert
// Test variable reassignment
10 'x #
x 10 == assert
20 'x #
x 20 == assert
// Test using variables in expressions
5 'a #
10 'b #
a b + 15 == assert
// Test variable scoping
{
// Local variable that shouldn't affect outer scope
99 'local #
local 99 == assert
} &
// Verify local variable isn't available outside its scope
'local exists not assert
// Test function-like variables
{ 1 2 + } 'add3 #
3 add3 & + 6 == assert
// Test variables as arguments to continuations
{ 'n # n n * } 'square #
5 square & 25 == assert
// Clean up
clear