April 20, 2012
On 20.04.2012 19:14, Xan wrote:
> On Friday, 20 April 2012 at 14:18:37 UTC, Dmitry Olshansky wrote:
>> On 20.04.2012 18:10, Xan wrote:
>>> What fails if I want to define this:
>>>
>>> Algorisme!(T,V) opBinary(string op)(Algorisme!(T,U) alg) {
>>
>> Algorisme!(T,V) opBinary(string op, T)(Algorisme!(T,U) alg) {
>>
>> You need to name what T is and that is *sometype*. Anyway I suggest
>> getting a decent book (TDPL).
>>
>>> if (op=="*") {
>>
>> static if is conceptually and technically better here.
>
>
> Thanks, Dmitry, for your suggestions, but it does not work too:
>
> $ gdmd-4.6 algorisme
> algorisme.d:54: Error: 'alg' is not of arithmetic type, it is a
> algorisme.Algorisme!(int,int).Algorisme
> algorisme.d:54: Error: 'alg2' is not of arithmetic type, it is a
> algorisme.Algorisme!(int,int).Algorisme
>
>
> I update de gist: https://gist.github.com/2429005
>
> By the other hand, is there any way to put the definition of operator *
> in the class (not out like I have now)?
>

it should be inside the class. Why would you put it outside and hope it work? What 'this' can refer to in free function?

Please read spec at the very least.
http://dlang.org/operatoroverloading.html

>
> Thanks,
> Xan.


-- 
Dmitry Olshansky
April 20, 2012
On Friday, 20 April 2012 at 18:47:14 UTC, Dmitry Olshansky wrote:
> On 20.04.2012 19:14, Xan wrote:
>> On Friday, 20 April 2012 at 14:18:37 UTC, Dmitry Olshansky wrote:
>>> On 20.04.2012 18:10, Xan wrote:
>>>> What fails if I want to define this:
>>>>
>>>> Algorisme!(T,V) opBinary(string op)(Algorisme!(T,U) alg) {
>>>
>>> Algorisme!(T,V) opBinary(string op, T)(Algorisme!(T,U) alg) {
>>>
>>> You need to name what T is and that is *sometype*. Anyway I suggest
>>> getting a decent book (TDPL).
>>>
>>>> if (op=="*") {
>>>
>>> static if is conceptually and technically better here.
>>
>>
>> Thanks, Dmitry, for your suggestions, but it does not work too:
>>
>> $ gdmd-4.6 algorisme
>> algorisme.d:54: Error: 'alg' is not of arithmetic type, it is a
>> algorisme.Algorisme!(int,int).Algorisme
>> algorisme.d:54: Error: 'alg2' is not of arithmetic type, it is a
>> algorisme.Algorisme!(int,int).Algorisme
>>
>>
>> I update de gist: https://gist.github.com/2429005
>>
>> By the other hand, is there any way to put the definition of operator *
>> in the class (not out like I have now)?
>>
>
> it should be inside the class. Why would you put it outside and hope it work? What 'this' can refer to in free function?

Yes, you're wright. So in.

But what fails?

I reveice these errors and I have no idea what fails!


>
> Please read spec at the very least.
> http://dlang.org/operatoroverloading.html

I read it. It served me as guide. But not I'm in trouble....
Can you help me fixing the bug!

Regards,
Xan.


>
>>
>> Thanks,
>> Xan.



April 20, 2012
> Yes, you're wright. So in.
>
> But what fails?
>
> I reveice these errors and I have no idea what fails!
>

Sorry, the errors are:

$ gdmd-4.6 algorisme.d
algorisme.d:35: Error: 'this' is only defined in non-static member functions, not __funcliteral1
algorisme.d:35: Error: function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1 cannot access frame of function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
algorisme.d:35: Error: function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1 cannot access frame of function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
algorisme.d:35: Error: function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1 cannot access frame of function algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
algorisme.d:35: Error: constructor algorisme.Algorisme!(int,int).Algorisme.this (string nom, uint versio, int function(int) funcio) is not callable using argument types (string,int,_error_ function(int t) nothrow @system)
algorisme.d:35: Error: cannot implicitly convert expression (__funcliteral1) of type _error_ function(int t) nothrow @system to int function(int)
algorisme.d:52: Error: template instance algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int) error instantiating



I update the gist: https://gist.github.com/2429005
April 20, 2012
On 20.04.2012 23:33, Xan wrote:
>> Yes, you're wright. So in.
>>
>> But what fails?
>>
>> I reveice these errors and I have no idea what fails!
>>
>
> Sorry, the errors are:
>
> $ gdmd-4.6 algorisme.d
> algorisme.d:35: Error: 'this' is only defined in non-static member
> functions, not __funcliteral1

Easy - _this_ inside of
 function (T t) { return this.funcio(alg.funcio(t)); }

Is not going to fly because there is no way to "store" _this_ in function, use delegates (this is a context and it has to be "copied" -> use delegates). But then you'd have to change to delegate everywhere.

(and there is toDelegate function in std.functional, that converts function to delegate)

> algorisme.d:35: Error: function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
> cannot access frame of function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
> algorisme.d:35: Error: function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
> cannot access frame of function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
> algorisme.d:35: Error: function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
> cannot access frame of function
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
> algorisme.d:35: Error: constructor
> algorisme.Algorisme!(int,int).Algorisme.this (string nom, uint versio,
> int function(int) funcio) is not callable using argument types
> (string,int,_error_ function(int t) nothrow @system)
> algorisme.d:35: Error: cannot implicitly convert expression
> (__funcliteral1) of type _error_ function(int t) nothrow @system to int
> function(int)
> algorisme.d:52: Error: template instance
> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int) error
> instantiating
>
>
>
> I update the gist: https://gist.github.com/2429005


-- 
Dmitry Olshansky
April 21, 2012
Thank you very very much, Dmitry. Now all it's fine!

Xan.

On Friday, 20 April 2012 at 19:51:40 UTC, Dmitry Olshansky wrote:
> On 20.04.2012 23:33, Xan wrote:
>>> Yes, you're wright. So in.
>>>
>>> But what fails?
>>>
>>> I reveice these errors and I have no idea what fails!
>>>
>>
>> Sorry, the errors are:
>>
>> $ gdmd-4.6 algorisme.d
>> algorisme.d:35: Error: 'this' is only defined in non-static member
>> functions, not __funcliteral1
>
> Easy - _this_ inside of
>  function (T t) { return this.funcio(alg.funcio(t)); }
>
> Is not going to fly because there is no way to "store" _this_ in function, use delegates (this is a context and it has to be "copied" -> use delegates). But then you'd have to change to delegate everywhere.
>
> (and there is toDelegate function in std.functional, that converts function to delegate)
>
>> algorisme.d:35: Error: function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
>> cannot access frame of function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
>> algorisme.d:35: Error: function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
>> cannot access frame of function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
>> algorisme.d:35: Error: function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary.__funcliteral1
>> cannot access frame of function
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int).opBinary
>> algorisme.d:35: Error: constructor
>> algorisme.Algorisme!(int,int).Algorisme.this (string nom, uint versio,
>> int function(int) funcio) is not callable using argument types
>> (string,int,_error_ function(int t) nothrow @system)
>> algorisme.d:35: Error: cannot implicitly convert expression
>> (__funcliteral1) of type _error_ function(int t) nothrow @system to int
>> function(int)
>> algorisme.d:52: Error: template instance
>> algorisme.Algorisme!(int,int).Algorisme.opBinary!("*",int) error
>> instantiating
>>
>>
>>
>> I update the gist: https://gist.github.com/2429005


1 2
Next ›   Last »