View mode: basic / threaded / horizontal-split · Log in · Help
October 17, 2006
DMD 0.170 release
Added foreach_reverse, which addresses a serious shortcoming.

http://www.digitalmars.com/d/changelog.html
October 17, 2006
Re: DMD 0.170 release
Walter Bright wrote:
> Added foreach_reverse, which addresses a serious shortcoming.
> 
> http://www.digitalmars.com/d/changelog.html


Lots of background for the foreach improvements in:

http://www.digitalmars.com/d/archives/digitalmars/D/17320.html
October 17, 2006
Re: DMD 0.170 release
Walter Bright wrote:

> Added foreach_reverse, which addresses a serious shortcoming.
> 
> http://www.digitalmars.com/d/changelog.html

But foreach_reverse is such an ugly name, then I like 'reveach' (courtesy of
Mr Panek) much better :P

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
October 17, 2006
Re: DMD 0.170 release
Hi Walter Bright, you wrote:
> Added foreach_reverse, which addresses a serious shortcoming.
> http://www.digitalmars.com/d/changelog.html

Thanks for great work, Walter!

Although could someone explain what exactly "null is now an exact match 
for null pointers, delegates, arrays, class objects, etc." changed?

thanks
-- 
serg.
October 17, 2006
Re: DMD 0.170 release
Walter Bright schrieb:
> Added foreach_reverse, which addresses a serious shortcoming.
> 
> http://www.digitalmars.com/d/changelog.html

Thanks for the release and the bug fixes.

You can improve the change log with this:
- Add the heading of the bug report also to the changelog. So the
changelog is searchable for a specific change. And the reader does not
need to click through all bugs.
- Add a link to the doc of each language change.
October 17, 2006
Re: DMD 0.170 release
On Tue, 17 Oct 2006 13:08:06 +0300, Lars Ivar Igesund  
<larsivar@igesund.net> wrote:

> Walter Bright wrote:
>
>> Added foreach_reverse, which addresses a serious shortcoming.
>>
>> http://www.digitalmars.com/d/changelog.html
>
> But foreach_reverse is such an ugly name, then I like 'reveach'  
> (courtesy of
> Mr Panek) much better :P

'reveach' sounds good; I too think that 'foreach_reverse' is a bit awkward  
and lengthy.
October 17, 2006
Re: DMD 0.170 release
Kristian wrote:

> On Tue, 17 Oct 2006 13:08:06 +0300, Lars Ivar Igesund
> <larsivar@igesund.net> wrote:
> 
>> Walter Bright wrote:
>>
>>> Added foreach_reverse, which addresses a serious shortcoming.
>>>
>>> http://www.digitalmars.com/d/changelog.html
>>
>> But foreach_reverse is such an ugly name, then I like 'reveach'
>> (courtesy of
>> Mr Panek) much better :P
> 
> 'reveach' sounds good; I too think that 'foreach_reverse' is a bit awkward
> and lengthy.

I'm not sure reveach is that good ;) I'd really like something else,
though. 'rforeach' maybe?

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
October 17, 2006
Re: DMD 0.170 release
Walter Bright wrote:
> Added foreach_reverse, which addresses a serious shortcoming.
> 
> http://www.digitalmars.com/d/changelog.html

Thanks for the new release :)

The foreach-on-delegate seems like a great feature, but in a somewhat 
harder to implement shape, it has been available for quite a while:

----

import std.stdio;


template opHackedApply(alias theImplFunc, IterType) {
	Iter entry() {
		Iter it; it.impl = &theImplFunc; return it;
	}
	struct Iter {
		int delegate(IterType) impl;
		int opApply(IterType dg) {
			return impl(dg);
		}
	}
}


class Foo {
	int oldIterImpl(int delegate(inout int) dg) {
		int a;
		a = 3; dg(a);
		a = 9; dg(a);
		return 0;
	}
	mixin opHackedApply!(oldIterImpl, int delegate(inout int)) oldIterMix;
	alias oldIterMix.entry oldIter;
}


void main() {
	Foo f = new Foo;

	foreach (i; f.oldIter) {
		writefln(i);
	}
}

----

Sure it doesn't look as nice, but at least it doesn't require the '&' 
token... But the point is that delegates don't have to be considered 
aggregates in order to implement this feature. Let's now assume that we 
have a few other features in D:

1. tuples
2. better metainfo for delegates and functions
3. hiding of private template members (so they dont interfere with 
automatic name promotion)
4. automatic name promotion of mixins:

template foo() {
	void foo() {}
}

struct Bar {
	mixin foo myFunc;
	void otherFunc() {
		myFunc();	// currently requires `myFunc.foo();`
	}
}


Then the hacked opApply can be used like:

