| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
myFunc(x) { return x + 1; } |
| 4 |
ident(x) { return x; } |
| 5 |
|
| 6 |
ident2(...) { return argcount; } |
| 7 |
|
| 8 |
main(args) |
| 9 |
{ |
| 10 |
local a = 2000000000; |
| 11 |
local b = 2000000000; |
| 12 |
|
| 13 |
"a=<<a>>, b=<<b>>, a*b=<<a*b>>\n"; |
| 14 |
|
| 15 |
a = -8; |
| 16 |
b = 3; |
| 17 |
"a=<<a>>, b=<<b>>, a/b=<<a/b>>\n"; |
| 18 |
|
| 19 |
a = myFunc; |
| 20 |
b = a(5); |
| 21 |
"myFunc: b=<<b>>\n"; |
| 22 |
|
| 23 |
a = 17.000; |
| 24 |
b = 17; |
| 25 |
"a=<<a>>, b=<<b>>, a==b=<<a==b ? 'true' : 'nil'>>\n"; |
| 26 |
|
| 27 |
a = 181; |
| 28 |
b = 181.000; |
| 29 |
"a=<<a>>, b=<<b>>, a==b=<<a==b ? 'true' : 'nil'>>\n"; |
| 30 |
|
| 31 |
a = [1, 2, 3]; |
| 32 |
a[1] = 10; |
| 33 |
ident(a)[2] = 20; |
| 34 |
"a=[ "; |
| 35 |
foreach (local x in a) "<<x>> "; |
| 36 |
"]\n"; |
| 37 |
|
| 38 |
"ident2(a,b) = <<ident2(a,b)>>\n"; |
| 39 |
|
| 40 |
for (a = 1 ; a <= 10 ; ++a) |
| 41 |
{ |
| 42 |
local j = 3, k = 5; |
| 43 |
|
| 44 |
if (a == 1) |
| 45 |
j = 10; |
| 46 |
|
| 47 |
"loop: a=<<a>>, j=<<j>>\n"; |
| 48 |
} |
| 49 |
|
| 50 |
local h = new LookupTable(10, 20); |
| 51 |
h[10] = 'ten'; |
| 52 |
h[11] = 'eleven'; |
| 53 |
h[12] = 'twelve'; |
| 54 |
foreach (a in h) |
| 55 |
"foreach: <<a>>\n"; |
| 56 |
|
| 57 |
try |
| 58 |
{ |
| 59 |
"\bThis is the try!\n"; |
| 60 |
throw Exception; |
| 61 |
} |
| 62 |
catch (Exception e) |
| 63 |
{ |
| 64 |
"This is the exception handler!\n"; |
| 65 |
goto done1; |
| 66 |
} |
| 67 |
finally |
| 68 |
{ |
| 69 |
"This is the finally block!\n"; |
| 70 |
} |
| 71 |
|
| 72 |
done1: |
| 73 |
"This is done1!\n"; |
| 74 |
|
| 75 |
try |
| 76 |
{ |
| 77 |
"\bThis is try #2 outer!\n"; |
| 78 |
|
| 79 |
try |
| 80 |
{ |
| 81 |
"This is try #2 inner!\n"; |
| 82 |
throw Exception; |
| 83 |
} |
| 84 |
catch (Exception e) |
| 85 |
{ |
| 86 |
"This catch #2 inner!\n"; |
| 87 |
throw e; |
| 88 |
} |
| 89 |
finally |
| 90 |
{ |
| 91 |
"This is the inner #2 finally block!\n"; |
| 92 |
} |
| 93 |
} |
| 94 |
catch (Exception e) |
| 95 |
{ |
| 96 |
"This is catch #2 outer!\n"; |
| 97 |
} |
| 98 |
finally |
| 99 |
{ |
| 100 |
"This is the outer #2 finally block\n"; |
| 101 |
} |
| 102 |
|
| 103 |
"\^<a href='test'><i>hello from caps-flag html test!</i></a>\n"; |
| 104 |
} |