comp.lang.ada
 help / color / mirror / Atom feed
* Out parameters in a function
@ 2002-04-14 18:29 Nazgul
  2002-04-14 19:45 ` David C. Hoos, Sr.
                   ` (5 more replies)
  0 siblings, 6 replies; 37+ messages in thread
From: Nazgul @ 2002-04-14 18:29 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]

Hi, I need to use an output parameter in an Ada function, something like

function ReadChar(f: File; c: out character) return boolean;

The function must return a boolean, so the only way to read the character is
via the 'c' parameter. In other context, I use

function (something: tpSomething) return ...; where tpSomething is an access
to a record type, and I can modify the contents of the record in the
function, but if I use

function ReadChar(f: File; c: access character) return boolean;

the compiler gives an error when i do something like

c:=anything;

Is there any way of using c as an output parameter?

Thanks.

--

 (:==================:)
     �lvaro Iradier
    airadier@able.es
     (+34)660133259
 (:==================:)





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

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
@ 2002-04-14 19:45 ` David C. Hoos, Sr.
  2002-04-15 10:49 ` John McCabe
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 37+ messages in thread
From: David C. Hoos, Sr. @ 2002-04-14 19:45 UTC (permalink / raw)


You need to say
C.all := anything; (assuming "anything" is a character expression);

----- Original Message -----
From: "Nazgul" <darkelf@aim.homelinux.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: April 14, 2002 1:29 PM
Subject: Out parameters in a function


> Hi, I need to use an output parameter in an Ada function, something like
>
> function ReadChar(f: File; c: out character) return boolean;
>
> The function must return a boolean, so the only way to read the character is
> via the 'c' parameter. In other context, I use
>
> function (something: tpSomething) return ...; where tpSomething is an access
> to a record type, and I can modify the contents of the record in the
> function, but if I use
>
> function ReadChar(f: File; c: access character) return boolean;
>
> the compiler gives an error when i do something like
>
> c:=anything;
>
> Is there any way of using c as an output parameter?
>
> Thanks.
>
> --
>
>  (:==================:)
>      �lvaro Iradier
>     airadier@able.es
>      (+34)660133259
>  (:==================:)
>
>
> _______________________________________________
> 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] 37+ messages in thread

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
  2002-04-14 19:45 ` David C. Hoos, Sr.
@ 2002-04-15 10:49 ` John McCabe
  2002-04-15 11:51   ` John McCabe
  2002-04-15 13:43 ` Steve Doiel
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 37+ messages in thread
From: John McCabe @ 2002-04-15 10:49 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1152 bytes --]

On Sun, 14 Apr 2002 20:29:10 +0200, "Nazgul"
<darkelf@aim.homelinux.com> wrote:

You could use a procedure, or you could use a function that returns a
record containing a boolean and the character you want.

As far as I can remember, a way of getting round the no-side-effects
feature of functions is to pass it a pointer then update the contents
of the pointed to location.

>Hi, I need to use an output parameter in an Ada function, something like
>
>function ReadChar(f: File; c: out character) return boolean;
>
>The function must return a boolean, so the only way to read the character is
>via the 'c' parameter. In other context, I use
>
>function (something: tpSomething) return ...; where tpSomething is an access
>to a record type, and I can modify the contents of the record in the
>function, but if I use
>
>function ReadChar(f: File; c: access character) return boolean;
>
>the compiler gives an error when i do something like
>
>c:=anything;
>
>Is there any way of using c as an output parameter?
>
>Thanks.
>
>--
>
> (:==================:)
>     �lvaro Iradier
>    airadier@able.es
>     (+34)660133259
> (:==================:)
>
>




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

* Re: Out parameters in a function
  2002-04-15 10:49 ` John McCabe
@ 2002-04-15 11:51   ` John McCabe
  0 siblings, 0 replies; 37+ messages in thread
From: John McCabe @ 2002-04-15 11:51 UTC (permalink / raw)


On Mon, 15 Apr 2002 10:49:04 GMT, john.mccabe@emrad.ns.com (John
McCabe) wrote:

>On Sun, 14 Apr 2002 20:29:10 +0200, "Nazgul"
><darkelf@aim.homelinux.com> wrote:
>
>You could use a procedure, or you could use a function that returns a
>record containing a boolean and the character you want.
>
>As far as I can remember, a way of getting round the no-side-effects
>feature of functions is to pass it a pointer then update the contents
>of the pointed to location.

"pointers"! access types I mean :-)

>>function ReadChar(f: File; c: access character) return boolean;

>>the compiler gives an error when i do something like

>>c:=anything;

Missed this bit but, as David says:

c.all := anything;



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

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
  2002-04-14 19:45 ` David C. Hoos, Sr.
  2002-04-15 10:49 ` John McCabe
@ 2002-04-15 13:43 ` Steve Doiel
  2002-04-15 15:09 ` Ted Dennison
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 37+ messages in thread
From: Steve Doiel @ 2002-04-15 13:43 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1129 bytes --]

"Nazgul" <darkelf@aim.homelinux.com> wrote in message
news:a9chqr$23e76$1@ID-107015.news.dfncis.de...
> Hi, I need to use an output parameter in an Ada function, something like
>
> function ReadChar(f: File; c: out character) return boolean;
>

If you "need" this function because you're used to the C construct

  while ( (c=getchar()) != EOF )

May I suggest

  loop
    ReadChar( file, char, end_of_file );
    exit when end_of_file;
    ...
  end loop;

instead?

SteveD

> The function must return a boolean, so the only way to read the character
is
> via the 'c' parameter. In other context, I use
>
> function (something: tpSomething) return ...; where tpSomething is an
access
> to a record type, and I can modify the contents of the record in the
> function, but if I use
>
> function ReadChar(f: File; c: access character) return boolean;
>
> the compiler gives an error when i do something like
>
> c:=anything;
>
> Is there any way of using c as an output parameter?
>
> Thanks.
>
> --
>
>  (:==================:)
>      �lvaro Iradier
>     airadier@able.es
>      (+34)660133259
>  (:==================:)
>
>





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

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
                   ` (2 preceding siblings ...)
  2002-04-15 13:43 ` Steve Doiel
