* array of operations @ 2002-09-10 13:45 marco 2002-09-10 15:28 ` Mark Biggar 2002-09-11 2:17 ` Ted Dennison 0 siblings, 2 replies; 12+ messages in thread From: marco @ 2002-09-10 13:45 UTC (permalink / raw) Do you know if there is some way of bulding up arrays of functions and/or procedures?... ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-10 13:45 array of operations marco @ 2002-09-10 15:28 ` Mark Biggar 2002-09-10 17:09 ` Ehud Lamm 2002-09-11 2:17 ` Ted Dennison 1 sibling, 1 reply; 12+ messages in thread From: Mark Biggar @ 2002-09-10 15:28 UTC (permalink / raw) marco wrote: > Do you know if there is some way of bulding up arrays of functions and/or > procedures?... Sure, Ada allows for access types to functions and procedures so you construct an array of those. But there are some things to consider. If your array is static, then a case statement is probably a better solution. -- -- Mark Biggar mark.a.biggar@attbi.com ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-10 15:28 ` Mark Biggar @ 2002-09-10 17:09 ` Ehud Lamm 2002-09-11 7:43 ` Ole-Hjalmar Kristensen 0 siblings, 1 reply; 12+ messages in thread From: Ehud Lamm @ 2002-09-10 17:09 UTC (permalink / raw) "Mark Biggar" <mark.a.biggar@attbi.com> wrote in message news:3D7E0EB1.2070708@attbi.com... > marco wrote: > > Do you know if there is some way of bulding up arrays of functions and/or > > procedures?... > > Sure, Ada allows for access types to functions and procedures so you > construct an array of those. Notice that all the procedures must have the same parameter profile. There are cases where this isn't what you want. There are also nesting issues (you can't have a top level array linking to nested subroutines) [Note to language lawyers: The last sentence was not meant to be a formal definition...] So in many cases you may decide (after thinking about "access procedure" and "access function") to use a dispatching routine that is invoked with an "opcode" (operation code) and calls the appropriate routine. Ehud ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-10 17:09 ` Ehud Lamm @ 2002-09-11 7:43 ` Ole-Hjalmar Kristensen 2002-09-11 10:10 ` Ehud Lamm 0 siblings, 1 reply; 12+ messages in thread From: Ole-Hjalmar Kristensen @ 2002-09-11 7:43 UTC (permalink / raw) "Ehud Lamm" <mslamm@huji.ac.il> writes: > "Mark Biggar" <mark.a.biggar@attbi.com> wrote in message > news:3D7E0EB1.2070708@attbi.com... > > marco wrote: > > > Do you know if there is some way of bulding up arrays of functions > and/or > > > procedures?... > > > > Sure, Ada allows for access types to functions and procedures so you > > construct an array of those. > > Notice that all the procedures must have the same parameter profile. There > are cases where this isn't what you want. > There are also nesting issues (you can't have a top level array linking to > nested subroutines) [Note to language lawyers: The last sentence was not > meant to be a formal definition...] > > So in many cases you may decide (after thinking about "access procedure" and > "access function") to use a dispatching routine that is invoked with an > "opcode" (operation code) and calls the appropriate routine. > > Ehud Or a pointer to an object and let the dispatching mechanism implement the function pointer behind the scenes. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-11 7:43 ` Ole-Hjalmar Kristensen @ 2002-09-11 10:10 ` Ehud Lamm 2002-09-11 23:43 ` Randy Brukardt 0 siblings, 1 reply; 12+ messages in thread From: Ehud Lamm @ 2002-09-11 10:10 UTC (permalink / raw) "Ole-Hjalmar Kristensen" <oleh@vlinux.voxelvision.no> wrote in message news:7vfzwh9dkl.fsf@vlinux.voxelvision.no... > Or a pointer to an object and let the dispatching mechanism implement > the function pointer behind the scenes. This indeed another useful technique. However, there are some small gotchas. You can usually use singleton objects, but in many cases you will need access values so you have to make them "aliased." By the way, several of these techniques are described in detail in my paper "Building Frameworks in Ada95", proceedings Ada-Belgium'99 Seminar, Leuven, 1999. Ehud Lamm ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-11 10:10 ` Ehud Lamm @ 2002-09-11 23:43 ` Randy Brukardt 2002-09-12 9:01 ` Ehud Lamm 0 siblings, 1 reply; 12+ messages in thread From: Randy Brukardt @ 2002-09-11 23:43 UTC (permalink / raw) Ehud Lamm wrote in message ... > >"Ole-Hjalmar Kristensen" <oleh@vlinux.voxelvision.no> wrote in message >news:7vfzwh9dkl.fsf@vlinux.voxelvision.no... > >> Or a pointer to an object and let the dispatching mechanism implement >> the function pointer behind the scenes. > >This indeed another useful technique. However, there are some small gotchas. >You can usually use singleton objects, but in many cases you will need >access values so you have to make them "aliased." Not true. Since it is always OK to take 'Unchecked_Access of a parameter of a tagged type in Ada 95, you generally do not need to explicitly use "aliased". Claw uses this extensively to provide an interface which is mostly without access types, yet internally everything is linked together. (Claw uses finalization to prevent dangling pointers in this case). There are very few 'aliased' tagged objects in the Claw sample programs (3 in 74 samples). Randy Brukardt. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-11 23:43 ` Randy Brukardt @ 2002-09-12 9:01 ` Ehud Lamm 2002-09-12 14:32 ` Mark Biggar 0 siblings, 1 reply; 12+ messages in thread From: Ehud Lamm @ 2002-09-12 9:01 UTC (permalink / raw) > Not true. Since it is always OK to take 'Unchecked_Access of a parameter > of a tagged type in Ada 95, you generally do not need to explicitly use > "aliased". Claw uses this extensively to provide an interface which is > mostly without access types, yet internally everything is linked > together. (Claw uses finalization to prevent dangling pointers in this > case). > Sure. You can rephrase what I wrote, "You usually need to decalre aliased objects, or use 'Unchecked_Access." :-) Ehud ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-12 9:01 ` Ehud Lamm @ 2002-09-12 14:32 ` Mark Biggar 2002-09-12 16:15 ` John McCabe 0 siblings, 1 reply; 12+ messages in thread From: Mark Biggar @ 2002-09-12 14:32 UTC (permalink / raw) Ehud Lamm wrote: >>Not true. Since it is always OK to take 'Unchecked_Access of a parameter >>of a tagged type in Ada 95, you generally do not need to explicitly use >>"aliased". Claw uses this extensively to provide an interface which is >>mostly without access types, yet internally everything is linked >>together. (Claw uses finalization to prevent dangling pointers in this >>case). > Sure. You can rephrase what I wrote, "You usually need to decalre aliased > objects, or use 'Unchecked_Access." :-) um, tagged objects are by definition aliased, see ARM 3.10(9). No need for an explisit declaration. -- Mark Biggar mark.a.biggar@attbi.com ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-12 14:32 ` Mark Biggar @ 2002-09-12 16:15 ` John McCabe 2002-09-12 16:37 ` David C. Hoos 0 siblings, 1 reply; 12+ messages in thread From: John McCabe @ 2002-09-12 16:15 UTC (permalink / raw) On Thu, 12 Sep 2002 14:32:10 GMT, Mark Biggar <mark.a.biggar@attbi.com> wrote: >Ehud Lamm wrote: >>>Not true. Since it is always OK to take 'Unchecked_Access of a parameter >>>of a tagged type in Ada 95, you generally do not need to explicitly use >>>"aliased". Claw uses this extensively to provide an interface which is >>>mostly without access types, yet internally everything is linked >>>together. (Claw uses finalization to prevent dangling pointers in this >>>case). > >> Sure. You can rephrase what I wrote, "You usually need to decalre aliased >> objects, or use 'Unchecked_Access." :-) > >um, tagged objects are by definition aliased, see ARM 3.10(9). No need >for an explisit declaration. Do you mean this bit: "and a formal parameter or generic formal object of a tagged type are defined to be aliased"? Note the word "generic". As far as I can see, you are mistaken. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-12 16:15 ` John McCabe @ 2002-09-12 16:37 ` David C. Hoos 2002-09-12 17:45 ` John McCabe 0 siblings, 1 reply; 12+ messages in thread From: David C. Hoos @ 2002-09-12 16:37 UTC (permalink / raw) Note the word "or". As far as I can see, _you_ are mistaken. ----- Original Message ----- From: "John McCabe" <john.nospam@nospamassen.nospamdemon.co.uk> Newsgroups: comp.lang.ada To: <comp.lang.ada@ada.eu.org> Sent: Thursday, September 12, 2002 11:15 AM Subject: Re: array of operations > On Thu, 12 Sep 2002 14:32:10 GMT, Mark Biggar > <mark.a.biggar@attbi.com> wrote: > > >Ehud Lamm wrote: > >>>Not true. Since it is always OK to take 'Unchecked_Access of a parameter > >>>of a tagged type in Ada 95, you generally do not need to explicitly use > >>>"aliased". Claw uses this extensively to provide an interface which is > >>>mostly without access types, yet internally everything is linked > >>>together. (Claw uses finalization to prevent dangling pointers in this > >>>case). > > > >> Sure. You can rephrase what I wrote, "You usually need to decalre aliased > >> objects, or use 'Unchecked_Access." :-) > > > >um, tagged objects are by definition aliased, see ARM 3.10(9). No need > >for an explisit declaration. > > Do you mean this bit: > > "and a formal parameter or generic formal object of a tagged type are > defined to be aliased"? > > Note the word "generic". As far as I can see, you are mistaken. > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-12 16:37 ` David C. Hoos @ 2002-09-12 17:45 ` John McCabe 0 siblings, 0 replies; 12+ messages in thread From: John McCabe @ 2002-09-12 17:45 UTC (permalink / raw) "David C. Hoos" <david.c.hoos.sr@ada95.com> wrote: >Note the word "or". As far as I can see, _you_ are mistaken. Bit of both by the looks of it. The phrase I responded to sounded like it was suggesting *any* tagged object was, by defnition, aliased. Should have made it more explicit that he meant any tagged parameter. By the way - I really *don't* need to have messages sent as email as well!! >----- Original Message ----- >From: "John McCabe" <john.nospam@nospamassen.nospamdemon.co.uk> >Newsgroups: comp.lang.ada >To: <comp.lang.ada@ada.eu.org> >Sent: Thursday, September 12, 2002 11:15 AM >Subject: Re: array of operations > > >> On Thu, 12 Sep 2002 14:32:10 GMT, Mark Biggar >> <mark.a.biggar@attbi.com> wrote: >> >> >Ehud Lamm wrote: >> >>>Not true. Since it is always OK to take 'Unchecked_Access of a >parameter >> >>>of a tagged type in Ada 95, you generally do not need to explicitly use >> >>>"aliased". Claw uses this extensively to provide an interface which is >> >>>mostly without access types, yet internally everything is linked >> >>>together. (Claw uses finalization to prevent dangling pointers in this >> >>>case). >> > >> >> Sure. You can rephrase what I wrote, "You usually need to decalre >aliased >> >> objects, or use 'Unchecked_Access." :-) >> > >> >um, tagged objects are by definition aliased, see ARM 3.10(9). No need >> >for an explisit declaration. >> >> Do you mean this bit: >> >> "and a formal parameter or generic formal object of a tagged type are >> defined to be aliased"? >> >> Note the word "generic". As far as I can see, you are mistaken. >> >> _______________________________________________ >> comp.lang.ada mailing list >> comp.lang.ada@ada.eu.org >> http://ada.eu.org/mailman/listinfo/comp.lang.ada >> > Best Regards John McCabe <john@assen.demon.co.uk> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: array of operations 2002-09-10 13:45 array of operations marco 2002-09-10 15:28 ` Mark Biggar @ 2002-09-11 2:17 ` Ted Dennison 1 sibling, 0 replies; 12+ messages in thread From: Ted Dennison @ 2002-09-11 2:17 UTC (permalink / raw) "marco" <pippo@libero.it> wrote in message news:<alkt6b$t73$1@e3k.asi.ansaldo.it>... > Do you know if there is some way of bulding up arrays of functions and/or > procedures?... Yes, there are ways. However, the usual answer here to a "how do I do this very C-ish thing in Ada?" question is "Why do you want to?" So...Why do you want to? :-) If it is to interface to a C routine that requires that exact type, then OK, that's a legitimate reason. However, if you just want an array that can be populated by clients where the client gets to specify a behavior, there are other better ways of doing it. For instance, have you considered using tagged types and runtime polymorphisim? You make an array of pointers to some base tagged type's "'Class", which has a primitive routine for you to call (let's call it "Do_It"). Then each client can derive their own version of that tagged type and override "Do_It" with their own operation. This is much more powerful than meer function pointers, is generally considered better OO design, and is better supported by the language. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2002-09-12 17:45 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-09-10 13:45 array of operations marco 2002-09-10 15:28 ` Mark Biggar 2002-09-10 17:09 ` Ehud Lamm 2002-09-11 7:43 ` Ole-Hjalmar Kristensen 2002-09-11 10:10 ` Ehud Lamm 2002-09-11 23:43 ` Randy Brukardt 2002-09-12 9:01 ` Ehud Lamm 2002-09-12 14:32 ` Mark Biggar 2002-09-12 16:15 ` John McCabe 2002-09-12 16:37 ` David C. Hoos 2002-09-12 17:45 ` John McCabe 2002-09-11 2:17 ` Ted Dennison
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox