comp.lang.ada
 help / color / mirror / Atom feed
* Re: if X in 1..35000 versus Boolean
  2002-07-13 19:10 Jan Prazak
@ 2002-07-13 16:27 ` Frank J. Lhota
  2002-07-13 20:36   ` Jan Prazak
  2002-07-13 16:32 ` David C. Hoos, Sr.
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 37+ messages in thread
From: Frank J. Lhota @ 2002-07-13 16:27 UTC (permalink / raw)


> if X in 1..35000 then
>
> is the same as
>
> if (X >= 1) and (X <= 35000) then
>
> ???
>
> Or does the compiler really create an enumeration type with 35000 entries
> with values from 1 to 35000, just to check if X is in there???

Yes, every compiler I know of will evaluate

    X in 1 .. 35000

as

    X >= 1 and then x <= 35000

Also, 1 .. 35000 is an integer range, not an enumeration type.







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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 19:10 Jan Prazak
  2002-07-13 16:27 ` Frank J. Lhota
@ 2002-07-13 16:32 ` David C. Hoos, Sr.
  2002-07-13 20:36   ` Jan Prazak
  2002-07-13 16:44 ` Christopher Browne
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 37+ messages in thread
From: David C. Hoos, Sr. @ 2002-07-13 16:32 UTC (permalink / raw)


Jan,

Some questions for you:
  1.  What does any of the code you supplied have to do
      with any enumeration type?

  2.  Why don't you compile your file to generate assembly
      language output, and see for yourself what the
      compiler does?

----- Original Message ----- 
From: "Jan Prazak" <janp9@gmx.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: July 13, 2002 2:10 PM
Subject: if X in 1..35000 versus Boolean


> Hello,
> 
> I have a simple question:
> 
> does the compiler (I am using GNAT) "see", that
> 
> if X in 1..35000 then
> 
> is the same as
> 
> if (X >= 1) and (X <= 35000) then
> 
> ???
> 
> Or does the compiler really create an enumeration type with 35000 entries
> with values from 1 to 35000, just to check if X is in there???
> 
> Jan
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 





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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 19:10 Jan Prazak
  2002-07-13 16:27 ` Frank J. Lhota
  2002-07-13 16:32 ` David C. Hoos, Sr.
@ 2002-07-13 16:44 ` Christopher Browne
  2002-07-13 22:09   ` Robert Dewar
  2002-07-13 17:17 ` tmoran
  2002-07-13 19:44 ` Florian Weimer
  4 siblings, 1 reply; 37+ messages in thread
From: Christopher Browne @ 2002-07-13 16:44 UTC (permalink / raw)


The world rejoiced as Jan Prazak <janp9@gmx.net> wrote:
> Hello,
>
> I have a simple question:
>
> does the compiler (I am using GNAT) "see", that
> 	if X in 1..35000 then
>
> is the same as
> 	if (X >= 1) and (X <= 35000) then
>
> ???
>
> Or does the compiler really create an enumeration type with 35000 entries
> with values from 1 to 35000, just to check if X is in there???

I just changed a "if (fsm < proposal) and ..otherstuff.."  to "if (fsm
in 1..proposal) and ...otherstuff..." in a prime number sieve.

The size of the object code increased by 20 bytes, so it evidently
changed _something_.  I'll bet that it created an anonymous
enumeration type, and that some extra code is describing/referencing
that.

But it appears that optimization does The Right Thing so that the
result amounts to "X in 1..35000" ultimately being transformed into
something rather resembling "(X >= 1) and (X <= 35000)".
-- 
(concatenate 'string "cbbrowne" "@cbbrowne.com")
http://www3.sympatico.ca/cbbrowne/pascal.html
The IETF motto: "Rough consensus *and* working code."



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

* re: if X in 1..35000 versus Boolean
  2002-07-13 19:10 Jan Prazak
                   ` (2 preceding siblings ...)
  2002-07-13 16:44 ` Christopher Browne
@ 2002-07-13 17:17 ` tmoran
  2002-07-13 19:44 ` Florian Weimer
  4 siblings, 0 replies; 37+ messages in thread
From: tmoran @ 2002-07-13 17:17 UTC (permalink / raw)


> Or does the compiler really ...
Reason thusly:
The compiler could do A or B with similar ease.  Both give the right
answer.  A is efficient.  B is unusably inefficient.  If I was a compiler
writer who wanted his compiler to be used, which would I choose?



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 20:36   ` Jan Prazak
@ 2002-07-13 18:02     ` David C. Hoos, Sr.
  2002-07-13 18:17     ` sk
       [not found]     ` <3D306ED5.33E80E09@myob.com>
  2 siblings, 0 replies; 37+ messages in thread
From: David C. Hoos, Sr. @ 2002-07-13 18:02 UTC (permalink / raw)



----- Original Message ----- 
From: "Jan Prazak" <janp9@gmx.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: July 13, 2002 3:36 PM
Subject: Re: if X in 1..35000 versus Boolean


> On Sat, 13 Jul 2002 15:32:19 -0100, David C. Hoos, Sr. wrote:
> 
> > Jan,
> > 
> > Some questions for you:
> >   1.  What does any of the code you supplied have to do
> >       with any enumeration type?
> 
> See my second posting (reply).
Note: Section 4.5.2 (2) of the Ada Reference Manual says:
A membership test, using in or not in, determines whether or not a value
belongs to a given subtype or range, or has a tag that identifies a type
that is covered by a given type. Membership tests are allowed for all types.

The expression 1 .. 3500 declares an integer range, _not_ an enumeration.

> 
> > 
> >   2.  Why don't you compile your file to generate assembly
> >       language output, and see for yourself what the compiler does?
> > 
> 
> I know only basics of Assembler, so this would be pointless in my case.
The point would be that you might learn more about Assembler, Ada, and
programming in general, if you did as I suggest.
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 





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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 20:36   ` Jan Prazak
@ 2002-07-13 18:05     ` Jeffrey Carter
  2002-07-14 15:02       ` Jan Prazak
  2002-07-13 22:10     ` Robert Dewar
  2002-07-16  8:18     ` Keith Thompson
  2 siblings, 1 reply; 37+ messages in thread
