File: rtest_stringproc.mac

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (259 lines) | stat: -rw-r--r-- 7,694 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
(kill (all), 0);
0;

m : "text";
"text"$
stringp(m);
true;
l : sconcat("\"", "text", "\"");
''(string("text"))$
stringp(l);
true;
c : "e";
"e"$
[charp(c), lcharp(c)];
[true, false]$
c : supcase(c);
"E"$
charp(c);
true$
control : "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%";
"~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%"$
printf(false, control, 'true, [1, 2, 3], 42)$
"  An atom:          true
  and a list:       one two three 
  and an integer:   42
"$
printf(false, "~a ~a ~4f ~a ~@r", "String", sym, bound, sqrt(12), 144), bound = 1.234;
"String sym 1.23 2*sqrt(3) CXLIV"$
printf(false, "~{~a ~}", ["one", 2, "THREE"]);
"one 2 THREE "$
printf(false, "~{~{~9,1f ~}~%~}", mat), mat = args(matrix([1.1, 2, 3.33], [4, 5, 6], [7, 8.88, 9]))$
"      1.1       2.0       3.3 
      4.0       5.0       6.0 
      7.0       8.9       9.0 
"$
control : "~:(~r~) bird~p ~[is~;are~] singing.";
"~:(~r~) bird~p ~[is~;are~] singing."$
printf(false, control, n, n, if n = 1 then 1 else 2), n = 2;
"Two birds are singing."$

block([res:{},tmp],
  for n from 0 thru 127 do (
    tmp : ascii(n), 
    if alphacharp(tmp) then res : adjoin (tmp, res) ), 
  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) );
true;

block([res:{},tmp],
  for n from 0 thru 127 do (
    tmp : ascii(n), 
    if constituent(tmp) then res : adjoin (tmp, res) ), 
  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) );
true;

charat("Lisp", 1);
"L"$
l : charlist("Lisp");
["L","i","s","p"]$
l[1];
"L"$
cint("$");
36$
[cequal("e","E"),cequalignore("e","E")];
[false, true]$
[alphacharp("2"),alphanumericp("2")];
[false, true]$
[clessp("E","e"),clesspignore("E","e")];
[true, false]$
[lowercasep("e"),lowercasep("E")];
[true, false]$

2*parse_string ("1.234; 5.678");
2.468$

3*parse_string ("1/2");
3/2$

parse_string ("2.3e10");
2.3e10$

parse_string (".25e-1");
0.025$

2*parse_string ("2.3b1");
4.6b1$

parse_string (".25b-1");
2.5b-2$

parse_string ("foo");
foo$

parse_string ("foo;");
foo$

parse_string ("foo$;$;");
foo$

parse_string ("\"semicolon ; string\"");
"semicolon ; string"$

parse_string ("\"dollar $ string\"");
"dollar $ string"$

parse_string ("[2]");
[2];

parse_string ("(foo : 1234, expand ((foo + bar)^2))");
(foo : 1234, expand ((foo + bar)^2));

eval_string ("(foo : 1234, expand ((foo + bar)^2))");
bar^2 + 2468*bar + 1522756;

(kill (bar), parse_string ("bar (x) := x^2"), bar (7));
bar (7);

(eval_string ("bar (x) := x^2"), bar (7));
49;

s : sconcat ("xx[", 3, "]:", expand((y + x)^3));
"xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
scopy("Original");
"Original"$
[sequal("gnuplot","Gnuplot"),sequalignore("gnuplot","Gnuplot")];
[false, true]$
stringp(s);
true$
simplode(["xx[", 3, "]:", expand((y + x)^3 )]);
"xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
simplode(charlist("stars"), " * ");
"s * t * a * r * s"$
simplode(["One", "more", "coffee."], " ");
"One more coffee."$

/* SF bug report #3329: "Simplode overlimited at Maxima with GCL" */
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]],
  simplode(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";

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]],
  simplode(l2));
"123456789101112131415161718192021222324252627\
282930313233";

simplode (flatten (makelist (["A", "B", "C", "D"], 50)), "-");
"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\
-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\
-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\
-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\
-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";

simplode (flatten (makelist (["A", "B", "C", "D"], 50)));
"ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD";

/* Bug #3439: Simplode output on empty list */

simplode ([], "");
""$

/* This used to return the string "false" */
simplode ([], " ");
""$

