From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: Newbie question:procedural variables(call by reference)?
Date: Mon, 15 Sep 2003 23:22:29 GMT
Date: 2003-09-15T23:22:29+00:00 [thread overview]
Message-ID: <upti17i0y.fsf@earthlink.net> (raw)
In-Reply-To: 3F65EBF4.7CF3@mail.ru
Dmytry Lavrov <m31415@mail.ru> writes:
> There are no procedural variables(calls by reference) in Ada,right?
> (or I missed something...)
Yes, there are procedure variables in Ada95:
type Procedure_Access is
access procedure (I : Integer);
type Function_Access is
access function (I : Integer) return Float;
> How to live without 'em? (i guess , 'like in java' ;-)
You don't have to, but you have procedure pointers in Ada95.
However, you probably don't need them. Instead, you'll probably want to
use a "generic formal subprogram," like this:
generic
with procedure Process (I : Integer) is <>;
procedure Generic_Op;
To call Op, you must "instantiate" it, and supply the procedure a the
"generic actual argument," like this:
procedure Process (I : Integer) is ...;
procedure Op is new Generic_Op (Process);
Now you can call Op, and it will call Process.
> What for example if I have wrote, say.... expression evaluator. In
> Pascal(bit extended), and with way to add custom functions, like
>
> procedure AddFunc
> (name:string;
> numparams:integer;
> additionalparam:machine_word;
> fn:CustomFunction);
You could use a function pointer here, but you probably don't want to.
To convert this to Ada95, to this:
generic
with procedure Custom_Function (O : T) is <>;
procedure Generic_AddFunc
(Name : String;
NumParams : Integer;
AdditionalParam : Integer_32);
You first have to instantiate Generic_AddFunc, and supply an actual
Custom_Function. Something like:
procedure Do_Something (O : T);
procedure AddFunc is new Generic_AddFunc (Do_Something);
> How I can move it to Ada....(of course I know that it's sometimes
> better to do all with OOP, but here is much simpler to have array with
> references, than doing crazy extensible objects).
See above.
> Why peoples sometime talking about OS in ada?...it's inpossible w/o call
> by reference,OOP is based on call by reference,right?.
Yes, OOP is done with call-by-reference. Tagged types in Ada95 are
passed by reference, so dispatching works.
next prev parent reply other threads:[~2003-09-15 23:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-15 16:42 Newbie question:procedural variables(call by reference)? Dmytry Lavrov
2003-09-15 18:20 ` Stephen Leake
2003-09-15 18:50 ` Gautier Write-only
2003-09-15 18:56 ` Jeffrey Carter
2003-09-16 10:45 ` Georg Bauhaus
2003-09-15 23:22 ` Matthew Heaney [this message]
2003-09-18 9:06 ` Dmytry Lavrov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox