comp.lang.ada
 help / color / mirror / Atom feed
* What evil would happen?
@ 2003-07-11 19:51 Wojtek Narczynski
  2003-07-11 20:07 ` Hyman Rosen
                   ` (5 more replies)
  0 siblings, 6 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-11 19:51 UTC (permalink / raw)


Hello,

What would happen if a procedure could return a value like a function,
or a function could accept an out parameter? Would it make procedures
less procedural? Or impure functions even less impure? Or is there a
reason for this in compiler implementation details?

I feel like with SML like tagged union datatypes I'd be done long
ago... Is there an AI for this maybe?

I am trying to create a parser for CLFF files.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
@ 2003-07-11 20:07 ` Hyman Rosen
  2003-07-12 12:30   ` Wojtek Narczynski
  2003-07-11 20:08 ` chris.danx
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 47+ messages in thread
From: Hyman Rosen @ 2003-07-11 20:07 UTC (permalink / raw)


Wojtek Narczynski wrote:
> What would happen if a procedure could return a value like a function,
> or a function could accept an out parameter?

I don't know Ada well enough to answer this myself,
so I'll ask here - can you make a generic function
with generic parameters which correspond to the out
parameters that you would like to pass into the
function, and have the function write to those? If
so, is that an acceptable workaround?




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

* Re: What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
  2003-07-11 20:07 ` Hyman Rosen
@ 2003-07-11 20:08 ` chris.danx
  2003-07-12  4:31   ` Nick Roberts
  2003-07-11 21:26 ` Robert I. Eachus
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 47+ messages in thread
From: chris.danx @ 2003-07-11 20:08 UTC (permalink / raw)


Wojtek Narczynski wrote:
> Hello,
> 
> What would happen if a procedure could return a value like a function,

Surely, it would be a function?




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

* Re: What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
  2003-07-11 20:07 ` Hyman Rosen
  2003-07-11 20:08 ` chris.danx
@ 2003-07-11 21:26 ` Robert I. Eachus
  2003-07-12 12:38   ` Wojtek Narczynski
  2003-07-14 18:52 ` Randy Brukardt
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 47+ messages in thread
From: Robert I. Eachus @ 2003-07-11 21:26 UTC (permalink / raw)


Wojtek Narczynski wrote:

> What would happen if a procedure could return a value like a function,
> or a function could accept an out parameter? Would it make procedures
> less procedural? Or impure functions even less impure? Or is there a
> reason for this in compiler implementation details?
> 
> I feel like with SML like tagged union datatypes I'd be done long
> ago... Is there an AI for this maybe?

Yes, several, and some language study notes, and I think some sections 
in the Ada Rationale.

> I am trying to create a parser for CLFF files.

I don't follow from this to what you are asking.  Assuming you want to 
parse common log file format files which have a format of

     remotehost rfc931 authuser [date] "request" status bytes

(per http://www.w3.org/Daemon/User/Config/Logging.html) I can't imagine 
why you would be asking about such a feature.  But if I were you I would 
be looking at Ada.Strings.Unbounded.

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




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

* RE: What evil would happen?
@ 2003-07-11 23:04 Beard, Frank Randolph CIV
  2003-07-12 12:46 ` Wojtek Narczynski
  0 siblings, 1 reply; 47+ messages in thread
From: Beard, Frank Randolph CIV @ 2003-07-11 23:04 UTC (permalink / raw)
  To: comp.lang.ada

-----Original Message-----
From: Hyman Rosen

>Wojtek Narczynski wrote:
>> What would happen if a procedure could return a value like a function,
>> or a function could accept an out parameter?

> I don't know Ada well enough to answer this myself,
> so I'll ask here - can you make a generic function
> with generic parameters which correspond to the out
> parameters that you would like to pass into the
> function, and have the function write to those? If
> so, is that an acceptable workaround?

Well, if you really wanted the C/C++ function characteristics
for whatever reason, you could use aliased types and pass them
as access parameters to the function.

      type X_Type is ...

      function Do_Something (to_X : access X_Type) return integer;

      function Do_Something (to_X : access X_Type) return integer is
      begin
         ...
         to_X.all := ...;  -- update to_X
         ...
         return 0;
      exception
        when others => return -1;
      end Do_Somthing;

      x           : aliased X_Type;
      return_Code : integer := 0;

   begin

      ...
      return_Code := Do_Something(to_X => x'access);
      ...


Sorry I didn't have time to come up with something more concrete,
but hopefully you get my meaning.

Hope it helps.
Frank



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

* Re: What evil would happen?
  2003-07-11 20:08 ` chris.danx
@ 2003-07-12  4:31   ` Nick Roberts
  2003-07-12 12:26     ` Wojtek Narczynski
  0 siblings, 1 reply; 47+ messages in thread
From: Nick Roberts @ 2003-07-12  4:31 UTC (permalink / raw)


"chris.danx" <spamoff.danx@ntlworld.com> wrote in message
news:1LEPa.9034$nP.7178@newsfep4-winn.server.ntli.net...
> Wojtek Narczynski wrote:
> > Hello,
> >
> > What would happen if a procedure could return a value
> > like a function,
>
> Surely, it would be a function?

I think the idea is that the result returned by the procedure is written
into an implicit variable with a conventional name. Suppose the name is
'Result', then you might have something such as:

   procedure P(...) is
   begin
      ...
      return X*25.4;
   end;

and then:

   P(...);
   if Result > 200.0 then
      ...

Some languages which are typeless (and/or fully polymorphic) have this kind
of facility. Nearly all assembly languages essentially work this way (think
of registers). I think it is clear how badly suited it is to a strongly
typed language such as Ada.

Obviously you could simulate the effect by simply writing into a global
variable, e.g.:

   Result: Float;

   procedure P(...) is
   begin
      ...
      Result := X*25.4;
   end;

but this is not considered good programming style.

A situation in which it might make sense for Ada to permit a return
statement with an expression in a procedure body is for a procedure which
will be called from a foreign language (and so to which pragma Export
applies). The call in the foreign language may look like a procedure call,
but the language may require a value to be invisibly returned by the
procedure (e.g. indicating success or some kind of failure).

Regarding the parameter modes of functions, I think the main Ada Issue to
refer to is AI-323.

--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]






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

* Re: What evil would happen?
  2003-07-12  4:31   ` Nick Roberts
@ 2003-07-12 12:26     ` Wojtek Narczynski
  2003-07-12 12:39       ` Preben Randhol
  0 siblings, 1 reply; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-12 12:26 UTC (permalink / raw)


I don't follow. 

What would be unsafe about:

procedure Parse_Username( S: in String; Result: out Boolean) return String;

?

> Regarding the parameter modes of functions, I think the main Ada Issue to
> refer to is AI-323.

I have read, well - at lest some of it :-)

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-11 20:07 ` Hyman Rosen
@ 2003-07-12 12:30   ` Wojtek Narczynski
  2003-07-12 17:17     ` Martin Dowie
  2003-07-13  1:46     ` Hyman Rosen
  0 siblings, 2 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-12 12:30 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> wrote in message news:<1057954025.510093@master.nyc.kbcfp.com>...
����
>(...) - can you make a generic function
> with generic parameters which correspond to the out
> parameters that you would like to pass into the
> function, and have the function write to those? If
> so, is that an acceptable workaround?

I have tried it and the compiler told me "left hand side of assignment
must be a variable".

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-11 21:26 ` Robert I. Eachus
@ 2003-07-12 12:38   ` Wojtek Narczynski
  2003-07-16  0:07     ` Robert I. Eachus
  0 siblings, 1 reply; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-12 12:38 UTC (permalink / raw)


"Robert I. Eachus" <rieachus@attbi.com> wrote in message 

> I don't follow from this to what you are asking.  Assuming you want to 
> parse common log file format files which have a format of
> 
>      remotehost rfc931 authuser [date] "request" status bytes
> 
> (per http://www.w3.org/Daemon/User/Config/Logging.html) I can't imagine 
> why you would be asking about such a feature.  But if I were you I would 
> be looking at Ada.Strings.Unbounded.

I have a lot of those logfiles so I wanted it to be fast => tried to
stick with fixed strings and no exceptions. Indeed I may be trying to
optimize something that is not slow...

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-12 12:26     ` Wojtek Narczynski
@ 2003-07-12 12:39       ` Preben Randhol
  2003-07-12 13:11         ` Larry Kilgallen
  0 siblings, 1 reply; 47+ messages in thread
From: Preben Randhol @ 2003-07-12 12:39 UTC (permalink / raw)


Wojtek Narczynski wrote:
> I don't follow. 
> 
> What would be unsafe about:
> 
> procedure Parse_Username( S: in String; Result: out Boolean) return String;

What would be the point of it?

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: What evil would happen?
  2003-07-11 23:04 What evil would happen? Beard, Frank Randolph CIV
@ 2003-07-12 12:46 ` Wojtek Narczynski
  0 siblings, 0 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-12 12:46 UTC (permalink / raw)


"Beard, Frank Randolph CIV" <frank.beard@navy.mil> wrote in message news:<mailman.8.1057964701.24167.comp.lang.ada@ada.eu.org>...

Thanks, I will try this.

> Sorry I didn't have time to come up with something more concrete,
> but hopefully you get my meaning.

But you wrote me an example!

Thanks,
Wojtek



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

* Re: What evil would happen?
  2003-07-12 12:39       ` Preben Randhol
@ 2003-07-12 13:11         ` Larry Kilgallen
  2003-07-12 13:22           ` Preben Randhol
  0 siblings, 1 reply; 47+ messages in thread
From: Larry Kilgallen @ 2003-07-12 13:11 UTC (permalink / raw)


In article <slrnbh00ch.3fv.randhol+abuse@kiuk0152.chembio.ntnu.no>, Preben Randhol <randhol+abuse@pvv.org> writes:
> Wojtek Narczynski wrote:
>> I don't follow. 
>> 
>> What would be unsafe about:
>> 
>> procedure Parse_Username( S: in String; Result: out Boolean) return String;
> 
> What would be the point of it?

Being able to return an unconstrained value along with one or more
constrained values from the same subprogram:

	declare
	    my_result : Boolean;
	    my_username : constant := Parse_Username (
		s => "SYSTEM",
		result => my_result );
	begin
	    -- make use of that
	end;



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

* Re: What evil would happen?
  2003-07-12 13:11         ` Larry Kilgallen
@ 2003-07-12 13:22           ` Preben Randhol
  2003-07-12 19:04             ` Larry Kilgallen
  2003-07-13 15:26             ` Wojtek Narczynski
  0 siblings, 2 replies; 47+ messages in thread
From: Preben Randhol @ 2003-07-12 13:22 UTC (permalink / raw)


Larry Kilgallen wrote:
> Being able to return an unconstrained value along with one or more
> constrained values from the same subprogram:
> 
> 	declare
> 	    my_result : Boolean;
> 	    my_username : constant := Parse_Username (

       my_username : constant String := ...


> 		s => "SYSTEM",
> 		result => my_result );
> 	begin
> 	    -- make use of that
> 	end;

Well then functions with side effects should be more resonable than to
make procedures into functions.

But one could also simply use a function here and return "" if the
parsing failed and then simply check if my_username /= "". You have to
do if my_result then anyway so there is really not much difference to
the code. However I would have concidered throwing an exception in the
case the parsing failed.

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: What evil would happen?
  2003-07-12 12:30   ` Wojtek Narczynski
@ 2003-07-12 17:17     ` Martin Dowie
  2003-07-13  1:46     ` Hyman Rosen
  1 sibling, 0 replies; 47+ messages in thread
From: Martin Dowie @ 2003-07-12 17:17 UTC (permalink / raw)


"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0307120430.56d11616@posting.google.com...
> Hyman Rosen <hyrosen@mail.com> wrote in message
news:<1057954025.510093@master.nyc.kbcfp.com>...
>
> >(...) - can you make a generic function
> > with generic parameters which correspond to the out
> > parameters that you would like to pass into the
> > function, and have the function write to those? If
> > so, is that an acceptable workaround?
>
> I have tried it and the compiler told me "left hand side of assignment
> must be a variable".

Have you looked at the 'Rosen Trick' for converting a constant view into
a variable one? See
http://home.earthlink.net/~matthewjheaney/charles/charles-vectors-limited_bounded.html
and search for 'rosen'.





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

* Re: What evil would happen?
  2003-07-12 13:22           ` Preben Randhol
@ 2003-07-12 19:04             ` Larry Kilgallen
  2003-07-14  8:43               ` Preben Randhol
  2003-07-13 15:26             ` Wojtek Narczynski
  1 sibling, 1 reply; 47+ messages in thread
From: Larry Kilgallen @ 2003-07-12 19:04 UTC (permalink / raw)


In article <slrnbh02sj.4kj.randhol+abuse@kiuk0152.chembio.ntnu.no>, Preben Randhol <randhol+abuse@pvv.org> writes:
> Larry Kilgallen wrote:
>> Being able to return an unconstrained value along with one or more
>> constrained values from the same subprogram:
>> 
>> 	declare
>> 	    my_result : Boolean;
>> 	    my_username : constant := Parse_Username (
> 
>        my_username : constant String := ...
> 
> 
>> 		s => "SYSTEM",
>> 		result => my_result );
>> 	begin
>> 	    -- make use of that
>> 	end;
> 
> Well then functions with side effects should be more resonable than to
> make procedures into functions.
> 
> But one could also simply use a function here and return "" if the
> parsing failed and then simply check if my_username /= "".

That presumes:

	1. There is no valid meaning for returning a null username.
	2. There is no desire to return _two_ constrained values.
	3. There is no desire to return a non-Boolean constrained value.

> You have to
> do if my_result then anyway so there is really not much difference to
> the code. However I would have concidered throwing an exception in the
> case the parsing failed.

That presumes:

	4. The only use for a constrained value return is to indicate
	   failure.



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

* Re: What evil would happen?
  2003-07-12 12:30   ` Wojtek Narczynski
  2003-07-12 17:17     ` Martin Dowie
@ 2003-07-13  1:46     ` Hyman Rosen
  2003-07-13 15:29       ` Wojtek Narczynski
  1 sibling, 1 reply; 47+ messages in thread
From: Hyman Rosen @ 2003-07-13  1:46 UTC (permalink / raw)


Wojtek Narczynski wrote:
> I have tried it and the compiler told me "left hand side of assignment
> must be a variable".

Hmm... The Ada Reference manual says that "formal objects" can have mode
"in" or "in out". Did you use the latter?




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

* Re: What evil would happen?
  2003-07-12 13:22           ` Preben Randhol
  2003-07-12 19:04             ` Larry Kilgallen
@ 2003-07-13 15:26             ` Wojtek Narczynski
  2003-07-13 17:28               ` Chad R. Meiners
  1 sibling, 1 reply; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-13 15:26 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> wrote in message news:<slrnbh02sj.4kj.randhol+abuse@kiuk0152.chembio.ntnu.no>...

> Well then functions with side effects should be more resonable

"Functions" with side effects can only inject their side effect into
where they have been hardcoded to. �This is a serious limitation.
Generics won't help here either as stated in a sibling of this thread.

> than to  make procedures into functions.

Sorry, the reasoning that everything that has return <x> statement is
a function is not very viable.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-13  1:46     ` Hyman Rosen
@ 2003-07-13 15:29       ` Wojtek Narczynski
  0 siblings, 0 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-13 15:29 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> wrote in message news:<8S2Qa.2572$3G5.1937@nwrdny03.gnilink.net>...
> Wojtek Narczynski wrote:
> > I have tried it and the compiler told me "left hand side of assignment
> > must be a variable".
> 
> Hmm... The Ada Reference manual says that "formal objects" can have mode
> "in" or "in out". Did you use the latter?

No. Thanks!

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-13 15:26             ` Wojtek Narczynski
@ 2003-07-13 17:28               ` Chad R. Meiners
  2003-07-13 22:35                 ` Wojtek Narczynski
                                   ` (3 more replies)
  0 siblings, 4 replies; 47+ messages in thread
From: Chad R. Meiners @ 2003-07-13 17:28 UTC (permalink / raw)



"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0307130417.41548778@posting.google.com...
> Preben Randhol <randhol+abuse@pvv.org> wrote in message
news:<slrnbh02sj.4kj.randhol+abuse@kiuk0152.chembio.ntnu.no>...
>
> > Well then functions with side effects should be more resonable
>
> "Functions" with side effects can only inject their side effect into
> where they have been hardcoded to.
This is wrong.  Function have the capability to randomly introduce side
effects just like any other section of code.

>This is a serious limitation.
If it were true, I doubt it.  In my experience, functions are more useful
when they are pure.  Sure there are times when a function cannot be pure,
but sub-routine with a side-effect should be made a procedure in most cases.

> Sorry, the reasoning that everything that has return <x> statement is
> a function is not very viable.

In mathematics, functions only return single elements, which may be a
composite of some sort.  I suggest that if you want return composites from
functions you should return a record type.

type Composite(StringSize : Natural) is record
     User_Name : String(1..StringSize);
     Result    : Boolean;
end record;

function Parse_User_Name(Item : String) return Composite;

However, the following might also be a suitable procedure for the task

procedure Parse_UserName (Item : String;
                                              UserName : out String;
                                              NameSize : out Natural) ;

> Regards,
> Wojtek
-CRM





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

* Re: What evil would happen?
  2003-07-13 17:28               ` Chad R. Meiners
@ 2003-07-13 22:35                 ` Wojtek Narczynski
  2003-07-14  0:06                   ` Chad R. Meiners
  2003-07-13 22:36                 ` Wojtek Narczynski
                                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-13 22:35 UTC (permalink / raw)


"Chad R. Meiners" <crmeiners@hotmail.com> wrote in message news:<bes4uv$1o29$1@msunews.cl.msu.edu>...

> > "Functions" with side effects can only inject their side effect into
> > where they have been hardcoded to.
> This is wrong.  Function have the capability to randomly introduce side
> effects just like any other section of code.

Have you read the whole thread?

> In my experience, functions are more useful
> when they are pure.  Sure there are times when a function cannot be pure,
> but sub-routine with a side-effect should be made a procedure in most cases.

I agree that functions should be pure. But procedures cannot return an
unconstrained value. Again, this is what this thread is about.

> In mathematics, functions only return single elements, which may be a
> composite of some sort.

Well, in the mathematical definition there is no "call" so there may
not be a "return". Instead there are two sets...

> I suggest that if you want return composites from
> functions you should return a record type.
> 
> type Composite(StringSize : Natural) is record
>      User_Name : String(1..StringSize);
>      Result    : Boolean;
> end record;
> 
> function Parse_User_Name(Item : String) return Composite;
> 
> However, the following might also be a suitable procedure for the task

Yes, this works, but causes code explosion, and memory copying (when
gathering all the parsed pieces together). This is what you can neatly
do in SML with tagged union types, by the way :-)
 
> procedure Parse_UserName (Item : String;
>                                               UserName : out String;
>                                               NameSize : out Natural) ;

This works fine for shor strings, but for longer there will be
unnecessary storage allocation.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-13 17:28               ` Chad R. Meiners
  2003-07-13 22:35                 ` Wojtek Narczynski
@ 2003-07-13 22:36                 ` Wojtek Narczynski
  2003-07-14  3:01                 ` Hyman Rosen
  2003-07-14  9:09                 ` Dmitry A. Kazakov
  3 siblings, 0 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-13 22:36 UTC (permalink / raw)


"Chad R. Meiners" <crmeiners@hotmail.com> wrote in message news:<bes4uv$1o29$1@msunews.cl.msu.edu>...

> > "Functions" with side effects can only inject their side effect into
> > where they have been hardcoded to.
> This is wrong.  Function have the capability to randomly introduce side
> effects just like any other section of code.

Have you read the whole thread?

> In my experience, functions are more useful
> when they are pure.  Sure there are times when a function cannot be pure,
> but sub-routine with a side-effect should be made a procedure in most cases.

I agree that functions should be pure. But procedures cannot return an
unconstrained value. Again, this is what this thread is about.

> In mathematics, functions only return single elements, which may be a
> composite of some sort.

Well, in the mathematical definition there is no "call" so there may
not be a "return". Instead there are two sets...

> I suggest that if you want return composites from
> functions you should return a record type.
> 
> type Composite(StringSize : Natural) is record
>      User_Name : String(1..StringSize);
>      Result    : Boolean;
> end record;
> 
> function Parse_User_Name(Item : String) return Composite;
> 
> However, the following might also be a suitable procedure for the task

Yes, this works, but causes code explosion, and memory copying (when
gathering all the parsed pieces together). This is what you can neatly
do in SML with tagged union types, by the way :-)
 
> procedure Parse_UserName (Item : String;
>                                               UserName : out String;
>                                               NameSize : out Natural) ;

This works fine for shor strings, but for longer there will be
unnecessary storage allocation.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-13 22:35                 ` Wojtek Narczynski
@ 2003-07-14  0:06                   ` Chad R. Meiners
  0 siblings, 0 replies; 47+ messages in thread
From: Chad R. Meiners @ 2003-07-14  0:06 UTC (permalink / raw)



"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0307131407.4955979e@posting.google.com...
> "Chad R. Meiners" <crmeiners@hotmail.com> wrote in message
news:<bes4uv$1o29$1@msunews.cl.msu.edu>...
>
> > > "Functions" with side effects can only inject their side effect into
> > > where they have been hardcoded to.
> > This is wrong.  Function have the capability to randomly introduce side
> > effects just like any other section of code.
>
> Have you read the whole thread?
I read all the root nodes, but I was responding to the single sentence which
is incorrect.
>
> > In my experience, functions are more useful
> > when they are pure.  Sure there are times when a function cannot be
pure,
> > but sub-routine with a side-effect should be made a procedure in most
cases.
>
> I agree that functions should be pure. But procedures cannot return an
> unconstrained value. Again, this is what this thread is about.

However, procedure's can return parse trees.

> > I suggest that if you want to return composites from
> > functions you should return a record type.
> >
> > type Composite(StringSize : Natural) is record
> >      User_Name : String(1..StringSize);
> >      Result    : Boolean;
> > end record;
> >
> > function Parse_User_Name(Item : String) return Composite;
> >
> > However, the following might also be a suitable procedure for the task
>
> Yes, this works, but causes code explosion, and memory copying (when
> gathering all the parsed pieces together). This is what you can neatly
> do in SML with tagged union types, by the way :-)

You are prematurely trying to optimize.  Furthermore,  returning records
does not automatically cause code explosion or extra memory copying.  I have
used similar techniques when writing recursive decent parsers.  The code is
both readable and concise (it is also fast enough for any test I cared to
give it).  If you are going to write any sort of language parser, I
recommended browsing the source for GNAT's parser.  It is probably overkill
for what you want but you can get a lot of good ideas from it.  The way it
represents tokens is inspired. ;-)

-CRM





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

* Re: What evil would happen?
  2003-07-13 17:28               ` Chad R. Meiners
  2003-07-13 22:35                 ` Wojtek Narczynski
  2003-07-13 22:36                 ` Wojtek Narczynski
@ 2003-07-14  3:01                 ` Hyman Rosen
  2003-07-14  4:41                   ` Chad R. Meiners
  2003-07-14  9:09                 ` Dmitry A. Kazakov
  3 siblings, 1 reply; 47+ messages in thread
From: Hyman Rosen @ 2003-07-14  3:01 UTC (permalink / raw)


Chad R. Meiners wrote:
> In mathematics, functions only return single elements, which may be a
> composite of some sort.

As I have said before, one of the most fundamental mistakes made by
academics who get involved in computing is to forget that programming
languages are a means of instructing a computer to accomplish a task,
not a reification of some abstract concept whose beauty and purity
must be preserved at all costs.




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

* Re: What evil would happen?
  2003-07-14  3:01                 ` Hyman Rosen
@ 2003-07-14  4:41                   ` Chad R. Meiners
  0 siblings, 0 replies; 47+ messages in thread
From: Chad R. Meiners @ 2003-07-14  4:41 UTC (permalink / raw)



"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:r2pQa.8422$Y92.1451@nwrdny01.gnilink.net...
> Chad R. Meiners wrote:
> > In mathematics, functions only return single elements, which may be a
> > composite of some sort.
>
> As I have said before, one of the most fundamental mistakes made by
> academics who get involved in computing is to forget that programming
> languages are a means of instructing a computer to accomplish a task,
> not a reification of some abstract concept whose beauty and purity
> must be preserved at all costs.
>

Of course you are reading too much into what I said.  I was stating
inspiration towards a solution.
Therefore, your so called saying does apply here. ;-)

On a more serious note, if you think that academics formalize computer
science for the sake of beauty and purity, you are in a sad state of
ignorance.





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

* Re: What evil would happen?
  2003-07-12 19:04             ` Larry Kilgallen
@ 2003-07-14  8:43               ` Preben Randhol
  2003-07-14 10:32                 ` Larry Kilgallen
  0 siblings, 1 reply; 47+ messages in thread
From: Preben Randhol @ 2003-07-14  8:43 UTC (permalink / raw)


Larry Kilgallen wrote:
> 
> That presumes:
> 
> 	1. There is no valid meaning for returning a null username.
> 	2. There is no desire to return _two_ constrained values.
> 	3. There is no desire to return a non-Boolean constrained value.
> 
>> You have to
>> do if my_result then anyway so there is really not much difference to
>> the code. However I would have concidered throwing an exception in the
>> case the parsing failed.
> 
> That presumes:
> 
> 	4. The only use for a constrained value return is to indicate
> 	   failure.

Well if not then use a record with username and the boolean variable and
return that

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: What evil would happen?
  2003-07-13 17:28               ` Chad R. Meiners
                                   ` (2 preceding siblings ...)
  2003-07-14  3:01                 ` Hyman Rosen
@ 2003-07-14  9:09                 ` Dmitry A. Kazakov
  2003-07-14 17:44                   ` Chad R. Meiners
  3 siblings, 1 reply; 47+ messages in thread
From: Dmitry A. Kazakov @ 2003-07-14  9:09 UTC (permalink / raw)


On Sun, 13 Jul 2003 13:28:54 -0400, "Chad R. Meiners"
<crmeiners@hotmail.com> wrote:

>"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
>news:5ad0dd8a.0307130417.41548778@posting.google.com...
>> Preben Randhol <randhol+abuse@pvv.org> wrote in message
>news:<slrnbh02sj.4kj.randhol+abuse@kiuk0152.chembio.ntnu.no>...
>>
>> > Well then functions with side effects should be more resonable
>>
>> "Functions" with side effects can only inject their side effect into
>> where they have been hardcoded to.
>This is wrong.  Function have the capability to randomly introduce side
>effects just like any other section of code.

So what is the point?

>>This is a serious limitation.
>If it were true, I doubt it.  In my experience, functions are more useful
>when they are pure.  Sure there are times when a function cannot be pure,
>but sub-routine with a side-effect should be made a procedure in most cases.

It is also my view. But I see rather other consecuences from this:

1. All functions are pure. So no access parameters allowed, no access
to global data from the body is allowed etc.

2. But procedures are allowed to have a result.

This would be perfectly consistent and as safe as possible.

>> Sorry, the reasoning that everything that has return <x> statement is
>> a function is not very viable.
>
>In mathematics, functions only return single elements, which may be a
>composite of some sort.

In mathematics you can encapsulate all side effects in objects of
unlimited complexity. It is not the case for programming languages.
Especially ones with weak type inference capability.

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



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

* Re: What evil would happen?
  2003-07-14  8:43               ` Preben Randhol
@ 2003-07-14 10:32                 ` Larry Kilgallen
  2003-07-14 11:05                   ` Preben Randhol
                                     ` (2 more replies)
  0 siblings, 3 replies; 47+ messages in thread
From: Larry Kilgallen @ 2003-07-14 10:32 UTC (permalink / raw)


In article <slrnbh4r8u.hn.randhol+abuse@kiuk0152.chembio.ntnu.no>, Preben Randhol <randhol+abuse@pvv.org> writes:
> Larry Kilgallen wrote:
>> 
>> That presumes:
>> 
>> 	1. There is no valid meaning for returning a null username.
>> 	2. There is no desire to return _two_ constrained values.
>> 	3. There is no desire to return a non-Boolean constrained value.
>> 
>>> You have to
>>> do if my_result then anyway so there is really not much difference to
>>> the code. However I would have concidered throwing an exception in the
>>> case the parsing failed.
>> 
>> That presumes:
>> 
>> 	4. The only use for a constrained value return is to indicate
>> 	   failure.
> 
> Well if not then use a record with username and the boolean variable and
> return that

Nobody has claimed there was no way to program around this obstacle.
The claim under discussion was that there is "no use" for the capability.



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

* Re: What evil would happen?
  2003-07-14 10:32                 ` Larry Kilgallen
@ 2003-07-14 11:05                   ` Preben Randhol
  2003-07-14 11:31                   ` Larry Kilgallen
       [not found]                   ` <slrnbh53ir.48d.Organization: LJK Software <zSeTW0M3CTPU@eisner.encompasserve.org>
  2 siblings, 0 replies; 47+ messages in thread
From: Preben Randhol @ 2003-07-14 11:05 UTC (permalink / raw)


Larry Kilgallen wrote:
> Nobody has claimed there was no way to program around this obstacle.
> The claim under discussion was that there is "no use" for the capability.

Well a great many things can have some usage, but it doesn't mean it has
to be implemented.

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: What evil would happen?
  2003-07-14 10:32                 ` Larry Kilgallen
  2003-07-14 11:05                   ` Preben Randhol
@ 2003-07-14 11:31                   ` Larry Kilgallen
       [not found]                   ` <slrnbh53ir.48d.Organization: LJK Software <zSeTW0M3CTPU@eisner.encompasserve.org>
  2 siblings, 0 replies; 47+ messages in thread
From: Larry Kilgallen @ 2003-07-14 11:31 UTC (permalink / raw)


In article <slrnbh53ir.48d.randhol+abuse@kiuk0152.chembio.ntnu.no>, Preben Randhol <randhol+abuse@pvv.org> writes:
> Larry Kilgallen wrote:
>> Nobody has claimed there was no way to program around this obstacle.
>> The claim under discussion was that there is "no use" for the capability.
> 
> Well a great many things can have some usage, but it doesn't mean it has
> to be implemented.

Certainly if everything suggested were implemented Ada _would_ be as
overly large as claimed by detractors.



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

* Re: What evil would happen?
       [not found]                   ` <slrnbh53ir.48d.Organization: LJK Software <zSeTW0M3CTPU@eisner.encompasserve.org>
@ 2003-07-14 17:31                     ` Wojtek Narczynski
  0 siblings, 0 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-14 17:31 UTC (permalink / raw)


Kilgallen@SpamCop.net (Larry Kilgallen) wrote in message news:<zSeTW0M3CTPU@eisner.encompasserve.org>...
> In article <slrnbh53ir.48d.randhol+abuse@kiuk0152.chembio.ntnu.no>, Preben Randhol <randhol+abuse@pvv.org> writes:
> > Larry Kilgallen wrote:
> >> Nobody has claimed there was no way to program around this obstacle.
> >> The claim under discussion was that there is "no use" for the capability.
> > 
> > Well a great many things can have some usage, but it doesn't mean it has
> > to be implemented.
> 
> Certainly if everything suggested were implemented Ada _would_ be as
> overly large as claimed by detractors.

Oh, then I know one thing that could go away:

type X is (One, Two, Three);

type Y is new Integer;

[new] can go away.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-14  9:09                 ` Dmitry A. Kazakov
@ 2003-07-14 17:44                   ` Chad R. Meiners
  2003-07-14 18:15                     ` tmoran
  2003-07-15  8:06                     ` Dmitry A. Kazakov
  0 siblings, 2 replies; 47+ messages in thread
From: Chad R. Meiners @ 2003-07-14 17:44 UTC (permalink / raw)



"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:o9s4hvofb2mtn8ga9ahf7uu530pfacald8@4ax.com...
> On Sun, 13 Jul 2003 13:28:54 -0400, "Chad R. Meiners"
> <crmeiners@hotmail.com> wrote:
>
> >"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
> >news:5ad0dd8a.0307130417.41548778@posting.google.com...
> >> Preben Randhol <randhol+abuse@pvv.org> wrote in message
> >news:<slrnbh02sj.4kj.randhol+abuse@kiuk0152.chembio.ntnu.no>...
> >>
> >> > Well then functions with side effects should be more resonable
> >>
> >> "Functions" with side effects can only inject their side effect into
> >> where they have been hardcoded to.
> >This is wrong.  Function have the capability to randomly introduce side
> >effects just like any other section of code.
>
> So what is the point?

The point is that the statement was wrong.  It was a statement of fact.

> >>This is a serious limitation.
> >If it were true, I doubt it.  In my experience, functions are more useful
> >when they are pure.  Sure there are times when a function cannot be pure,
> >but sub-routine with a side-effect should be made a procedure in most
cases.
>
> It is also my view. But I see rather other consecuences from this:
>
> 1. All functions are pure. So no access parameters allowed, no access
> to global data from the body is allowed etc.
>
> 2. But procedures are allowed to have a result.
>
> This would be perfectly consistent and as safe as possible.

I prefer SPARK's rules on functions, but I think that we should just allow
in out parameters for our unpure functions since passing access parameters
can be ugly.  I really do not see the harm in allowing unpure functions
because good modularity usually nudges the programmer towards writing pure
functions.  However, when an exception is needed being able to write unpure
function should be straight forward and easy to detect at the specification
level.

> >In mathematics, functions only return single elements, which may be a
> >composite of some sort.
>
> In mathematics you can encapsulate all side effects in objects of
> unlimited complexity. It is not the case for programming languages.
> Especially ones with weak type inference capability.
True, I was only stating inspiration for using records to return multiple
values.

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





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

* Re: What evil would happen?
  2003-07-14 17:44                   ` Chad R. Meiners
