comp.lang.ada
 help / color / mirror / Atom feed
* specification file ads problem
@ 2014-10-05 15:39 Stribor40
  2014-10-05 16:20 ` mockturtle
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Stribor40 @ 2014-10-05 15:39 UTC (permalink / raw)


I am trying to put this in spec file...
***********************************************************
generic
  type myType is array (1 ..N-1) of String (1..N);
  N : Integer;
 
package myPackage is
     function tt (a : in String) return myType;
end Neighbours;

************************************************************
Then in body.....

package body myPackage is
 myNewType : myType; 

     function tt (a : in String) return myType is
        begin
      --
      --

      return myNewType;
        end tt;


end myPackage;
*****************************************************************************
actual file that i compile and use to test this,,,

with Ada.Text_IO, Ada.Command_Line, myPackage;
 
  
   procedure testing is
   
  
  begin
   Null;
  end testing;
***************************************************************************

I am getting all these type errors..what am i doing wrong here? How do i spec file specify function return type when my spec file doesnt know about it?
    


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

* Re: specification file ads problem
  2014-10-05 15:39 specification file ads problem Stribor40
@ 2014-10-05 16:20 ` mockturtle
  2014-10-06 21:34   ` Adam Beneschan
  2014-10-05 16:29 ` AdaMagica
  2014-10-05 16:32 ` Simon Wright
  2 siblings, 1 reply; 16+ messages in thread
From: mockturtle @ 2014-10-05 16:20 UTC (permalink / raw)



I see an easy error in your code, but I am not sure if it is an error introduced by doing cut'n'paste: the spec of your package  "MyPackage" ends with "end Neighbours" rather than with "end MyPackage."

Moreover, I think that you should put "N : Integer" before the 
definition of myType since when the compiler sees "type myType is..." does not know what N is.  

Moreover, I am not 100% sure that you can use N-1 as array boundary.  I know you cannot do that in a record declaration. Actually, I am quite confident that your usage is right, but I should check with a compiler.

Finally, you "with" your package, but you do not instantiate it.  This, however, should not cause any error, unless you try to "use" it.


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

* Re: specification file ads problem
  2014-10-05 15:39 specification file ads problem Stribor40
  2014-10-05 16:20 ` mockturtle
@ 2014-10-05 16:29 ` AdaMagica
  2014-10-05 16:32 ` Simon Wright
  2 siblings, 0 replies; 16+ messages in thread
From: AdaMagica @ 2014-10-05 16:29 UTC (permalink / raw)


Further, N declared as Integer does not make much sense. Should be Positive.

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

* Re: specification file ads problem
  2014-10-05 15:39 specification file ads problem Stribor40
  2014-10-05 16:20 ` mockturtle
  2014-10-05 16:29 ` AdaMagica
@ 2014-10-05 16:32 ` Simon Wright
  2014-10-05 17:06   ` Online conceptual/tutorial material for Ada, was: " Simon Clubley
  2 siblings, 1 reply; 16+ messages in thread
From: Simon Wright @ 2014-10-05 16:32 UTC (permalink / raw)


Stribor40 <ikamzic@gmail.com> writes:

> generic
>   type myType is array (1 ..N-1) of String (1..N);
>   N : Integer;
>  
> package myPackage is
>      function tt (a : in String) return myType;
> end Neighbours;

Try

generic
   N : Integer;
package myPackage is
   type myType is array (1 ..N-1) of String (1..N);
   function tt (a : in String) return myType;
end myPackage;

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

* Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-05 16:32 ` Simon Wright
@ 2014-10-05 17:06   ` Simon Clubley
  2014-10-05 18:44     ` Niklas Holsti
                       ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Simon Clubley @ 2014-10-05 17:06 UTC (permalink / raw)


On 2014-10-05, Simon Wright <simon@pushface.org> wrote:
> Stribor40 <ikamzic@gmail.com> writes:
>
>> generic
>>   type myType is array (1 ..N-1) of String (1..N);
>>   N : Integer;
>>  
>> package myPackage is
>>      function tt (a : in String) return myType;
>> end Neighbours;
>
> Try
>
> generic
>    N : Integer;
> package myPackage is
>    type myType is array (1 ..N-1) of String (1..N);
>    function tt (a : in String) return myType;
> end myPackage;

At this point, I wonder if there are some good online tutorials which
cover the basic Ada concepts which we could point Stribor40 to ?

I'm thinking maybe something which _isn't_ a full book length but
manages to cover the basic Ada concepts in a coherent manner and links
them all together.

The kind of thing I'm thinking of is maybe something like Ada Distilled.

Any comments ?

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-05 17:06   ` Online conceptual/tutorial material for Ada, was: " Simon Clubley
@ 2014-10-05 18:44     ` Niklas Holsti
  2014-10-05 19:53     ` Peter Chapin
  2014-10-06  8:12     ` Jacob Sparre Andersen
  2 siblings, 0 replies; 16+ messages in thread
From: Niklas Holsti @ 2014-10-05 18:44 UTC (permalink / raw)


On 14-10-05 20:06 , Simon Clubley wrote:
> At this point, I wonder if there are some good online tutorials which
> cover the basic Ada concepts which we could point Stribor40 to ?
> 
> I'm thinking maybe something which _isn't_ a full book length but
> manages to cover the basic Ada concepts in a coherent manner and links
> them all together.
> 
> The kind of thing I'm thinking of is maybe something like Ada Distilled.
> 
> Any comments ?

Stribor40 could look at http://en.wikibooks.org/wiki/Ada_Programming,
but perhaps it is not tutorial enough. Some useful examples, at least.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-05 17:06   ` Online conceptual/tutorial material for Ada, was: " Simon Clubley
  2014-10-05 18:44     ` Niklas Holsti
@ 2014-10-05 19:53     ` Peter Chapin
  2014-10-06  7:55       ` Simon Wright
  2014-10-06  8:12     ` Jacob Sparre Andersen
  2 siblings, 1 reply; 16+ messages in thread
From: Peter Chapin @ 2014-10-05 19:53 UTC (permalink / raw)


On 2014-10-05 13:06, Simon Clubley wrote:

> At this point, I wonder if there are some good online tutorials which
> cover the basic Ada concepts which we could point Stribor40 to ?
> 
> I'm thinking maybe something which _isn't_ a full book length but
> manages to cover the basic Ada concepts in a coherent manner and links
> them all together.
> 
> The kind of thing I'm thinking of is maybe something like Ada Distilled.
> 
> Any comments ?
> 
> Simon.
> 

I wrote this some time ago

	http://web.vtc.edu/users/pcc09070/Ada/AdaCrash.pdf

but it's incomplete and in need of updating/editing.

Peter

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-05 19:53     ` Peter Chapin
@ 2014-10-06  7:55       ` Simon Wright
  2014-10-06 11:08         ` Peter Chapin
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Wright @ 2014-10-06  7:55 UTC (permalink / raw)


Peter Chapin <PChapin@vtc.vsc.edu> writes:

> I wrote this some time ago
>
> 	http://web.vtc.edu/users/pcc09070/Ada/AdaCrash.pdf
>
> but it's incomplete and in need of updating/editing.

I'd have thought it a good first read. But I'm not a newbie.

It's (now) possible to get Libre Office to use hyperlinks in the ToC,
which would be a help for the reader ...

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-05 17:06   ` Online conceptual/tutorial material for Ada, was: " Simon Clubley
  2014-10-05 18:44     ` Niklas Holsti
  2014-10-05 19:53     ` Peter Chapin
@ 2014-10-06  8:12     ` Jacob Sparre Andersen
  2 siblings, 0 replies; 16+ messages in thread
From: Jacob Sparre Andersen @ 2014-10-06  8:12 UTC (permalink / raw)


Simon Clubley wrote:

> At this point, I wonder if there are some good online tutorials which
> cover the basic Ada concepts which we could point Stribor40 to?

The "Lovelace" tutorial might be a good option:

   http://www.dwheeler.com/lovelace/s1s1.htm

Greetings,

Jacob
-- 
Warning: Dates in calendars are closer than they appear.

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06  7:55       ` Simon Wright
@ 2014-10-06 11:08         ` Peter Chapin
  2014-10-06 12:13           ` G.B.
  0 siblings, 1 reply; 16+ messages in thread
From: Peter Chapin @ 2014-10-06 11:08 UTC (permalink / raw)


On 2014-10-06 03:55, Simon Wright wrote:

>> I wrote this some time ago
>>
>> 	http://web.vtc.edu/users/pcc09070/Ada/AdaCrash.pdf
>>
>> but it's incomplete and in need of updating/editing.
> 
> I'd have thought it a good first read. But I'm not a newbie.
> 
> It's (now) possible to get Libre Office to use hyperlinks in the ToC,
> which would be a help for the reader ...

That's good to know, thanks. I'll look into that if/when I get around to
finishing it up.

Peter



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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06 11:08         ` Peter Chapin
@ 2014-10-06 12:13           ` G.B.
  2014-10-06 13:07             ` Peter Chapin
  2014-10-06 22:30             ` Simon Clubley
  0 siblings, 2 replies; 16+ messages in thread
From: G.B. @ 2014-10-06 12:13 UTC (permalink / raw)


On 06.10.14 13:08, Peter Chapin wrote:
> On 2014-10-06 03:55, Simon Wright wrote:
>
>>> I wrote this some time ago
>>>
>>> 	http://web.vtc.edu/users/pcc09070/Ada/AdaCrash.pdf
>>>
>>> but it's incomplete and in need of updating/editing.
>>
>> I'd have thought it a good first read. But I'm not a newbie.
>>
>> It's (now) possible to get Libre Office to use hyperlinks in the ToC,
>> which would be a help for the reader ...
>
> That's good to know, thanks. I'll look into that if/when I get around to
> finishing it up.

Would there possibly be some way of introducing Ada's user defined
scalar types earlier?  This would give credit to McCormick's most
prominent finding, namely that use of Ada's user defined scalars
is a real, non-marketing boost in productivity. In particular, this
feature of the Ada language has been found to boost newcomers' results.

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06 12:13           ` G.B.
@ 2014-10-06 13:07             ` Peter Chapin
  2014-10-06 13:40               ` J-P. Rosen
  2014-10-06 22:30             ` Simon Clubley
  1 sibling, 1 reply; 16+ messages in thread
From: Peter Chapin @ 2014-10-06 13:07 UTC (permalink / raw)


On 2014-10-06 08:13, G.B. wrote:

>> That's good to know, thanks. I'll look into that if/when I get around to
>> finishing it up.
> 
> Would there possibly be some way of introducing Ada's user defined
> scalar types earlier?  This would give credit to McCormick's most
> prominent finding, namely that use of Ada's user defined scalars
> is a real, non-marketing boost in productivity. In particular, this
> feature of the Ada language has been found to boost newcomers' results.

Yes, I'm sure it could be done... just have to reflect a little on the
best way to present it. I think some students, at least the ones I've
had, find detailed discussion of types up front rather dry. Of course it
wouldn't be necessary to talk about every detail and nuance to get the
important ideas across. In fact, the point of my little tutorial is to
try and present the core ideas in as minimalistic a way as possible so
cutting out details is in keeping with that philosophy.

Thanks for the suggestion.

Peter


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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06 13:07             ` Peter Chapin
@ 2014-10-06 13:40               ` J-P. Rosen
  0 siblings, 0 replies; 16+ messages in thread
From: J-P. Rosen @ 2014-10-06 13:40 UTC (permalink / raw)


