comp.lang.ada
 help / color / mirror / Atom feed
* Learning Ada & a question
@ 2000-04-11  0:00 G
  2000-04-11  0:00 ` Robert A Duff
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: G @ 2000-04-11  0:00 UTC (permalink / raw)


I'm going slow on learning Ada95 just now and hitting the C++ textbooks.

Why ? (Or does it even matter...)

because I am finding that to get a handle on programming techniques and
data structures, etc. - it is neccessary to "triangulate" between
several resources
and then work the meaning out from there.   As there are many more books
out there
on C++, it gives me a broader view of things.  I live in Australia and
have to order books from overseas if I want texts on Ada.  (Hard copies
are more comfortable).
I don't think it C++ "feels" as good as Ada,
in a cognitive sense of a language and using that language but I have  a
question about something which I am dealing with now in C++ which
relates to something I was thinking about in Ada.


In C++ they have devised all these ingenious little techniques for
getting more than one return value from a function.  I am just wrapping
my mind around the notion of pass-by-reference with pointers and
references.  I know that access types are a sort of pointer in Ada.  Can
you do the same things in Ada ?  Do you need to when Procedures can be
called just as easily as functions anyways and return as many things as
you need ?  (I maybe didnt say that right).



--
----------------------------------------------------------------


G.M. Wallace
Australia


----------------------------------------------------------------


p.s. - if that Serbian hack is true, that is I guess what is called
information warfare.
It is interesting that as with terrorism and the media - the real effect
such acts may have probably lies in the proliferation of knowledge about
the act... as evidenced by the fact that this person has probably posted
to just about every newsgroup available in an attempt top achieve
notoriety.   that's my two bits worth





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

* Re: Learning Ada & a question
  2000-04-11  0:00 Learning Ada & a question G
  2000-04-11  0:00 ` Robert A Duff
@ 2000-04-11  0:00 ` Larry Kilgallen
  2000-04-11  0:00 ` Marin D. Condic
  2000-04-11  0:00 ` Ehud Lamm
  3 siblings, 0 replies; 5+ messages in thread
From: Larry Kilgallen @ 2000-04-11  0:00 UTC (permalink / raw)


In article <38F2E992.EDB2DCCE@interact.net.au>, G <gmw@interact.net.au> writes:

> and then work the meaning out from there.   As there are many more books
> out there
> on C++, it gives me a broader view of things.  I live in Australia and
> have to order books from overseas if I want texts on Ada.  (Hard copies
> are more comfortable).

In the US many people order Ada text by mail, and although delivery
may be quicker the principle in the same.  Yes, I find Ada books in
a few technical bookstores around Boston, but unfortunately they are
usually books I already own.

> In C++ they have devised all these ingenious little techniques for
> getting more than one return value from a function.  I am just wrapping
> my mind around the notion of pass-by-reference with pointers and
> references.  I know that access types are a sort of pointer in Ada.  Can
> you do the same things in Ada ?  Do you need to when Procedures can be
> called just as easily as functions anyways and return as many things as
> you need ?  (I maybe didnt say that right).

In my experience writing a procedure with OUT (or IN OUT) parameters
is much easier than writing a data structure with multiple components
to be returned.  There are certainly cases where I use the technique
involving a data structure, but that is mainly where the data structure
must be used by many different procedures and functions in the program.




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

* Re: Learning Ada & a question
  2000-04-11  0:00 Learning Ada & a question G
@ 2000-04-11  0:00 ` Robert A Duff
  2000-04-11  0:00 ` Larry Kilgallen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2000-04-11  0:00 UTC (permalink / raw)


G <gmw@interact.net.au> writes:

> In C++ they have devised all these ingenious little techniques for
> getting more than one return value from a function.  I am just wrapping
> my mind around the notion of pass-by-reference with pointers and
> references.  I know that access types are a sort of pointer in Ada.  Can
> you do the same things in Ada ?  Do you need to when Procedures can be
> called just as easily as functions anyways and return as many things as
> you need ?  (I maybe didnt say that right).

Yes, you can pass access values as parameters in Ada.  If you want the
thing to return two different values, it's usually better to make it a
procedure with 'in out' or 'out' parameters, rather than a function with
a result and an access-value parameter.  You can do the same in C++; a
void-returning function is essentially the same thing as an Ada
procedure.  Except that C++ doesn't have 'in out'; you have to pass
pointers or references.

Or, if the two values are really part of a single conceptual "thing",
then you can wrap them in a record, and return the record from the
function.  Same thing in C++; use a struct.

Or, if one of the things you're returning is an error code, consider
raising an exception instead.

Ada functions are not allowed to have 'in out' or 'out' parameters, by
the way.

- Bob




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

* Re: Learning Ada & a question
  2000-04-11  0:00 Learning Ada & a question G
                   ` (2 preceding siblings ...)
  2000-04-11  0:00 ` Marin D. Condic
@ 2000-04-11  0:00 ` Ehud Lamm
  3 siblings, 0 replies; 5+ messages in thread
