1
2
3Testing("Apply");
4Verify(Apply("+",{2,3}),5);
5[
6  Local(x,y);
7  Verify(Apply({{x,y},x+y},{2,3}),5);
8  Verify(Apply(Lambda({x,y},x+y),{2,3}),5);
9  Verify(Lambda({x,y},x+y) @ {2,3},5);
10
11  Verify(Apply(Lambda({x},Length(x)),{"aaa"}),3);
12
13  Verify(x,x);
14  Verify(y,y);
15
16  Testing("ThreadingListables");
17  x:={bb,cc,dd};
18  Verify(Sin(aa*x),{Sin(aa*bb),Sin(aa*cc),Sin(aa*dd)});
19];
20
21
22
23Testing("MapSingle");
24Verify(MapSingle("!",{1,2,3,4}),{1,2,6,24});
25
26/* Example: using the for function. */
27Function("count",{from,to})
28[
29   Local(i);
30   Local(sum);
31   Set(sum,0);
32   For(i:=from,i<to,i:=i+1)
33   [
34     Set(sum,sum+i);
35   ];
36   sum;
37];
38
39Testing("Function definitions");
40Verify(count(1,11),55);
41
42Retract("count",2);
43
44Testing("LocalVariables");
45[
46  Verify(IsBound({}),False);
47  Local(a);
48  Verify(IsBound(a),False);
49  a:=1;
50  Verify(IsBound(a),True);
51  Clear(a);
52  Verify(IsBound(a),False);
53];
54
55Verify(Atom("a"),a);
56Verify(String(a),"a");
57Verify(ConcatStrings("a","b","c"),"abc");
58
59Testing("Symbol protection");
60
61Verify(TrapError(Cos := True, False), False);
62
63Protect(item);
64Verify(Simplify(x+x), 2*x);
65UnProtect(item);