From: Jeffrey Carter @ 2002-07-13 18:05 UTC (permalink / raw)


Jan Prazak wrote:
> 
> But the word "in" tests, if given object (variable...) is
> in given enumeration type.

No, it doesn't. "in" checks for subtype membership. It is defined for
ALL types.

X in 1 .. 35_000

checks for membership of the value of X in an anonymous subtype. But you
can also write things like

type C is (Red, Yellow, Blue);

type R (D : C) is record ...

subtype RC is R (D => Yellow);

function F return C is ...

V : R (D => F);

if V in RC ...

-- 
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 20:36   ` Jan Prazak
  2002-07-13 18:02     ` David C. Hoos, Sr.
@ 2002-07-13 18:17     ` sk
  2002-07-13 20:02       ` Jeffrey Creem
       [not found]     ` <3D306ED5.33E80E09@myob.com>
  2 siblings, 1 reply; 37+ messages in thread
From: sk @ 2002-07-13 18:17 UTC (permalink / raw)



Hi,

> I know only basics of Assembler, so this would be pointless in my case.

Pointless ?

---------------------------------------------------
procedure xxx is
begin
    Loop_Name : for i in 1 .. 1000 loop
        null;
    end loop Loop_Name;
end xxx;

---------------------------------------------------
gcc -S -c xxx.adb (Linux, Gnat 3.13p)

---------------------------------------------------
	.file	"xxx.adb"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl _ada_xxx
	.type	 _ada_xxx,@function
_ada_xxx:                          -- Set up
	pushl %ebp
	movl %esp,%ebp             <-- Set base to stack 
	subl $4,%esp               <-- Decrement stack 4 bytes for loop
variable
	movl $1,-4(%ebp)           <-- Set loop variable to 1
.L2:
	cmpl $1000,-4(%ebp)        <-- Is the loop variable = 1000 ?
	jle .L5                    <-- No, variable is less than 1000, jump
to .L5
	jmp .L3                    <-- Yes, jump to .L3
	.align 4
.L5:
	jmp .L4                    <-- Jump to .L4
	.align 4
	jmp .L3
	.align 4
.L6:
.L4:
	incl -4(%ebp)              <-- Increment the loop counter
	jmp .L2                    <-- Go to beginning of loop
	.align 4
.L3:
	jmp .L1                    <-- Ok, finished
	.align 4
.L1:                               -- Clean up
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 _ada_xxx,.Lfe1-_ada_xxx
	.ident	"GCC: (GNU) 2.8.1"

---------------------------------------------------
Play with the Ada code by changing the "x in 1 .. 1000" to 
"x in 5 .. 57" for example, and look at the resultant 
assembly listing.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: if X in 1..35000 versus Boolean
       [not found]     ` <3D306ED5.33E80E09@myob.com>
@ 2002-07-13 18:52       ` David C. Hoos, Sr.
       [not found]       ` <020a01c22a9f$2b50d6c0$6400000a@dhoos>
  1 sibling, 0 replies; 37+ messages in thread
From: David C. Hoos, Sr. @ 2002-07-13 18:52 UTC (permalink / raw)



----- Original Message ----- 
From: "sk" <noname@myob.com>
To: <comp.lang.ada@ada.eu.org>
Sent: July 13, 2002 1:17 PM
Subject: Re: if X in 1..35000 versus Boolean
<snip>

You should have said
> cmpl $1000,-4(%ebp)        <-- Compare loop variable to 1000
> jle .L5                    <-- If less than or equalto 1000, jump to .L5
> to .L5
> jmp .L3                    <-- It's > 1000, jump to .L3
<snip>





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

* Re: if X in 1..35000 versus Boolean
       [not found]       ` <020a01c22a9f$2b50d6c0$6400000a@dhoos>
@ 2002-07-13 19:02         ` sk
  2002-07-14 15:02           ` Jan Prazak
  0 siblings, 1 reply; 37+ messages in thread
From: sk @ 2002-07-13 19:02 UTC (permalink / raw)


Hi,

"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
> You should have said ...

JLE, jump less or equal, sorry

My goal was to try and show that an assembly dump
was not particularly intimidating.

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* if X in 1..35000 versus Boolean
@ 2002-07-13 19:10 Jan Prazak
  2002-07-13 16:27 ` Frank J. Lhota
                   ` (4 more replies)
  0 siblings, 5 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-13 19:10 UTC (permalink / raw)


Hello,

I have a simple question:

does the compiler (I am using GNAT) "see", that

	if X in 1..35000 then

is the same as

	if (X >= 1) and (X <= 35000) then

???

Or does the compiler really create an enumeration type with 35000 entries
with values from 1 to 35000, just to check if X is in there???

Jan




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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 19:10 Jan Prazak
                   ` (3 preceding siblings ...)
  2002-07-13 17:17 ` tmoran
@ 2002-07-13 19:44 ` Florian Weimer
  4 siblings, 0 replies; 37+ messages in thread
