April 11, 2013 Re: To help LDC/GDC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 04/11/2013 08:16 PM, Jacob Carlborg wrote:
> Why should I have to explicitly specify "immutable" when that could be default for strongly pure functions?
Oh, sorry, I misunderstood your meaning. I thought you were saying that a "strong pure" keyword wasn't necessary because it was sufficient to have pure with immutable/const input.
|
April 11, 2013 Re: To help LDC/GDC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Thursday, 11 April 2013 at 17:52:43 UTC, Walter Bright wrote:
> On 4/11/2013 3:02 AM, deadalnix wrote:
>> On Thursday, 11 April 2013 at 00:41:01 UTC, Walter Bright wrote:
>>> On 4/10/2013 5:33 PM, deadalnix wrote:
>>>> call with const parameter can be considered strongly pure if the argument is
>>>> immutable
>>>
>>> The argument doesn't need to be immutable because nobody can change it while
>>> the function is running.
>>
>> I explained the sentence just above how it is possible. Ignoring issue rarely
>> help when it come to solve them.
>
> The delegate issue is a known one, and can be solved, and is not relevant to this point.
See Timon's post. Both are deeply linked.
|
May 02, 2013 Re: To help LDC/GDC | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | To: NG D Subject: Re: To help LDC/GDC This D code comes from a Haskell solution by tanakh of the Lawnmower problem of the Google Code Jam 2013 Qualification Round: import std.stdio, std.string, std.conv, std.range, std.algorithm; void main() { immutable n = stdin.readln.strip.to!int; foreach (immutable cn; 1 .. n + 1) { const hw = stdin.readln.split.to!(int[]); const bd = hw[0].iota.map!(i => stdin.readln.split.to!(int[])).array; const tbd = hw[1].iota.map!(i => bd.transversal(i).array).array; bool checkH(in int ch) { const okX = tbd.map!(xl => xl.all!(x => x <= ch)).array; foreach (oky, r; bd.map!(yl => yl.all!(y => y <= ch)).zip(bd)) //foreach (okx, c; tbd.map!(xl => xl.all!(x => x <= ch)).zip(r))//Slow. foreach (okx, c; okX.zip(r)) if (c <= ch && !(okx || oky)) return false; return true; } writefln("Case #%d: %s", cn, iota(1, 101).all!checkH ? "YES" : "NO"); } } In the inner foreach I have had to compute okX before the loops otherwise the code gets several times slower. Is such optimization possible from a D compiler? Both "map" and "all" should be pure. The Haskell compiler uses library-defined "rewrite rules" to help in such cases. Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation