John~

It can be made to sort of work.  Consider the following

struct point {
  double x;
  double y;
};

struct circle {
  point center;
  double radius;
}

boolean contains(circle c, point p) {
  double dx = c.center.x * p.x;
  double dy = c.center.y * p.y;
  double dist2 = dx*dx + dy*dy;
  return dist2 < c.radius*c.radius;
}

This example can be made to work by statically expanding center into
circle and then rewriting c.center.* to access the expanded fields.
The following, however, cannot be made to work (without a data copy):

boolean foo(circle c1, circle c2) {
    return contains(c1, c2.center);
}

The problem is the access to c2.center as a top-level structure.
Recall from the previous step that you had to expand its field's into
the top level structure.  In the case where a struct contains at most
1 other struct, you can cheat and use inheritance to get the correct
behavior, but that is a total hack and does not work in the general
case.  What you would need to do, is generate a  method to pack
circle's center fields into a point struct on demand.  This would
incur a data-copy when you directly reference a sub-struct, but the
common case of only accessing leaves would still be able to implement
efficiently.  For more deeply nested structures, recurse ;-)

Matt



On Mon, Dec 7, 2009 at 1:01 PM, John Wilson <[email protected]> wrote:
> I don't think you can do this in a straightforward way (but possibly
> somebody will be long soon to enlighten both of us!).
>
> When I want a large number of identical "structures" in Java I use an
> array of arrays. Would this work for you?
>
>
> John Wilson
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "JVM Languages" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/jvm-languages?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.


Reply via email to