@ 2002-04-15 15:09 ` Ted Dennison
  2002-04-16  8:49   ` John McCabe
  2002-04-15 16:24 ` Stephen Leake
  2002-04-17 11:55 ` Ingo Marks
  5 siblings, 1 reply; 37+ messages in thread
From: Ted Dennison @ 2002-04-15 15:09 UTC (permalink / raw)


"Nazgul" <darkelf@aim.homelinux.com> wrote in message news:<a9chqr$23e76$1@ID-107015.news.dfncis.de>...
> function ReadChar(f: File; c: out character) return boolean;
> 
> The function must return a boolean, so the only way to read the character is
> via the 'c' parameter. In other context, I use
...
> Is there any way of using c as an output parameter?

No. In Ada functions take multiple "in" parameters, and return only
one value via the "return" machanisim. If you have multiple values you
need to return, you should be using a procedure, not a function.

Given that, yes there are some ways to hack it. You can hack it the
same way C coders have hacked it since 1970; by passing in a pointer
to an object instead of the object itself. There is also the Rosen
trick (which is not something we should really get into with a newbie,
it relies on several things you probably don't even know about yet,
and has some weird gotchas). You could also make the character the
"return" value, and use exceptions rather than a boolean.

What method to use really depends a lot on your situation, so it would
be nice to have a little more information on *why* you want to do
this. Any one of the above can be the most appropirate method, or
completely unappropriate, depending on what you are trying to do.


-- 
T.E.D.
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



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

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
                   ` (3 preceding siblings ...)
  2002-04-15 15:09 ` Ted Dennison
@ 2002-04-15 16:24 ` Stephen Leake
  2002-04-16 13:38   ` Ted Dennison
  2002-04-17 11:55 ` Ingo Marks
  5 siblings, 1 reply; 37+ messages in thread
From: Stephen Leake @ 2002-04-15 16:24 UTC (permalink / raw)


"Nazgul" <darkelf@aim.homelinux.com> writes:

> Hi, I need to use an output parameter in an Ada function, something like
> 
> function ReadChar(f: File; c: out character) return boolean;
> 

Why do you "need" to do this? If you are writing your own Ada
subprogram, just declare two 'out' parameters, one character and one
boolean.

If you are trying to import a C function that has this profile, you
need to use the non-standard GNAT pragma Import_Valued_Procedure; see
the GNAT user's guide.

-- 
-- Stephe



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

* Re: Out parameters in a function
  2002-04-15 15:09 ` Ted Dennison
@ 2002-04-16  8:49   ` John McCabe
  2002-04-16 10:05     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 37+ messages in thread
From: John McCabe @ 2002-04-16  8:49 UTC (permalink / raw)


On 15 Apr 2002 08:09:24 -0700, dennison@telepath.com (Ted Dennison)
wrote:

>"Nazgul" <darkelf@aim.homelinux.com> wrote in message news:<a9chqr$23e76$1@ID-107015.news.dfncis.de>...
>> function ReadChar(f: File; c: out character) return boolean;
>> 
>> The function must return a boolean, so the only way to read the character is
>> via the 'c' parameter. In other context, I use
>...
>> Is there any way of using c as an output parameter?
>
>No. In Ada functions take multiple "in" parameters, and return only
>one value via the "return" machanisim. If you have multiple values you
>need to return, you should be using a procedure, not a function.

Unfortunate that they didn't follow the Occam example of having a
function capable of returning multiple values!



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

* Re: Out parameters in a function
  2002-04-16  8:49   ` John McCabe
@ 2002-04-16 10:05     ` Dmitry A. Kazakov
  2002-04-16 15:26       ` John McCabe
  0 siblings, 1 reply; 37+ messages in thread
From: Dmitry A. Kazakov @ 2002-04-16 10:05 UTC (permalink / raw)


On Tue, 16 Apr 2002 08:49:44 GMT, john.mccabe@emrad.ns.com (John
McCabe) wrote:

>On 15 Apr 2002 08:09:24 -0700, dennison@telepath.com (Ted Dennison)
>wrote:
>
>>"Nazgul" <darkelf@aim.homelinux.com> wrote in message news:<a9chqr$23e76$1@ID-107015.news.dfncis.de>...
>>> function ReadChar(f: File; c: out character) return boolean;
>>> 
>>> The function must return a boolean, so the only way to read the character is
>>> via the 'c' parameter. In other context, I use
>>...
>>> Is there any way of using c as an output parameter?
>>
>>No. In Ada functions take multiple "in" parameters, and return only
>>one value via the "return" machanisim. If you have multiple values you
>>need to return, you should be using a procedure, not a function.
>
>Unfortunate that they didn't follow the Occam example of having a
>function capable of returning multiple values!

Let they do. I.e. let a function return an object of anonymous record
type which components are returned values:

function Match_Pattern (..) return
   record
      Place : Position;
      Matched : String;
   end record;

How could we use such object? It does not well fit in a language with
named parameter association and very limited possibilities of matching
types by structure. IMO out parameters make more sense.

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



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

* Re: Out parameters in a function
  2002-04-15 16:24 ` Stephen Leake
@ 2002-04-16 13:38   ` Ted Dennison
  0 siblings, 0 replies; 37+ messages in thread
From: Ted Dennison @ 2002-04-16 13:38 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> wrote in message news:<uelhh0w1d.fsf@gsfc.nasa.gov>...
> If you are trying to import a C function that has this profile, you
> need to use the non-standard GNAT pragma Import_Valued_Procedure; see
> the GNAT user's guide.

First off, you don't know that he's using Gnat. Secondly, I'd advise
*against* using that pragma unless you know for a fact that you'll
never want to use the code with another compiler. Instead, you should
just use an access value (or System.Address). That may seem annoying
and ugly, but its exactly what the C coders who use that routine will
be doing. Its a C interface; there's no sense in polishing a turd.


-- 
T.E.D.
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



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

