Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #1959

Re: repeating something n times

From "BartC" <bc@freeuk.com>
Newsgroups comp.programming
Subject Re: repeating something n times
Date 2012-07-15 13:21 +0100
Organization A noiseless patient Spider
Message-ID <jtucjo$tie$1@dont-email.me> (permalink)
References <repeat-20120705210751@ram.dialup.fu-berlin.de> <jt7jdv$247$1@dont-email.me> <b73472b3-9e35-45e4-b9cf-ab8366f4e770@googlegroups.com> <jtsqtf$q73$2@dont-email.me> <jtu8tl$ucv$1@speranza.aioe.org>

Show all headers | View raw



"Rui Maciel" <rui.maciel@gmail.com> wrote in message
news:jtu8tl$ucv$1@speranza.aioe.org...
> BartC wrote:
>
>>> Once in a blue moon you might need
>>>
>>> /* Islamic divorce */
>>> for(i=0;i<3;i++)
>>>printf("I divorce you\n");
>>
>> It's not as common as loops needing the index, but it does come up often
>> enough that it wouldn't hurt to have a special loop form for it:
>>
>> to 4 do
>> println "I divorce you"
>> end
>
> I suspect that it would be a case of "damned if one does, damned if one
> doesn't".  If that new loop type was proposed I would expect a number of
> users criticising the proposal for being redundant and a needless
> contribution for bloating a programming language which once upon a time
> was
> actually lean.

The syntax I use for 'for' loops (originally from Algol68; not all mine)
goes something like this:

for i := A to B do ...

It is possible leave various elements where they are not needed:

for i to B do..., to B do..., or just do... for an infinite loop.

Just one loop type. But the design of C's 'for' makes it harder to do the 
same
sort of thing.

> IIRC, some people already criticise C for having too many
> loop types.

This is the same language that has these integer types:

int8_t
uint8_t
int_least8_t
uint_least8_t
int_fast8_t
uint_fast8_t

int16_t
uint16_t
int_least16_t
uint_least16_t
int_fast16_t
uint_fast16_t

int32_t
uint32_t
int_least32_t
uint_least32_t
int_fast32_t
uint_fast32_t

int64_t
uint64_t
int_least64_t
uint_least64_t
int_fast64_t
uint_fast64_t ?

With, for each one of those, a dedicated macro to give it's _MIN and _MAX
value? (In place of just two property tags, perhaps 'min and 'max, that can
be applied to any type and any value.)

A single extra loop statement would be completely lost amongst that lot!

> Nevertheless, if a repeat() loop is so desperately needed then why not
> make
> do with a simple macro?  With C99, the following would do quite well:
>
> <code>
> #include <stdio.h>
>
> #define repeat(n) for(int i = 0; i < n; i++)
>
> int main(void)
> {
>        repeat(3)
>                printf("I divorce you\n");
>        return 0;
> }

I think that C relies too much on its macro processor, in a way that has
held the language back. In this case, it might work, yes, with C99, and if
everyone defined the same macro in the same way and with the same name. But 
that doesn't always happen, so people avoid using such a thing, and that 
means it's take-up is even less than it might be, which in turn means you 
avoid using it because you then can't share code...

I remember proposing (probably more than once actually) that C might have
binary constants (such as 2x11010 or 11010B), but it was unbelievable how
much hostility there was to that! All sorts of arguments from 'it's never
needed', 'a competent programmer can convert to/from hex in his head', to
someone posting some hairy macro where you could give it a number like
0x11010 and it would interpret it as binary!

This is for a language change that one compiler writer admitted might take
half-an-hour to implement.

So as far as C is concerned, I've given up. The proposals for loops stand on
their own merits, not on whether they are implementable in a half-assed way
in a C preprocessor! (BTW other languages than C are available, but it has
had an annoying influence on too many others.)

-- 
Bartc 

Back to comp.programming | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-06 21:56 +0100
  Re: repeating something n times Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-06 22:16 +0100
    Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-06 23:18 +0100
  Re: repeating something n times malcolm.mclean5@btinternet.com - 2012-07-14 14:11 -0700
    Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-14 23:11 +0100
      Re: repeating something n times Ike Naar <ike@iceland.freeshell.org> - 2012-07-14 23:37 +0000
        Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 01:16 +0100
          Re: repeating something n times malcolm.mclean5@btinternet.com - 2012-07-14 17:35 -0700
            Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-14 22:23 -0500
          Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-14 22:19 -0500
            Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 11:00 +0100
      Re: repeating something n times malcolm.mclean5@btinternet.com - 2012-07-14 17:44 -0700
      Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-14 22:17 -0500
        Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 11:49 +0100
          Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-15 09:53 -0500
      Re: repeating something n times Rui Maciel <rui.maciel@gmail.com> - 2012-07-15 12:18 +0100
        Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 13:21 +0100
          Re: repeating something n times Willem <willem@toad.stack.nl> - 2012-07-15 13:02 +0000
            Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 14:36 +0100
              Re: repeating something n times Willem <willem@toad.stack.nl> - 2012-07-15 14:18 +0000
                Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 15:45 +0100
                Re: repeating something n times Willem <willem@toad.stack.nl> - 2012-07-15 16:25 +0000
                Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 18:02 +0100
          Re: repeating something n times Rui Maciel <rui.maciel@gmail.com> - 2012-07-15 15:10 +0100
            Re: repeating something n times "BartC" <bc@freeuk.com> - 2012-07-15 16:10 +0100
              Re: repeating something n times malcolm.mclean5@btinternet.com - 2012-07-15 13:00 -0700
    Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-14 21:55 -0500
      Re: repeating something n times "io_x" <a@b.c.invalid> - 2012-07-17 20:47 +0200
        Re: repeating something n times "io_x" <a@b.c.invalid> - 2012-07-18 14:19 +0200
          Re: repeating something n times Aaron W. Hsu <arcfide@sacrideo.us> - 2012-07-18 12:55 -0500
            Re: repeating something n times malcolm.mclean5@btinternet.com - 2012-07-18 11:57 -0700

csiph-web