www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - chaining immutable methods vs functions

reply "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
Why do I get the error message:

Error: immutable method fbool.fbool.and is not callable using a 
mutable object

when chaining methods? It works fine using regular function calls?

struct fbool {
   ubyte data;
   pure immutable fbool and(immutable fbool b){return b.data < 
data ? b : this;}
   pure immutable fbool or(immutable fbool b){return b.data > data 
? b : this; }
   pure immutable fbool not(){ return fbool(data^255);}
}

immutable fbool not(immutable fbool a){ return fbool(a.data^255); 
}
immutable fbool and(immutable fbool a, immutable fbool b){ return 
a.data < b.data ? a : b;}
immutable fbool or(immutable fbool a, immutable fbool b){ return 
a.data > b.data ? a : b;}

or(and(not(a),b),and(not(a),b)); //this works
a.not().and(b).or( b.not().and(a) ); // this does not work
Jan 16 2014
parent "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Friday, 17 January 2014 at 01:49:24 UTC, Ola Fosheim Grøstad 
wrote:
   pure immutable fbool and(immutable fbool b){return b.data <
Nevermind, I figured this out. immutable(fbool), not immutable fbool...
Jan 16 2014