Feature or bug: print braces

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 14 15:55:42 PDT 2015


On 05/14/2015 03:39 PM, Dennis Ritchie wrote:
> On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote:
>> On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote:
>>> On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote:
>>>> You told it to output a function literal, so it did.
>>>
>>> Yes, but it would be logical to deduce something like:
>>> -----
>>> writeln({}); // prints literal[{}]
>>>
>>> Or the compiler will not be able to distinguish the literal from the
>>> ordinary function arguments?
>>
>> Literal what?
>>
>> Associative array? That uses square brackets, not curly brackets.
>> Struct? What struct would you be creating? And curly braces only works
>> for initialization.
>> Lambda? Well you can omit the parameters if there are none, and `{}`
>> in a lambda will give you a block to write, so `{}` is a valid lambda
>> that accepts nothing and does nothing.
>
> I just wanted to say that writeln function of demand should not print
> anything else at this challenge, not 804CF88 :)
>
> -----
> writeln({});

Yes, it is weird but that value happens to be the address of the 
function. Here is another test:

import std.stdio;

void foo() pure nothrow @nogc @safe
{}

void main()
{
     void printInfo(T)(T t)
     {
         writefln("%s %s", T.stringof, t);
     }

     auto f = (){};    // <-- Why the need for () here?

     printInfo(&foo);
     printInfo(f);
     printInfo({});    // <-- No need for () here.
}

There is an inconsistency where a lambda need to be defined with empty 
parentheses in one context while it is just fine without in another context.

One output shows that they are all of the same type (function pointers):

void function() pure nothrow @nogc @safe 473264
void function() pure nothrow @nogc @safe 4732BC
void function() pure nothrow @nogc @safe 4732C4

Ali



More information about the Digitalmars-d-learn mailing list