@ 2003-07-14 18:15                     ` tmoran
  2003-07-15  8:06                     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 47+ messages in thread
From: tmoran @ 2003-07-14 18:15 UTC (permalink / raw)


> In mathematics ...
  There's a good essay on the pluses and minuses of metaphor in last
week's Science magazine:
http://www.sciencemag.org/cgi/content/full/301/5629/52



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

* Re: What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
                   ` (2 preceding siblings ...)
  2003-07-11 21:26 ` Robert I. Eachus
@ 2003-07-14 18:52 ` Randy Brukardt
  2003-07-14 20:12   ` Hyman Rosen
                     ` (2 more replies)
  2003-07-15  5:16 ` Kenneth Almquist
  2003-07-18  8:23 ` Wojtek Narczynski
  5 siblings, 3 replies; 47+ messages in thread
From: Randy Brukardt @ 2003-07-14 18:52 UTC (permalink / raw)


"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0307111151.4a08f95a@posting.google.com...
> Hello,
>
> What would happen if a procedure could return a value like a function,
> or a function could accept an out parameter? Would it make procedures
> less procedural? Or impure functions even less impure? Or is there a
> reason for this in compiler implementation details?
>
> I feel like with SML like tagged union datatypes I'd be done long
> ago... Is there an AI for this maybe?

No evil would happen. The world would continue. :-)

However, its clear that it is never going to happen (see the result of
AI-323). There is enough opposition to the idea that it could never get a
consensus.

So functions in Ada will continue to be able to have side effects, just not
be able to show them in their specification. (A paraphrase of Robert Dewar).

Note that the Object.Operation notation (if approved) will help that for
tagged types, as that notation allows using access parameters without
explicitly saying 'Access. (So, for a function with the first parameter as
an access parameter, the call would look the same as an IN parameter).

                  Randy.

P.S. Do we have to discuss this AGAIN?






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

* Re: What evil would happen?
  2003-07-14 18:52 ` Randy Brukardt
@ 2003-07-14 20:12   ` Hyman Rosen
  2003-07-15  2:32   ` Alexander Kopilovitch
  2003-07-15  8:19   ` Wojtek Narczynski
  2 siblings, 0 replies; 47+ messages in thread
From: Hyman Rosen @ 2003-07-14 20:12 UTC (permalink / raw)


Randy Brukardt wrote:
> P.S. Do we have to discuss this AGAIN?

That's the price to be paid for continuing
to allow the mulish and senseless opposition
to keep its roadblock in place.




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

* Re: What evil would happen?
  2003-07-14 18:52 ` Randy Brukardt
  2003-07-14 20:12   ` Hyman Rosen
@ 2003-07-15  2:32   ` Alexander Kopilovitch
  2003-07-15  8:19   ` Wojtek Narczynski
  2 siblings, 0 replies; 47+ messages in thread
From: Alexander Kopilovitch @ 2003-07-15  2:32 UTC (permalink / raw)


Randy Brukardt wrote:

> > What would happen if a procedure could return a value like a function,
> > or a function could accept an out parameter?
>...
>P.S. Do we have to discuss this AGAIN?

Yes, for sure. Just because "there is enough opposition and no hope of
consensus" is not a technical argument. And it isn't an argument at all
outside of the ARG.

Hyman Rosen wrote:

>That's the price to be paid for continuing
>to allow the mulish and senseless opposition
>to keep its roadblock in place.

I am not sure that this is "mulish and senseless" opposition, but the fact is
that this is the silent opposition. There was outbreak of that discussion in
Ada-Comment (past year, I think), and within that discussion I reviewed all
arguments (against IN OUT parameters in functions), which was stated in 1993-1995,
and which blocked this feature in Ada 95. But no one seemed interested in
technical discussion: all participated ARG members simply stated their position
- pro and contra. (Most interesting was Robert Dewar's position: he firmly
stated that for all technical reasons IN OUT parameters for functions should
be permitted, but nevertheless, he warned that he will vote against this feature,
because this feature certainly will not gain consensus within ARG.)



Alexander Kopilovitch                      aek@vib.usr.pu.ru
Saint-Petersburg
Russia



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

* What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
                   ` (3 preceding siblings ...)
  2003-07-14 18:52 ` Randy Brukardt
@ 2003-07-15  5:16 ` Kenneth Almquist
  2003-07-15 11:31   ` Wojtek Narczynski
  2003-07-18  8:23 ` Wojtek Narczynski
  5 siblings, 1 reply; 47+ messages in thread
From: Kenneth Almquist @ 2003-07-15  5:16 UTC (permalink / raw)


wojtek@power.com.pl (Wojtek Narczynski) wrote:
> I feel like with SML like tagged union datatypes I'd be done long
> ago... Is there an AI for this maybe?

I'm not sure what the problem is here.  In SML you can write
things such as:

    datatype tree = Leaf of int
                  | Tree of {
                        value : int,
                        left : tree,
                        right : tree
                    }
                  | Empty

In Ada, you achieve the same effect by writing:

    type Tree_Tag is (Leaf, General_Tree, Empty);
    type Tree(Tag : Tree_Tag);
    type Tree_Ptr is access Tree;
    type Tree(Tag : Tree_Tag) is record
        case Tag is
            when Leaf =>
                Leaf : Integer;
            when General_Tree =>
                Value : Integer;
                Left : Tree_Ptr;
                Right : Tree_Ptr;
            when Empty =>
                null;
        end case;
    end record;

The Ada code is slightly more complex than the SML code because in
Ada we have to include a type declaration for the tag, and have to
declare an access type.  (The reason we have to declare an access
type in Ada but not in SML is that in SML the fields of a tree cannot
be modified after a tree is created, so the semantics of SML don't
need to distinguish between a tree and a pointer to a tree.)
				Kenneth Almquist



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

* Re: What evil would happen?
  2003-07-14 17:44                   ` Chad R. Meiners
  2003-07-14 18:15                     ` tmoran
@ 2003-07-15  8:06                     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 47+ messages in thread
From: Dmitry A. Kazakov @ 2003-07-15  8:06 UTC (permalink / raw)


On Mon, 14 Jul 2003 13:44:26 -0400, "Chad R. Meiners"
<crmeiners@hotmail.com> wrote:

>"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>news:o9s4hvofb2mtn8ga9ahf7uu530pfacald8@4ax.com...

>> 1. All functions are pure. So no access parameters allowed, no access
>> to global data from the body is allowed etc.
>>
>> 2. But procedures are allowed to have a result.
>>
>> This would be perfectly consistent and as safe as possible.
>
>I prefer SPARK's rules on functions, but I think that we should just allow
>in out parameters for our unpure functions since passing access parameters
>can be ugly.  I really do not see the harm in allowing unpure functions
>because good modularity usually nudges the programmer towards writing pure
>functions.  However, when an exception is needed being able to write unpure
>function should be straight forward and easy to detect at the specification
>level.

Exactly, this is why I'd prefer procedures with a result and functions
enforced (as much as possible) to be pure. Then a code reader could
easily figure out from the declaration what to expect, rather than
searching for some obscure pragmas or inspecting the bodies. I believe
that code purity is important enough to deserve extra syntax sugar.
Then we are already going this way - the functions of a protected
object may not change its state, which influences the implementation.
Similarly, function calls could be implemented differently from calls
to procedures. For example, the language could require the exact call
order for procedures. I mean nasty pitfalls like:

Character'Pos (Read (Socket)) * 256 + Character'Pos (Read (Socket))

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



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

* Re: What evil would happen?
  2003-07-14 18:52 ` Randy Brukardt
  2003-07-14 20:12   ` Hyman Rosen
  2003-07-15  2:32   ` Alexander Kopilovitch