/* This used to return the symbol foo */
simplode (['foo]);
"foo"$

s : "A submarine.";
"A submarine."$
sconcat (substring(s, 1, 3), "yellow ", substring(s, 3));
"A yellow submarine."$
sinsert("hollow ", s, 3);
"A hollow submarine."$
sinvertcase("sInvertCase");
"SiNVERTcASE"$
smake(3, "w");
"www"$
smismatch("seven","seventh");
6$
split("1.2   2.3   3.4   4.5");
["1.2","2.3","3.4","4.5"]$
split("first;;third;fourth", ";", false);
["first","","third","fourth"]$
sposition("e","seventh");
2$
sremove("n't", "I don't like coffee.");
"I do like coffee."$
sremove("DO ", %, 'sequalignore);
"I like coffee."$
sreverse("einnegermitgazellezagtimregennie");
"einnegermitgazellezagtimregennie"$

/* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
 * (same bug in sreverse; ensure it works OK for long strings
 */
sreverse ("dCBCba1A310acBaACAD0DB13dA2200c32AbADA0aB0cAa2D2aDB12AdABa030Ba03c3d0DbA\
3aBba2c00a10DA3C3AAa1a00bc1BCa33bBDb1da0baBBaAa01D11AA0adcaaB13323A33Ac3DCdcAC\
1131bCdB1d1BddaCaAD0Ab131bad2d30abBaca0D2bccd2Ccd2");
"2dcC2dccb2D0acaBba03d2dab131bA0DAaCaddB1d1BdCb1311CAcdCD3cA33A32331Baacd\
a0AA11D10aAaBBab0ad1bDBb33aCB1cb00a1aAA3C3AD01a00c2abBa3AbD0d3c30aB030aBAdA21B\
Da2D2aAc0Ba0ADAbA23c0022Ad31BD0DACAaBca013A1abCBCd";

ssearch("~s", "~{~S ~}~%", 'sequalignore);
3$
ssearch ("foo", "bar");
false;
ssort("I don't like Mondays.");
"   '.IMaddeiklnnoosty"$
block([us_ascii_only:true], ssort("I don't like Mondays.", 'cgreaterpignore));
"ytsoonnMlkIiedda.'   "$   

/* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
 * (same bug in ssort; ensure it works OK for long strings
 */
ssort ("fTgTgHZyfUfYOWTTWezffIITTfQxwWaWyTdaIfyeawITRfaTfywaIgWdePTefegfIaOeIWT\
WgOgHfOIddgOTdZIdIwwPTfOaIITeyygxdddTWdfyWOOOOTZPHfTHHydIaTTdTeggwwHZHWHTfeHfZ\
IOydPgTTeHORaweaZPIHaefHTgXaTwdTgZyOReTyfIaZZeZeyfPTHHZfWage");
"HHHHHHHHHHHHHHIIIIIIIIIIIIIIIIOOOOOOOOOOOOOPPPPPPQRRRTTTTTTTTTTTTTTTTTT\
TTTTTTTTTTUWWWWWWWWWWWXYZZZZZZZZZZZaaaaaaaaaaaaaaddddddddddddddeeeeeeeeeeeeeee\
efffffffffffffffffffffggggggggggggggwwwwwwwwwxxyyyyyyyyyyyyz";

ssubst("like", "hate", "I hate Thai food. I hate green tea.");
"I like Thai food. I like green tea."$
ssubst("Black", "Green", "Green light. Green tea. Greenwich.", 'sequal, 10, 20);
"Green light. Black tea. Greenwich."$

/* SF bug #3700, ssubst crashes with large number of substitutions
   construct the long strings via concat
*/
block([s:lreduce(concat,makelist("a",k,1,1400)), r:lreduce(concat,makelist("b",k,1,1400))],
  sequal(r,ssubst("b","a",s))) $
true $

"  /* comment */  ";
"  /* comment */  "$
strim(" /*", %);
"comment"$
slength(%);
7$
substring("substring", 4);
"string"$
substring(%, 4, 6);
"in"$
supcase("english", 1, 2);
"English"$
tokens("24 October 2005");
["24","October","2005"]$
tokens("05-10-24", 'digitcharp);
["05","10","24"]$
map(parse_string, %);
[5,10,24]$

(remvalue(m,l,c,control,foo,bar,s), 0); 
0;