View mode: basic / threaded / horizontal-split · Log in · Help
December 27, 2011
Re: A nice way to step into 2012
On 27-12-2011 05:25, Andrei Alexandrescu wrote:
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>
>
> Andrei

Awesome!

Now the only gripe I have left is type inference for lambdas passed as 
regular function parameters. Is this something we will see anytime soon?

- Alex
December 27, 2011
Re: A nice way to step into 2012
On 27-12-2011 15:19, Alex Rønne Petersen wrote:
> On 27-12-2011 05:25, Andrei Alexandrescu wrote:
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>>
>> Andrei
>
> Awesome!
>
> Now the only gripe I have left is type inference for lambdas passed as
> regular function parameters. Is this something we will see anytime soon?
>
> - Alex

Just to make it clear what I want to be able to do (simple example with 
arrays):

T[] filter(T)(T[] items, scope bool delegate(T) predicate)
{
    T[] newItems;

    foreach (item; items)
        if (predicate(item))
            newItems ~= item;

    return newItems;
}

auto ints = filter([0, 1, 2, 3, 4, 5], x => x % 2 != 0);

Or perhaps even better, when we get fully working UFCS:

auto ints = [0, 1, 2, 3, 4, 5].filter(x => x % 2 != 0);

DMD should be able to infer the parameter type(s) of the delegate I'm 
passing, since that's clear from the array being passed. (I would 
recommend looking at how C#'s type inference rules work; they're quite 
sophisticated for an imperative language.)

- Alex
December 27, 2011
Re: A nice way to step into 2012
On 12/27/11 8:19 AM, Alex Rønne Petersen wrote:
> Now the only gripe I have left is type inference for lambdas passed as
> regular function parameters. Is this something we will see anytime soon?

It's among the [tdpl] bugs, so I hope fairly soon.

Andrei
December 27, 2011
Re: A nice way to step into 2012
On 12/27/11 4:51 AM, deadalnix wrote:
> Le 27/12/2011 05:25, Andrei Alexandrescu a écrit :
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>>
>> Andrei
>
> Maybe I'll seem bitter, but I do not think this changement was really
> that important. This is nice, ok, but we have some other really serious
> flaw, like shared not doing what it is supposed to do.

Imagine how bitter I am that the string lambda syntax didn't catch on!

Andrei
December 27, 2011
Re: A nice way to step into 2012
On 12/27/11 3:35 AM, bearophile wrote:
> This program contains wrong syntax because x lacks a type:
>
> void main() {
>      double delegate(double) f;
>      f = (x) =>  x + 1;
> }
>
>
> DMD gives the error messages:
>
> test.d(3): Error: undefined identifier x, did you mean variable f?
> test.d(3): Error: cannot implicitly convert expression (__dgliteral1) of type _error_ delegate(_error_) to double delegate(double)
>
> Is it wise to try to improve the second error message?

Actually that's an old bug in the compiler. Lambdas without parameter 
types are really templates, and a template should be assignable to a 
function or delegate if the parameter type binding works.


Andrei
December 27, 2011
Re: A nice way to step into 2012
On Tuesday, 27 December 2011 at 15:11:25 UTC, Andrei Alexandrescu 
wrote:
> Imagine how bitter I am that the string lambda syntax didn't 
> catch on!
>
> Andrei

Please tell me they're not going anywhere.  I **really** don't 
want to deal with those being deprecated.
December 27, 2011
Re: A nice way to step into 2012
On Tuesday, 27 December 2011 at 15:19:07 UTC, dsimcha wrote:
> On Tuesday, 27 December 2011 at 15:11:25 UTC, Andrei 
> Alexandrescu wrote:
>> Imagine how bitter I am that the string lambda syntax didn't 
>> catch on!
>>
>> Andrei
>
> Please tell me they're not going anywhere.  I **really** don't 
> want to deal with those being deprecated.

...and they were kind of useful in that you could introspect the 
string and apply optimizations depending on what the lambda was.  
I wrote a sorting function that introspected the lambda that was 
passed to it.  If it was "a < b", "a<b", "a > b", etc., and the 
array to be sorted was floating point, it punned and bit twiddled 
the floats/doubles to ints/longs, sorted them and bit twiddled 
and punned them back.
December 27, 2011
Re: A nice way to step into 2012
Am 27.12.2011 05:25, schrieb Andrei Alexandrescu:
> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>
>
> Andrei

-------------
import std.algorithm;

void main() {
	auto arr = [0, 5, 4, 3, 2, 1];
	sort!((a, b) => a < b)(arr);
}
-------------
$ ./dmd lambda_test
dmd: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) 
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct 
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= 
(unsigned long)((((__builtin_offsetof (struct malloc_chunk, 
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) 
== 0)' failed.
$


This also "works" with other functions from std.algorithm.
December 27, 2011
Re: A nice way to step into 2012
On 12/27/11 9:21 AM, Joshua Reusch wrote:
> Am 27.12.2011 05:25, schrieb Andrei Alexandrescu:
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>>
>> Andrei
>
> -------------
> import std.algorithm;
>
> void main() {
> auto arr = [0, 5, 4, 3, 2, 1];
> sort!((a, b) => a < b)(arr);
> }
> -------------
> $ ./dmd lambda_test
> dmd: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
> (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
> malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
> (unsigned long)((((__builtin_offsetof (struct malloc_chunk,
> fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
> 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask)
> == 0)' failed.
> $
>
>
> This also "works" with other functions from std.algorithm.

Not even 11h before the first bug report. What's odd about this is that 
the code works with both the string syntax and the "long lambda" syntax, 
and the new syntax is simply doing a rewrite to the long lambda syntax.

Andrei
December 27, 2011
Re: A nice way to step into 2012
2011/12/27 Joshua Reusch <yoschi@arkandos.de>:
> Am 27.12.2011 05:25, schrieb Andrei Alexandrescu:
>>
>>
>> https://github.com/D-Programming-Language/dmd/commit/675898721c04d0bf155a85abf986eae99c37c0dc
>>
>>
>> Andrei
>
>
> -------------
> import std.algorithm;
>
> void main() {
>        auto arr = [0, 5, 4, 3, 2, 1];
>        sort!((a, b) => a < b)(arr);
> }
> -------------
> $ ./dmd lambda_test
> dmd: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *)
> &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk,
> fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned
> long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *
> (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) &&
> ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)'
> failed.
> $
>
>
> This also "works" with other functions from std.algorithm.

Did you do a clean before compiling? I forgot, and got the same error.

Torarin
1 2 3 4 5 6
Top | Discussion index | About this forum | D home