@ 2003-07-15  8:19   ` Wojtek Narczynski
  2003-07-15 17:33     ` Randy Brukardt
  2 siblings, 1 reply; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-15  8:19 UTC (permalink / raw)


Randy,

> P.S. Do we have to discuss this AGAIN?

Sorry, my knowledge of what has been discussed, when, and how many
times, is fairly limited.

But AI-323 only discusses functions. It doesn't discuss return <X>
statement for procedures.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-15  5:16 ` Kenneth Almquist
@ 2003-07-15 11:31   ` Wojtek Narczynski
  0 siblings, 0 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-15 11:31 UTC (permalink / raw)


ka@sorry.no.email (Kenneth Almquist) wrote in message news:<bf02o2$dno$1@shell.monmouth.com>...
> wojtek@power.com.pl (Wojtek Narczynski) wrote:
> > I feel like with SML like tagged union datatypes I'd be done long
> > ago... Is there an AI for this maybe?
> 
> I'm not sure what the problem is here.  In SML you can write
> things such as:
> 
>     datatype tree = Leaf of int
>                   | Tree of {
>                         value : int,
>                         left : tree,
>                         right : tree
>                     }
>                   | Empty
> 
> In Ada, you achieve the same effect by writing:
> 
>     type Tree_Tag is (Leaf, General_Tree, Empty);
>     type Tree(Tag : Tree_Tag);
>     type Tree_Ptr is access Tree;
>     type Tree(Tag : Tree_Tag) is record
>         case Tag is
>             when Leaf =>
>                 Leaf : Integer;
>             when General_Tree =>
>                 Value : Integer;
>                 Left : Tree_Ptr;
>                 Right : Tree_Ptr;
>             when Empty =>
>                 null;
>         end case;
>     end record;
> 

Thanks for the example.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-15  8:19   ` Wojtek Narczynski
@ 2003-07-15 17:33     ` Randy Brukardt
  2003-07-16  0:22       ` Robert I. Eachus
  2003-07-16  8:36       ` Dmitry A. Kazakov
  0 siblings, 2 replies; 47+ messages in thread
From: Randy Brukardt @ 2003-07-15 17:33 UTC (permalink / raw)


"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0307150019.5370f3a3@posting.google.com...
> Randy,
>
> > P.S. Do we have to discuss this AGAIN?
>
> Sorry, my knowledge of what has been discussed, when, and how many
> times, is fairly limited.
>
> But AI-323 only discusses functions. It doesn't discuss return <X>
> statement for procedures.

I've never heard of any real support for that. Functions in Ada have
side-effects and that is not going to change (else virtually all existing
Ada code would cease to work). There is no point in having value-returning
procedures which are identical to functions with side-effects -- that's just
an extra complication.

In any case, this is a political issue, not a technical one, and it is very
unlikely that a consensus for any change will ever occur. Of course that's
stupid, but politics is generally stupid (look at the majority of our
elected officials).

I've toyed with adding a mode to Janus/Ada to allow in out parameters on
functions, but I haven't seen a compelling use for it (the most valuable
uses would be in Claw, but that has to work with standard Ada).

                             Randy.






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

* Re: What evil would happen?
  2003-07-12 12:38   ` Wojtek Narczynski
@ 2003-07-16  0:07     ` Robert I. Eachus
  2003-07-16  8:11       ` Preben Randhol
  0 siblings, 1 reply; 47+ messages in thread
From: Robert I. Eachus @ 2003-07-16  0:07 UTC (permalink / raw)


Wojtek Narczynski wrote:

> I have a lot of those logfiles so I wanted it to be fast => tried to
> stick with fixed strings and no exceptions. Indeed I may be trying to
> optimize something that is not slow...

The usual is to start out using Ada.Strings.Unbounded, then IF you run 
into time issues, try instantiating Ada.Strings.Bounded for a reasonable 
size, or sizes.

Of course, the rapid increase in computer speeds means that we could 
probably drop Ada.Strings.Bounded and Ada.Strings.Fixed from Ada0Y. 
(But we won't.)  It seems that today any case where you want to use 
these types involves disk I/O, and with modern processors, it is hard to 
get even 30% processor utilization when processing a disk file.

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




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

* Re: What evil would happen?
  2003-07-15 17:33     ` Randy Brukardt
@ 2003-07-16  0:22       ` Robert I. Eachus
  2003-07-16  8:36       ` Dmitry A. Kazakov
  1 sibling, 0 replies; 47+ messages in thread
From: Robert I. Eachus @ 2003-07-16  0:22 UTC (permalink / raw)


Randy Brukardt wrote:

> I've toyed with adding a mode to Janus/Ada to allow in out parameters on
> functions, but I haven't seen a compelling use for it (the most valuable
> uses would be in Claw, but that has to work with standard Ada).

And AFAIK, GNAT still supports the "value returning procedures pragmas 
from DEC Ada.

But the rule still won't change, and the reason is not just "politics." 
  This is just one area of the Ada programming culture that seems to rub 
foreigners (to Ada) the wrong way.  If you are used to Ada, the current 
Ada idioms for the few cases that seem to some people to be problems are 
natural to you.

Since I have done a lot of work on random number generators, the Ada 
idiom now seems natural to me:

function Random(Gen: in Generator) return ...
   Local: Generator;
   for Local'Address use Gen'Address;
begin
   ...
end Random;

Unlike RBKD, I did strongly argue for an in out parameter mode for 
functions in Ada 9X.  But in doing so I knew that it would be misused 
more than it would be correctly used.  By now with good implementations 
of Unbounded_String, most of the real needs for functions with in out 
parameters have gone away.  You can always declare a procedure with an 
out parameter of Unbounded_String.  So if the question is reraised I 
will vote against it.  And I will also vote in favor of a generic that 
provides the equivalent of Unbounded_String for all array types, 
including multidimensional array types.

-- 

                                                 Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




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

* Re: What evil would happen?
  2003-07-16  0:07     ` Robert I. Eachus
@ 2003-07-16  8:11       ` Preben Randhol
  0 siblings, 0 replies; 47+ messages in thread
From: Preben Randhol @ 2003-07-16  8:11 UTC (permalink / raw)


