Hey all... I just threw together a quick macro to save some typing when
working with the fields of an object.  Disclaimer: this should not be used
in library code, or in anything that will stick around longer than a REPL
session.  Hopefully it's self explanatory with this example.  Is there a
good home for this?  Does anyone want to use it?

julia> type T; a; b; end; t = T(0,0)
T(0,0)

julia> macroexpand(:(
       @with t::T begin
           a = 1
           b = 2
           c = a + b - 4
           d = c - b
           a = d / c
       end
       ))
quote  # REPL[3], line 3:
    t.a = 1 # REPL[3], line 4:
    t.b = 2 # REPL[3], line 5:
    c = (t.a + t.b) - 4 # REPL[3], line 6:
    d = c - t.b # REPL[3], line 7:
    t.a = d / c
end

julia> @with t::T begin
           a = 1
           b = 2
           c = a + b - 4
           d = c - b
           a = d / c
       end
3.0

julia> t
T(3.0,2)

Reply via email to