From: anon@anon.org (anon)
Subject: Re: urgent question - generics
Date: Tue, 04 Sep 2007 00:38:10 GMT
Date: 2007-09-04T00:38:10+00:00 [thread overview]
Message-ID: <SN1Di.488393$p47.360230@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1188837355.753212.161150@r34g2000hsd.googlegroups.com
-- A more complete answer since your through with your test. And yes
-- you can copy and paste this code into a a file and use the gnat
-- system to compile/bind/link and then excute the program.
--
-- In most cases there are a number of ways to create code. Some are
-- more direct or aids the compiler to help you while others are more
-- indirect or toward the system performance and code usage. I did have
-- seven ways of answering the question but the other 3 were too
-- complex for a beginner. Even one use the generic package
-- caled "System.Address_To_Access_Conversions"
--
-- But in true Generic the function should be able to handle all
-- types of calls both Ada and non-Ada procedure.
--
-- In GNAT both Access and Address are the same but with other
-- system where memory is protected or even using seperate
-- memories this may not be the case.
--
with Ada.text_IO ;
with System ;
--
-- see function_3, might be too complex.
--
with Ada.Unchecked_Conversion ;
procedure zzero is
--
-- This allows all types of procedures both Ada and external
-- with or without parameters. Creates a static procedure
-- design effect.
--
function function_0 ( func : System.Address ; Data : Float )
return float is
procedure tst ;
pragma Import ( Ada, tst ) ;
for tst'address use func ;
begin -- function_0
tst ;
return Data * 2.0 ;
end function_0 ;
------------------------------------------------------------------------------
-- The Probability the answer that she ask for: --
-- --
-- type proc_access is access procedure ; -- is the generic statement --
-- -- that she needed. --
-- --
-- tst.all ; -- statement to call set --
-- -- procedure --
-- --
------------------------------------------------------------------------------
--
-- This version allows only procedures that are Ada without
-- parameters.
--
type proc_access is access procedure ;
function function_1 ( tst : proc_access ; Data : Float )
return float is
begin -- function_1
tst.all ;
return Data * 2.0 ;
end function_1 ;
--
-- This version allows only procedures that are Ada without
-- parameters. Creates a static procedure design effect for
-- calling procedure.
--
type func_access is access procedure ;
function function_2 ( func : func_access ; Data : Float )
return float is
procedure tst ;
pragma Import ( Ada, tst ) ;
for tst'address use func.all'address ;
begin -- function_2
tst ;
return Data * 2.0 ;
end function_2 ;
--
-- This version allows only procedures that are Ada without
-- parameters. And also use another Generic package to
-- convert the addressing schemes that creates a static
-- procedure design effect. But shows that both can be used
-- in the same package.
--
type procedure_access is access procedure ;
function function_3 ( func : procedure_access ; Data : Float )
return float is
-- --------------------------------------- --
-- use for calling method version two only --
-- --------------------------------------- --
--
-- limit this conversion function to function_3 usage only
--
function PA_To_A is new Ada.Unchecked_Conversion
( Source => procedure_access,
Target => System.Address ) ;
procedure tst ;
pragma Import ( Ada, tst ) ;
for tst'address use PA_To_A ( func ) ;
begin -- function_3
--
-- simple dynamic call version method 1
--
func.all ;
--
-- simple static call version method 2
--
tst ;
return Data * 2.0 ;
end function_3 ;
-- ---------- --
-- Test: Proc --
-- ---------- --
procedure test is
begin -- test
Ada.Text_IO.Put_Line ( "Testing" ) ;
end test ;
Result : Float ;
begin
Result := function_0 ( test'address, 0.5 ) ;
--
Result := function_1 ( test'access, 0.7 ) ;
Result := function_2 ( test'access, 0.9 ) ;
--
Result := function_3 ( test'access, 0.1 ) ;
end zzero ;
In <1188837355.753212.161150@r34g2000hsd.googlegroups.com>, shoshanister@gmail.com writes:
>On Sep 3, 4:01 pm, a...@anon.org (anon) wrote:
>> In <1188819393.588005.23...@r34g2000hsd.googlegroups.com>, shoshanis...@gmail.com writes:
>>
>> >Hi, First, I'm a female.
>>
>> Sorry about calling you a guy, it is an easy mistake to make on the net.
>>
>> >Please don't post any more answers or such.
>>
>> If you look here I will always answer a question with code if
>> possible! Its just the way I am. I even jump of people here for not
>> posting code. Because in a test my code or anyone else code is
>> not going to help, unless you understand it! And the only way is to
>> see the code.
>>
>> >I understand according to what you wrote that I probably did not fully
>> >understand the generics mechanism. In this case, even if you will
>> >answer my question, it will not help me because my exam starts in an
>> >hour.
>> >I posted the question here, after trying to figure things out by my
>> >self, and I had no intention to insult any one of you or to take
>> >advantage of you.
>>
>> No insult or advantage of taken!
>>
>> >In a way, I'm not worried of not passing the exam. The worse thing
>> >that can happen is that I will take the course again, and gain my
>> >knowledge from the teacher as well as from the books, because studying
>> >ADA by your self is not simple.
>>
>> Actually, installing a free GNAT Ada version and starting to program
>> is the BEST way to learn. Teachers only have time to give you an
>> brief understand of any language. In the US that less than 45 hours
>> spanning 15 weeks. Outside programming is the only way to gain a
>> deeper understanding. And asking question with an expectation of an
>> answer is the second best way to gain a direction for that deeper
>> understand.
>>
>> Plus, in my many years experience if a person just say read a section
>> or chapter than they also do not understand the problem or the
>> language. Even my professor would not do that, they would give an
>> example (like I did) and then assign someone an extra assignment that
>> would include the example as a small part of the whole project.
>>
>> The only thing was their projects, either homework or extra
>> assignments were too simple for me, (bored me to death). I actually
>> had to expand them to make the worth my time. My Ada professor
>> use most of my work in Ada to teach his other classes at two
>> universities and wrote a number of text books using my classwork
>> that were used in both Europe and US universities.
>>
>> What I did for my first Ada assignment after modifying it, was
>> rated at doctoral level programming. I even had to have permission
>> from 3 universities and their computer systems to fully execute the
>> assignment.
>>
>> >Thanks a lot for your help.
>> >I hope that some day I will be able to join this group as an equal
>> >member and not just a student.
>>
>> I kind of believe that 50+ % of this group is students.
>
>Hi, Thanks for your kind response.
>I just came back from the exam. It was not very difficult but I can't
>say it was easy. I don't believe I passed, but it's ok. I don't mind
>attending the course again, Ada is a nice and very powerful language,
>and I wouldn't mind getting to know it better.
>I'm going to get some rest now. Thanks :)
>
next prev parent reply other threads:[~2007-09-04 0:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-03 8:47 urgent question - generics shoshanister
2007-09-03 9:14 ` Pascal Obry
2007-09-03 9:28 ` shoshanister
2007-09-03 9:58 ` Dmitry A. Kazakov
2007-09-03 10:19 ` shoshanister
2007-09-03 10:48 ` Markus E L
2007-09-03 13:41 ` Pascal Obry
2007-09-03 14:08 ` Niklas Holsti
2007-09-03 14:44 ` Pascal Obry
2007-09-03 15:01 ` Dmitry A. Kazakov
2007-09-03 14:36 ` Jean-Pierre Rosen
2007-09-03 16:46 ` shoshanister
2007-09-03 19:58 ` Georg Bauhaus
2007-09-03 10:23 ` anon
2007-09-03 10:42 ` Niklas Holsti
2007-09-03 10:58 ` shoshanister
2007-09-03 11:04 ` Georg Bauhaus
2007-09-03 11:06 ` shoshanister
2007-09-03 12:00 ` Georg Bauhaus
2007-09-03 11:24 ` anon
2007-09-03 11:36 ` shoshanister
2007-09-03 13:01 ` anon
2007-09-03 16:35 ` shoshanister
2007-09-04 0:38 ` anon [this message]
2007-09-04 6:38 ` Georg Bauhaus
2007-09-05 3:47 ` anon
2007-09-05 10:11 ` Georg Bauhaus
2007-09-05 12:36 ` To Georg Bauhaus anon
2007-09-05 13:50 ` Keep slang words in describing Ada programming? (was: To Georg Bauhaus) Georg Bauhaus
2007-09-05 14:40 ` To new TROLL named Georg Bauhaus anon
2007-09-05 18:10 ` Georg Bauhaus
[not found] ` <op.tx7g6crr5afhvo@dogen>
2007-09-06 2:54 ` anon
2007-09-06 9:20 ` Markus E L
2007-09-06 6:15 ` Dirk Heinrichs
2007-09-06 9:18 ` Markus E L
2007-09-05 11:37 ` urgent question - generics Markus E L
2007-09-03 13:27 ` Ludovic Brenta
2007-09-03 13:18 ` Markus E L
2007-09-03 10:56 ` Markus E L
2007-09-05 3:49 ` Troll -- Markus E L anon
2007-09-05 11:35 ` Markus E L
2007-09-03 16:18 ` urgent question - generics tmoran
2007-09-03 21:39 ` anon
2007-09-03 11:39 ` gautier_niouzes
2007-09-03 11:59 ` shoshanister
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox