November 23, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote:
> Being able to get an alias to (ref int) seems like a bug.
you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type.
yeah, `ref` is very special beast. but it is still type modifier. ;-)
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote:
> On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote:
>> Being able to get an alias to (ref int) seems like a bug.
>
> you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type.
>
> yeah, `ref` is very special beast. but it is still type modifier. ;-)
Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks...
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Thursday, 24 November 2016 at 00:04:51 UTC, Tofu Ninja wrote:
> On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote:
>> On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote:
>>> Being able to get an alias to (ref int) seems like a bug.
>>
>> you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type.
>>
>> yeah, `ref` is very special beast. but it is still type modifier. ;-)
>
> Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks...
either this, or you won't be able to replicate function with it's exact args; you won't be able to even check if some arg is ref.
but not having `ref int` as a valid type declaration has it's reasons.
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Thursday, 24 November 2016 at 00:15:07 UTC, ketmar wrote:
> On Thursday, 24 November 2016 at 00:04:51 UTC, Tofu Ninja wrote:
>> On Wednesday, 23 November 2016 at 23:21:53 UTC, ketmar wrote:
>>> On Wednesday, 23 November 2016 at 23:02:30 UTC, Tofu Ninja wrote:
>>>> Being able to get an alias to (ref int) seems like a bug.
>>>
>>> you are unable to alias it, `ref` will be erased on aliasing. the only way to retain it is to have a tuple with it. that trick aliases *function* *argument* *tuple*, not a single type.
>>>
>>> yeah, `ref` is very special beast. but it is still type modifier. ;-)
>>
>> Unless I can write "alias refint = ref int;", this should not be a feature at all... how did anyone think this is a good idea. Seriously I used to love D but now it's just a mess of hacks...
>
> either this, or you won't be able to replicate function with it's exact args; you won't be able to even check if some arg is ref.
>
> but not having `ref int` as a valid type declaration has it's reasons.
You still can't replicate a function with this. No way to replicate or even know if a parameter is variadic. No way to replicate the ref on the return. No way to replicate the linkage or attributes of the function. This is a hack that solves nothing.
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Thursday, 24 November 2016 at 00:19:04 UTC, Tofu Ninja wrote:
> You still can't replicate a function with this.
you can, by using std.traits and string mixins.
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Thursday, 24 November 2016 at 00:36:54 UTC, ketmar wrote:
> On Thursday, 24 November 2016 at 00:19:04 UTC, Tofu Ninja wrote:
>> You still can't replicate a function with this.
> you can, by using std.traits and string mixins.
Even with std.traits, you can't know which arguments are variadic. The only way to actually replicate a function is with string mixins and parsing the stringof of the function you want to replicate. This (ref int) thing does not help one bit and will only trick people into thinking they are properly replicating the call signature when they are not.
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote: > Even with std.traits, you can't know which arguments are variadic. sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature. |
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Thursday, 24 November 2016 at 02:11:21 UTC, ketmar wrote:
> On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote:
>> Even with std.traits, you can't know which arguments are variadic.
> sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html
>
> that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature.
Oh well that is my bad, for some reason I was under the impression that there could be more than one typesafe variadic. Still I think the way all of this currently works is very misleading, certainly there is lots of code out there trying to replicate call signatures but are doing it wrong. Having Parameters!(fun) capture things like ref is only going to mislead people(like me!) into thinking it is enough.
|
November 24, 2016 Re: How to declare function with the same call signature as another? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | On Thursday, 24 November 2016 at 02:52:05 UTC, Tofu Ninja wrote:
> On Thursday, 24 November 2016 at 02:11:21 UTC, ketmar wrote:
>> On Thursday, 24 November 2016 at 00:51:01 UTC, Tofu Ninja wrote:
>>> Even with std.traits, you can't know which arguments are variadic.
>> sure, you can. see http://dpldocs.info/experimental-docs/std.traits.variadicFunctionStyle.html
>>
>> that will return variadic style. and the only argument that can be variadic is last. it is enough to reconstruct the signature.
>
> Oh well that is my bad, for some reason I was under the impression that there could be more than one typesafe variadic. Still I think the way all of this currently works is very misleading, certainly there is lots of code out there trying to replicate call signatures but are doing it wrong. Having Parameters!(fun) capture things like ref is only going to mislead people(like me!) into thinking it is enough.
here i agree. ;-) still, i can't think out a better way to do that. if you have any solid (or at least semi-solid ;-) ideas, feel free to start a new thread, we love bikeshedding! ;-)
|
Copyright © 1999-2021 by the D Language Foundation