Functional oriented programming in D

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 16 07:21:49 PDT 2015


On Thursday, 16 July 2015 at 09:57:55 UTC, Jarl André Hübenthal 
wrote:
> On Thursday, 16 July 2015 at 09:52:59 UTC, ponce wrote:
>> On Thursday, 16 July 2015 at 09:49:03 UTC, Jarl André 
>> Hübenthal wrote:
>>> Why?
>>
>> The syntax for delegate literals with braces is
>>
>>> listenHTTP(settings, (req, res) {
>>> 	res.writeBody("Hello, World!");
>>> });
>
> Thanks. Those small details you forget to test before asking is 
> a bit embarrassing. I blame Scala for it :) In Scala its 
> (req,res) => { ... } consistently.

The difference in D is that (req, res) => { ... } is still valid 
syntax, but it doesn't do what you'd expect. { /* some code */ } 
is a valid delegate literal in D, specifying a delegate literal 
that takes no arguments. Thus, (req, res) => { /* some code */ } 
actually creates a delegate literal than returns *another* 
delegate literal.


More information about the Digitalmars-d-learn mailing list