Ok, afaik examples on README.md work with v0.4.5+ and v0.5.0-dev. Here they 
are:
 

> import Base: length, last
> type MyInts elems::Vector{Int} end;
> type MyNums{T} elems::Vector{T} end;
> @delegate_1field1var( MyInts, elems, [ length, last ] );
> @delegate_1field1var( MyNums, elems, [ length, last ] );
> myInts = MyInts([5, 4, 3, 2, 1]);
> myNums = MyNums([1.0, 2.0, 3.0]);
> length(myInts), length(myNums) # 5, 3
> last(myInts), last(myNums) # 1, 3.0
>
 

> import Base: (<), (<=), isequal, isless
> type MyInt val::Int end;
> @delegate_1field2vars( MyInt, val, [ (<), (<=), isequal, isless ] );
> myFirstInt = MyInt(3)
> mySecondInt = MyInt(7)
> myFirstInt < mySecondInt # true
> mySecondInt <= myFirstInt # false
>
 

> import Base: hypot
> type RightTriangle legA::Float64; legB::Float64; end;
> @delegate_2fields1var( RightTriangle, legA, legB, [ hypot, ] );
> myRightTriangle = RightTriangle( 3.0, 4.0 )
> hypot(myRightTriangle) # 5.0
>
 

> import Base: (+), (-), (*)
> type MyInt val::Int end;
> @traject_1field2vars( MyInt, val, [ (+), (-), (*) ] );
> myFirstInt = MyInt(3)
> mySecondInt = MyInt(7)
> myIntAdds = myFirstInt + mySecondInt # MyInt(10)
> myIntSubtracts = myFirstInt - mySecondInt # MyInt(-4)
> myIntMultiplies = myFirstInt * mySecondInt # MyInt(21)
>
 

> function renormalize(a::Float64, b::Float64)
> hi = a + b
> t = hi - a
> lo = (a - (hi - t)) + (b - t)
> hi, lo
> end
> type HiLo hi::Float64; lo::Float64; end;
> @traject_2fields1var HiLo hi lo [ renormalize, ];
> myHiLo = renormalize( HiLo(12.555555555, 8000.333333333) )
> # HiLo(8012.89,4.44089e-14)
> showall(myHiLo)
> # HiLo(8012.888888888,4.440892098500626e-14)


On Wednesday, June 15, 2016 at 11:59:45 AM UTC-4, Jeffrey Sarnoff wrote:
>
> hmm .. cleaning up (thx)
>
> On Wednesday, June 15, 2016 at 11:38:27 AM UTC-4, ggggg wrote:
>>
>> Looks super useful, thanks.
>>
>> It looks like you let your example get out of date, here is a corrected 
>> version
>> using Delegate
>> import Base: <, <=, +, *, - # later I get WARNING: module Main should 
>> explicitly import < from Base if I don't import Base:
>>
>> immutable AnInt
>>   val::Int
>> end
>> int1 = AnInt(1)
>> int2 = AnInt(2)
>>
>> @delegate_1field2vars AnInt val [ (<), (<=) ]; # returns <=
>> @traject_1field2vars  AnInt val [ (+), (-), (*) ]; # returns *
>>
>> int1+int2 # returns AnInt(3)
>> int1<int2 # returns true
>>
>> # dont use the following, wrong number of arguments
>> #@delegate_1field2vars AnInt.val [ (<), (<=) ];
>>
>>
>>
>> On Wednesday, June 15, 2016 at 4:18:50 AM UTC-6, Jeffrey Sarnoff wrote:
>>>
>>> Pkg.clone("https://github.com/Jeffrey-Sarnoff/Delegate.jl";)
>>>
>>>  
>>>
>>>> using Delegate 
>>>
>>> import <, <=, +, *
>>>
>>> immutable AnInt
>>>
>>>     val::Int 
>>>
>>> end 
>>>
>>>  
>>>
>>> int1 = AnInt(1) 
>>>
>>> int2 = AnInt(2) 
>>>
>>>  
>>>
>>> @delegate_1field2vars AnInt.val [ (<), (<=) ];           # plain results
>>>
>>> @traject_1field2vars( MyInt, val, [ (+), (-), (*) ] );   # type 
>>>> re-wrapped results
>>>
>>>  
>>>
>>> int1 < int2
>>>
>>> true 
>>>
>>>  
>>>
>>> int1 + int2
>>>
>>> AnInt(3) 
>>>
>>>  
>>>
>>>
>>> Also exports 2field versions and 1var versions.
>>> More examples are available in the README.md and in the tests.
>>>
>>> This is built on the work of John Myles White and Toivo Hennigsson.
>>>
>>>

Reply via email to