Robert I. Eachus wrote:
> Of course, the rapid increase in computer speeds means that we could 
> probably drop Ada.Strings.Bounded and Ada.Strings.Fixed from Ada0Y. 
> (But we won't.) 

Good as I think there will be more gadgets that in the future could run
home made apps on slow CPUs (PDAs and stuff). So eventhough the desktop
may be of high speed it may not be so for other things. I would guess
this is also very true for the embedded market?

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



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

* Re: What evil would happen?
  2003-07-15 17:33     ` Randy Brukardt
  2003-07-16  0:22       ` Robert I. Eachus
@ 2003-07-16  8:36       ` Dmitry A. Kazakov
  1 sibling, 0 replies; 47+ messages in thread
From: Dmitry A. Kazakov @ 2003-07-16  8:36 UTC (permalink / raw)


On Tue, 15 Jul 2003 12:33:12 -0500, "Randy Brukardt"
<randy@rrsoftware.com> wrote:

>I've never heard of any real support for that. Functions in Ada have
>side-effects and that is not going to change (else virtually all existing
>Ada code would cease to work). There is no point in having value-returning
>procedures which are identical to functions with side-effects -- that's just
>an extra complication.

There is one. One could impose additional restrictions on procedures
with results, which do not apply to functions:

1. The call order is as-is
2. No call is allowed to be optimized out

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



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

* Re: What evil would happen?
  2003-07-11 19:51 Wojtek Narczynski
                   ` (4 preceding siblings ...)
  2003-07-15  5:16 ` Kenneth Almquist
@ 2003-07-18  8:23 ` Wojtek Narczynski
  2003-07-18 14:45   ` Hyman Rosen
  2003-07-19  0:55   ` Robert I. Eachus
  5 siblings, 2 replies; 47+ messages in thread
From: Wojtek Narczynski @ 2003-07-18  8:23 UTC (permalink / raw)


Hello,

Now I have a wealth of soluions (no order):

- generic functions with "in out" formal objects(HR),
- Addres clause (RIE),
- passing access types (FR) ,
- SML-like tagged unions (KA),
- ......

Sorry for reviving my old thread, but I wanted to sum up and�to thank everybody.

Regards,
Wojtek



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

* Re: What evil would happen?
  2003-07-18  8:23 ` Wojtek Narczynski
@ 2003-07-18 14:45   ` Hyman Rosen
  2003-07-19  0:55   ` Robert I. Eachus
  1 sibling, 0 replies; 47+ messages in thread
From: Hyman Rosen @ 2003-07-18 14:45 UTC (permalink / raw)


Wojtek Narczynski wrote:
> - generic functions with "in out" formal objects(HR)

Hey, you mean I was the only one to propose this solution?
I'm going to lose my reputation for not knowing Ada! :-)




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

* Re: What evil would happen?
  2003-07-18  8:23 ` Wojtek Narczynski
  2003-07-18 14:45   ` Hyman Rosen
@ 2003-07-19  0:55   ` Robert I. Eachus
  1 sibling, 0 replies; 47+ messages in thread
From: Robert I. Eachus @ 2003-07-19  0:55 UTC (permalink / raw)


Wojtek Narczynski wrote:
> Hello,
> 
> Now I have a wealth of soluions (no order):
> 
> - generic functions with "in out" formal objects(HR),
> - Addres clause (RIE),

Incidently this is known as the Rosen trick, for Jean Pierre Rosen.  And 
there is a discussion in the ARG right now on the meaning of RM 
13.3(19).  My "notational" new wording is "the Rosen trick works, plus 
some other things."  (There are other cases being discussed as well.)
The issue is that the RM should say something about the effect on the 
object whose address may have been taken, and whether it is meaningful 
to try to exend that to cases where there is a more complex expression 
for the address.  But:

for A'Address use B'Address; when A and B are the same size, it shoud 
imply the same things about both A and B.

> Sorry for reviving my old thread, but I wanted to sum up and to thank everybody.

Believe me, no matter what is said, thanks are always appreciated.

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




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

end of thread, other threads:[~2003-07-19  0:55 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-11 23:04 What evil would happen? Beard, Frank Randolph CIV
2003-07-12 12:46 ` Wojtek Narczynski
  -- strict thread matches above, loose matches on Subject: below --
2003-07-11 19:51 Wojtek Narczynski
2003-07-11 20:07 ` Hyman Rosen
2003-07-12 12:30   ` Wojtek Narczynski
2003-07-12 17:17     ` Martin Dowie
2003-07-13  1:46     ` Hyman Rosen
2003-07-13 15:29       ` Wojtek Narczynski
2003-07-11 20:08 ` chris.danx
2003-07-12  4:31   ` Nick Roberts
2003-07-12 12:26     ` Wojtek Narczynski
2003-07-12 12:39       ` Preben Randhol
2003-07-12 13:11         ` Larry Kilgallen
2003-07-12 13:22           ` Preben Randhol
2003-07-12 19:04             ` Larry Kilgallen
2003-07-14  8:43               ` Preben Randhol
2003-07-14 10:32                 ` Larry Kilgallen
2003-07-14 11:05                   ` Preben Randhol
2003-07-14 11:31                   ` Larry Kilgallen
     [not found]                   ` <slrnbh53ir.48d.Organization: LJK Software <zSeTW0M3CTPU@eisner.encompasserve.org>
2003-07-14 17:31                     ` Wojtek Narczynski
2003-07-13 15:26             ` Wojtek Narczynski
2003-07-13 17:28               ` Chad R. Meiners
2003-07-13 22:35                 ` Wojtek Narczynski
2003-07-14  0:06                   ` Chad R. Meiners
2003-07-13 22:36                 ` Wojtek Narczynski
2003-07-14  3:01                 ` Hyman Rosen
2003-07-14  4:41                   ` Chad R. Meiners
2003-07-14  9:09                 ` Dmitry A. Kazakov
2003-07-14 17:44                   ` Chad R. Meiners
2003-07-14 18:15                     ` tmoran
2003-07-15  8:06                     ` Dmitry A. Kazakov
2003-07-11 21:26 ` Robert I. Eachus
2003-07-12 12:38   ` Wojtek Narczynski
2003-07-16  0:07     ` Robert I. Eachus
2003-07-16  8:11       ` Preben Randhol
2003-07-14 18:52 ` Randy Brukardt
2003-07-14 20:12   ` Hyman Rosen
2003-07-15  2:32   ` Alexander Kopilovitch
2003-07-15  8:19   ` Wojtek Narczynski
2003-07-15 17:33     ` Randy Brukardt
2003-07-16  0:22       ` Robert I. Eachus
2003-07-16  8:36       ` Dmitry A. Kazakov
2003-07-15  5:16 ` Kenneth Almquist
2003-07-15 11:31   ` Wojtek Narczynski
2003-07-18  8:23 ` Wojtek Narczynski
2003-07-18 14:45   ` Hyman Rosen
2003-07-19  0:55   ` Robert I. Eachus

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