November 22, 2001
???????

I don't see anything there about array slicing.  Did I miss it?

Walter wrote:

> Check out:
>
>     www.digitalmars.com/d/ctod.html

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


November 22, 2001
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BFCBF71.144F6E8F@deming-os.org...
> ???????
>
> I don't see anything there about array slicing.  Did I miss it?

Sorry, I missed the context. Here's a rewrite of "wordcount" in D, showing how to use slicing. It actually does compile & run, too <g>. It's a lot shorter and faster than the equivalent C program. Note how slicing is used to just map over the input buffer rather than copying and appending a 0. Note the use of an associative array as a simple symbol table.

----------------------------------------------------------------------------
---
import stdio;
import file;

int main (char[][] args)
{
    int w_total;
    int l_total;
    int c_total;
    int[char[]] dictionary;

    printf("   lines   words   bytes file\n");
    for (int i = 1; i < args.length; ++i)
    {
         char[] input;
         int w_cnt, l_cnt, c_cnt;
         int inword;
         int wstart;

         input = File.read(args[i]);

         for (int j = 0; j < input.length; j++)
         {   char c;

             c = input[j];
             if (c == "\n")
                  ++l_cnt;
             if (c >= "0" && c <= "9")
             {
             }
             else if (c >= "a" && c <= "z" ||
                          c >= "A" && c <= "Z")
             {
                  if (!inword)
                  {
                      wstart = j;
                      inword = 1;
                      ++w_cnt;
                  }
             }
             else if (inword)
             {    char[] word = input[wstart .. j];

                  dictionary[word]++;
                  inword = 0;
             }
             ++c_cnt;
         }
         if (inword)
         {   char[] word = input[wstart .. input.length];
             dictionary[word]++;
         }
         printf("%8lu%8lu%8lu %s\n", l_cnt, w_cnt, c_cnt, (char *)args[i]);
         l_total += l_cnt;
         w_total += w_cnt;
         c_total += c_cnt;
    }

    if (args.length > 2)
    {
         printf("--------------------------------------\n%8lu%8lu%8lu
total",
             l_total, w_total, c_total);
    }

    printf("--------------------------------------\n");
    char[][] keys = dictionary.keys;
    for (int i = 0; i < keys.length; i++)
    {    char[] word;

         word = keys[i];
         printf("%3d %.*s\n", dictionary[word], word);
    }
    return 0;
}



November 22, 2001
"Walter" <walter@digitalmars.com> wrote in message news:9tihd9$1h76$1@digitaldaemon.com...

> Sorry, I missed the context. Here's a rewrite of "wordcount" in D, showing how to use slicing. It actually does compile & run, too <g>. It's a lot shorter and faster than the equivalent C program. Note how slicing is used to just map over the input buffer rather than copying and appending a 0.

In this context, slicing as you defined it is simpler, of course.
Still, there are many other cases where the inclusive range works
better. And I must also say that when I see [..], I tend to think
of it as of inclusive range, and I believe most people do so as well.


November 22, 2001
The entire STL is based on the first one being inclusive and the second one being exclusive pointer (iterator), so a lot of people are familiar with this concept.

- Rajiv Bhagwat


Pavel Minayev <evilone@omen.ru> wrote in message news:9tikn6$1k79$1@digitaldaemon.com...
>
> "Walter" <walter@digitalmars.com> wrote in message news:9tihd9$1h76$1@digitaldaemon.com...
>
> > Sorry, I missed the context. Here's a rewrite of "wordcount" in D,
showing
> > how to use slicing. It actually does compile & run, too <g>. It's a lot shorter and faster than the equivalent C program. Note how slicing is
used
> > to just map over the input buffer rather than copying and appending a 0.
>
> In this context, slicing as you defined it is simpler, of course.
> Still, there are many other cases where the inclusive range works
> better. And I must also say that when I see [..], I tend to think
> of it as of inclusive range, and I believe most people do so as well.
>
>


November 22, 2001
"Rajiv Bhagwat" <dataflow@vsnl.com> wrote in message news:9tisnr$1rtn$1@digitaldaemon.com...

> The entire STL is based on the first one being inclusive and the second
one
> being exclusive pointer (iterator), so a lot of people are familiar with
> this concept.

Iterators don't use ".." semantic.


November 22, 2001
I don't know about you, but I use the STL.  I don't think that I'll EVER be "familiar" with it.

It's exactly stuff like that that makes me want to write my own generic libraries.  Plus the horridly complex template paramter names I get in the debugger :(

Rajiv Bhagwat wrote:

> The entire STL is based on the first one being inclusive and the second one being exclusive pointer (iterator), so a lot of people are familiar with this concept.

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]


November 22, 2001
The obtuseness of STL is a prime motivator for me to find another way to do it in D.


"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BFD425B.D5CBAD1C@deming-os.org...
> I don't know about you, but I use the STL.  I don't think that I'll EVER
be
> "familiar" with it.
>
> It's exactly stuff like that that makes me want to write my own generic libraries.  Plus the horridly complex template paramter names I get in the debugger :(
>
> Rajiv Bhagwat wrote:
>
> > The entire STL is based on the first one being inclusive and the second
one
> > being exclusive pointer (iterator), so a lot of people are familiar with
> > this concept.
>
> --
> The Villagers are Online! http://villagersonline.com
>
> .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
> .[ (a version.of(English).(precise.more)) is(possible) ]
> ?[ you want.to(help(develop(it))) ]
>
>


December 02, 2001
Pavel Minayev a écrit :

> "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BFA97A0.66C04CBE@deming-os.org...
>
> > This whole exclusive/inclusive thing is, IMHO, *very* non-intuitive.
>
> Agreed!
>

Agree too.
Perhaps this inclusive/exclusive is more practical than it looks, but it is
difficult to sell.

What about inclusive/exclusive be determined by the choice of '[' or ']' ?:

int[index1..index2]    array;    //index1 and index2 are both inclusive int[index1..index2[    array;    //index1 is inclusive, index2 is exclusive int]index1..index2]    array;    //index1 is exclusive, index2 is inclusive int]index1..index2[    array;    //index1 and index2 are both exclusive

just an idea, i don't study the side effects.

int]char[][    array;    //how readeable is it ?

Roland

December 02, 2001
nancyetroland a écrit :

> int]char[][    array;    //how readeable is it ?

Forget this.  It does not have sens.

Roland

December 02, 2001
"nancyetroland" <nancyetroland@free.fr> wrote in message news:3C096EEF.A664A722@free.fr...
> Pavel Minayev a écrit :
> > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BFA97A0.66C04CBE@deming-os.org...
> > > This whole exclusive/inclusive thing is, IMHO, *very* non-intuitive.
> > Agreed!
> Agree too.
> Perhaps this inclusive/exclusive is more practical than it looks, but it
is
> difficult to sell.

Think about it this way. We declare an array as:

    int array[max];

loop through it as:

    for (i = 0; i < array.length; i++)

wouldn't it make sense to slice it as [0 .. array.length]?