Le 06/10/2014 15:07, Peter Chapin a écrit :
> On 2014-10-06 08:13, G.B. wrote:
> 
>> Would there possibly be some way of introducing Ada's user defined
>> scalar types earlier?  This would give credit to McCormick's most
>> prominent finding, namely that use of Ada's user defined scalars
>> is a real, non-marketing boost in productivity. In particular, this
>> feature of the Ada language has been found to boost newcomers' results.
> 
> Yes, I'm sure it could be done... just have to reflect a little on the
> best way to present it. I think some students, at least the ones I've
> had, find detailed discussion of types up front rather dry. Of course it
> wouldn't be necessary to talk about every detail and nuance to get the
> important ideas across. In fact, the point of my little tutorial is to
> try and present the core ideas in as minimalistic a way as possible so
> cutting out details is in keeping with that philosophy.
> 

Just a note from a long-long-time teacher:

1) People remember what they see first
2) People reproduce what they remember
3) Disclaimers are not remembered

Therefore, starting with Integer, even with a disclaimer that it's just
for the purpose of small examples, will completely weaken the message
that proper types should be defined.

My advice (and what I do in my own courses):
Introduce very early simple (and easy to understand) types like:
   type Age is range 0..125;
   type Floor is range -5 .. 15;
   type Color is (Black, Red, Green, Blue, White);

and use only these in all examples.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


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

* Re: specification file ads problem
  2014-10-05 16:20 ` mockturtle
@ 2014-10-06 21:34   ` Adam Beneschan
  0 siblings, 0 replies; 16+ messages in thread
From: Adam Beneschan @ 2014-10-06 21:34 UTC (permalink / raw)


On Sunday, October 5, 2014 9:20:35 AM UTC-7, mockturtle wrote:
> I see an easy error in your code, but I am not sure if it is an error introduced by doing cut'n'paste: the spec of your package  "MyPackage" ends with "end Neighbours" rather than with "end MyPackage."
> 
> 
> 
> Moreover, I think that you should put "N : Integer" before the 
> 
> definition of myType since when the compiler sees "type myType is..." does not know what N is.  
> 
> 
> 
> Moreover, I am not 100% sure that you can use N-1 as array boundary.  I know you cannot do that in a record declaration. 

Actually, you *can* do that in a record declaration, as long as "N" isn't a discriminant.  The rules that disallow arithmetic on array bounds in a record component apply only to discriminants.

For a generic formal array type, however, you can't use ranges at all, by RM 12.5.3(3).  The official reason for this, according to the AARM, is "it simplifies the elaboration of generic_declarations (since there is nothing to evaluate), and that it simplifies the matching rules, and makes them more checkable at compile time."  (12.1(7.a))  This rule prohibits both 1..N-1 on the outer array type and 1..N on the String element type.  

I don't see a way to get the compiler to check this at compile time.  Checking at run time is really clunky; this is the only way I could find to get things to work:

generic
  type String_Index is range <>;
  type Array_Index is range <>;
  type String_Subtype is array (String_Index) of Character;
  type myType is array (Array_Index) of String_Subtype;
  N : Integer;
package myPackage is
  function tt (a : in String) return myType;
end myPackage;

package body myPackage is
  -- define tt 