* Re: Out parameters in a function
  2002-04-16 10:05     ` Dmitry A. Kazakov
@ 2002-04-16 15:26       ` John McCabe
  2002-04-16 19:34         ` Matthew Woodcraft
                           ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: John McCabe @ 2002-04-16 15:26 UTC (permalink / raw)


On Tue, 16 Apr 2002 12:05:01 +0200, Dmitry A. Kazakov
<mailbox@dmitry-kazakov.de> wrote:

>>Unfortunate that they didn't follow the Occam example of having a
>>function capable of returning multiple values!

>Let they do. I.e. let a function return an object of anonymous record
>type which components are returned values:
>
>function Match_Pattern (..) return
>   record
>      Place : Position;
>      Matched : String;
>   end record;

It was more of a:

    BYTE, BYTE FUNCTION split.int16 (VAL INT16 n)
      BYTE high, low:
      VALOF
        SEQ
          high := BYTE (n >> 8)
          low := BYTE (n /\ 8)
        RESULT high, low
    :

type of thing, but I can't remember off-hand how you would use a
returned status with multiple return values!




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

* Re: Out parameters in a function
  2002-04-16 15:26       ` John McCabe
@ 2002-04-16 19:34         ` Matthew Woodcraft
  2002-04-16 20:10           ` Darren New
  2002-04-17 10:17           ` John McCabe
  2002-04-16 19:58         ` Kent Paul Dolan
  2002-04-16 20:00         ` Kent Paul Dolan
  2 siblings, 2 replies; 37+ messages in thread
From: Matthew Woodcraft @ 2002-04-16 19:34 UTC (permalink / raw)


In article <3cbc3f05.26543327@news.demon.co.uk>,
John McCabe <john.mccabe@emrad.ns.com> wrote:
>It was more of a:
>
>    BYTE, BYTE FUNCTION split.int16 (VAL INT16 n)
>      BYTE high, low:
>      VALOF
>        SEQ
>          high := BYTE (n >> 8)
>          low := BYTE (n /\ 8)
>        RESULT high, low
>    :
>
>type of thing, but I can't remember off-hand how you would use a
>returned status with multiple return values!

 h, l := split.int16 (365)

-M-





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

* Re: Out parameters in a function
  2002-04-16 15:26       ` John McCabe
  2002-04-16 19:34         ` Matthew Woodcraft
@ 2002-04-16 19:58         ` Kent Paul Dolan
  2002-04-16 20:00         ` Kent Paul Dolan
  2 siblings, 0 replies; 37+ messages in thread
From: Kent Paul Dolan @ 2002-04-16 19:58 UTC (permalink / raw)


"John McCabe" <john.mccabe@emrad.ns.com> wrote:

> type of thing, but I can't remember off-hand how you would use a
> returned status with multiple return values!

Well, if I'm not inventing capabilities, in C the syntax is fairly
direct (and forgive that with several dozen languages mixed in my head I
cannot write any one correctly without manual in lap, which I don't have
these days):

if
(
  (
    aSomestructTypedVariable =
      aSomestructReturningFunction
      (
        lots,
        of,
        parms
      )
  ).booleanPart
)
{
  usefulVal = somestruct.usefulPart;
}

Does Ada support a similar "assignment en passant" mechanism?

xanthian.

(Does C return structures, for that matter?)




-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



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

* Re: Out parameters in a function
  2002-04-16 15:26       ` John McCabe
  2002-04-16 19:34         ` Matthew Woodcraft
  2002-04-16 19:58         ` Kent Paul Dolan
@ 2002-04-16 20:00         ` Kent Paul Dolan
  2002-04-17  4:40           ` Jim Rogers
  2002-04-17  7:57           ` Dmitry A. Kazakov
  2 siblings, 2 replies; 37+ messages in thread
From: Kent Paul Dolan @ 2002-04-16 20:00 UTC (permalink / raw)


"John McCabe" <john.mccabe@emrad.ns.com> wrote:

 > type of thing, but I can't remember off-hand how you would use a
 > returned status with multiple return values!

Well, if I'm not inventing capabilities, in C the syntax is fairly
direct (and forgive that with several dozen languages mixed in my head I
cannot write any one correctly without manual in lap, which I don't have
these days):

if
(
  (
    aSomestructTypedVariable =
      aSomestructReturningFunction
      (
        lots,
        of,
        parms
      )
  ).booleanPart
)
{
  usefulVal = aSomestructTypedVariable.usefulPart;
}

Does Ada support a similar "assignment en passant" mechanism?

xanthian.

(Does C return structures, for that matter?)





-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



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

* Re: Out parameters in a function
  2002-04-16 19:34         ` Matthew Woodcraft
@ 2002-04-16 20:10           ` Darren New
  2002-04-17  1:30             ` Kent Paul Dolan
                               ` (2 more replies)
  2002-04-17 10:17           ` John McCabe
  1 sibling, 3 replies; 37+ messages in thread
From: Darren New @ 2002-04-16 20:10 UTC (permalink / raw)


> >        RESULT high, low
>  h, l := split.int16 (365)

Note that in virtually all these languages, what this means is "return
an anonymous tuple from the function."  AFAIK, FORTH is the only
reasonably common language where you can *actually* return multiple
values from a function, rather than returning a single structured value.

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
   The 90/10 rule of toothpaste: the last 10% of 
         the tube lasts as long as the first 90%.



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

* Re: Out parameters in a function
  2002-04-16 20:10           ` Darren New
@ 2002-04-17  1:30             ` Kent Paul Dolan
  2002-04-17 16:15               ` Darren New
  2002-04-19 17:39               ` Florian Weimer
  2002-04-17 13:24             ` Stephen Leake
  2002-04-18 12:14             ` Wolfgang Gellerich
  2 siblings, 2 replies; 37+ messages in thread
From: Kent Paul Dolan @ 2002-04-17  1:30 UTC (permalink / raw)


"Darren New" <dnew@san.rr.com> wrote:

> > >        RESULT high, low
> >  h, l := split.int16 (365)

> Note that in virtually all these languages, what this means is "return
> an anonymous tuple from the function."  AFAIK, FORTH is the only
> reasonably common language where you can *actually* return multiple
> values from a function, rather than returning a single structured value.