----
template opHackedApply(alias theImplFunc) {
	Iter opHackedApply() {
		Iter it; it.impl = &theImplFunc; return it;
	}

	private alias theImplFunc.paramTypesTuple;
	private struct Iter {
		int delegate(IterType) impl;
		int opApply(IterType dg) {
			return impl(dg);
		}
	}
}

class Foo {
	int oldIterImpl(int delegate(inout int) dg) {
		int a;
		a = 3; dg(a);
		a = 9; dg(a);
		return 0;
	}
	mixin opHackedApply!(oldIterImpl) oldIter;
}
----

It's not as short as the treatment-of-delegates-as-aggregates but it 
only uses builtin features. Yeah, builtin features of my dreamed D 
version, but all the required features have been proposed before and 
would make the whole language better (IMHO, but I'm sure more people 
would agree with me here). On the other side, allowing iteration on 
delegates only because they match a required signature doesn't make the 
language simpler at all.


--
Tomasz Stachowiak
October 17, 2006
Re: DMD 0.170 release
Walter, you always say that new features shouldn't be added if they fairly
easily can be done with existing language constructs. Now, the post below
is about possible new features in D (of general interest and with many
possible applications), and it is shown how they can be used to implement
an existing (and specific) feature in D. I'm not sure if this should be
used as an argument for removing the new delegate-as-aggregate feature, but
it certainly shows that the proposed features have merit.


Tom S wrote:

> Walter Bright wrote:
>> Added foreach_reverse, which addresses a serious shortcoming.
>> 
>> http://www.digitalmars.com/d/changelog.html
> 
> Thanks for the new release :)
> 
> The foreach-on-delegate seems like a great feature, but in a somewhat
> harder to implement shape, it has been available for quite a while:
> 
> ----
> 
> import std.stdio;
> 
> 
> template opHackedApply(alias theImplFunc, IterType) {
> Iter entry() {
> Iter it; it.impl = &theImplFunc; return it;
> }
> struct Iter {
> int delegate(IterType) impl;
> int opApply(IterType dg) {
> return impl(dg);
> }
> }
> }
> 
> 
> class Foo {
> int oldIterImpl(int delegate(inout int) dg) {
> int a;
> a = 3; dg(a);
> a = 9; dg(a);
> return 0;
> }
> mixin opHackedApply!(oldIterImpl, int delegate(inout int)) oldIterMix;
> alias oldIterMix.entry oldIter;
> }
> 
> 
> void main() {
> Foo f = new Foo;
> 
> foreach (i; f.oldIter) {
> writefln(i);
> }
> }
> 
> ----
> 
> Sure it doesn't look as nice, but at least it doesn't require the '&'
> token... But the point is that delegates don't have to be considered
> aggregates in order to implement this feature. Let's now assume that we
> have a few other features in D:
> 
> 1. tuples
> 2. better metainfo for delegates and functions
> 3. hiding of private template members (so they dont interfere with
> automatic name promotion)
> 4. automatic name promotion of mixins:
> 
> template foo() {
> void foo() {}
> }
> 
> struct Bar {
> mixin foo myFunc;
> void otherFunc() {
> myFunc();     // currently requires `myFunc.foo();`
> }
> }
> 
> 
> Then the hacked opApply can be used like:
> 
> ----
> template opHackedApply(alias theImplFunc) {
> Iter opHackedApply() {
> Iter it; it.impl = &theImplFunc; return it;
> }
> 
> private alias theImplFunc.paramTypesTuple;
> private struct Iter {
> int delegate(IterType) impl;
> int opApply(IterType dg) {
> return impl(dg);
> }
> }
> }
> 
> class Foo {
> int oldIterImpl(int delegate(inout int) dg) {
> int a;
> a = 3; dg(a);
> a = 9; dg(a);
> return 0;
> }
> mixin opHackedApply!(oldIterImpl) oldIter;
> }
> ----
> 
> It's not as short as the treatment-of-delegates-as-aggregates but it
> only uses builtin features. Yeah, builtin features of my dreamed D
> version, but all the required features have been proposed before and
> would make the whole language better (IMHO, but I'm sure more people
> would agree with me here). On the other side, allowing iteration on
> delegates only because they match a required signature doesn't make the
> language simpler at all.
> 
> 
> --
> Tomasz Stachowiak

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
October 17, 2006
Re: DMD 0.170 release
Walter Bright wrote:
> Added foreach_reverse, which addresses a serious shortcoming.
> 
> http://www.digitalmars.com/d/changelog.html

foreach_reverse addresses a serious shortcoming? What is that, if 
instead of:
  foreach_reverse(Foo f; aggregate) { ...
I can do:
  foreach(Foo f; &aggregate.opApplyReverse) { ...

The latter form is both more general (allows any kind of iterators) and 
more simple/orthogonal (no extra special statements are needed).

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
« First   ‹ Prev
1 2 3 4 5
Top | Discussion index | About this forum | D home