comp.lang.ada
 help / color / mirror / Atom feed
* types and non-contigous ranges
@ 2004-02-26 14:17 Erlo Haugen
  2004-02-26 15:52 ` Jacob Sparre Andersen
  2004-02-26 16:07 ` types and non-contigous ranges Dmitry A. Kazakov
  0 siblings, 2 replies; 10+ messages in thread
From: Erlo Haugen @ 2004-02-26 14:17 UTC (permalink / raw)


Hello everyone,
what is the easiest way to define a (sub)type consisting of ranges and 
single values?
Let me give an example:

I want a type, based on character, that contains 'A'..'Z' and '0'..'9'
and some single characters like '�','�' and '�'.

subtype Valid_Characters is character range 'A'..'Z' ????? and what then??


Do I really have list all the values?

-- 
Erlo
-----
Remove underscores from mail address.
The statements and opinions are mine and does not
neccesarily reflect those of my employers




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

* Re: types and non-contigous ranges
  2004-02-26 14:17 types and non-contigous ranges Erlo Haugen
@ 2004-02-26 15:52 ` Jacob Sparre Andersen
  2004-02-27  7:55   ` Erlo Haugen
  2004-02-26 16:07 ` types and non-contigous ranges Dmitry A. Kazakov
  1 sibling, 1 reply; 10+ messages in thread
From: Jacob Sparre Andersen @ 2004-02-26 15:52 UTC (permalink / raw)


Erlo Haugen skrev:

> what is the easiest way to define a (sub)type consisting of ranges
> and single values?

I don't think you can do that.

> Let me give an example:
> 
> I want a type, based on character, that contains 'A'..'Z' and '0'..'9'
> and some single characters like '�','�' and '�'.
> 
> subtype Valid_Characters is character range 'A'..'Z' ????? and what then??

I think you have to declare it as a new enumerated type:

   type Valid_Characters is ('0', '1', '2', ... '9',
                             'A', 'B', 'C', ... '�', '�', '�');

> Do I really have list all the values?

I think so (even though I didn't do it in the example).

Jacob
-- 
"Any, sufficiently advanced, technology is indistinguishable from magic."



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

* Re: types and non-contigous ranges
  2004-02-26 14:17 types and non-contigous ranges Erlo Haugen
  2004-02-26 15:52 ` Jacob Sparre Andersen
@ 2004-02-26 16:07 ` Dmitry A. Kazakov
  2004-02-27  7:53   ` Erlo Haugen
  1 sibling, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2004-02-26 16:07 UTC (permalink / raw)


On Thu, 26 Feb 2004 15:17:38 +0100, Erlo Haugen <_elh_@_tema_._com_>
wrote:

>Hello everyone,
>what is the easiest way to define a (sub)type consisting of ranges and 
>single values?

Only ranges are allowed.

>Let me give an example:
>
>I want a type, based on character, that contains 'A'..'Z' and '0'..'9'
>and some single characters like '�','�' and '�'.
>
>subtype Valid_Characters is character range 'A'..'Z' ????? and what then??
>
>
>Do I really have list all the values?

Take a look at Ada.Strings.Maps and Strings.Maps.Constants. They
provide sets of characters, operations on them and useful constant
sets like Alphanumeric_Set etc. I think that