Ummm.  APL, PL/PGSQL, CLAIRE, ML (and so OCaml, JoCaml), ...

Polyadic valued functions are actually fairly common programming
features, I found one reference proposing installing them in Java, and
the Java Enumeration is vaguely such a beast already.

xanthian.


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



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

* Re: Out parameters in a function
  2002-04-16 20:00         ` Kent Paul Dolan
@ 2002-04-17  4:40           ` Jim Rogers
  2002-04-17  5:27             ` Kent Paul Dolan
                               ` (2 more replies)
  2002-04-17  7:57           ` Dmitry A. Kazakov
  1 sibling, 3 replies; 37+ messages in thread
From: Jim Rogers @ 2002-04-17  4:40 UTC (permalink / raw)


Kent Paul Dolan wrote:

> "John McCabe" <john.mccabe@emrad.ns.com> wrote:
> 
>  > type of thing, but I can't remember off-hand how you would use a
>  > returned status with multiple return values!
> 
> Well, if I'm not inventing capabilities, in C the syntax is fairly
> direct (and forgive that with several dozen languages mixed in my head I
> cannot write any one correctly without manual in lap, which I don't have
> these days):
> 
> if
> (
>   (
>     aSomestructTypedVariable =
>       aSomestructReturningFunction
>       (
>         lots,
>         of,
>         parms
>       )
>   ).booleanPart
> )
> {
>   usefulVal = aSomestructTypedVariable.usefulPart;
> }
> 
> Does Ada support a similar "assignment en passant" mechanism?
> 
> xanthian.
> 
> (Does C return structures, for that matter?)


Well, almost. C does not have a boolean type. C (since its first
ANSI standard) does support returning structures. It could always
return a pointer to a structure.

Ada does not have the same sense of expressions as C.
Specifically, an assignment operator in Ada does not return a value.

Jim Rogers





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

* Re: Out parameters in a function
  2002-04-17  4:40           ` Jim Rogers
@ 2002-04-17  5:27             ` Kent Paul Dolan
  2002-04-17  5:50             ` Eric G. Miller
  2002-04-19 17:40             ` Florian Weimer
  2 siblings, 0 replies; 37+ messages in thread
From: Kent Paul Dolan @ 2002-04-17  5:27 UTC (permalink / raw)


"Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote:

> Well, almost. C does not have a boolean type.

Sorry, of course you're correct.  The standard C include files have
defined TRUE and FALSE for so long and I've used them for so long I tend
to forget they aren't, per se, part of C, but just some of those
programming "implicit contracts" spoken of in another thread.

[And my usual usage before they came along was always:

#define TRUE ( 0 == 0 )
#define FALSE ( 0 == 1 )

anyway, since I didn't want to be dependent on a particular compiler
writer's picking the usual choice of treatments of 0 versus non-zero as
true or false, which I should have remembered.]

> C (since its first
> ANSI standard) does support returning structures. It could always
> return a pointer to a structure.

> Ada does not have the same sense of expressions as C.
> Specifically, an assignment operator in Ada does not return a value.

That is probably both good and bad; good, because stack cleanups or
alternate compilation paths for unused optionally produced values aren't
an issue; in this case unfortunate, since it prevents a fairly natural
way to accomplish what the original poster was seeking.  Not that the
obvious way of breaking the suggestion I presented down into several
steps won't work, it is just much more awkward than using
value-providing assignment statements or polyadic valued functions.

Thanks for the corrections and further advice.

> Jim Rogers

xanthian, happiest probably programming in languages where one can
return a list of values from a procedure.


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



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

* Re: Out parameters in a function
  2002-04-17  4:40           ` Jim Rogers
  2002-04-17  5:27             ` Kent Paul Dolan
@ 2002-04-17  5:50             ` Eric G. Miller
  2002-04-24  2:45               ` David Thompson
  2002-04-19 17:40             ` Florian Weimer
  2 siblings, 1 reply; 37+ messages in thread
From: Eric G. Miller @ 2002-04-17  5:50 UTC (permalink / raw)


In <3CBCFCC8.6000206@worldnet.att.net>, Jim Rogers wrote:

