comp.lang.ada
 help / color / mirror / Atom feed
* Why is this not legal
@ 2009-09-29  0:11 Rob Solomon
  2009-09-29  0:23 ` Adam Beneschan
  2009-09-30  8:39 ` Martin Krischik
  0 siblings, 2 replies; 6+ messages in thread
From: Rob Solomon @ 2009-09-29  0:11 UTC (permalink / raw)


I am trying to write some simple string manipulations but am getting
an error I don't understand.

  type WordEntryType is String(1..MaxLineLength);

This is flagged as not legal.  GNAT want it to read 
IS NEW String

But that means the type is not a standard string.

What am I missing?

Thanks



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

* Re: Why is this not legal
  2009-09-29  0:11 Why is this not legal Rob Solomon
@ 2009-09-29  0:23 ` Adam Beneschan
  2009-09-29  2:06   ` Rob Solomon
  2009-10-01 20:54   ` Keith Thompson
  2009-09-30  8:39 ` Martin Krischik
  1 sibling, 2 replies; 6+ messages in thread
From: Adam Beneschan @ 2009-09-29  0:23 UTC (permalink / raw)


On Sep 28, 5:11 pm, Rob Solomon <use...@drrob1-noreply.com> wrote:
> I am trying to write some simple string manipulations but am getting
> an error I don't understand.
>
>   type WordEntryType is String(1..MaxLineLength);
>
> This is flagged as not legal.  GNAT want it to read
> IS NEW String
>
> But that means the type is not a standard string.
>
> What am I missing?

The three letters "sub" in front of the keyword "type".

TYPE declarations always create a new type.  SUBTYPE declarations will
declare an identifier that refers to the same *type*, but puts
additional constraints on it.  But if you use a SUBTYPE declaration,
and you declare something of type

  X : WordEntryType;

then X's *type* will be STRING and you can pass it to procedures that
require a STRING parameter.

If this is still confusing to you, then I'd say you need to go back
and read some more about Ada's type system.  This is an important
feature of Ada that distinguishes it from C, Pascal, and possibly
Modula (I don't know Modula well enough to say), and any decent
introductory book on Ada should have a good exposition of this
concept.

                               -- Adam




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

* Re: Why is this not legal
  2009-09-29  0:23 ` Adam Beneschan
@ 2009-09-29  2:06   ` Rob Solomon
  2009-10-01 20:54   ` Keith Thompson
  1 sibling, 0 replies; 6+ messages in thread
From: Rob Solomon @ 2009-09-29  2:06 UTC (permalink / raw)


>On Sep 28, 5:11�pm, Rob Solomon <use...@drrob1-noreply.com> wrote:
>> I am trying to write some simple string manipulations but am getting
>> an error I don't understand.
>>
>> � type WordEntryType is String(1..MaxLineLength);
>>
>> This is flagged as not legal. �GNAT want it to read
>> IS NEW String
>>
>> But that means the type is not a standard string.
>>
>> What am I missing?
>
>The three letters "sub" in front of the keyword "type".
>
>TYPE declarations always create a new type.  SUBTYPE declarations will
>declare an identifier that refers to the same *type*, but puts
>additional constraints on it.  But if you use a SUBTYPE declaration,
>and you declare something of type
>
>  X : WordEntryType;
>
>then X's *type* will be STRING and you can pass it to procedures that
>require a STRING parameter.
>
>If this is still confusing to you, then I'd say you need to go back
>and read some more about Ada's type system.  This is an important
>feature of Ada that distinguishes it from C, Pascal, and possibly
>Modula (I don't know Modula well enough to say), and any decent
>introductory book on Ada should have a good exposition of this
>concept.
>
>                               -- Adam

That worked.  Thanks.

I find it confusing when I need a type vs subtype.  Modula-2 does not
have the subtype concept; it probably could use it though.

And your comment that a subtype adds constraints to a type also helps.

--rob



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

* Re: Why is this not legal
  2009-09-30  8:39 ` Martin Krischik
@ 2009-09-30  5:10   ` stefan-lucks
  0 siblings, 0 replies; 6+ messages in thread
From: stefan-lucks @ 2009-09-30  5:10 UTC (permalink / raw)


While the question has been answered, and the wikibook is a good 
reference, this appears to be a frequently asked question. Obviously, 
GNAT's error message in this case ("missing new") is leading beginners
into the wrong direction. 

Stefan

On Wed, 30 Sep 2009, Martin Krischik wrote:

> Rob Solomon schrieb:
> > I am trying to write some simple string manipulations but am getting
> > an error I don't understand.
> > 
> >   type WordEntryType is String(1..MaxLineLength);
> > 
> > This is flagged as not legal.  GNAT want it to read 
> > IS NEW String
> > 
> > But that means the type is not a standard string.
> > 
> > What am I missing?
> 
> The question has been answered but for more info see:
> 
> http://en.wikibooks.org/wiki/Ada_Programming/Type_System
> 
> ;-)
> 
> Martin
> 

-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




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

* Re: Why is this not legal
  2009-09-29  0:11 Why is this not legal Rob Solomon
  2009-09-29  0:23 ` Adam Beneschan
@ 2009-09-30  8:39 ` Martin Krischik
  2009-09-30  5:10   ` stefan-lucks
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Krischik @ 2009-09-30  8:39 UTC (permalink / raw)


Rob Solomon schrieb:
> I am trying to write some simple string manipulations but am getting
> an error I don't understand.
> 
>   type WordEntryType is String(1..MaxLineLength);
> 
> This is flagged as not legal.  GNAT want it to read 
> IS NEW String
> 
> But that means the type is not a standard string.
> 
> What am I missing?

The question has been answered but for more info see:

http://en.wikibooks.org/wiki/Ada_Programming/Type_System

;-)

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: Why is this not legal
  2009-09-29  0:23 ` Adam Beneschan
  2009-09-29  2:06   ` Rob Solomon
@ 2009-10-01 20:54   ` Keith Thompson
  1 sibling, 0 replies; 6+ messages in thread
From: Keith Thompson @ 2009-10-01 20:54 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> writes:
[...]
> TYPE declarations always create a new type.  SUBTYPE declarations will
> declare an identifier that refers to the same *type*, but puts
> additional constraints on it.
[...]

Small correction: a subtype declaration may or may not add additional
constraints.  For example:

subtype My_String is String;

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



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

end of thread, other threads:[~2009-10-01 20:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-29  0:11 Why is this not legal Rob Solomon
2009-09-29  0:23 ` Adam Beneschan
2009-09-29  2:06   ` Rob Solomon
2009-10-01 20:54   ` Keith Thompson
2009-09-30  8:39 ` Martin Krischik
2009-09-30  5:10   ` stefan-lucks

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