Richard Birkett

Feb 26, 2012, 09:39 AM

I have a macro like this:

#define IntMethods(lower, cap, parameter) \

- (MMExpressionType)symboliccapWithInt:(SInt64)parameter\

{\

return [(MMExpressionType)self symboliccap:[[MMTerm alloc] initWithInteger:parameter]];\

}\

\

- (MMExpressionType)lowerWithInt:(SInt64)parameter\

{\

return [(MMExpressionType)self lower:[[MMTerm alloc] initWithInteger:parameter]];\

}

It is supposed to replace a repetitive set of implementations, I hope you understand what I am trying to do. My code here gets errors, it seems to think I'm literally using symboliccap etc. instead of something using the macro parameter.

Here is some desired output to input that will hopefully help if you don't understand.

IntMethods(add, Add, addend)

should be equivalent to

- (MMExpressionType)symbolicAddWithInt:(SInt64)exponent

{

return [(MMExpressionType)self symbolicAdd:[[MMTerm alloc] initWithInteger:addend]];

}

- (MMExpressionType)addWithInt:(SInt64)exponent

{

return [(MMExpressionType)self add:[[MMTerm alloc] initWithInteger:addend]];

}

Help greatly appreciated. :)

#define IntMethods(lower, cap, parameter) \

- (MMExpressionType)symboliccapWithInt:(SInt64)parameter\

{\

return [(MMExpressionType)self symboliccap:[[MMTerm alloc] initWithInteger:parameter]];\

}\

\

- (MMExpressionType)lowerWithInt:(SInt64)parameter\

{\

return [(MMExpressionType)self lower:[[MMTerm alloc] initWithInteger:parameter]];\

}

It is supposed to replace a repetitive set of implementations, I hope you understand what I am trying to do. My code here gets errors, it seems to think I'm literally using symboliccap etc. instead of something using the macro parameter.

Here is some desired output to input that will hopefully help if you don't understand.

IntMethods(add, Add, addend)

should be equivalent to

- (MMExpressionType)symbolicAddWithInt:(SInt64)exponent

{

return [(MMExpressionType)self symbolicAdd:[[MMTerm alloc] initWithInteger:addend]];

}

- (MMExpressionType)addWithInt:(SInt64)exponent

{

return [(MMExpressionType)self add:[[MMTerm alloc] initWithInteger:addend]];

}

Help greatly appreciated. :)