> Well, almost. C does not have a boolean type. C (since its first

Umm, mostly true. C99 has stdbool.h, but it's still not really a
builtin type of the language (int macros ...).

And curiously, C can return structs containing arrays, but can't
return arrays (as arrays are not "lvalues"). Boggle...



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

* Re: Out parameters in a function
  2002-04-16 20:00         ` Kent Paul Dolan
  2002-04-17  4:40           ` Jim Rogers
@ 2002-04-17  7:57           ` Dmitry A. Kazakov
  2002-04-17 10:21             ` John McCabe
  2002-04-24 17:21             ` Warren W. Gay VE3WWG
  1 sibling, 2 replies; 37+ messages in thread
From: Dmitry A. Kazakov @ 2002-04-17  7:57 UTC (permalink / raw)


On Tue, 16 Apr 2002 20:00:42 +0000 (UTC), "Kent Paul Dolan"
<xanthian@well.com> wrote:

>"John McCabe" <john.mccabe@emrad.ns.com> wrote:
>
> > type of thing, but I can't remember off-hand how you would use a
> > returned status with multiple return values!
>
>Well, if I'm not inventing capabilities, in C the syntax is fairly
>direct (and forgive that with several dozen languages mixed in my head I
>cannot write any one correctly without manual in lap, which I don't have
>these days):
>
>if
>(
>  (
>    aSomestructTypedVariable =
>      aSomestructReturningFunction
>      (
>        lots,
>        of,
>        parms
>      )
>  ).booleanPart
>)
>{
>  usefulVal = aSomestructTypedVariable.usefulPart;
>}

Same in Ada:

declare
   aSomestructTypedVariable : constant SomestructType :=
      aSomestructReturningFunction (...);
begin
   if aSomestructTypedVariable.booleanPart then
      usefulVal := aSomestructTypedVariable.usefulPart;
   end if;
end;

Not a big deal.

A real advantage [and possible the single one] of returned tuples of
values is when you are able to use them as a part of the parameter
list for some other subroutine. There are things that cannot be done
with temp variables + out parameters. For instance

Text :String := Get_Nobody_Knows_How_Many_Characters (...);

cannot be replaced with:

   Text : String; -- Error!
begin
   Get_Nobody_Knows_How_Many_Characters (..., Text);

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



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

* Re: Out parameters in a function
  2002-04-16 19:34         ` Matthew Woodcraft
  2002-04-16 20:10           ` Darren New
@ 2002-04-17 10:17           ` John McCabe
  1 sibling, 0 replies; 37+ messages in thread
From: John McCabe @ 2002-04-17 10:17 UTC (permalink / raw)


On 16 Apr 2002 20:34:04 +0100 (BST), Matthew Woodcraft
<mattheww@chiark.greenend.org.uk> wrote:

>In article <3cbc3f05.26543327@news.demon.co.uk>,
>John McCabe <john.mccabe@emrad.ns.com> wrote:
>>It was more of a:
>>
>>    BYTE, BYTE FUNCTION split.int16 (VAL INT16 n)
>>      BYTE high, low:
>>      VALOF
>>        SEQ
>>          high := BYTE (n >> 8)
>>          low := BYTE (n /\ 8)
>>        RESULT high, low
>>    :
>>
>>type of thing, but I can't remember off-hand how you would use a
>>returned status with multiple return values!
>
> h, l := split.int16 (365)

Thanks, but that's not what I meant. What I meant was if one of the
return values was boolean, and one an int for example, and you wanted
to check the returned boolean without bothering to assign it to a
variable! I presume that this doesn't make sense to do (so probably
can't be done) - I'll have to check my Occam books toinight!

It probably wasn't worth mentioning in the first place :-)




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

* Re: Out parameters in a function
  2002-04-17  7:57           ` Dmitry A. Kazakov
@ 2002-04-17 10:21             ` John McCabe
  2002-04-24 17:21             ` Warren W. Gay VE3WWG
  1 sibling, 0 replies; 37+ messages in thread
From: John McCabe @ 2002-04-17 10:21 UTC (permalink / raw)


On Wed, 17 Apr 2002 09:57:26 +0200, Dmitry A. Kazakov
<mailbox@dmitry-kazakov.de> wrote:

>A real advantage [and possible the single one] of returned tuples of
>values is when you are able to use them as a part of the parameter
>list for some other subroutine.

Cant be done in Occam with multi-valued return parameters (As far as I
remember).




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

* Re: Out parameters in a function
  2002-04-14 18:29 Out parameters in a function Nazgul
                   ` (4 preceding siblings ...)
  2002-04-15 16:24 ` Stephen Leake
@ 2002-04-17 11:55 ` Ingo Marks
  5 siblings, 0 replies; 37+ messages in thread
From: Ingo Marks @ 2002-04-17 11:55 UTC (permalink / raw)


Nazgul wrote:

> Hi, I need to use an output parameter in an Ada function, something like
> 
> function ReadChar(f: File; c: out character) return boolean;
> 
> The function must return a boolean, so the only way to read the character
> is via the 'c' parameter. In other context, I use
> 
> function (something: tpSomething) return ...; where tpSomething is an
> access to a record type, and I can modify the contents of the record in
> the function, but if I use
> 
> function ReadChar(f: File; c: access character) return boolean;
> 
> the compiler gives an error when i do something like
> 
> c:=anything;
> 
> Is there any way of using c as an output parameter?
> 
> Thanks.

You can simulate out parameters in functions with access:

   procedure Test is

      function Increment (Var : access Integer; Max : Integer) 
         return Boolean 
      is
         Value : Integer renames Var.all;
      begin
         Value := Value + 1;
         return Value <= Max;
      end;

      X : aliased Integer := 0;

   begin
      for I in 1..5 loop
         if Increment (X'Access, 3) then
            Put_Line("ok");
         else
            Put_Line("overflow");
         end if;
      end loop;
   end Test;

Result:

ok
ok
ok
overflow
overflow

Sometimes it may be better to use exceptions in favor of boolean tests:

   procedure Test is

      procedure Increment (Value : in out Integer; Max : Integer) is
      begin
         Value := Value + 1;
         if Value > Max then
            raise Constraint_Error;
         end if;
      end;

      X : Integer := 0;

   begin
      for I in 1..5 loop
         begin
            Increment (X, 3);
            Put_Line("ok");
         exception when Constraint_Error =>
            Put_Line("overflow");
         end;
      end loop;
   end Test;

If you define your own integer type with range 1..3 then you can spare the 
conditional statement in the function. The program will raise a runtime 
constraint error automatically provided that you have used the necessary 
compiler options.

Regards,
Ingo




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

* Re: Out parameters in a function
  2002-04-16 20:10           ` Darren New
  2002-04-17  1:30             ` Kent Paul Dolan
@ 2002-04-17 13:24             ` Stephen Leake
  2002-04-17 16:32               ` Darren New
  2002-04-17 21:03               ` Kent Paul Dolan
  2002-04-18 12:14             ` Wolfgang Gellerich
  2 siblings, 2 replies; 37+ messages in thread
From: Stephen Leake @ 2002-04-17 13:24 UTC (permalink / raw)


Darren New <dnew@san.rr.com> writes:

> > >        RESULT high, low
> >  h, l := split.int16 (365)
> 
> Note that in virtually all these languages, what this means is "return
> an anonymous tuple from the function."  AFAIK, FORTH is the only
> reasonably common language where you can *actually* return multiple
> values from a function, rather than returning a single structured value.

What is the difference between an "anonymous tuple" and "multiple
values"? That's how I would _define_ "anonymous tuple"!

In Forth, I can push several values on the stack, and then return
from the word (it's _not_ a "function", it's a "word" :). In Ada, I
can set several values in the return type, and then return. I don't
see that the difference is significant. The syntax is different, but
not the semantics.

Hmm. In Forth I can decide at run time how many values to push on the
stack. I can do that in Ada with an unconstrained array; not quite as
flexible, but way safer :). 

-- 
-- Stephe



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

* Re: Out parameters in a function
  2002-04-17  1:30             ` Kent Paul Dolan
@ 2002-04-17 16:15               ` Darren New
  2002-04-19 17:39               ` Florian Weimer
  1 sibling, 0 replies; 37+ messages in thread
From: Darren New @ 2002-04-17 16:15 UTC (permalink / raw)


Kent Paul Dolan wrote:
> 
> "Darren New" <dnew@san.rr.com> wrote:
> 
> > > >        RESULT high, low
> > >  h, l := split.int16 (365)
> 
> > Note that in virtually all these languages, what this means is "return
> > an anonymous tuple from the function."  AFAIK, FORTH is the only
> > reasonably common language where you can *actually* return multiple
> > values from a function, rather than returning a single structured value.
> 
> Ummm.  APL, PL/PGSQL, CLAIRE, ML (and so OCaml, JoCaml), ...

APL returns one value, which might be an array. SQL returns one value
which might be a table. I don't know CLAIRE. ML (if I understand it
correctly) returns one value, which is a tuple or list or scalar. Python
returns a tuple of values, or an object with slots, or whatever.

FORTH, on the other hand, allows for the equivalent of
 being
   do some computations
   return the first value
   do more computations
   return the second value
   do more computations
   if some condition holds
      return a third value
 end

Altho the syntax of the other languages make it pretty much as
convenient and efficient to return a single tuple/array/whatever and
treat it as an entire list.

If you actually compare it with the difference in Ada between out
parameters and multiple return values, I think you'll see why FORTH is
different from (my understanding of) these other languages, where said
languages are strongly typed. I don't think occam would allow you to
declare a function that returns either a string, or two integers, or an
array of floats, depending on the arguments, yes?

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
   The 90/10 rule of toothpaste: the last 10% of 
         the tube lasts as long as the first 90%.



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

* Re: Out parameters in a function
  2002-04-17 13:24             ` Stephen Leake
@ 2002-04-17 16:32               ` Darren New
  2002-04-17 21:03               ` Kent Paul Dolan
  1 sibling, 0 replies; 37+ messages in thread
From: Darren New @ 2002-04-17 16:32 UTC (permalink / raw)


Stephen Leake wrote:
> What is the difference between an "anonymous tuple" and "multiple
> values"? That's how I would _define_ "anonymous tuple"!

Typing, how you access them, etc. It's quite reasonable to postulate a
FORTH word that returns multiple values which could not all be assigned
to the same variable. In addition, consider "ROT3". What does that
"return"? :-)

(And of course there's assembler, where you can do things like "if
AX==1, then HL points to the string return value, else DE contains an
integer...")

> In Forth, I can push several values on the stack, and then return
> from the word (it's _not_ a "function", it's a "word" :).

I've written FORTH interpreters. But I'm posting in an Ada newsgroup.
:-)

> In Ada, I
> can set several values in the return type, and then return. I don't
> see that the difference is significant. The syntax is different, but
> not the semantics.

One (minor) difference is that I can (for example) decide to return a
value or not, or return a boolean saying whether or not the other return
value is a file descriptor or a string, or whether I returned a second
value at all, or etc. I can also "return" values at various places in
the code without actually returning execution control at the same point.

I haven't thought it thru, but the fact that I can return 4 values, and
use 2 in the next call and 1 in the call after that and leave one as the
return might count as well. (All without assigning anything anywhere, of
course.)

> Hmm. In Forth I can decide at run time how many values to push on the
> stack. I can do that in Ada with an unconstrained array; not quite as
> flexible, but way safer :).

Of course returning multiple values vs returning a single value with
multiple components is pretty close, so getting all nitpicky over it is
kind of silly. Just like you *could* program something like Ada without
functions, turning functions into procedures with an out parameter and
just declaring a lot of excess variables. (Modulo needing functions to
create values for unconstrained types, etc etc.) Kind of like arguing
that Fortran has I/O built in, while C doesn't, because in C it's just
standard libraries rather than language statements. A minor and
mostly-irrelevant point.

I'm just saying that I expect if you look at the definition of a
language like occaml, you'll see that technically functions return a
single value which may be a tuple, just like in APL a function returns a
single value which may be an array. It's just easier, cleaner, and with
modern compiler technologies just as efficient, I'd expect. (Not saying
FORTH is better, just different.)

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
   The 90/10 rule of toothpaste: the last 10% of 
         the tube lasts as long as the first 90%.



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

* Re: Out parameters in a function
  2002-04-17 13:24             ` Stephen Leake
  2002-04-17 16:32               ` Darren New
@ 2002-04-17 21:03               ` Kent Paul Dolan
  1 sibling, 0 replies; 37+ messages in thread
From: Kent Paul Dolan @ 2002-04-17 21:03 UTC (permalink / raw)


"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote:

> In Forth, I can push several values on the stack, and then return
> from the word (it's _not_ a "function", it's a "word" :). In Ada, I
> can set several values in the return type, and then return. I don't
> see that the difference is significant. The syntax is different, but
> not the semantics.

Yes.  In Java, the Enumeration provides a similar facility for returning
a (possibly mixed, if they were hooked that way in the container from
which the Enumeration is derived) bag of objects which it will then
regurgitate one by one as requested; since they can be of Java's
essentially anonymous type "Object", it is up to the recipient or to an
agreement between producer and consumer to sort out what is what.

So, in comparision to Darren's model for Forth, in Java, you do "hook,
hook, hook, create Enumeration, return Enumeration, receive Enumeration,
unhook, unhook, unhook"; same result, different details.

xanthian.

Unfortunately it would _not_ support the C model of using the third
thing hooked as a boolean to a conditional before accessing the first
and second things hooked.  Strictly FIFO, so far as I can tell.  Thus it
wouldn't satisfy the original request.


-- 
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



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

* Re: Out parameters in a function
  2002-04-16 20:10           ` Darren New
  2002-04-17  1:30             ` Kent Paul Dolan
  2002-04-17 13:24             ` Stephen Leake
@ 2002-04-18 12:14             ` Wolfgang Gellerich
  2002-04-18 13:52               ` Dmitry A. Kazakov
  2 siblings, 1 reply; 37+ messages in thread
