comp.lang.ada
 help / color / mirror / Atom feed
* recursive map specification
@ 2019-06-25  8:21 mario.blunk.gplus
  2019-06-25  8:44 ` Egil H H
  2019-06-26  5:23 ` Randy Brukardt
  0 siblings, 2 replies; 6+ messages in thread
From: mario.blunk.gplus @ 2019-06-25  8:21 UTC (permalink / raw)


Hello,

I want to specify a recursive map. To simplify the problem I use the example of a person and its ancestors and ancestors ... The problem does not seem special but I haven't found a solution. The approach below does not compile:

type person is record
 name : unbounded_string;
end record;

package tree is new ordered_maps 
 (
 key_type => person,
 element_type => tree.map -- compiler error. "tree" undefined
 );

Any ideas ? Thanks a lot !

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recursive map specification
  2019-06-25  8:21 recursive map specification mario.blunk.gplus
@ 2019-06-25  8:44 ` Egil H H
  2019-06-25  9:09   ` mario.blunk.gplus
  2019-06-26  5:23 ` Randy Brukardt
  1 sibling, 1 reply; 6+ messages in thread
From: Egil H H @ 2019-06-25  8:44 UTC (permalink / raw)


On Tuesday, June 25, 2019 at 10:21:03 AM UTC+2, mario.b...@gmail.com wrote:
> Hello,
> 
> I want to specify a recursive map. To simplify the problem I use the example of a person and its ancestors and ancestors ... The problem does not seem special but I haven't found a solution. The approach below does not compile:
> 
> type person is record
>  name : unbounded_string;
> end record;
> 
> package tree is new ordered_maps 
>  (
>  key_type => person,
>  element_type => tree.map -- compiler error. "tree" undefined
>  );
> 
> Any ideas ? Thanks a lot !


Is there a reason you don't use Ada.Containers.Multiway_Trees instead?


-- 
~egilhh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recursive map specification
  2019-06-25  8:44 ` Egil H H
@ 2019-06-25  9:09   ` mario.blunk.gplus
  2019-06-25  9:22     ` Egil H H
  0 siblings, 1 reply; 6+ messages in thread
From: mario.blunk.gplus @ 2019-06-25  9:09 UTC (permalink / raw)


On Tuesday, June 25, 2019 at 10:44:11 AM UTC+2, Egil H H wrote:
> On Tuesday, June 25, 2019 at 10:21:03 AM UTC+2, mario.b...@gmail.com wrote:
> > Hello,
> > 
> > I want to specify a recursive map. To simplify the problem I use the example of a person and its ancestors and ancestors ... The problem does not seem special but I haven't found a solution. The approach below does not compile:
> > 
> > type person is record
> >  name : unbounded_string;
> > end record;
> > 
> > package tree is new ordered_maps 
> >  (
> >  key_type => person,
> >  element_type => tree.map -- compiler error. "tree" undefined
> >  );
> > 
> > Any ideas ? Thanks a lot !
> 
> 
> Is there a reason you don't use Ada.Containers.Multiway_Trees instead?
> 
> 
> -- 
> ~egilhh

It is the first time I read about multiway_trees. Do you have a simple example ready ? Otherwise I would dig into the package docs which lack practical examples... Thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recursive map specification
  2019-06-25  9:09   ` mario.blunk.gplus
@ 2019-06-25  9:22     ` Egil H H
  2019-06-25  9:24       ` mario.blunk.gplus
  0 siblings, 1 reply; 6+ messages in thread
From: Egil H H @ 2019-06-25  9:22 UTC (permalink / raw)


On Tuesday, June 25, 2019 at 11:09:20 AM UTC+2, mario.b...@gmail.com wrote:
> On Tuesday, June 25, 2019 at 10:44:11 AM UTC+2, Egil H H wrote:
> > On Tuesday, June 25, 2019 at 10:21:03 AM UTC+2, mario.b...@gmail.com wrote:
> > > Hello,
> > > 
> > > I want to specify a recursive map. To simplify the problem I use the example of a person and its ancestors and ancestors ... The problem does not seem special but I haven't found a solution. The approach below does not compile:
> > > 
> > > type person is record
> > >  name : unbounded_string;
> > > end record;
> > > 
> > > package tree is new ordered_maps 
> > >  (
> > >  key_type => person,
> > >  element_type => tree.map -- compiler error. "tree" undefined
> > >  );
> > > 
> > > Any ideas ? Thanks a lot !
> > 
> > 
> > Is there a reason you don't use Ada.Containers.Multiway_Trees instead?
> > 
> > 
> > -- 
> > ~egilhh
> 
> It is the first time I read about multiway_trees. Do you have a simple example ready ? Otherwise I would dig into the package docs which lack practical examples... Thanks


Sorry, I haven't used that package myself, but there's some additional explanation and example in the Rationale, http://www.ada-auth.org/standards/12rat/html/Rat12-8-4.html


-- 
~egilhh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recursive map specification
  2019-06-25  9:22     ` Egil H H
