JuliaLang/julia — pull request #3292 by johnmyleswhite (2013-06-04 19:58:16+00:00)
Title: RFC: Macro for delegating methods to the fields of a composite type

As discussed long ago on the mailing list (https://groups.google.com/d/msg/julia-dev/MV7lYRgAcB0/s6_RMeHLpEYJ), I've created a simple `@delegate` macro that allows one to delegate methods to the fields of a composite types. An example is shown below in which a new container type can delegate methods like `size` and `length` to an array contained inside of it:

type MyContainer
elems::Array
end

importall Base

@delegate MyContainer.elems [size, length]

x = MyContainer([1, 2, 3, 4])

size(x)
length(x)

Right now, this only supports functions for which the first argument is the field which delegated methods need. Before we merge this, I think we'll want to find a clean generalization.