From: Ehud Lamm @ 2000-04-11  0:00 UTC (permalink / raw)


Hi

I love programming languages, and agree with you that knowing more than
one is helpful. BUT it can also be confusing. Esp. if you think at the
wrong level. I think that comparing things like the ones you are referring
to can be detrimental to your health.. Comperative linguistics are for
after you grasp the general notions. Things that may be wroth comparing
are things like the notion of class, modularization techniques (packages),
approach to inheritance etc. (By the way, my paper on "frameworks"
provides some examples of such a comparison).
The feeling I get from studetns is that they try to compare too early -
before they understand the Ada concepts well enough -- and then they
simply get confused/frustrated.

As to your question. In many cases using "unconstrained arrays" can be
useful if you need to return more than one value (of the same type) inside
an Ada system.Notice that this is on a different abstraction level than
the C/C++ mechanisms.

HTH

Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== My home on the web 
Check it out and subscribe to the E-List- for interesting essays and more!






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

* Re: Learning Ada & a question
  2000-04-11  0:00 Learning Ada & a question G
  2000-04-11  0:00 ` Robert A Duff
  2000-04-11  0:00 ` Larry Kilgallen
@ 2000-04-11  0:00 ` Marin D. Condic
  2000-04-11  0:00 ` Ehud Lamm
  3 siblings, 0 replies; 5+ messages in thread
From: Marin D. Condic @ 2000-04-11  0:00 UTC (permalink / raw)


G wrote:
> 
> In C++ they have devised all these ingenious little techniques for
> getting more than one return value from a function.  I am just wrapping
> my mind around the notion of pass-by-reference with pointers and
> references.  I know that access types are a sort of pointer in Ada.  Can
> you do the same things in Ada ?  Do you need to when Procedures can be
> called just as easily as functions anyways and return as many things as
> you need ?  (I maybe didnt say that right).
> 
I think what you're asking is "Can functions in Ada have 'out'
parameters so that more than just the function result can be returned?"
The short answer is 'no'. C/C++ never developed the notion of a
"procedure" which does not return a single result and cannot be used in
an equation. They sort of tacked that on by creating void functions and
having you pass the address of parameters (or ref in C++).

If you need something that computes multiple values and returns multiple
results, the correct way to do that in Ada is with a procedure. You
can't use a procedure in an equation, specifically because it doesn't
return a single result. If for some reason (and those reasons are rare)
you need a function that returns a single result and then has side
effects on its parameters, there is something called "The Rosen Trick"
which you can find on www.adapower.com or on my web site. (See below). I
would *strongly* advise avoiding this as a general programming technique
since it violates the general intent of the language, but it does have
its place.

If you want to get multiple results for a calculation, the way to do it
is basically like this:

procedure Get_Three_Results (X, Y, Z : out Integer) is.....

...

Get_Three_Results (A, B, C) ;
K := A + B + C ;

.....


Hope this is helpful

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"I'd trade it all for just a little more"
    --  Charles Montgomery Burns, [4F10]
======================================================================




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

end of thread, other threads:[~2000-04-11  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-11  0:00 Learning Ada & a question G
2000-04-11  0:00 ` Robert A Duff
2000-04-11  0:00 ` Larry Kilgallen
2000-04-11  0:00 ` Marin D. Condic
2000-04-11  0:00 ` Ehud Lamm

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