@ 2019-06-25  9:24       ` mario.blunk.gplus
  0 siblings, 0 replies; 6+ messages in thread
From: mario.blunk.gplus @ 2019-06-25  9:24 UTC (permalink / raw)


On Tuesday, June 25, 2019 at 11:22:25 AM UTC+2, Egil H H wrote:
> On Tuesday, June 25, 2019 at 11:09:20 AM UTC+2, mario.b...@gmail.com wrote:
> > On Tuesday, June 25, 2019 at 10:44:11 AM UTC+2, Egil H H wrote:
> > > On Tuesday, June 25, 2019 at 10:21:03 AM UTC+2, mario.b...@gmail.com wrote:
> > > > Hello,
> > > > 
> > > > I want to specify a recursive map. To simplify the problem I use the example of a person and its ancestors and ancestors ... The problem does not seem special but I haven't found a solution. The approach below does not compile:
> > > > 
> > > > type person is record
> > > >  name : unbounded_string;
> > > > end record;
> > > > 
> > > > package tree is new ordered_maps 
> > > >  (
> > > >  key_type => person,
> > > >  element_type => tree.map -- compiler error. "tree" undefined
> > > >  );
> > > > 
> > > > Any ideas ? Thanks a lot !
> > > 
> > > 
> > > Is there a reason you don't use Ada.Containers.Multiway_Trees instead?
> > > 
> > > 
> > > -- 
> > > ~egilhh
> > 
> > It is the first time I read about multiway_trees. Do you have a simple example ready ? Otherwise I would dig into the package docs which lack practical examples... Thanks
> 
> 
> Sorry, I haven't used that package myself, but there's some additional explanation and example in the Rationale, http://www.ada-auth.org/standards/12rat/html/Rat12-8-4.html
> 
> 
> -- 
> ~egilhh

Yep, I just found that too. Thanks. Time for reading :-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: recursive map specification
  2019-06-25  8:21 recursive map specification mario.blunk.gplus
  2019-06-25  8:44 ` Egil H H
@ 2019-06-26  5:23 ` Randy Brukardt
  1 sibling, 0 replies; 6+ messages in thread
From: Randy Brukardt @ 2019-06-26  5:23 UTC (permalink / raw)


<mario.blunk.gplus@gmail.com> wrote in message 
news:187147dc-94fe-4019-bc42-5b214db452db@googlegroups.com...
> Hello,
>
> I want to specify a recursive map. To simplify the problem I use the 
> example of a person and its ancestors and ancestors ... The problem does 
> not seem special but I haven't found a solution. The approach below does 
> not compile:
>
> type person is record
> name : unbounded_string;
> end record;
>
> package tree is new ordered_maps
> (
> key_type => person,
> element_type => tree.map -- compiler error. "tree" undefined
> );
>
> Any ideas ? Thanks a lot !

This is the reason that we defined the Multiway_Tree, as it isn't sensible 
to define a recursive container. (Otherwise, a recursive list is essentially 
a tree.) If you also need a map (for instance, to make the names easily 
found), I'd suggest making a map of tree cursors, and keep the real data in 
the tree (where the relationships also live).

                                              Randy.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-26  5:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25  8:21 recursive map specification mario.blunk.gplus
2019-06-25  8:44 ` Egil H H
2019-06-25  9:09   ` mario.blunk.gplus
2019-06-25  9:22     ` Egil H H
2019-06-25  9:24       ` mario.blunk.gplus
2019-06-26  5:23 ` Randy Brukardt

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