From: Wolfgang Gellerich @ 2002-04-18 12:14 UTC (permalink / raw)


In article <3CBC855D.148232E3@san.rr.com>,

|> Note that in virtually all these languages, what this means is "return
|> an anonymous tuple from the function."  AFAIK, FORTH is the only
|> reasonably common language where you can *actually* return multiple
|> values from a function, rather than returning a single structured value.

The dataflow language SISAL provides this feaure, too.

Regards, Wolfgang Gellerich



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

* Re: Out parameters in a function
  2002-04-18 12:14             ` Wolfgang Gellerich
@ 2002-04-18 13:52               ` Dmitry A. Kazakov
  2002-04-18 16:28                 ` Darren New
  0 siblings, 1 reply; 37+ messages in thread
From: Dmitry A. Kazakov @ 2002-04-18 13:52 UTC (permalink / raw)


On Thu, 18 Apr 2002 12:14:45 +0000 (UTC),
gelleric@tp-wg.boeblingen.de.ibm.com (Wolfgang Gellerich) wrote:

>In article <3CBC855D.148232E3@san.rr.com>,
>
>|> Note that in virtually all these languages, what this means is "return
>|> an anonymous tuple from the function."  AFAIK, FORTH is the only
>|> reasonably common language where you can *actually* return multiple
>|> values from a function, rather than returning a single structured value.
>
>The dataflow language SISAL provides this feaure, too.

Looking at less conventional languages, there are graphic ones like
LabView, MatLab/Simulink, Diadem, which also have multiple results
(=outputs of a block).

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



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

* Re: Out parameters in a function
  2002-04-18 13:52               ` Dmitry A. Kazakov
@ 2002-04-18 16:28                 ` Darren New
  0 siblings, 0 replies; 37+ messages in thread
From: Darren New @ 2002-04-18 16:28 UTC (permalink / raw)


> >The dataflow language SISAL provides this feaure, too.
> Looking at less conventional languages, there are graphic ones like
> LabView, MatLab/Simulink, Diadem, which also have multiple results

OK, I hadn't been thinking about dataflow or graphical languages, or
(for that matter) languages like Prolog. (It would probably even be hard
to categorize what's an "output" of a Prolog statement.) But yes, now
that you mention it, there's a number of languages probably as popular
as FORTH that do this. (I expect I'd class LOTOS, which is kind of a
calculus of rendezvous, as maybe returning multiple values as well.)
Thanks for correcting me!

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
   The 90/10 rule of toothpaste: the last 10% of 
         the tube lasts as long as the first 90%.



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

* Re: Out parameters in a function
  2002-04-17  1:30             ` Kent Paul Dolan
  2002-04-17 16:15               ` Darren New
@ 2002-04-19 17:39               ` Florian Weimer
  1 sibling, 0 replies; 37+ messages in thread
From: Florian Weimer @ 2002-04-19 17:39 UTC (permalink / raw)


"Kent Paul Dolan" <xanthian@well.com> writes:

> "Darren New" <dnew@san.rr.com> wrote:
>
>> > >        RESULT high, low
>> >  h, l := split.int16 (365)
>
>> Note that in virtually all these languages, what this means is "return
>> an anonymous tuple from the function."  AFAIK, FORTH is the only
>> reasonably common language where you can *actually* return multiple
>> values from a function, rather than returning a single structured value.
>
> Ummm.  APL, PL/PGSQL, CLAIRE, ML (and so OCaml, JoCaml), ...

And Common Lisp.



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

* Re: Out parameters in a function
  2002-04-17  4:40           ` Jim Rogers
  2002-04-17  5:27             ` Kent Paul Dolan
  2002-04-17  5:50             ` Eric G. Miller
@ 2002-04-19 17:40             ` Florian Weimer
  2002-04-19 18:26               ` Jim Rogers
  2 siblings, 1 reply; 37+ messages in thread
From: Florian Weimer @ 2002-04-19 17:40 UTC (permalink / raw)


Jim Rogers <jimmaureenrogers@worldnet.att.net> writes:

> Well, almost. C does not have a boolean type.

What about the standard type _Bool?



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

* Re: Out parameters in a function
  2002-04-19 17:40             ` Florian Weimer
@ 2002-04-19 18:26               ` Jim Rogers
  2002-04-19 18:53                 ` Florian Weimer
  0 siblings, 1 reply; 37+ messages in thread
From: Jim Rogers @ 2002-04-19 18:26 UTC (permalink / raw)


Is _Bool part of the new C standard? It certainly is not
part of the initial ANSI C standard. There have been a number
of commonly used preprocessor definitions for YES/NO and
TRUE/FALSE.

As we all know, preprocessor definitions are not types.

My guess is that _Bool is an enum, which is not actually
a type in C either. It is merely an alias for int values.

Jim Rogers

Florian Weimer wrote:

> Jim Rogers <jimmaureenrogers@worldnet.att.net> writes:
> 
> 
>>Well, almost. C does not have a boolean type.
>>
> 
> What about the standard type _Bool?
> 




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

* Re: Out parameters in a function
  2002-04-19 18:26               ` Jim Rogers
@ 2002-04-19 18:53                 ` Florian Weimer
  0 siblings, 0 replies; 37+ messages in thread
From: Florian Weimer @ 2002-04-19 18:53 UTC (permalink / raw)


Jim Rogers <jimmaureenrogers@worldnet.att.net> writes:

> Is _Bool part of the new C standard?

Yes, it is.

> My guess is that _Bool is an enum, which is not actually
> a type in C either.

No, _Bool is a keyword.  "bool" from <stdbool.h> is a preprocessor
macro, though.



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

* Re: Out parameters in a function
  2002-04-17  5:50             ` Eric G. Miller
@ 2002-04-24  2:45               ` David Thompson
  0 siblings, 0 replies; 37+ messages in thread
From: David Thompson @ 2002-04-24  2:45 UTC (permalink / raw)