begin
  if String_Index'first /= 1 or else
     Integer(String_Index'last) /= N or else
     Array_Index'first /= 1 or else
     Integer(Array_Index'last) /= N - 1 then
     raise Program_Error with "Instantiation with wrong types";
  end if;
end myPackage;

and to instantiate it, you need something like

    subtype Integer_3 is integer range 1..3;
    subtype String3 is String(Integer_3);
    subtype Integer_2 is integer range 1..2;
    type Arr is array(Integer_2) of String3;
    package myPack is new myPackage(Integer_3, Integer_2, String3, Arr, 3);

When the instantiation is elaborated, the package body is elaborated, which causes the code in the "begin..end" of the package body to be executed, which raises an exception at run time if the array bounds are wrong.

I think the design probably needs reworking; to start with, it isn't clear to me that a generic is needed at all.  But it's hard to tell without more information about what the OP is actually trying to accomplish.

                                   -- Adam

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06 12:13           ` G.B.
  2014-10-06 13:07             ` Peter Chapin
@ 2014-10-06 22:30             ` Simon Clubley
  2014-10-07 18:39               ` Peter Chapin
  1 sibling, 1 reply; 16+ messages in thread
From: Simon Clubley @ 2014-10-06 22:30 UTC (permalink / raw)


On 2014-10-06, G.B. <bauhaus@futureapps.invalid> wrote:
> On 06.10.14 13:08, Peter Chapin wrote:
>> On 2014-10-06 03:55, Simon Wright wrote:
>>
>>>> I wrote this some time ago
>>>>
>>>> 	http://web.vtc.edu/users/pcc09070/Ada/AdaCrash.pdf
>>>>
>>>> but it's incomplete and in need of updating/editing.

This is the kind of thing I am thinking of (with one reservation in
what I have read of it).

>>>
>>> I'd have thought it a good first read. But I'm not a newbie.
>>>

And not being a newbit is a potential problem. The stupid little things
which trip you up in the first few days of learning a new language
rapidly become common knowledge (to you) and after a while you might not
even remember those early problems.

>>> It's (now) possible to get Libre Office to use hyperlinks in the ToC,
>>> which would be a help for the reader ...
>>
>> That's good to know, thanks. I'll look into that if/when I get around to
>> finishing it up.
>
> Would there possibly be some way of introducing Ada's user defined
> scalar types earlier?  This would give credit to McCormick's most
> prominent finding, namely that use of Ada's user defined scalars
> is a real, non-marketing boost in productivity. In particular, this
> feature of the Ada language has been found to boost newcomers' results.
>

And _that's_ the same reservation I have.

Ada style user defined datatypes need to be much closer to the start
of the document. However, I also understand the need not to overwhelm
the reader with new things.

How about early examples which show just _one_ of the really simple
types J-P Rosen mentions and uses (say) Integer for the rest of the
example ?

That way you give the reader an example they can mostly compare directly
to other languages such as C, but you have also planted in their mind
the idea of Ada style user defined datatypes.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

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

* Re: Online conceptual/tutorial material for Ada, was: Re: specification file ads problem
  2014-10-06 22:30             ` Simon Clubley
@ 2014-10-07 18:39               ` Peter Chapin
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Chapin @ 2014-10-07 18:39 UTC (permalink / raw)


On 2014-10-06 18:30, Simon Clubley wrote:

>> Would there possibly be some way of introducing Ada's user defined
>> scalar types earlier?  This would give credit to McCormick's most
>> prominent finding, namely that use of Ada's user defined scalars
>> is a real, non-marketing boost in productivity. In particular, this
>> feature of the Ada language has been found to boost newcomers' results.
>>
> 
> And _that's_ the same reservation I have.
> 
> Ada style user defined datatypes need to be much closer to the start
> of the document. However, I also understand the need not to overwhelm
> the reader with new things.
> 
> How about early examples which show just _one_ of the really simple
> types J-P Rosen mentions and uses (say) Integer for the rest of the
> example ?

Thanks for the feedback on my tutorial. I do agree that talking about
user defined scalar types is important and moving it up makes sense.
I'll definitely look into doing that when I make my updates. That might
be sooner rather than later as I'm teaching Ada in a course at Vermont
Technical College next semester and it might be nice to point the
students to my tutorial as one (of several) resources.

Peter


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

end of thread, other threads:[~2014-10-07 18:39 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-05 15:39 specification file ads problem Stribor40
2014-10-05 16:20 ` mockturtle
2014-10-06 21:34   ` Adam Beneschan
2014-10-05 16:29 ` AdaMagica
2014-10-05 16:32 ` Simon Wright
2014-10-05 17:06   ` Online conceptual/tutorial material for Ada, was: " Simon Clubley
2014-10-05 18:44     ` Niklas Holsti
2014-10-05 19:53     ` Peter Chapin
2014-10-06  7:55       ` Simon Wright
2014-10-06 11:08         ` Peter Chapin
2014-10-06 12:13           ` G.B.
2014-10-06 13:07             ` Peter Chapin
2014-10-06 13:40               ` J-P. Rosen
2014-10-06 22:30             ` Simon Clubley
2014-10-07 18:39               ` Peter Chapin
2014-10-06  8:12     ` Jacob Sparre Andersen

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