November 17, 2016 Re: Boston D Language Meetup in Back Bay | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On 11/17/16 10:38 AM, John Colvin wrote:
> On Thursday, 17 November 2016 at 13:59:25 UTC, Steven Schveighoffer wrote:
>> nullStream!char
>> .bufferedInput
>> .pushTo(
>> arrayCastPipe!ubyte
>> .outputFile("output.txt")
>> );
>>
>> But then the parameters to the "pushTo" hypothetical function don't
>> know what the source type is before calling. By inserting valves, I
>> get the equivalent thing, but the types all are passed down the chain
>> properly.
>
> Can't you use a template lambda alias argument to pushTo instead, so
> then you can instantiate it inside pushTo?
>
> something like
> nullStream!char
> .bufferedInput
> .pushTo!(_ => _
> .arrayCastPipe!ubyte
> .outputFile("output.txt")
> );
> maybe?
I could do that. But I don't like it ;)
I will note that Adrian Matoga's flod library has a different solution that I think is similar to this, but I don't understand it very well.
I'm also concerned that using a lambda is going to confuse or prevent optimization.
I think with some better naming, the push feature will look better.
-Steve
|
November 17, 2016 Re: Boston D Language Meetup in Back Bay | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 17 November 2016 at 16:28:08 UTC, Steven Schveighoffer wrote: > On 11/17/16 10:38 AM, John Colvin wrote: >> On Thursday, 17 November 2016 at 13:59:25 UTC, Steven Schveighoffer wrote: >>> [...] >> >> Can't you use a template lambda alias argument to pushTo instead, so >> then you can instantiate it inside pushTo? >> >> something like >> nullStream!char >> .bufferedInput >> .pushTo!(_ => _ >> .arrayCastPipe!ubyte >> .outputFile("output.txt") >> ); >> maybe? > > I could do that. But I don't like it ;) I don't think it's so bad, but fair enough > I will note that Adrian Matoga's flod library has a different solution that I think is similar to this, but I don't understand it very well. > > I'm also concerned that using a lambda is going to confuse or prevent optimization. Why would you think that? If we can't trust the optimiser (dmd aside) to inline a template lambda argument then phobos is totally screwed! > I think with some better naming, the push feature will look better. > > -Steve I look forward to it. |
November 17, 2016 Re: Boston D Language Meetup in Back Bay | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On 11/17/16 12:42 PM, John Colvin wrote: > On Thursday, 17 November 2016 at 16:28:08 UTC, Steven Schveighoffer wrote: >> On 11/17/16 10:38 AM, John Colvin wrote: >>> On Thursday, 17 November 2016 at 13:59:25 UTC, Steven Schveighoffer >>> wrote: >>>> [...] >>> >>> Can't you use a template lambda alias argument to pushTo instead, so >>> then you can instantiate it inside pushTo? >>> >>> something like >>> nullStream!char >>> .bufferedInput >>> .pushTo!(_ => _ >>> .arrayCastPipe!ubyte >>> .outputFile("output.txt") >>> ); >>> maybe? >> >> I could do that. But I don't like it ;) > > I don't think it's so bad, but fair enough I can say the part I don't like is the _ => _ thing. Ugly. Other than that, it's actually quite nice syntax-wise. >> I'm also concerned that using a lambda is going to confuse or prevent >> optimization. > > Why would you think that? If we can't trust the optimiser (dmd aside) to > inline a template lambda argument then phobos is totally screwed! I admit this isn't a rational fear ;) I just have had experience with lambdas where this does happen. The fear part of my brain is warning me, but the memory part can't remember the specifics of when this happened... What happens when you use a local variable in your lambda expression? -Steve |
Copyright © 1999-2021 by the D Language Foundation