www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Digital Mars Ate My Computer!

reply "Matthew Wilson" <admin.hat stlsoft.dot.org> writes:
You know you're pushing the language to the limits when you cause the
compiler to eat your machine. I just had an unhappy 10 minutes waiting for
my virtual memory to be completely eaten up by dmd.exe, and another 5 while
I rebooted the
oh-so-stable OS that is WinXP. Pleuch!

Anyway, I think I've found a serious flaw in D's templates architecture.

Here's the issue:

In DTL, there are several different ways of treating containers, supporting
different paradigms. The first, and most important one of these, is based on
ranges, usually in combination with foreach. "In D-world, foreach is King!"
(That's the title of a section in the book ... <g>).

Containers provide a number of standard methods (some template, some
non-template) that allow one to provide a filtered (sub-)set of their
contents. The one I've been banging on about in other threads is select(),
so we'll stick with that.

    Container
    {
        <range>    select(<some function / predicate / function-object);


This allows us to write something such as the following extract from my test
suites:


        printf("\nselect()-ing the numbers, with IsOdd's fn, as a
delegate\n");
        foreach(int i; cont.select(&IsOdd.fn))
        {
            printf("%d ", i);
        }
        printf("\n");

        printf("\nselect()-ing the numbers, with IsEven\n");
        foreach(int i; cont.select0!(IsEven)())
        {
            printf("%d ", i);
        }
        printf("\n");

        printf("\nselect()-ing the numbers, with DivisibleBy\n");
        foreach(int i; cont.select1!(DivisibleBy)(new DivisibleBy(3)))
        {
            printf("%d ", i);
        }
        printf("\n");

These give:

    select()-ing the numbers, with IsOdd's fn, as a delegate
    -9 -7 -5 -3 -1 1 3 5 7 9

    select()-ing the numbers, with IsEven
    -10 -8 -6 -4 -2 0 2 4 6 8

    select()-ing the numbers, with DivisibleBy
    -9 -6 -3 0 3 6 9


Ok, that's nice, but that's not the whole picture. Given the set of
methods that filter output of a given container exist (or, rather, they will
when I've got it all working) in a mixin, the obvious - and intended!! -
step is to mix-in the mixin to the range types themselves. This is to give
the far more powerful composition of filters, e.g.

    foreach( . . . ,
container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
DivisibleBy(3)))
    {
    }

or (the more accessible):

    container.select(&IsEven).max();


I trust you'll agree this a very powerful model, (almost) matching the
declarative notation of some of the power powerful (albeit barely
compilable) stuff in bleeding edge C++.

Unfortunately, there's a fly in my ointment. Because D appears to evaluate
the types generated ( / generatable), it gets in an infinite loop here. This
does not happen in C++.

I don't know what the answer is, other than this aspect of the language, or
the current compiler's interpretation of it, should be changed.

I'll try and boil this down to a simple example and post it soon.
Jul 17 2004
next sibling parent reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjuxNO SPAMyahoo.es> writes:
Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }
 
 or (the more accessible):
 
 container.select(&IsEven).max();
 
 
 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?
Jul 17 2004
next sibling parent reply Charlie <Charlie_member pathlink.com> writes:
It does indeed look very cool, but why select, select0, select1, can they not
fit under the same umbrella ?

Charlie

In article <cdbb5b$1b41$1 digitaldaemon.com>, Juanjo =?ISO-8859-15?Q?=C1lvarez?=
says...
Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }
 
 or (the more accessible):
 
 container.select(&IsEven).max();
 
 
 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?

Jul 17 2004
parent reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Charlie" <Charlie_member pathlink.com> wrote in message
news:cdbpbp$1g1r$1 digitaldaemon.com...
 It does indeed look very cool, but why select, select0, select1, can they not
 fit under the same umbrella ?

Alas no. Walter has ruled out overloading of template and non-template member functions. There may be another way, of course. We're wandering out onto a new planet here, and people may be able to find paths I can't see. I very much want to get over the few language/compiiler hurdles that are holding me up, and then release 0.1, so all you smart(er) people can point out easier paths to me. :)
 Charlie

 In article <cdbb5b$1b41$1 digitaldaemon.com>, Juanjo

 says...
Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }

 or (the more accessible):

 container.select(&IsEven).max();


 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?


Jul 17 2004
next sibling parent reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjuxNO SPAMyahoo.es> writes:
Matthew wrote:

 
 "Charlie" <Charlie_member pathlink.com> wrote in message
 news:cdbpbp$1g1r$1 digitaldaemon.com...
 It does indeed look very cool, but why select, select0, select1, can they
 not fit under the same umbrella ?

Alas no. Walter has ruled out overloading of template and non-template member functions.

Yes, but select_dlg (from delegate), select_mix, etc, are more descriptive names.
Jul 17 2004
parent reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
news:cdcfrh$1pei$3 digitaldaemon.com...
 Matthew wrote:

 "Charlie" <Charlie_member pathlink.com> wrote in message
 news:cdbpbp$1g1r$1 digitaldaemon.com...
 It does indeed look very cool, but why select, select0, select1, can they
 not fit under the same umbrella ?

Alas no. Walter has ruled out overloading of template and non-template member functions.

Yes, but select_dlg (from delegate), select_mix, etc, are more descriptive names.

Again, please don't worry about the names. All will be sorted in due course. :-)
Jul 17 2004
parent reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjuxNO SPAMyahoo.es> writes:
Matthew wrote:

 Yes, but select_dlg (from delegate), select_mix, etc, are more
 descriptive names.

Again, please don't worry about the names. All will be sorted in due course. :-)

I hear Dennis Ritchie saying that about std C lib "creat" 30 years ago... ;)
Jul 18 2004
parent "Matthew Wilson" <admin.hat stlsoft.dot.org> writes:
"Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
news:cddoaq$29c4$1 digitaldaemon.com...
 Matthew wrote:

 Yes, but select_dlg (from delegate), select_mix, etc, are more
 descriptive names.

Again, please don't worry about the names. All will be sorted in due course. :-)

I hear Dennis Ritchie saying that about std C lib "creat" 30 years ago...

He he. Well, I tell you, the amount of compiler/language hassles I've had over the last four days, I've had to keep reminding myself that this is a new language. If it was otherwise, I'd have thrown my hands up and gone and written some VB!
Jul 18 2004
prev sibling parent John Reimer <brk_6502 NO_S_PAM.yahoo.com> writes:
On Sun, 18 Jul 2004 06:37:30 +1000, Matthew wrote:
<snip>

 I very much want to get over the few language/compiiler hurdles

 holding me up, and then release 0.1, so all you smart(er) people can
 point out easier paths to me. :)
 

LOL! Smart answer! :-D
Jul 17 2004
prev sibling parent reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
news:cdbb5b$1b41$1 digitaldaemon.com...
 Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }

 or (the more accessible):

 container.select(&IsEven).max();


 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?

select() selects out those matching a given predicate, e.g. only selects those that are even collect() transforms all elements using a given transformation function, e.g. multiplies them by 3 reject() is the opposite of select(). It works by applying the Not!() template predicate and returns a Not'ed range otherwise identical to select(). The names for all these operations are borrowed from Ruby, and are open to change once it's released. It's the mechanisms that I'm interested in - and losing my hair over - at the moment. :)
Jul 17 2004
parent reply Juanjo =?ISO-8859-15?Q?=C1lvarez?= <juanjuxNO SPAMyahoo.es> writes:
Matthew wrote:

 
 "Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
 news:cdbb5b$1b41$1 digitaldaemon.com...
 Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }

 or (the more accessible):

 container.select(&IsEven).max();


 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?

select() selects out those matching a given predicate, e.g. only selects those that are even collect() transforms all elements using a given transformation function, e.g. multiplies them by 3 reject() is the opposite of select(). It works by applying the Not!() template predicate and returns a Not'ed range otherwise identical to select(). The names for all these operations are borrowed from Ruby, and are open to change once it's released. It's the mechanisms that I'm interested in - and losing my hair over - at the moment. :)

Maybe "transform" would be a better name than collect? When I first saw the code I thought "collect(&Multiply)" would be multipliying all the values and returning the outcome (collecting all the values on a single one). Maybe it's because english is (obviously :) not my native language and in my language (spanish) the word closer to "collect" (recolectar) means "to join" or "to take together".
Jul 17 2004
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
news:cdcfpg$1pei$2 digitaldaemon.com...
 Matthew wrote:

 "Juanjo Álvarez" <juanjuxNO SPAMyahoo.es> wrote in message
 news:cdbb5b$1b41$1 digitaldaemon.com...
 Matthew Wilson wrote:

 container.select(&IsEven).collect(&Multiply).reject0!(DivisibleBy)(new
 DivisibleBy(3)))
 {
 }

 or (the more accessible):

 container.select(&IsEven).max();


 I trust you'll agree this a very powerful model, (almost) matching the
 declarative notation of some of the power powerful (albeit barely
 compilable) stuff in bleeding edge C++.

It's not only powerful, it's easy and beautiful which is a very rare combination nowadays. Man, your DTL have earned a new fan today :) Only a question, what does collect do?

select() selects out those matching a given predicate, e.g. only selects those that are even collect() transforms all elements using a given transformation function, e.g. multiplies them by 3 reject() is the opposite of select(). It works by applying the Not!() template predicate and returns a Not'ed range otherwise identical to select(). The names for all these operations are borrowed from Ruby, and are open to change once it's released. It's the mechanisms that I'm interested in - and losing my hair over - at the moment. :)

Maybe "transform" would be a better name than collect? When I first saw the code I thought "collect(&Multiply)" would be multipliying all the values and returning the outcome (collecting all the values on a single one). Maybe it's because english is (obviously :) not my native language and in my language (spanish) the word closer to "collect" (recolectar) means "to join" or "to take together".

Sure. I've just borrowed the names from their Ruby counterparts - Ruby's my current fave language <g> - and they most certainly will be up for review/standardisation. We're just not at that stage of the game, and I wanted something established so as not to focus on that issue at the moment. Rest assured, I'm a *big* fan of unambiguous naming conventions. :-)
Jul 17 2004
prev sibling parent reply "Blandger" <zeroman aport.ru> writes:
"Matthew Wilson" <admin.hat stlsoft.dot.org> wrote in message
news:cdat7l$176e$1 digitaldaemon.com...
 You know you're pushing the language to the limits when you cause the
 compiler to eat your machine. I just had an unhappy 10 minutes waiting for
 my virtual memory to be completely eaten up by dmd.exe, and another 5

 I rebooted the
 oh-so-stable OS that is WinXP. Pleuch!

I've encountered the same problem. Recently I've converted and added some event processing java code to the DWT and got the same result. Shortly speaking adding only one new class 'private import' into the one 'old source file' force DMD 0.95 go to the infinite loop and it gives 'out of memory' error after a few minutes. I hadn't to reboot the PC though.
 Anyway, I think I've found a serious flaw in D's templates architecture.

May be it's not only 'D's templates architecture' issue. --- Yuriy.
Jul 18 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
Blandger wrote:

Anyway, I think I've found a serious flaw in D's templates architecture.
    

May be it's not only 'D's templates architecture' issue. --- Yuriy.

-- -Anderson: http://badmama.com.au/~anderson/
Jul 23 2004