This offers updated macros to assist with delegating into/through fields of 
a defined type.  

Two macros apply a function to field value(s) yielding the functional 
result; 
and two others do that and then rewrap the result in the source type.

The exports are:
       @delegate_oneField, 
       @delegate_oneField_fromTwoVars,
       @delegate_oneField_asType, 
       @delegate_oneField_fromTwoVars_asType

They work so:

import Base:string, show, (<), (<=), abs, (-), (+), (*)

immutable MyInt16
   value::Int16
end

three = MyInt16(3)
seven = MyInt16(7)


@delegate_oneField( MyInt16, value, [string, show])

string(three) == "3"          # true
show(seven)                   # 7


@delegate_oneField_fromTwoVars( MyInt16, value, [ (<), (<=) ] )

three <  seven                # true
seven <= seven                # true


@delegate_oneField_asType( MyInt16, value, [abs, (-)])

abs(three) == three           # true
-seven == MyInt16(-7)         # true


@delegate_oneField_fromTwoVars_asType( MyInt16, value, [ (+), (*) ] )

three + seven == MyInt16(3+7) # true
three * seven == MyInt16(3*7) # true





Reply via email to