May 31, 2016
On Monday, 23 May 2016 at 19:00:40 UTC, Adam D. Ruppe wrote:
> Have I gone completely mad?!?!
>
> ---
> void main() {
>         import std.stdio;
>         writeln(obj!(
>                 foo => "bar",
>                 baz => 12
>         ));
> }
> ---
>
> Prints out:
>
> {
>         foo: bar
>         baz: 12
> }

 Pretty snazzy :) Like enums, except not...
June 08, 2016
On Friday, 27 May 2016 at 18:10:59 UTC, Vladimir Panteleev wrote:
> This is by far the most appealing way to implement named arguments that I've seen so far:
>
> https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d

Another cool thing this enables: object initializers.

  T init(T, Args...)() {
    import std.traits : FunctionTypeOf;

    static struct DummyType {}
    static if (is(T == class)) T r = new T;
    else T r;

    foreach (arg; Args) {
      alias fun = arg!DummyType;
      static if (is(FunctionTypeOf!fun PT == __parameters)) {
        enum name = __traits(identifier, PT);
        foreach (m; __traits(allMembers, T)) {
          static if (name == m) __traits(getMember, r, m) = fun(DummyType.init);
        }
      }
    }
    return r;
  }

  struct Point {
    int x, y;
  }

  void main() {
    auto pt = init!(Point, x => 123, y => 456);
    assert(pt.x == 123 && pt.y == 456);
  }
June 11, 2016
On Wednesday, 8 June 2016 at 09:19:46 UTC, John wrote:
> On Friday, 27 May 2016 at 18:10:59 UTC, Vladimir Panteleev wrote:
>> This is by far the most appealing way to implement named arguments that I've seen so far:
>>
>> https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d
>
> Another cool thing this enables: object initializers.

Already in the link you quoted, FYI.
June 11, 2016
On Tuesday, 31 May 2016 at 06:21:03 UTC, Andrei Alexandrescu wrote:
> On 5/27/16 10:17 PM, Taylor Hillegeist wrote:
>> On Friday, 27 May 2016 at 18:10:59 UTC, Vladimir Panteleev wrote:
>>> On Monday, 23 May 2016 at 19:00:40 UTC, Adam D. Ruppe wrote:
>>>> Have I gone completely mad?!?!
>>>
>>> Yes, though what does it have to do with this thread? :D
>>>
>>> This is by far the most appealing way to implement named arguments
>>> that I've seen so far:
>>>
>>> https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d
>>
>> This is very nice... way more clean than I imagined possible.
>
> s/args/make/g and we have a nice function for std.conv. -- Andrei

Do I gather from that that you propose adding only the overload that creates structs?

June 11, 2016
On 6/11/16 3:57 AM, Vladimir Panteleev wrote:
> On Tuesday, 31 May 2016 at 06:21:03 UTC, Andrei Alexandrescu wrote:
>> On 5/27/16 10:17 PM, Taylor Hillegeist wrote:
>>> On Friday, 27 May 2016 at 18:10:59 UTC, Vladimir Panteleev wrote:
>>>> On Monday, 23 May 2016 at 19:00:40 UTC, Adam D. Ruppe wrote:
>>>>> Have I gone completely mad?!?!
>>>>
>>>> Yes, though what does it have to do with this thread? :D
>>>>
>>>> This is by far the most appealing way to implement named arguments
>>>> that I've seen so far:
>>>>
>>>> https://github.com/CyberShadow/ae/blob/master/utils/meta/args.d
>>>
>>> This is very nice... way more clean than I imagined possible.
>>
>> s/args/make/g and we have a nice function for std.conv. -- Andrei
>
> Do I gather from that that you propose adding only the overload that
> creates structs?

No, both are nice to have. If one name is needed for both, "args" is indeed a good commonality. "Invoke function f with these args" and "Construct an object of type T with these args". The problem is it's not very intuitive in usage.

Perhaps "call" for functions and "make" for objects are better. If we add these to std.experimental.functional and std.experimental.conv and they get a lot of usage we might make a small change to the language.


Andrei

June 11, 2016
On Saturday, 11 June 2016 at 09:07:43 UTC, Andrei Alexandrescu wrote:

> No, both are nice to have. If one name is needed for both, "args" is indeed a good commonality. "Invoke function f with these args" and "Construct an object of type T with these args". The problem is it's not very intuitive in usage.
>
> Perhaps "call" for functions and "make" for objects are better. If we add these to std.experimental.functional and std.experimental.conv and they get a lot of usage we might make a small change to the language.
>
>
> Andrei

would'nt it be possible to take the type as a runtime param
and support struct, class and all callables?
e.g.

(&fun).args!(a=>5, b=>6);

auto st = SomeStruct().args!(a=>3);

auto sc = new SomeClass().args!(x => 20, y => 50);

(&sc.fun).args!(x => 6);

or named and positional args
(&sc.fun).args!(x => 9)(3, 6);
June 11, 2016
On Saturday, 11 June 2016 at 11:15:43 UTC, ArturG wrote:
> On Saturday, 11 June 2016 at 09:07:43 UTC, Andrei Alexandrescu wrote:
>
>> No, both are nice to have. If one name is needed for both, "args" is indeed a good commonality. "Invoke function f with these args" and "Construct an object of type T with these args". The problem is it's not very intuitive in usage.
>>
>> Perhaps "call" for functions and "make" for objects are better. If we add these to std.experimental.functional and std.experimental.conv and they get a lot of usage we might make a small change to the language.
>>
>>
>> Andrei
>
> would'nt it be possible to take the type as a runtime param
> and support struct, class and all callables?
> e.g.
>
> (&fun).args!(a=>5, b=>6);

Taking an address creates a function pointer, which loses the argument names. (Doesn't it?)

June 11, 2016
On Saturday, 11 June 2016 at 15:46:59 UTC, Vladimir Panteleev wrote:

> Taking an address creates a function pointer, which loses the argument names. (Doesn't it?)

unfortunatly yes, but it works as a struct or class initializer
https://dpaste.dzfl.pl/6aad852aea90
1 2 3
Next ›   Last »