Eric G. Miller <egm2@jps-nospam.net> wrote :
> In <3CBCFCC8.6000206@worldnet.att.net>, Jim Rogers wrote:
>
> > Well, almost. C does not have a boolean type. C (since its first
>
> Umm, mostly true. C99 has stdbool.h, but it's still not really a
> builtin type of the language (int macros ...).
>
But stdbool.h bool is just sugar for _Bool, which _is_ builtin.
In C99.  But only for things you write; the builtin comparison
and logic (&& ||) operators (still) produce 0 or 1 of type int,
and all predicate contexts (if, while, etc.) expect and
isalpha() et al produce 0 or nonzero of type int.
(In C++ bool is builtin, and formally is used for predicates,
though there is still an implicit conversion from or to int.)

> And curiously, C can return structs containing arrays, but can't
> return arrays (as arrays are not "lvalues"). Boggle...

Actually arrays (or at least array variables) are lvalues, but in C
array types are not first-class:  inter alia you cannot assign one,
or pass it as an argument, or return it; instead (a primary expression
denoting) an array lvalue "decays" (converts) to a _pointer_ rvalue.
Which like all rvalues you cannot assign to, hence the diagnostic
(error) message you may have gotten.

You can assign/pass/return any struct, containing an array or not,
since before C89 though not at the very beginning.  And C99
cleans up a missed dark corner so you can standardly access
(the elements of) an array member of a struct rvalue e.g. function
return.  Implementations actually allocate such rvalues in the same
places as variables so this invariably worked in C89, it just wasn't
guaranteed by the standard.  (AFAICT it was in C++98.)

--
- David.Thompson 1 now at worldnet.att.net








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

* Re: Out parameters in a function
  2002-04-17  7:57           ` Dmitry A. Kazakov
  2002-04-17 10:21             ` John McCabe
@ 2002-04-24 17:21             ` Warren W. Gay VE3WWG
  2002-04-26  7:32               ` Dmitry A. Kazakov
  1 sibling, 1 reply; 37+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-04-24 17:21 UTC (permalink / raw)


Dmitry A. Kazakov wrote:

> On Tue, 16 Apr 2002 20:00:42 +0000 (UTC), "Kent Paul Dolan"
> <xanthian@well.com> wrote:

...

> Same in Ada:
> 
> declare
>    aSomestructTypedVariable : constant SomestructType :=
>       aSomestructReturningFunction (...);
> begin
>    if aSomestructTypedVariable.booleanPart then
>       usefulVal := aSomestructTypedVariable.usefulPart;
>    end if;
> end;

You could take this one step further (or perhaps this is implied)
and make the returned "SomestructType" a discriminated type. That
way if the value .booleanPart is false, the other member(s) of the
record/structure is invalid to access, maintaining safety.

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

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




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

* Re: Out parameters in a function
  2002-04-24 17:21             ` Warren W. Gay VE3WWG
@ 2002-04-26  7:32               ` Dmitry A. Kazakov
  0 siblings, 0 replies; 37+ messages in thread
From: Dmitry A. Kazakov @ 2002-04-26  7:32 UTC (permalink / raw)


On Wed, 24 Apr 2002 17:21:37 GMT, "Warren W. Gay VE3WWG"
<ve3wwg@home.com> wrote:

>Dmitry A. Kazakov wrote:
>
>> On Tue, 16 Apr 2002 20:00:42 +0000 (UTC), "Kent Paul Dolan"
>> <xanthian@well.com> wrote:
>
>...
>
>> Same in Ada:
>> 
>> declare
>>    aSomestructTypedVariable : constant SomestructType :=
>>       aSomestructReturningFunction (...);
>> begin
>>    if aSomestructTypedVariable.booleanPart then
>>       usefulVal := aSomestructTypedVariable.usefulPart;
>>    end if;
>> end;
>
>You could take this one step further (or perhaps this is implied)
>and make the returned "SomestructType" a discriminated type. That
>way if the value .booleanPart is false, the other member(s) of the
>record/structure is invalid to access, maintaining safety.

Yes, indeed. Safety is a good point. Ada offers many nice
possibilities with that respect. Another is to return a class wide
object with later dispatch on something like Use_That_Stuff.

Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

end of thread, other threads:[~2002-04-26  7:32 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-14 18:29 Out parameters in a function Nazgul
2002-04-14 19:45 ` David C. Hoos, Sr.
2002-04-15 10:49 ` John McCabe
2002-04-15 11:51   ` John McCabe
2002-04-15 13:43 ` Steve Doiel
2002-04-15 15:09 ` Ted Dennison
2002-04-16  8:49   ` John McCabe
2002-04-16 10:05     ` Dmitry A. Kazakov
2002-04-16 15:26       ` John McCabe
2002-04-16 19:34         ` Matthew Woodcraft
2002-04-16 20:10           ` Darren New
2002-04-17  1:30             ` Kent Paul Dolan
2002-04-17 16:15               ` Darren New
2002-04-19 17:39               ` Florian Weimer
2002-04-17 13:24             ` Stephen Leake
2002-04-17 16:32               ` Darren New
2002-04-17 21:03               ` Kent Paul Dolan
2002-04-18 12:14             ` Wolfgang Gellerich
2002-04-18 13:52               ` Dmitry A. Kazakov
2002-04-18 16:28                 ` Darren New
2002-04-17 10:17           ` John McCabe
2002-04-16 19:58         ` Kent Paul Dolan
2002-04-16 20:00         ` Kent Paul Dolan
2002-04-17  4:40           ` Jim Rogers
2002-04-17  5:27             ` Kent Paul Dolan
2002-04-17  5:50             ` Eric G. Miller
2002-04-24  2:45               ` David Thompson
2002-04-19 17:40             ` Florian Weimer
2002-04-19 18:26               ` Jim Rogers
2002-04-19 18:53                 ` Florian Weimer
2002-04-17  7:57           ` Dmitry A. Kazakov
2002-04-17 10:21             ` John McCabe
2002-04-24 17:21             ` Warren W. Gay VE3WWG
2002-04-26  7:32               ` Dmitry A. Kazakov
2002-04-15 16:24 ` Stephen Leake
2002-04-16 13:38   ` Ted Dennison
2002-04-17 11:55 ` Ingo Marks

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