1//<-- CLI SHELL MODE --> 2// ============================================================================= 3// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 4// Copyright (C) ????-2008 - INRIA 5// 6// This file is distributed under the same license as the Scilab package. 7// ============================================================================= 8prot=funcprot();funcprot(0); 9global a 10a=133; 11clear a; 12if exists("a") then pause,end 13global a; 14if a<>133 then pause,end 15a=["1234","456"]; 16if a(1)<>"1234" then pause,end 17 18global b 19b=10;a=-1; 20clear a b 21global a b 22if a<>-1|b<>10 then pause,end 23// 24clearglobal() 25try 26 a 27 n=0 28catch 29 [str,n]=lasterror(%t); 30end 31if n == 0 then pause,end 32 33global a b c 34a=1;b=2;c=3; 35clearglobal b 36try 37 b 38 n=0 39catch 40 [str,n]=lasterror(%t); 41end 42if n == 0 then pause,end 43 44if a<>1|c<>3 then pause,end 45 46clearglobal c 47try 48 c 49 n=0 50catch 51 [str,n]=lasterror(%t); 52end 53if n == 0 then pause,end 54if a<>1 then pause,end 55 56clearglobal a 57try 58 a 59 n=0 60catch 61 [str,n]=lasterror(%t); 62end 63if n == 0 then pause,end 64 65clearglobal() 66 67 68// 69global a 70a=133; 71//insertion 72a(2,2)=10; 73if or(a<>[133 0;0 10]) then pause,end 74clear a; 75global a; 76if or(a<>[133 0;0 10]) then pause,end 77 78clear a; 79global a; 80if a(1,1)<>133 then pause,end 81 82// global between the base workspace and the function workspace 83 84deff("foo()","global a;if a<>133 then pause,end,a=10") 85a=133; 86foo(); 87if a<>10 then pause,end 88 89// skipping a level 90deff("y=foo()","y=f1()") 91deff("y=f1(x)","global a,y=a^2") 92 93a=5; 94if foo()<>a^2 then pause,end 95 96// a global variable used as an argument 97deff("y=foo()","global a;a=143;y=f1(a)") 98deff("y=f1(x)","a=1;y=x^2") 99if foo()<>143^2|a<>143 then pause,end 100 101 102//dealing with insertion and extraction 103deff("foo()","global a;a=[];for k=1:5,a(1,k)=k;end") 104foo(); 105if or(a<>(1:5)) then pause,end 106 107deff("y=foo()","global a;y=a(1:2:$)") 108if or(foo()<>(1:2:5)) then pause,end 109 110if ~isglobal("a") then pause,end 111clearglobal a 112a=1; 113if isglobal("a") then pause,end 114if isglobal("1") then pause,end 115 116clearglobal() 117 118gsz=int(rand() * 1000); 119 120global a b c 121n=int(sqrt(gsz(1)))-3; 122b=ones(n,n); 123deff("foo()","global b;for k=1:5,b=[b ones(n,10)];end") 124foo() 125if or(size(b)<>[n,n+50]) then pause,end 126if find(b<>1)<>[] then pause,end 127clearglobal a b c 128 129//test passing global variable as an argument 130global G; 131G=1; 132function foo(x),x=-1,endfunction 133foo(G);if G<>1 then pause,end 134 135//change the global variable that had been passed as an argument 136function y=foo(x),global G,G=33,y=x,endfunction 137if (foo(G)<>1) then pause,end 138clearglobal G 139 140function y=foo(),global a b,b=[],a=1:3,y=foo1(a),endfunction 141function y=foo1(x),global b,b=[b 1],y=x(3),endfunction 142if (foo()<>3) then pause,end 143clearglobal a b 144 145global G b; 146a=rand(3,3); 147G=mlist(["test","a"],a); 148 149function V=%s_i_test(i,j,I,V) 150 global b; b=[b 1:5]; V.a(i,j)=I; 151endfunction 152G(1,3)=0;a(1,3)=0; 153if or(a<>G.a) then pause,end 154 155// Is it the good choice? 156function r=%test_e(i,j,V) 157 global G; G.a(i,j)=1; r=V.a(i,j); 158endfunction 159a13=G.a(1,3); 160X=G(1,3); 161if or(G.a(1,3)<>1) then pause,end 162funcprot(prot); 163 164