Whatsoever : constant Character_Set :=
   Decimal_Digit_Set  or
   To_Set (Character_Range'('A', 'Z')) or
   To_Set ('�') or
   To_Set ('�') or
   To_Set ('�');

is what you are looking for.

--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



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

* Re: types and non-contigous ranges
  2004-02-26 16:07 ` types and non-contigous ranges Dmitry A. Kazakov
@ 2004-02-27  7:53   ` Erlo Haugen
  2004-02-27 23:59     ` Randy Brukardt
  0 siblings, 1 reply; 10+ messages in thread
From: Erlo Haugen @ 2004-02-27  7:53 UTC (permalink / raw)


Dmitry A. Kazakov skrev:
> On Thu, 26 Feb 2004 15:17:38 +0100, Erlo Haugen <_elh_@_tema_._com_>
> wrote:
> 
> 
>>Hello everyone,
>>what is the easiest way to define a (sub)type consisting of ranges and 
>>single values?
> 
> 
> Only ranges are allowed.
> 
> 
>>Let me give an example:
>>
>>I want a type, based on character, that contains 'A'..'Z' and '0'..'9'
>>and some single characters like '�','�' and '�'.
>>
>>subtype Valid_Characters is character range 'A'..'Z' ????? and what then??
>>
>>
>>Do I really have list all the values?
> 
> 
> Take a look at Ada.Strings.Maps and Strings.Maps.Constants. They
> provide sets of characters, operations on them and useful constant
> sets like Alphanumeric_Set etc. I think that
> 
> Whatsoever : constant Character_Set :=
>    Decimal_Digit_Set  or
>    To_Set (Character_Range'('A', 'Z')) or
>    To_Set ('�') or
>    To_Set ('�') or
>    To_Set ('�');
> 
> is what you are looking for.

I want to use the set/type like  this:
My_array : array[Valid_Characters] of something;
That excludes the character set, I guess.

-- 
Erlo
-----
Remove underscores from mail address.
The statements and opinions are mine and does not
neccesarily reflect those of my employers




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

* Re: types and non-contigous ranges
  2004-02-26 15:52 ` Jacob Sparre Andersen
@ 2004-02-27  7:55   ` Erlo Haugen
  2004-02-27 13:00     ` Jacob Sparre Andersen
  0 siblings, 1 reply; 10+ messages in thread
From: Erlo Haugen @ 2004-02-27  7:55 UTC (permalink / raw)


Jacob Sparre Andersen skrev:

> Erlo Haugen skrev:
> 
> 
>>what is the easiest way to define a (sub)type consisting of ranges
>>and single values?
> 
> 
> I don't think you can do that.
> 
> 
>>Let me give an example:
>>
>>I want a type, based on character, that contains 'A'..'Z' and '0'..'9'
>>and some single characters like '�','�' and '�'.
>>
>>subtype Valid_Characters is character range 'A'..'Z' ????? and what then??
> 
> 
> I think you have to declare it as a new enumerated type:
> 
>    type Valid_Characters is ('0', '1', '2', ... '9',
>                              'A', 'B', 'C', ... '�', '�', '�');
> 
> 
>>Do I really have list all the values?
> 
> 
> I think so (even though I didn't do it in the example).
After trying and reading, I came to the same conclusion.
But why is it that when i use '�', the compiler says that strings
are delimited by " ? Using UC_AE_Diphthong is OK.
-- 
Erlo
-----
Remove underscores from mail address.
The statements and opinions are mine and does not
neccesarily reflect those of my employers




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

* Re: types and non-contigous ranges
  2004-02-27  7:55   ` Erlo Haugen
@ 2004-02-27 13:00     ` Jacob Sparre Andersen
  2004-02-27 13:21       ` Erlo Haugen
  0 siblings, 1 reply; 10+ messages in thread
From: Jacob Sparre Andersen @ 2004-02-27 13:00 UTC (permalink / raw)


Erlo Haugen skrev:
> Jacob Sparre Andersen skrev:
> > Erlo Haugen skrev:

> >>what is the easiest way to define a (sub)type consisting of ranges
> >>and single values?

> >    type Valid_Characters is ('0', '1', '2', ... '9',
> >                              'A', 'B', 'C', ... '�', '�', '�');

> But why is it that when i use '�', the compiler says that strings
> are delimited by " ? Using UC_AE_Diphthong is OK.

That is probably because you and your compiler aren't in complete
agreement about which character encoding you are using.

If the compiler expects you to use ISO-8859-1 (which is very likely)
and you are actually using UTF-8 (which I would guess from the error
message), then the compiler will not read what you see as "�" as "�"
but as a sequence of two other characters.

Jacob
-- 
Rent-a-Minion Inc. Because good help is so hard to find.




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

* Re: types and non-contigous ranges
  2004-02-27 13:00     ` Jacob Sparre Andersen
@ 2004-02-27 13:21       ` Erlo Haugen
  2004-02-27 13:58         ` Character encoding (Was: types and non-contigous ranges) Jacob Sparre Andersen
  0 siblings, 1 reply; 10+ messages in thread
From: Erlo Haugen @ 2004-02-27 13:21 UTC (permalink / raw)


Jacob Sparre Andersen skrev:

> Erlo Haugen skrev:
> 
>>Jacob Sparre Andersen skrev:
>>
>>>Erlo Haugen skrev:
> 
> 
>>>>what is the easiest way to define a (sub)type consisting of ranges
>>>>and single values?
> 
> 
>>>   type Valid_Characters is ('0', '1', '2', ... '9',
>>>                             'A', 'B', 'C', ... '�', '�', '�');
> 
> 
>>But why is it that when i use '�', the compiler says that strings
>>are delimited by " ? Using UC_AE_Diphthong is OK.
> 
> 
> That is probably because you and your compiler aren't in complete
> agreement about which character encoding you are using.
> 
> If the compiler expects you to use ISO-8859-1 (which is very likely)
> and you are actually using UTF-8 (which I would guess from the error
> message), then the compiler will not read what you see as "�" as "�"
> but as a sequence of two other characters.
> 
In the source ??

type Valid_Characters is ('0', '1', '2', ... '9',
                           'A', 'B', 'C', ... '�'); <<<<-----this is 
where I get the error.
How do I get in sync with the compilers idea of which encoding we use??


-- 
Erlo
-----
Remove underscores from mail address.
The statements and opinions are mine and does not
neccesarily reflect those of my employers




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

* Character encoding (Was: types and non-contigous ranges)
  2004-02-27 13:21       ` Erlo Haugen
@ 2004-02-27 13:58         ` Jacob Sparre Andersen
  0 siblings, 0 replies; 10+ messages in thread
From: Jacob Sparre Andersen @ 2004-02-27 13:58 UTC (permalink / raw)


Erlo Haugen skrev:
> Jacob Sparre Andersen skrev:

> > That is probably because you and your compiler aren't in complete
> > agreement about which character encoding you are using.  If the
> > compiler expects you to use ISO-8859-1 (which is very likely) and
> > you are actually using UTF-8 (which I would guess from the error
> > message), then the compiler will not read what you see as "�" as
> > "�" but as a sequence of two other characters.
>
> In the source?

Yes.

> type Valid_Characters is ('0', '1', '2', ... '9',
>                            'A', 'B', 'C', ... '�'); <<<<-----this is
> where I get the error.

Yes.

> How do I get in sync with the compilers idea of which encoding we
> use?

It depends on which compiler you use.

If you are working on a Unix system, I think the command `locale`
should reveal which character encoding your system in general uses
(for your account).

If you use GNAT as you compiler, then it as the standard expects the
code to be coded in ISO-8859-1, but there are command line argumente
for making it work with other encodings.  I think it is the "-gnati?"
flags, but I am not sure, and I can't find a copy of the GNAT manual.

Jacob
-- 
�Fuck amerikansk kulturimperialisme!� - graffiti p� N�rrebro



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

* Re: types and non-contigous ranges
  2004-02-27  7:53   ` Erlo Haugen
@ 2004-02-27 23:59     ` Randy Brukardt
  2004-03-01  8:50       ` Erlo Haugen
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Brukardt @ 2004-02-27 23:59 UTC (permalink / raw)


"Erlo Haugen" <_elh_@_tema_._com_> wrote in message
news:403ef778$0$128$edfadb0f@dread11.news.tele.dk...
> I want to use the set/type like  this:
> My_array : array[Valid_Characters] of something;
> That excludes the character set, I guess.

No, that excludes using an array. :-)

There is no such thing as discontiguous ranges in Ada; you'll have to create
it yourself somehow. Ada.Strings.Maps is the easiest way for this particular
case. For the array, I'd just make it an array (Character) of something, and
just not use the 'invalid' slots. It's hardly worth the effort to do
anything else unless "something" is very large.

               Randy.






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

* Re: types and non-contigous ranges
  2004-02-27 23:59     ` Randy Brukardt
@ 2004-03-01  8:50       ` Erlo Haugen
  0 siblings, 0 replies; 10+ messages in thread
From: Erlo Haugen @ 2004-03-01  8:50 UTC (permalink / raw)


Randy Brukardt skrev:
> "Erlo Haugen" <_elh_@_tema_._com_> wrote in message
> news:403ef778$0$128$edfadb0f@dread11.news.tele.dk...
> 
>>I want to use the set/type like  this:
>>My_array : array[Valid_Characters] of something;
>>That excludes the character set, I guess.
> 
> 
> No, that excludes using an array. :-)
> 
> There is no such thing as discontiguous ranges in Ada; you'll have to create
> it yourself somehow. Ada.Strings.Maps is the easiest way for this particular
> case. For the array, I'd just make it an array (Character) of something, and
> just not use the 'invalid' slots. It's hardly worth the effort to do
> anything else unless "something" is very large.
> 
That was my conclusion too. So I create an array(character) of whatever 
and put empty (null) values in the unused positions.
It just seems like a "Non-Ada-ish" way..

-- 
Erlo
-----
Remove underscores from mail address.
The statements and opinions are mine and does not
neccesarily reflect those of my employers




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

end of thread, other threads:[~2004-03-01  8:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-26 14:17 types and non-contigous ranges Erlo Haugen
2004-02-26 15:52 ` Jacob Sparre Andersen
2004-02-27  7:55   ` Erlo Haugen
2004-02-27 13:00     ` Jacob Sparre Andersen
2004-02-27 13:21       ` Erlo Haugen
2004-02-27 13:58         ` Character encoding (Was: types and non-contigous ranges) Jacob Sparre Andersen
2004-02-26 16:07 ` types and non-contigous ranges Dmitry A. Kazakov
2004-02-27  7:53   ` Erlo Haugen
2004-02-27 23:59     ` Randy Brukardt
2004-03-01  8:50       ` Erlo Haugen

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