this case is pretty simple:
for letter in [:A,:B]
@eval begin
function $letter(T::test)
T.$letter
end
end
end
@eval == eval(quote .... end) == eval( :( .... ) )
Am Mittwoch, 2. September 2015 11:16:53 UTC+2 schrieb Robert DJ:
>
> Hi,
>
> I have a situation where a number of functions differ so little that it
> would make sense to define them by a loop.
> I don't know if I am using the correct jargon, but here is a small example
> to illustrate:
>
> type test
> A::Int
> B::Int
> end
>
> function A(T::test)
> T.A
> end
>
> function B(T::test)
> T.B
> end
>
>
> If possible, I would like to define the functions A and B along these
> lines:
>
> for letter in [A,B]
> function letter(T::Test)
> T.letter
> end
> end
>
>
> Thanks,
>
> Robert
>