7 defstruct (f (x, y, z));
19 [x, y, z, myrecord@x, myrecord@y, myrecord@z];
20 '[123, abc, z, myrecord@x, 45, myrecord@z];
22 ('(myrecord@y), [op (%%), args (%%)]);
23 '["@", [myrecord, y]];
25 (kill (y), myrecord@y);
28 [kill (f), errcatch (new (f)), errcatch (myrecord@x)];
29 [done, [], [f(x, 45, z)@x]];
31 defstruct (f (x, y=3.14159, z));
40 k : h (g (aa, bb), cc);
41 '(h (g (aa, bb), cc));
43 errcatch (k@1@2 : dd);
46 defstruct (h (xx, yy), g (uu, vv));
47 '[h (xx, yy), g (uu, vv)];
50 '(h (g (aa, dd), cc));
67 (yy : %i, vv : 1/2, 0);
73 string ('(x@yy + x@yy@vv));
76 (kill (x@yy@vv), [x, x@yy, x@yy@vv]);
77 '[h (xx, g (uu, vv)), g (uu, vv), x@yy@vv];
79 (kill (x@yy), [x, x@yy]);
85 block ([uu0 : 123, vv0 : 456], x : new (h (new (g), new (g (uu0, vv0)))));
86 '(h (g (uu, vv), g (123, 456)));
88 ([a00, a01, b00, b01] : [123, 456, 789, 987],
89 block ([a0 : '(a00 + a01), b0 : '(b00 + b01)], defstruct (foo (a = a0, b = b0))));
90 '[foo (a00 + a01, b00 + b01)];
93 '(foo (a00 + a01, b00 + b01));
96 foo (123 + 456, 789 + 987);
98 /* IN FOLLOWING EXAMPLES QUOTE SHOULD BE UNNECESSARY !!
99 * CHANGE $EV CODE TO MAKE IT WORK OK WITHOUT QUOTE !!
102 ev (sin (x@xx + 1), '(x@xx)=%e);
105 ev (sin (x@yy@uu + 1), '(x@yy@uu)=%i);
109 '(h (g (uu, vv), g (123, 456)));
114 [a, b, c]: [x, y, z];
117 [x, y, z]: [11, 22, 33];
129 (kill (a, b), [a, b]: [b, 2*a]);
144 (kgcd(a, b) := (while b#0 do [a, b]: [b, remainder(a, b)], abs(a)), kgcd(11*7*5*3, 17*13*11*7));
145 ''(gcd (11*7*5*3, 17*13*11*7));
147 (i:10, j:20, [i, j] : [j, i]);
153 /* QUESTIONABLE. MAYBE THIS ONE SHOULD CAUSE AN ERROR */
157 /* QUESTIONABLE. MAYBE PRECEDING ASSIGNMENT SHOULD HAVE FAILED */
164 (i : 2, [i, a[i]] : [4, 11]);
170 [ a[1], a[2] ] : [ a[3], a[4] ];
176 (a : [1, 2, 3, 4], i:0, [ a[i : i + 1], a[i : i + 1] ] : [ a[i : i + 1], a[i : i + 1] ]);
182 [a, [b, c], [[d, e], f]] : [1, [2, 3], [[4, 5], 6]];
183 [1, [2, 3], [[4, 5], 6]];
188 /* NEED TESTS FOR :: HERE */
190 (L : '[a, b, c], L :: [11, 22, 33], [a, b, c]);
193 /* example from mailing list 2014-02-27 "assigning to a list of structure fields does not work" */
195 (kill (P, N, D, Quot), defstruct(Quot(N,D=1)), P:new(Quot));
204 /* some more tests */
206 kill (x, y, z, a, b, c, d);
209 (x : [a, b], y : [c, d], 0);
212 [x, y] :: [[1, 2], [3, 4]];
218 [x[1], y[1]] :: [11, 22];
222 [[a, b], [c, d], 11, 2, 22, 4];
224 [x[1], y[1]] : [33, 44];
228 [[33, b], [44, d], 11, 2, 22, 4];
230 (kill (foo), defstruct (foo (a, b)));
233 z : new (foo (-1, -2));
236 [z@b, z@a] : [-3, -4];
245 [a[123], b[456]] : [17, 29];
254 [arrayinfo (a), listarray (a)];
255 [[hashed, 1, [123]], [17]];
257 [arrayinfo (b), listarray (b)];
258 [[hashed, 1, [456]], [29]];
260 [c[321], d[654]] : [19, 31];
266 [arrayinfo (c), arrayinfo (d)];
267 [[hashed, 1, [321]], [hashed, 1, [654]]];
269 [listarray ('c), listarray ('d)];
272 [a, [b, [c, [d, [x, [y, [z]]]]]]] : [-1, [-2, [-3, [-4, [-5, [-6, [-7]]]]]]];
273 [-1, [-2, [-3, [-4, [-5, [-6, [-7]]]]]]];
275 [a, b, c, d, x, y, z];
276 [-1, -2, -3, -4, -5, -6, -7];
278 (hash_assign (e, x) := ?marrayset (x, ?meval (first (e)), ?meval (second (e))),
279 translate (hash_assign), /* mset extension op must be a Lisp function */
281 ?putprop (verbify ("hash_get"), 'hash_assign, '?mset_extension_operator),
286 foo hash_get bar : 456,
290 [foo hash_get baz] : 789;
296 /* bug reported to mailing list 2017-02-02: "Structs broken?" */
300 defstruct (foo (a, b)),
302 aa : make_array (fixnum, 6),
309 [0, 0, 0, 0, 123, 0];
315 [0, 0, 0, 0, 123, 0];
317 (bb : make_array (fixnum, 6),
318 f(i) := if i = 1 then aa elseif i = 2 then bb,
324 [0, 0, 0, 0, 0, 456];
330 [0, 0, 0, 0, 0, 456];
338 [0, 789, 0, 0, 0, 456];
344 [0, 789, 0, 0, 0, 456];
351 (h1[mumble][3] : 333,
353 [0, 0, 0, 333, 123, 0];
355 ?arrayp (h1[mumble]);
358 listarray (h1[mumble]);
359 [0, 0, 0, 333, 123, 0];
361 (use_fast_arrays : true,
369 [0, 789, 555, 0, 0, 456];
374 listarray (h2[blurf]);
375 [0, 789, 555, 0, 0, 456];
377 (reset(use_fast_arrays),1);