comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Composing sequences (interesting to solve)
Date: Thu, 16 Jan 2003 19:20:38 +0100
Date: 2003-01-16T19:20:38+01:00	[thread overview]
Message-ID: <b06t4c$m4h27$3@ID-77047.news.dfncis.de> (raw)
In-Reply-To: 3e2620ad$0$33930$bed64819@news.gradwell.net

Victor Porton wrote:

> See an interesting and yet unsolved by me practical task to solve:
> 
> I have "elements" of various kinds (Base_Element'Class):
> 
> type Base_Element is null record;
> 
> There are many various types of element derived from
> Base_Element. Some of these contain accesses to other
> elements (which I allocate by "new"), so that this forms
> trees.
> 
> To eliminate access types conversions I decided to limit
> myself to use only Base_Element_Access (not accesses to
> derived types) (BTW, Is it right design decision?):
> 
> type Base_Element_Access is access Base_Element'Class;
> 
> One of the types of elements is "sequence" (it is an ordered
> container of elements):
> 
> type Sequence is new Base_Element with private;
> 
> I wish to produce sequences (allocated dynamically) by such
> the syntax using overloaded function "&":
> 
> E1 & E2 & E3
> 
> The question is how to define function "&" so that it would
> give the right result (access to one dynamically allocated
> sequence) independingly on the number of elements?

I think you should clarify whether A & B creates a new object or just binds 
A and B. Why an access type have to be returned? It is a bad style and 
error prone. If you really want heap allocated objects [with reference 
counting and garbage collection], use handles instead of raw pointers. & 
have to be defined on both handles and privately, on the objects. It is a 
bit nasty especially if you want to add some operations to derived 
elements. If so you have two [bad] alternatives:

1. Compile-time checkable. Derive new handle types and define new operations 
on them.

2. Run-time checkable. Define new operations on the handle type and leave 
checks to casting.

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-01-16 18:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-16  3:01 Composing sequences (interesting to solve) Victor Porton
2003-01-16 18:20 ` Dmitry A. Kazakov [this message]
2003-01-16 20:09 ` Victor Porton
2003-01-17  8:27   ` Fraser Wilson
2003-01-17 16:27   ` Dmitry A. Kazakov
2003-01-17 20:45 ` Victor Porton
2003-01-17 21:04 ` Victor Porton
2003-01-18 12:31   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox