* Newbie question:procedural variables(call by reference)?
@ 2003-09-15 16:42 Dmytry Lavrov
2003-09-15 18:20 ` Stephen Leake
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Dmytry Lavrov @ 2003-09-15 16:42 UTC (permalink / raw)
There are no procedural variables(calls by reference) in ADA,right?(or i
missed something...).
How to live without 'em? (i guess , 'like in java' ;-)
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:mashine_word;fn:CustomFunction);
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).
Normally i can use something like
type FunctionInfo=record
name:string;numparams:integer;additionalparam:mashine_word;fn:CustomFunction;
end;
and simple sorted array of 'em,finding right routine by binary search.
Why peoples sometime talking about OS in ada?...it's inpossible w/o call
by reference,OOP is based on call by reference,right?.
Heh,formally running a program from hard disk is a call by reference!
;-).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
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
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2003-09-15 18:20 UTC (permalink / raw)
Dmytry Lavrov <m31415@mail.ru> writes:
> There are no procedural variables(calls by reference) in ADA,right?(or i
> missed something...).
You can pass a pointer to a subprogram as a parameter to an Ada
subprogram. Generally, the subprogram must be a library-level
subprogram, but sometimes you can use a local subprogram.
> How to live without 'em? (i guess , 'like in java' ;-)
Generics usually provide a better way to get the same result. "Better"
here means more type-safe, more easily understood.
--
-- Stephe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
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
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Gautier Write-only @ 2003-09-15 18:50 UTC (permalink / raw)
Dmytry Lavrov:
> There are no procedural variables(calls by reference) in ADA,right?(or i
> missed something...).
I'm afraid you did ;-) : a small example (see the "My_feedback'access" etc.):
http://www.mysunrise.ch/users/gdm/uza_html/unzipada__adb.htm#23_3
> How to live without 'em? (i guess , 'like in java' ;-)
You can also use the genericity (no bad jokes with pointers), see e.g.
"procedure Count_files..." there:
http://www.mysunrise.ch/users/gdm/uza_html/comp_zip__adb.htm#108_13
Now you have to choose between TWO methods!
________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
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
2003-09-18 9:06 ` Dmytry Lavrov
4 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2003-09-15 18:56 UTC (permalink / raw)
Dmytry Lavrov wrote:
> There are no procedural variables(calls by reference) in ADA,right?(or i
> missed something...).
> How to live without 'em? (i guess , 'like in java' ;-)
>
> 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:mashine_word;fn:CustomFunction);
This is called access-to-subprogram in Ada; see ARM 3.10. You'd want
something like
type Custom_Function is access function (...) return Whatever;
procedure Add_Func (Name : in String;
Num_Params : in Natural;
Additional_Params : in Machine_Word;
Func : in Custom_Function);
Note, however, the restrictions on nesting.
--
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
2003-09-15 16:42 Newbie question:procedural variables(call by reference)? Dmytry Lavrov
` (2 preceding siblings ...)
2003-09-15 18:56 ` Jeffrey Carter
@ 2003-09-15 23:22 ` Matthew Heaney
2003-09-18 9:06 ` Dmytry Lavrov
4 siblings, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 2003-09-15 23:22 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
2003-09-15 18:56 ` Jeffrey Carter
@ 2003-09-16 10:45 ` Georg Bauhaus
0 siblings, 0 replies; 7+ messages in thread
From: Georg Bauhaus @ 2003-09-16 10:45 UTC (permalink / raw)
Jeffrey Carter <spam@spam.com> wrote:
: "Mr. President, we must not allow a mine-shaft gap!"
(That is General Turgidson speaking, though, not Dr. Strangelove
:-) :-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Newbie question:procedural variables(call by reference)?
2003-09-15 16:42 Newbie question:procedural variables(call by reference)? Dmytry Lavrov
` (3 preceding siblings ...)
2003-09-15 23:22 ` Matthew Heaney
@ 2003-09-18 9:06 ` Dmytry Lavrov
4 siblings, 0 replies; 7+ messages in thread
From: Dmytry Lavrov @ 2003-09-18 9:06 UTC (permalink / raw)
Thanks,
i found that i misunderstand sentence
like "without procedural variables we can ........ at compile time"
(in context of "without pointer arifmetics ....")
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-09-18 9:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2003-09-18 9:06 ` Dmytry Lavrov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox