Re: Best way to test predicate against a range

2010-06-27 Thread BCS
Hello Jonathan, For example, there are two functions that I'd like to be have: all() and any(). That is, I want a function which checks a predicate against a range and returns whether all elements in that range satisfy the predicate, and I want a function that checks a predicate against a range

Re: Best way to test predicate against a range

2010-06-27 Thread Philippe Sigaud
On Sun, Jun 27, 2010 at 08:07, BCS n...@anon.com wrote: Hello Jonathan, For example, there are two functions that I'd like to be have: all() and any(). That is, I want a function which checks a predicate against a range and returns whether all elements in that range satisfy the predicate,

Weird error on nested map

2010-06-27 Thread Simen kjaeraas
auto fn1 = ( string s ) { return s; }; auto fn2 = ( string s ) { return map!fn1( [] ); }; auto idirs = map!fn2( [] ); The above code gives the following errors: foo.d(114): Error: struct foo.main.Map!(fn2,string[]).Map inner struct Map cannot be a field foo.d(114): Error:

What are delimited string, heredoc and D token strings?

2010-06-27 Thread Pierre Rouleau
Hi all, The D2.0 lexical page describes delimited string and token string literals. Is there any example of how these are used and why, somewhere? Thanks -- Pierre

Re: What are delimited string, heredoc and D token strings?

2010-06-27 Thread Simen kjaeraas
Pierre Rouleau prouleau...@gmail.com wrote: Hi all, The D2.0 lexical page describes delimited string and token string literals. Is there any example of how these are used and why, somewhere? Token strings are added for the specific use case of string mixins[1]. They must contain valid D

Re: Weird error on nested map

2010-06-27 Thread Philippe Sigaud
On Sun, Jun 27, 2010 at 10:11, Simen kjaeraas simen.kja...@gmail.comwrote: auto fn1 = ( string s ) { return s; }; auto fn2 = ( string s ) { return map!fn1( [] ); }; auto idirs = map!fn2( [] ); The above code gives the following errors: foo.d(114): Error: struct

Re: What are delimited string, heredoc and D token strings?

2010-06-27 Thread Pierre Rouleau
On 27/06/10 9:52 AM, Simen kjaeraas wrote: Pierre Rouleau prouleau...@gmail.com wrote: Hi all, The D2.0 lexical page describes delimited string and token string literals. Is there any example of how these are used and why, somewhere? Token strings are added for the specific use case of

auto functions not authorized inside main?

2010-06-27 Thread Philippe Sigaud
Is it defined somewhere that auto functions are not authorized inside main? void main() { auto fun(string s) { return s;} // this does not compile } error: main.d|6|found 's' when expecting ')'| main.d|6|semicolon expected, not ')'| main.d|6|found ')' instead of statement|

Re: What are delimited string, heredoc and D token strings?

2010-06-27 Thread bearophile
Pierre Rouleau: I was wondering if D had the equivalnt of Python's triple quote string literals and it does: the delimited string serves the same purpose. Great! But keep in mind that normal D string literals can span more than one line :-) Bye, bearophile

Re: auto functions not authorized inside main?

2010-06-27 Thread bearophile
Philippe Sigaud: I couldn't find a bugzilla entry for this and I cannot believe no one ever tried to put an auto fun inside main! Maybe auto funcs are seen as instantiated templates, and templates can't be defined inside functions. Anyway, I think you can file this as enhancement request.

Re: Best way to test predicate against a range

2010-06-27 Thread bearophile
Jonathan M Davis: Okay. The functions in std.algorithm are quite powerful, but sometimes you have to play around with them a bit to figure out how to do exactly what you're trying to do. Some of them need to be improved in their concept and API. Some of them are awkward to use or they

Re: What are delimited string, heredoc and D token strings?

2010-06-27 Thread Pierre Rouleau
On 27/06/10 11:36 AM, bearophile wrote: But keep in mind that normal D string literals can span more than one line :-) In what sense? In the sense that adjacent strings are concatenated? If I want to create a string literal that embeds new line without explicitly placing a '\n' inside the

Why doesn't this work in D2?

2010-06-27 Thread Jacob Carlborg
Why doesn't the following code work in D2 (it works in D1)? void foo (T) (in T[] a, T b) { } void main () { asd.foo('s'); } The error I get is: main.d(10): Error: template main.foo(T) does not match any function template declaration main.d(10): Error: template main.foo(T)

Re: Why doesn't this work in D2?

2010-06-27 Thread Ellery Newcomer
On 06/27/2010 12:18 PM, Jacob Carlborg wrote: Why doesn't the following code work in D2 (it works in D1)? void foo (T) (in T[] a, T b) { } void main () { asd.foo('s'); } asd.foo(cast(immutable) 's');

Re: Why doesn't this work in D2?

2010-06-27 Thread Simen kjaeraas
Jacob Carlborg d...@me.com wrote: Why doesn't the following code work in D2 (it works in D1)? void foo (T) (in T[] a, T b) { } void main () { asd.foo('s'); } The error I get is: main.d(10): Error: template main.foo(T) does not match any function template declaration

Re: Why doesn't this work in D2?

2010-06-27 Thread Jacob Carlborg
On 2010-06-27 19:26, Simen kjaeraas wrote: Jacob Carlborg d...@me.com wrote: Why doesn't the following code work in D2 (it works in D1)? void foo (T) (in T[] a, T b) { } void main () { asd.foo('s'); } The error I get is: main.d(10): Error: template main.foo(T) does not match any function

Re: Why doesn't this work in D2?

2010-06-27 Thread BCS
Hello Jacob, That's annoying, specially since char is a value type. I would preferably have a solution for both D1 and D2. Can I use a template to cast/alias away the immutable part? One solution would be to have templates strip off const/immutable from the top level of args. void F1(T)(T

A module comprehensive template-specialization

2010-06-27 Thread Matthias Walter
Hi list, I tried to write a traits class comparable to iterator_traits in C++ STL or graph_traits in Boost Graph Library in D 2.0, but failed to do so via template specialization which is put into different modules. Putting everything into one module interferes with extensibility. I tried the