Improve the translation of notequal
[maxima.git] / share / stringproc / rtest_stringproc.mac
blob98d2e1af0d9be27a79672876c20add702abc4e96
1 (kill (all), 0);
2 0;
4 m : "text";
5 "text"$
6 stringp(m);
7 true;
8 l : sconcat("\"", "text", "\"");
9 ''(string("text"))$
10 stringp(l);
11 true;
12 c : "e";
13 "e"$
14 [charp(c), lcharp(c)];
15 [true, false]$
16 c : supcase(c);
17 "E"$
18 charp(c);
19 true$
20 control : "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%";
21 "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%"$
22 printf(false, control, 'true, [1, 2, 3], 42)$
23 "  An atom:          true
24   and a list:       one two three 
25   and an integer:   42
27 printf(false, "~a ~a ~4f ~a ~@r", "String", sym, bound, sqrt(12), 144), bound = 1.234;
28 "String sym 1.23 2*sqrt(3) CXLIV"$
29 printf(false, "~{~a ~}", ["one", 2, "THREE"]);
30 "one 2 THREE "$
31 printf(false, "~{~{~9,1f ~}~%~}", mat), mat = args(matrix([1.1, 2, 3.33], [4, 5, 6], [7, 8.88, 9]))$
32 "      1.1       2.0       3.3 
33       4.0       5.0       6.0 
34       7.0       8.9       9.0 
36 control : "~:(~r~) bird~p ~[is~;are~] singing.";
37 "~:(~r~) bird~p ~[is~;are~] singing."$
38 printf(false, control, n, n, if n = 1 then 1 else 2), n = 2;
39 "Two birds are singing."$
41 block([res:{},tmp],
42   for n from 0 thru 127 do (
43     tmp : ascii(n), 
44     if alphacharp(tmp) then res : adjoin (tmp, res) ), 
45   subsetp ({"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}, res) );
46 true;
48 block([res:{},tmp],
49   for n from 0 thru 127 do (
50     tmp : ascii(n), 
51     if constituent(tmp) then res : adjoin (tmp, res) ), 
52   subsetp ({"!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~"}, res) );
53 true;
55 charat("Lisp", 1);
56 "L"$
57 l : charlist("Lisp");
58 ["L","i","s","p"]$
59 l[1];
60 "L"$
61 cint("$");
62 36$
63 [cequal("e","E"),cequalignore("e","E")];
64 [false, true]$
65 [alphacharp("2"),alphanumericp("2")];
66 [false, true]$
67 [clessp("E","e"),clesspignore("E","e")];
68 [true, false]$
69 [lowercasep("e"),lowercasep("E")];
70 [true, false]$
72 2*parse_string ("1.234; 5.678");
73 2.468$
75 3*parse_string ("1/2");
76 3/2$
78 parse_string ("2.3e10");
79 2.3e10$
81 parse_string (".25e-1");
82 0.025$
84 2*parse_string ("2.3b1");
85 4.6b1$
87 parse_string (".25b-1");
88 2.5b-2$
90 parse_string ("foo");
91 foo$
93 parse_string ("[2]");
94 [2];
96 parse_string ("(foo : 1234, expand ((foo + bar)^2))");
97 (foo : 1234, expand ((foo + bar)^2));
99 eval_string ("(foo : 1234, expand ((foo + bar)^2))");
100 bar^2 + 2468*bar + 1522756;
102 (kill (bar), parse_string ("bar (x) := x^2"), bar (7));
103 bar (7);
105 (eval_string ("bar (x) := x^2"), bar (7));
108 s : sconcat ("xx[", 3, "]:", expand((y + x)^3));
109 "xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
110 scopy("Original");
111 "Original"$
112 [sequal("gnuplot","Gnuplot"),sequalignore("gnuplot","Gnuplot")];
113 [false, true]$
114 stringp(s);
115 true$
116 simplode(["xx[", 3, "]:", expand((y + x)^3 )]);
117 "xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
118 simplode(charlist("stars"), " * ");
119 "s * t * a * r * s"$
120 simplode(["One", "more", "coffee."], " ");
121 "One more coffee."$
123 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL" */
124 block ([l2: [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]],
125   simplode(l2,";"));
126 "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;\
127 28;29;30;31;32;33";
129 block ([l2: [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]],
130   simplode(l2));
131 "123456789101112131415161718192021222324252627\
132 282930313233";
134 simplode (flatten (makelist (["A", "B", "C", "D"], 50)), "-");
135 "A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
136 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
137 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
138 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
139 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D";
141 simplode (flatten (makelist (["A", "B", "C", "D"], 50)));
142 "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
143 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
144 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
145 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
146 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD";
148 /* Bug #3439: Simplode output on empty list */
150 simplode ([], "");
153 /* This used to return the string "false" */
154 simplode ([], " ");
157 /* This used to return the symbol foo */
158 simplode (['foo]);
159 "foo"$
161 s : "A submarine.";
162 "A submarine."$
163 sconcat (substring(s, 1, 3), "yellow ", substring(s, 3));
164 "A yellow submarine."$
165 sinsert("hollow ", s, 3);
166 "A hollow submarine."$
167 sinvertcase("sInvertCase");
168 "SiNVERTcASE"$
169 smake(3, "w");
170 "www"$
171 smismatch("seven","seventh");
173 split("1.2   2.3   3.4   4.5");
174 ["1.2","2.3","3.4","4.5"]$
175 split("first;;third;fourth", ";", false);
176 ["first","","third","fourth"]$
177 sposition("e","seventh");
179 sremove("n't", "I don't like coffee.");
180 "I do like coffee."$
181 sremove("DO ", %, 'sequalignore);
182 "I like coffee."$
183 sreverse("einnegermitgazellezagtimregennie");
184 "einnegermitgazellezagtimregennie"$
186 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
187  * (same bug in sreverse; ensure it works OK for long strings
188  */
189 sreverse ("dCBCba1A310acBaACAD0DB13dA2200c32AbADA0aB0cAa2D2aDB12AdABa030Ba03c3d0DbA\
190 3aBba2c00a10DA3C3AAa1a00bc1BCa33bBDb1da0baBBaAa01D11AA0adcaaB13323A33Ac3DCdcAC\
191 1131bCdB1d1BddaCaAD0Ab131bad2d30abBaca0D2bccd2Ccd2");
192 "2dcC2dccb2D0acaBba03d2dab131bA0DAaCaddB1d1BdCb1311CAcdCD3cA33A32331Baacd\
193 a0AA11D10aAaBBab0ad1bDBb33aCB1cb00a1aAA3C3AD01a00c2abBa3AbD0d3c30aB030aBAdA21B\
194 Da2D2aAc0Ba0ADAbA23c0022Ad31BD0DACAaBca013A1abCBCd";
196 ssearch("~s", "~{~S ~}~%", 'sequalignore);
198 ssearch ("foo", "bar");
199 false;
200 ssort("I don't like Mondays.");
201 "   '.IMaddeiklnnoosty"$
202 block([us_ascii_only:true], ssort("I don't like Mondays.", 'cgreaterpignore));
203 "ytsoonnMlkIiedda.'   "$   
205 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
206  * (same bug in ssort; ensure it works OK for long strings
207  */
208 ssort ("fTgTgHZyfUfYOWTTWezffIITTfQxwWaWyTdaIfyeawITRfaTfywaIgWdePTefegfIaOeIWT\
209 WgOgHfOIddgOTdZIdIwwPTfOaIITeyygxdddTWdfyWOOOOTZPHfTHHydIaTTdTeggwwHZHWHTfeHfZ\
210 IOydPgTTeHORaweaZPIHaefHTgXaTwdTgZyOReTyfIaZZeZeyfPTHHZfWage");
211 "HHHHHHHHHHHHHHIIIIIIIIIIIIIIIIOOOOOOOOOOOOOPPPPPPQRRRTTTTTTTTTTTTTTTTTT\
212 TTTTTTTTTTUWWWWWWWWWWWXYZZZZZZZZZZZaaaaaaaaaaaaaaddddddddddddddeeeeeeeeeeeeeee\
213 efffffffffffffffffffffggggggggggggggwwwwwwwwwxxyyyyyyyyyyyyz";
215 ssubst("like", "hate", "I hate Thai food. I hate green tea.");
216 "I like Thai food. I like green tea."$
217 ssubst("Black", "Green", "Green light. Green tea. Greenwich.", 'sequal, 10, 20);
218 "Green light. Black tea. Greenwich."$
220 /* SF bug #3700, ssubst crashes with large number of substitutions
221    construct the long strings via concat
223 block([s:lreduce(concat,makelist("a",k,1,1400)), r:lreduce(concat,makelist("b",k,1,1400))],
224   sequal(r,ssubst("b","a",s))) $
225 true $
227 "  /* comment */  ";
228 "  /* comment */  "$
229 strim(" /*", %);
230 "comment"$
231 slength(%);
233 substring("substring", 4);
234 "string"$
235 substring(%, 4, 6);
236 "in"$
237 supcase("english", 1, 2);
238 "English"$
239 tokens("24 October 2005");
240 ["24","October","2005"]$
241 tokens("05-10-24", 'digitcharp);
242 ["05","10","24"]$
243 map(parse_string, %);
244 [5,10,24]$
246 (remvalue(m,l,c,control,foo,bar,s), 0);