Prev: 100% without investment online part time jobs..(adsense,datawork,neobux..more jobs)
Next: installing SPARK GPL on Windows
From: Yannick Duchêne (Hibou57) on 9 Aug 2010 15:36 Le Mon, 09 Aug 2010 19:59:45 +0200, <tmoran(a)acm.org> a écrit: > They are also subject to the possible error > of failing to write the "mod" part, whereas with modular types the > compiler has the responsibility to remember to do the mod operation. DRY principle in action
From: Robert A Duff on 9 Aug 2010 17:38 "Yannick Duch�ne (Hibou57)" <yannick_duchene(a)yahoo.fr> writes: > Le Mon, 09 Aug 2010 19:59:45 +0200, <tmoran(a)acm.org> a �crit: >> They are also subject to the possible error >> of failing to write the "mod" part, whereas with modular types the >> compiler has the responsibility to remember to do the mod operation. > DRY principle in action It's a good point. But you can get DRY without an implicit-mod type. For example, for a circular buffer, you can write a Next_Index function that does the explicit "mod", so you don't scatter "mod" ops all over the code. You don't need modular types for that. And you don't want any "*"-with-implicit-mod operator for the index. Nor do you want "xor" on the index. - Bob
From: Robert A Duff on 9 Aug 2010 17:42 "Yannick Duch�ne (Hibou57)" <yannick_duchene(a)yahoo.fr> writes: > Le Mon, 09 Aug 2010 15:28:02 +0200, Robert A Duff > <bobduff(a)shell01.theworld.com> a �crit: >>> Hmmm... Hash coded tables? >> >> Signed integers work fine for that. Except when you need >> that one extra bit -- that's the problem. > > All of the hash functions I have seen so far use modular types. Do you > known ones computing on integers ? Modular types are integer types in Ada terms. So that should be "...computing on SIGNED integers". Sorry for nitpicking. ;-) Well, all the ones I wrote in Ada 83, or Pascal, or... used signed integers. But I concede the point -- modular types are appropriate for hash functions. - Bob
From: Jacob Sparre Andersen on 10 Aug 2010 06:00 Robert A Duff wrote: > Jeffrey Carter <spam.jrcarter.not(a)spam.not.acm.org> writes: >> type T is range 0 .. 2 ** N - 1; >> for T'Size use N; > Yes. And T'Size = N by default in Ada >= 95, so I would write: > > pragma Assert(T'Size = N); > > instead of the Size clause. But don't you loose the compile time error in case the compiler cannot make T'Size = N? Jacob -- PNG: Pretty Nice Graphics
From: Phil Clayton on 10 Aug 2010 08:26
On Aug 8, 9:51 pm, Robert A Duff <bobd...(a)shell01.TheWorld.com> wrote: > P.S. Can anybody recall the definition of "not" on modular > types, when the modulus is not a power of 2, without > looking it up? Hint: It makes no sense. The only feature > that's worse than "modular types" is "modular types with a > non-power-of-2 modulus". ;-) I have the identity not X + 1 = -X ingrained on my brain because I wrote too much in assembly language! I haven't checked (honest!) but I'm sure Ada just uses this identity to define "not" for modular types, i.e. not X = -X - 1 (rhs wraps around) In my view, this is still useful when the modulus is not a power of two, it's just that "not" is a terrible name for the operation. Only yesterday, I was working in another language with arrays starting at index 0 and needed the elements in reverse: the required effect was achieved by subscripting from the end rather than the start. Had I been working in Ada with an array indexed by a modular type, the effect of reversing the elements could have been achieved by replacing A(I) with A(not I) which I think that is nicer than A(-I - 1) provided people have the intuitive understanding that "not" is effectively an operator that reverses the elements of a modular type. In the other language I was using, I effectively had to write A(A'Length - I - 1) (not valid Ada, of course.) Perhaps "reverse" would be a better name for the operator "not" when the modulus is not a power of two? Phil |