From: Florian Weimer @ 2002-07-13 19:44 UTC (permalink / raw)


Jan Prazak <janp9@gmx.net> writes:

> does the compiler (I am using GNAT) "see", that
>
> 	if X in 1..35000 then
>
> is the same as
>
> 	if (X >= 1) and (X <= 35000) then
>
> ???

Yes, if X is a variable.  If X is a function, it can make a difference
if the function is called once or twice.



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 18:17     ` sk
@ 2002-07-13 20:02       ` Jeffrey Creem
  0 siblings, 0 replies; 37+ messages in thread
From: Jeffrey Creem @ 2002-07-13 20:02 UTC (permalink / raw)


Note that for anthing bigger than a trival program, it is often easier to
use objdump so you
can see the source code intermixed in the assembly code (perhaps this can be
done in
one step with gcc as well but I tend to use the approach below since it
follows
the ada xxx.ads, a.das xxx paradigm I got used to with VADS many years back
now).

For example (with the previous sample code):
gcc -c -O3 -g xxx.adb

C:\Documents and Settings\jcreem\Desktop>objdump --disassemble --source
xxx.o

xxx.o:     file format pe-i386

Disassembly of section .text:

00000000 <__ada_xxx>:
   0:   55              pushl  %ebp
begin
Loop_Name : for i in 1 .. 1000 loop
   1:   b8 e7 03 00 00  movl   $0x3e7,%eax
   6:   89 e5           movl   %esp,%ebp
   8:   48              decl   %eax
   9:   79 fd           jns    8 <__ada_xxx+8>
   b:   89 ec           movl   %ebp,%esp
   d:   5d              popl   %ebp
   e:   c3              ret
   f:   90              nop


