defstruct stuff in cvs



Hello,

I have merged the defstruct code (still present in
share/contrib/defstruct.lisp) into src/mlisp.lisp in cvs, and added
tests for the defstruct stuff to tests/rtest_mset.mac.
Thanks to RJF for writing the defstruct code (as well as the
multiple assignment code).

Here are some examples.
f is a structure, new(f) creates an instance of it, @ accesses fields.

defstruct (f (x, y, z));
  => [f (x, y, z)]
myrecord : new (f);
  => f (x, y, z)
myrecord at y : 45;
myrecord;
  => f (x, 45, z)

foo at bar evaluates to bar if the bar field does not otherwise have
a value. I think it would be better to have it evaluate to foo at bar
(so you don't lose the object reference).

[myrecord at x, myrecord at y, myrecord at z];
  => [x, 45, z]

defstruct recognizes initializer values.

kill (f);
defstruct (f (x, y=3.14159, z));
  => [f(x, y = 3.14159, z)]
ff : new (f);
  => f (x, 3.14159, z)
(ff at y : 2.71828, ff);
  => f (x, 2.71828, z)

The @ notation doesn't require the left-hand side to be
something created by defstruct. I'm not really in favor of that.
Also the right-hand side can be an integer instead of a field
name (then @ is essentially the same as inpart). I'm not
really in favor of that either.

k : h (g (aa, bb), cc);
(k at 1@2 : dd, k);
  => h (g (aa, dd), cc)

Nested objects are OK.

defstruct (h (xx, yy), g (uu, vv));
  => [h (xx, yy), g (uu, vv)]
x : new (h);
  => h (xx, yy)
x at yy : new (g);
  => g (uu, vv)
x;
  => h (xx, g (uu, vv))
x at yy@vv : 123;
x;
  => h (xx, g (uu, 123))

Field names are not evaluated.

(yy : %i, vv : 1/2);
[x at yy, x at yy@vv];
  => [g (uu, 123), 123]

The ev(expr, foo at bar=baz) notation doesn't work as expected because
foo at bar is evaluated, and it evaluates to just bar. Quoting works.

ev (sin (x at xx + 1), '(x at xx)=%e);
  => sin (%e + 1);

ev (sin (x at yy@uu + 1), '(x at yy@uu)=%i);
  => sin (%i + 1);

One other random thought here -- at present an object is displayed
with the values of fields only e.g. foo(1/2, 123, x + y). It might be
nice to display it with the field names foo(a=1/2, b=123, c=x + y).
Maybe we could suppress the a=a for fields which evaluate to
themselves.

Comments?

Robert