On Mon, Nov 14, 2011 at 1:29 PM, Timon Gehr <timon.g...@gmx.ch> wrote:
> On 11/14/2011 08:47 PM, Andrei Alexandrescu wrote: > >> On 11/14/11 1:15 AM, Timon Gehr wrote: >> >>> Looks good, I think this is the right direction. >>> >>> Nitpicks: >>> >>> 1. >>> >>> // Type deduction works for function results. This is important for >>> generic >>> // functions, such as min below, which works correctly for all comparable >>> // types. >>> auto min(T1, T2)(T1 lhs, T2 rhs) { >>> return rhs < lhs ? rhs : lhs; >>> } >>> >>> It does not. The two types need to have a common type as well. >>> >> >> It's difficult to be concise and complete simultaneously. The underlying >> assumption is that if two types are comparable, they also have a common >> type. >> > > hm, maybe call the them 'compatible comparable types'? > > > >> 2. >>> >>> The scope statement example should actually show transactional code. >>> Otherwise the poor reader feels fooled into clicking "See example". >>> Using scope(exit) to write something at function exit is useful for >>> debugging, but scope(failure) is the real thing that is important to >>> show. >>> >> >> Good point. >> >> 3. >>> >>> If contract inheritance is to be promoted on the front page (and it is >>> certainly something that may attract developers), it should actually >>> work. >>> >> >> Absolutely. >> > > There has been disagreement on whether or not my bug report on the matter > was valid. > > What it means for your example: > > // Interfaces and classe > interface Printable { > void print(uint level) > in { assert(level > 0); } // contract is part of the interface > } > > // Interface implementation > class Widget : Printable { > void print(uint level) { ... } > } > > void main(){ > Widget w = new Widget(); > w.print(0); // passes through, but should not > } > > Can you state in the issue tracker that the bug report is valid? > http://d.puremagic.com/issues/**show_bug.cgi?id=6856<http://d.puremagic.com/issues/show_bug.cgi?id=6856> > > > > >> 4. >>> >>> If we can find a less buzzy word than 'Multi-paradigm power' to describe >>> D's multi-paradigm power, that would be nice, but I am also fine with >>> the current state of affairs. >>> >>> 5. >>> >>> The most important language features are not displayed at all. Where are >>> Metaprogramming, CTFE and code generation? It sure is hard to come up >>> with a short but convincing example, but I think we should try to. >>> >> >> Those would be under the multi-paradigm thingie. >> >> > Ok. Maybe there could be a few LOC demonstrating the 'recurrence' function > generating a few fibonacci numbers. I think it is a nice showcase, although > I have never needed that particular function in real code :o). It has also > the potential of showing Phobos' lazy functional style features. But > unfortunately, most functional programmers will shriek for a moment when > they see the argument order of 'take'. > > > I think that's a good idea. While learning D I became impressed with it when I solved Project Euler problem 2 ("By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.") with: auto answer = reduce!"a + b"(filter!"a % 2 == 0"(until!"a > 4_000_000"(recurrence!"a[n-1] + a[n-2]"(1, 1)))); It'd look better with UFCS but it's still rather neat I think.