(If you want that boring program to be even easier to understand, omit the
frame pointer and then
there are no "surprise" instructions there (suprise for a non assembly
person)

C:\Documents and Settings\jcreem\Desktop>gcc -c -O3 -g -fomit-frame-pointer
xxx.
adb

C:\Documents and Settings\jcreem\Desktop>objdump --disassemble --source
xxx.o

xxx.o:     file format pe-i386

Disassembly of section .text:

00000000 <__ada_xxx>:
begin
Loop_Name : for i in 1 .. 1000 loop
   0:   b8 e7 03 00 00  movl   $0x3e7,%eax
   5:   90              nop
   6:   48              decl   %eax
   7:   79 fd           jns    6 <__ada_xxx+6>
   9:   c3              ret
   a:   89 f6           movl   %esi,%esi


"sk" <noname@myob.com> wrote in message
news:mailman.1026584402.3884.comp.lang.ada@ada.eu.org...
>
> Hi,
>
> > I know only basics of Assembler, so this would be pointless in my case.
>
> Pointless ?
>
> ---------------------------------------------------
> procedure xxx is
> begin
>     Loop_Name : for i in 1 .. 1000 loop
>         null;
>     end loop Loop_Name;
> end xxx;
>
> ---------------------------------------------------
> gcc -S -c xxx.adb (Linux, Gnat 3.13p)
>
> ---------------------------------------------------
> .file "xxx.adb"
> .version "01.01"
> gcc2_compiled.:
> .text
> .align 4
> .globl _ada_xxx
> .type _ada_xxx,@function
> _ada_xxx:                          -- Set up
> pushl %ebp
> movl %esp,%ebp             <-- Set base to stack
> subl $4,%esp               <-- Decrement stack 4 bytes for loop
> variable
> movl $1,-4(%ebp)           <-- Set loop variable to 1
> .L2:
> cmpl $1000,-4(%ebp)        <-- Is the loop variable = 1000 ?
> jle .L5                    <-- No, variable is less than 1000, jump
> to .L5
> jmp .L3                    <-- Yes, jump to .L3
> .align 4
> .L5:
> jmp .L4                    <-- Jump to .L4
> .align 4
> jmp .L3
> .align 4
> .L6:
> .L4:
> incl -4(%ebp)              <-- Increment the loop counter
> jmp .L2                    <-- Go to beginning of loop
> .align 4
> .L3:
> jmp .L1                    <-- Ok, finished
> .align 4
> .L1:                               -- Clean up
> movl %ebp,%esp
> popl %ebp
> ret
> .Lfe1:
> .size _ada_xxx,.Lfe1-_ada_xxx
> .ident "GCC: (GNU) 2.8.1"
>
> ---------------------------------------------------
> Play with the Ada code by changing the "x in 1 .. 1000" to
> "x in 5 .. 57" for example, and look at the resultant
> assembly listing.
>
> --
> -------------------------------------
> -- Merge vertically for real address
> -------------------------------------
> s n p @ t . o
>  k i e k c c m
> -------------------------------------





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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 16:27 ` Frank J. Lhota
@ 2002-07-13 20:36   ` Jan Prazak
  2002-07-13 18:05     ` Jeffrey Carter
                       ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-13 20:36 UTC (permalink / raw)


On Sat, 13 Jul 2002 15:27:03 -0100, Frank J. Lhota wrote:


> Also, 1 .. 35000 is an integer range, not an enumeration type.

But the word "in" tests, if given object (variable...) is
in given enumeration type.

type num : (1, 2, 3, 4);

if 3 in num then ...

-- this should be the same as: if 3 in (1,2,3,4);
-- and also the same as: if 3 in 1..4;

So I assume that "if X in 1..35000" has the same rules.




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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 16:32 ` David C. Hoos, Sr.
@ 2002-07-13 20:36   ` Jan Prazak
  2002-07-13 18:02     ` David C. Hoos, Sr.
                       ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-13 20:36 UTC (permalink / raw)


On Sat, 13 Jul 2002 15:32:19 -0100, David C. Hoos, Sr. wrote:

> Jan,
> 
> Some questions for you:
>   1.  What does any of the code you supplied have to do
>       with any enumeration type?

See my second posting (reply).

> 
>   2.  Why don't you compile your file to generate assembly
>       language output, and see for yourself what the compiler does?
> 

I know only basics of Assembler, so this would be pointless in my case.




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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 16:44 ` Christopher Browne
@ 2002-07-13 22:09   ` Robert Dewar
  0 siblings, 0 replies; 37+ messages in thread
From: Robert Dewar @ 2002-07-13 22:09 UTC (permalink / raw)


Christopher Browne <cbbrowne@acm.org> wrote in message news:<agpld4$niq17$1@ID-125932.news.dfncis.de>...
> The size of the object code increased by 20 bytes, so it 
> evidently changed _something_.  I'll bet that it created 
> an anonymous enumeration type, and that some extra code 
> is describing/referencing that.

As more than one person has pointed out, there is no
enumeration type in sight (your understanding of enumeration types is
quite flawed, as shown by your
example, you might want to get hold of an online Ada
tutorial to learn about these matters).

As for the extra code you are adding a test, your original
only tests an upper bound so of course testing both bounds
takes more.

Though very little more with a decent compiler. If you really got 20
bytes more, then either you have a junk
compiler, or you are misusing the compiler you have (e.g.
running in -O0 mode with GNAT, which is of course ludicrous if you are
interested in reducing the amount of generated
code :-)



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 20:36   ` Jan Prazak
  2002-07-13 18:05     ` Jeffrey Carter
@ 2002-07-13 22:10     ` Robert Dewar
  2002-07-14 21:16       ` Jan Prazak
  2002-07-16  8:18     ` Keith Thompson
  2 siblings, 1 reply; 37+ messages in thread
From: Robert Dewar @ 2002-07-13 22:10 UTC (permalink / raw)


Jan Prazak <janp9@gmx.net> wrote in message news:<pan.2002.07.13.19.33.33.634009.1168@gmx.net>...

> type num : (1, 2, 3, 4);

I have no idea what this is supposed to be, but it is not
even a reasonable approximation of an Ada type declaration.

> -- this should be the same as: if 3 in (1,2,3,4);

This is not even vaguely Ada, the right operand of a
membership test cannot be an aggregate



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 19:02         ` sk
@ 2002-07-14 15:02           ` Jan Prazak
  2002-07-14 19:25             ` Darren New
  0 siblings, 1 reply; 37+ messages in thread
From: Jan Prazak @ 2002-07-14 15:02 UTC (permalink / raw)


Thanks, but the only thing that could help me is

> cmpl $1000,-4(%ebp)        <-- Compare loop variable to 1000
> jle .L5                    <-- If less than or equalto 1000, jump
...

because I know nothing of Assembler stacks etc., so I don't understand
things like:

movl %esp,%ebp       <-- Set base to stack 
subl $4,%esp         <-- Decrement stack 4 bytes for loop variable

But I am programming in a high-level language, so there is mostly no need
to know anything about Assembler, but it could help sometimes, of course.




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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 18:05     ` Jeffrey Carter
@ 2002-07-14 15:02       ` Jan Prazak
  0 siblings, 0 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-14 15:02 UTC (permalink / raw)


On Sat, 13 Jul 2002 17:05:33 -0100, Jeffrey Carter wrote:


> No, it doesn't. "in" checks for subtype membership. It is defined for
> ALL types.

ok, then I have misunderstood something




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

* Re: if X in 1..35000 versus Boolean
  2002-07-14 15:02           ` Jan Prazak
@ 2002-07-14 19:25             ` Darren New
  2002-07-15 15:22               ` Steffen Huber
  0 siblings, 1 reply; 37+ messages in thread
From: Darren New @ 2002-07-14 19:25 UTC (permalink / raw)


Jan Prazak wrote:
> But I am programming in a high-level language, so there is mostly no need
> to know anything about Assembler, but it could help sometimes, of course.

It's probably a good idea to learn (eventually) at least one fairly simple
assembler/machine language. Something like a 68000, 8080, or one of the
older machines where the machine code was designed to be comprehensible to
mere mortals. Even tho there's a lot of new stuff going on, it'll help you
understand what a base pointer is, what a stack is, what an exception is,
and so on. Especially when you start getting into questions of "is this
efficient" and such.

Of course, moving on to processors that can implement virtual memory and
multi-user programming would help in most cases too.

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
** http://home.san.rr.com/dnew/DNResume.html **
** http://images.fbrtech.com/dnew/ **

 Proud to live in a country where "fashionable" 
     is denim, "stone-washed" faded, with rips.



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

* Re: if X in 1..35000 versus Boolean
@ 2002-07-14 20:22 Gautier direct_replies_not_read
  2002-07-15 11:36 ` Jan Prazak
  0 siblings, 1 reply; 37+ messages in thread
From: Gautier direct_replies_not_read @ 2002-07-14 20:22 UTC (permalink / raw)


Jan Prazak:

> >> type num : (1, 2, 3, 4);

>Maybe it's not the right syntax in Ada, because I haven't tested it,
>but this would work in Pascal and it should be quite similar in Ada
>(I am still reading my first Ada tutorial).

Did you test your Pascal assumptions ?...
At least I get under Turbo Pascal 6 and Delphi 6, for

program test; type t1234 = (1,2,3,4); begin end.
                            ^
Identifier expected.
____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




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

* Re: if X in 1..35000 versus Boolean
  2002-07-14 21:16       ` Jan Prazak
@ 2002-07-14 20:47         ` Frank J. Lhota
  2002-07-15  1:21         ` Jeffrey Carter
  1 sibling, 0 replies; 37+ messages in thread
From: Frank J. Lhota @ 2002-07-14 20:47 UTC (permalink / raw)



"Jan Prazak" <janp9@gmx.net> wrote in message
news:pan.2002.07.14.14.12.54.200318.1481@gmx.net...
> On Sat, 13 Jul 2002 21:10:40 -0100, Robert Dewar wrote:
>
> > Jan Prazak <janp9@gmx.net> wrote in message
> > news:<pan.2002.07.13.19.33.33.634009.1168@gmx.net>...
> >
> >> type num : (1, 2, 3, 4);
> > I have no idea what this is supposed to be, but it is not even a
> > reasonable approximation of an Ada type declaration.
>
> Maybe it's not the right syntax in Ada, because I haven't tested it, but
> this would work in Pascal and it should be quite similar in Ada

I do not know of ANY language where an enummeration type is defined this
way. The issue is not so much syntax as it is that 1, 2, 3 etc. are not
enumeration literals. Have you actually tried this in Pascal?






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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 22:10     ` Robert Dewar
@ 2002-07-14 21:16       ` Jan Prazak
  2002-07-14 20:47         ` Frank J. Lhota
  2002-07-15  1:21         ` Jeffrey Carter
  0 siblings, 2 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-14 21:16 UTC (permalink / raw)


On Sat, 13 Jul 2002 21:10:40 -0100, Robert Dewar wrote:

> Jan Prazak <janp9@gmx.net> wrote in message
> news:<pan.2002.07.13.19.33.33.634009.1168@gmx.net>...
> 
>> type num : (1, 2, 3, 4);
> I have no idea what this is supposed to be, but it is not even a
> reasonable approximation of an Ada type declaration.

Maybe it's not the right syntax in Ada, because I haven't tested it, but
this would work in Pascal and it should be quite similar in Ada (I am
still reading my first Ada tutorial).




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

* Re: if X in 1..35000 versus Boolean
  2002-07-14 21:16       ` Jan Prazak
  2002-07-14 20:47         ` Frank J. Lhota
@ 2002-07-15  1:21         ` Jeffrey Carter
  1 sibling, 0 replies; 37+ messages in thread
From: Jeffrey Carter @ 2002-07-15  1:21 UTC (permalink / raw)


Jan Prazak wrote:
> 
> On Sat, 13 Jul 2002 21:10:40 -0100, Robert Dewar wrote:
> 
> > Jan Prazak <janp9@gmx.net> wrote in message
> > news:<pan.2002.07.13.19.33.33.634009.1168@gmx.net>...
> >
> >> type num : (1, 2, 3, 4);
> > I have no idea what this is supposed to be, but it is not even a
> > reasonable approximation of an Ada type declaration.
> 
> Maybe it's not the right syntax in Ada, because I haven't tested it, but
> this would work in Pascal and it should be quite similar in Ada (I am
> still reading my first Ada tutorial).

Not in any dialect of Pascal I've ever seen. You can (probably) have

type Num = 1 .. 4;

or

type Num = (One, Two, Three, Four);

(I say "probably" because I don't have a Pascal compiler available, and
it's been some time since I used Pascal.)

The equivalents in Ada are

subtype Num is Integer range 1 .. 4;

and

type Num is (One, Two, Three, Four);

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail



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

* Re: if X in 1..35000 versus Boolean
  2002-07-14 20:22 if X in 1..35000 versus Boolean Gautier direct_replies_not_read
@ 2002-07-15 11:36 ` Jan Prazak
  0 siblings, 0 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-15 11:36 UTC (permalink / raw)


On Sun, 14 Jul 2002 19:22:26 -0100, Gautier direct_replies_not_read wrote:

> Did you test your Pascal assumptions ?... At least I get under Turbo
> Pascal 6 and Delphi 6, for
> 
> program test; type t1234 = (1,2,3,4); begin end.
>                             ^
> Identifier expected.

No, I didn't test it. It has been I while ago since I was programming,
and I use enumeration types very rarely, so don't wonder if you get an
error message :)




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

* Re: if X in 1..35000 versus Boolean
  2002-07-14 19:25             ` Darren New
@ 2002-07-15 15:22               ` Steffen Huber
  0 siblings, 0 replies; 37+ messages in thread
From: Steffen Huber @ 2002-07-15 15:22 UTC (permalink / raw)


Darren New wrote:
> Jan Prazak wrote:
> > But I am programming in a high-level language, so there is mostly no need
> > to know anything about Assembler, but it could help sometimes, of course.
> 
> It's probably a good idea to learn (eventually) at least one fairly simple
> assembler/machine language. Something like a 68000, 8080, or one of the
> older machines where the machine code was designed to be comprehensible to
> mere mortals.

I would recommend to learn Z80 Assembler for the "well, it is an 8bit
processor, but you can handle 16bit values anyway" and the "why can't
I combine every operation with every register?" experience, ARM Assembler
for the "why can't every instruction set be as simple?" experience and
finally HP PA-RISC Assembler for the "I hate delayed branching"
experience ;-)

[snip]

Steffen

-- 
steffen.huber@gmx.de               steffen@huber-net.de
GCC for RISC OS  - http://www.arcsite.de/hp/gcc/
Private homepage - http://www.huber-net.de/



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

* Re: if X in 1..35000 versus Boolean
  2002-07-13 20:36   ` Jan Prazak
  2002-07-13 18:05     ` Jeffrey Carter
  2002-07-13 22:10     ` Robert Dewar
@ 2002-07-16  8:18     ` Keith Thompson
  2002-07-16 13:54       ` Jan Prazak
  2002-07-16 19:24       ` Gautier
  2 siblings, 2 replies; 37+ messages in thread
From: Keith Thompson @ 2002-07-16  8:18 UTC (permalink / raw)


Jan Prazak <janp9@gmx.net> writes:
> On Sat, 13 Jul 2002 15:27:03 -0100, Frank J. Lhota wrote:
> > Also, 1 .. 35000 is an integer range, not an enumeration type.
> 
> But the word "in" tests, if given object (variable...) is
> in given enumeration type.
> 
> type num : (1, 2, 3, 4);
> 
> if 3 in num then ...
> 
> -- this should be the same as: if 3 in (1,2,3,4);
> -- and also the same as: if 3 in 1..4;
> 
> So I assume that "if X in 1..35000" has the same rules.

I think you're thinking of Pascal sets, not enumeration types.  Ada
doesn't have built-in set types, though they're easy enough to
implement.

If I recall correctly (it's been a while), in Pascal you can write
something like:

    if X in [1 .. 4] then (* This is Pascal, not Ada *)
    begin
        ...;
    end;

where [1 .. 4] is a set value constructor.  A naive Pascal compiler
would build a set value with bits 1, 2, 3, and 4 set, and all other
bits cleared, and test whether bit X is set.  A more clever Pascal
compiler might generate code equivalent to X >= 1 and X <= 4.

You can also do more complex things like

    if X in [1 .. 4, 7 .. 9, 12] then (* This is Pascal, not Ada *)
    begin
        ...;
    end;

The Ada construct 1 .. 4 is *not* a set value constructor, it's a
range.  Given the condition "X in 1 .. 4", there's no reason for the
compiler to generate anything more complicated than "X >= 1 and X <= 4".
There is no direct Ada equivalent to "X in [1..4, 7..9, 12]".

An enumeration type is something else; for example:
    type Color is (Red, Blue, Green);
Note that the values are identifiers, not numeric literals.

I suggest you find a good Ada textbook or online tutorial.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



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

* Re: if X in 1..35000 versus Boolean
  2002-07-16 13:54       ` Jan Prazak
@ 2002-07-16 11:13         ` Lutz Donnerhacke
  2002-07-17 19:04           ` Jan Prazak
  2002-07-16 20:25         ` Georg Bauhaus
  1 sibling, 1 reply; 37+ messages in thread
From: Lutz Donnerhacke @ 2002-07-16 11:13 UTC (permalink / raw)


* Jan Prazak wrote:
>On Tue, 16 Jul 2002 07:18:54 -0100, Keith Thompson wrote:
>> I think you're thinking of Pascal sets, not enumeration types.  Ada
>> doesn't have built-in set types, though they're easy enough to
>> implement.
>> 
>> If I recall correctly (it's been a while), in Pascal you can write
>> something like:
>> 
>>     if X in [1 .. 4] then (* This is Pascal, not Ada *) begin
>>         ...;
>>     end;
>> 
><snip>
>
>Yes! That's exactly what I meant, but I gave it only another name.
>Then I haven't misunderstood something, it just doesn't exist in Ada.

with Ada.Text_IO;
use Ada.Text_IO;

procedure t is
   type Offset is range 0 .. 20;
   package NIO is new Ada.Text_IO.Integer_IO (Offset);
   use NIO;
   x : Offset;
   testfeld : array (Offset) of Boolean :=
     (1..4 => True, others => False);
begin
   Put ("Enter a number: ");
   Get (x);      
   if testfeld (x) then
      Put_Line ("True");
   else
      Put_Line ("False");
   end if;
end t;   



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

* Re: if X in 1..35000 versus Boolean
  2002-07-16  8:18     ` Keith Thompson
@ 2002-07-16 13:54       ` Jan Prazak
  2002-07-16 11:13         ` Lutz Donnerhacke
  2002-07-16 20:25         ` Georg Bauhaus
  2002-07-16 19:24       ` Gautier
  1 sibling, 2 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-16 13:54 UTC (permalink / raw)


On Tue, 16 Jul 2002 07:18:54 -0100, Keith Thompson wrote:


> I think you're thinking of Pascal sets, not enumeration types.  Ada
> doesn't have built-in set types, though they're easy enough to
> implement.
> 
> If I recall correctly (it's been a while), in Pascal you can write
> something like:
> 
>     if X in [1 .. 4] then (* This is Pascal, not Ada *) begin
>         ...;
>     end;
> 
<snip>

Yes! That's exactly what I meant, but I gave it only another name.
Then I haven't misunderstood something, it just doesn't exist in Ada.

Jan




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

* Re: if X in 1..35000 versus Boolean
  2002-07-16  8:18     ` Keith Thompson
  2002-07-16 13:54       ` Jan Prazak
@ 2002-07-16 19:24       ` Gautier
  2002-07-17 19:04         ` Jan Prazak
  1 sibling, 1 reply; 37+ messages in thread
From: Gautier @ 2002-07-16 19:24 UTC (permalink / raw)


Keith Thompson:

> If I recall correctly (it's been a while), in Pascal you can write
> something like:
> 
>     if X in [1 .. 4] then (* This is Pascal, not Ada *)
>     begin
>         ...;
>     end;
> 
> where [1 .. 4] is a set value constructor.  A naive Pascal compiler
> would build a set value with bits 1, 2, 3, and 4 set, and all other
> bits cleared, and test whether bit X is set.  A more clever Pascal
> compiler might generate code equivalent to X >= 1 and X <= 4.

BTW what "all other bits" means is undefined in Pascal set expression.
Of course it is not the full integer range, otherwise a set
value with integers would be a quite huge object...
In fact Turbo Pascal 6 (1990) or Delphi 6 (2001) seem
to limit the values in sets to 0..255.

    if X in [1 .. 4, 254 .. 255] then ;

passes compilation,

    if X in [1 .. 4, 254 .. 256] then ;
or
    if X in [-1 .. 4] then ;

doesn't!
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, address on the Web site!



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

* Re: if X in 1..35000 versus Boolean
  2002-07-16 13:54       ` Jan Prazak
  2002-07-16 11:13         ` Lutz Donnerhacke
@ 2002-07-16 20:25         ` Georg Bauhaus
  2002-07-17 19:29           ` Jan Prazak
  1 sibling, 1 reply; 37+ messages in thread
From: Georg Bauhaus @ 2002-07-16 20:25 UTC (permalink / raw)


Jan Prazak <janp9@gmx.net> wrote:
: Yes! That's exactly what I meant, but I gave it only another name.
: Then I haven't misunderstood something, it just doesn't exist in Ada.
: 

Would this meet your needs?

procedure Set_Stuff is
   X: Integer;  -- at random
begin
   case X is
      when 1..100 =>
         -- ...

      when -12 .. -6 =>
         -- ...

      when 120 | 122..124 =>
         -- ...

      when others =>
         raise Constraint_Error;
   end case;
end Set_Stuff;

-- Georg



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

* Re: if X in 1..35000 versus Boolean
  2002-07-16 19:24       ` Gautier
@ 2002-07-17 19:04         ` Jan Prazak
  0 siblings, 0 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-17 19:04 UTC (permalink / raw)


On Tue, 16 Jul 2002 18:24:27 -0100, Gautier wrote:

> In fact Turbo Pascal 6 (1990)
> or Delphi 6 (2001) seem to limit the values in sets to 0..255.

You are right, then things like
  if X in [1..25000]
will not even work.

But FreePascal will probably have no limit in the future (it's in the "to
do" list). www.freepascal.org (if someone is interested, but switching
from Ada to FreePascal would not make much sense :))




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

* Re: if X in 1..35000 versus Boolean
  2002-07-16 11:13         ` Lutz Donnerhacke
@ 2002-07-17 19:04           ` Jan Prazak
  2002-07-17 20:00             ` Georg Bauhaus
  2002-07-18  8:11             ` Lutz Donnerhacke
  0 siblings, 2 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-17 19:04 UTC (permalink / raw)


On Tue, 16 Jul 2002 10:13:26 -0100, Lutz Donnerhacke wrote:


> with Ada.Text_IO;
> use Ada.Text_IO;
> 
> procedure t is
>    type Offset is range 0 .. 20;
...

No one said that it's not possible to create a similar thing in Ada, but
sets simply doesn't exist there (but they are also not necessary).




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

* Re: if X in 1..35000 versus Boolean
  2002-07-16 20:25         ` Georg Bauhaus
@ 2002-07-17 19:29           ` Jan Prazak
  0 siblings, 0 replies; 37+ messages in thread
From: Jan Prazak @ 2002-07-17 19:29 UTC (permalink / raw)


On Tue, 16 Jul 2002 19:25:52 -0100, Georg Bauhaus wrote:

> Would this meet your needs?
> 
> procedure Set_Stuff is
>    X: Integer;  -- at random
> begin

Yes and no. I don't need the set-type, or anything similar,
I was just comparing Pascal to Ada.




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

* Re: if X in 1..35000 versus Boolean
  2002-07-17 19:04           ` Jan Prazak
@ 2002-07-17 20:00             ` Georg Bauhaus
  2002-07-18  8:11             ` Lutz Donnerhacke
  1 sibling, 0 replies; 37+ messages in thread
From: Georg Bauhaus @ 2002-07-17 20:00 UTC (permalink / raw)


Jan Prazak <janp9@gmx.net> wrote:
: No one said that it's not possible to create a similar thing in Ada, but
: sets simply doesn't exist there (but they are also not necessary).

By the way, are there intersections for Pascal sets?
Or set constructors using predicates?

(O.K., I'm lazy, I'll see for my self :-).

-- Georg



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

* Re: if X in 1..35000 versus Boolean
  2002-07-17 19:04           ` Jan Prazak
  2002-07-17 20:00             ` Georg Bauhaus
@ 2002-07-18  8:11             ` Lutz Donnerhacke
  2002-07-18 14:39               ` Georg Bauhaus
  2002-07-20  0:37               ` Robert Dewar
  1 sibling, 2 replies; 37+ messages in thread
From: Lutz Donnerhacke @ 2002-07-18  8:11 UTC (permalink / raw)


* Jan Prazak wrote:
>On Tue, 16 Jul 2002 10:13:26 -0100, Lutz Donnerhacke wrote:
>> procedure t is
>>    type Offset is range 0 .. 20;
[array of Boolean]
>
>No one said that it's not possible to create a similar thing in Ada, but
>sets simply doesn't exist there (but they are also not necessary).

The pascal set type is a array of Boolean.

  type Set is array (1 .. Natural'Size) of Boolean;
  for Set'Size use Natural'Size;
  



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

* Re: if X in 1..35000 versus Boolean
  2002-07-18  8:11             ` Lutz Donnerhacke
@ 2002-07-18 14:39               ` Georg Bauhaus
  2002-07-20  0:37               ` Robert Dewar
  1 sibling, 0 replies; 37+ messages in thread
From: Georg Bauhaus @ 2002-07-18 14:39 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> wrote:
: 
:  type Set is array (1 .. Natural'Size) of Boolean;
:  for Set'Size use Natural'Size;

Uhm, at the very least I would have tried to compile this...

--  Georg
---
Microsoft Windows--a fresh perspective on information hiding



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

* Re: if X in 1..35000 versus Boolean
  2002-07-18  8:11             ` Lutz Donnerhacke
  2002-07-18 14:39               ` Georg Bauhaus
@ 2002-07-20  0:37               ` Robert Dewar
  1 sibling, 0 replies; 37+ messages in thread
From: Robert Dewar @ 2002-07-20  0:37 UTC (permalink / raw)


lutz@iks-jena.de (Lutz Donnerhacke) wrote in message news:<slrnajcu1u.om.lutz@taranis.iks-jena.de>...

> The pascal set type is a array of Boolean.
> 
>   type Set is array (1 .. Natural'Size) of Boolean;
>   for Set'Size use Natural'Size;

Please be careful not to recommend incorrect junk like this. If you
don't know for sure what is correct and what
is not correct, then *always* compile code snippets that
you post to CLA.

(I certainly don't trust myself to get things right and
I always compile snippets, it's just too easy to make
silly mistakes like the above one).



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

end of thread, other threads:[~2002-07-20  0:37 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-14 20:22 if X in 1..35000 versus Boolean Gautier direct_replies_not_read
2002-07-15 11:36 ` Jan Prazak
  -- strict thread matches above, loose matches on Subject: below --
2002-07-13 19:10 Jan Prazak
2002-07-13 16:27 ` Frank J. Lhota
2002-07-13 20:36   ` Jan Prazak
2002-07-13 18:05     ` Jeffrey Carter
2002-07-14 15:02       ` Jan Prazak
2002-07-13 22:10     ` Robert Dewar
2002-07-14 21:16       ` Jan Prazak
2002-07-14 20:47         ` Frank J. Lhota
2002-07-15  1:21         ` Jeffrey Carter
2002-07-16  8:18     ` Keith Thompson
2002-07-16 13:54       ` Jan Prazak
2002-07-16 11:13         ` Lutz Donnerhacke
2002-07-17 19:04           ` Jan Prazak
2002-07-17 20:00             ` Georg Bauhaus
2002-07-18  8:11             ` Lutz Donnerhacke
2002-07-18 14:39               ` Georg Bauhaus
2002-07-20  0:37               ` Robert Dewar
2002-07-16 20:25         ` Georg Bauhaus
2002-07-17 19:29           ` Jan Prazak
2002-07-16 19:24       ` Gautier
2002-07-17 19:04         ` Jan Prazak
2002-07-13 16:32 ` David C. Hoos, Sr.
2002-07-13 20:36   ` Jan Prazak
2002-07-13 18:02     ` David C. Hoos, Sr.
2002-07-13 18:17     ` sk
2002-07-13 20:02       ` Jeffrey Creem
     [not found]     ` <3D306ED5.33E80E09@myob.com>
2002-07-13 18:52       ` David C. Hoos, Sr.
     [not found]       ` <020a01c22a9f$2b50d6c0$6400000a@dhoos>
2002-07-13 19:02         ` sk
2002-07-14 15:02           ` Jan Prazak
2002-07-14 19:25             ` Darren New
2002-07-15 15:22               ` Steffen Huber
2002-07-13 16:44 ` Christopher Browne
2002-07-13 22:09   ` Robert Dewar
2002-07-13 17:17 ` tmoran
2002-07-13 19:44 ` Florian Weimer

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