Re: [julia-users] macro: with

2016-10-09 Thread Tom Breloff
Heh... it took a google search to figure out where I put it.

https://github.com/tbreloff/CTechCommon.jl/blob/master/src/macros.jl#L113-L155

On Sun, Oct 9, 2016 at 12:19 PM, Ben Lauwens  wrote:

> Hi Tom
>
> I am interested. I am building a macro mimicking how iterator blocks are
> transformed in a state-machine in C# (as an alternative to Tasks) and this
> is one of the (many) thinks I have to solve. Can you point me to the
> source? Thanks
>
> Ben


[julia-users] macro: with

2016-10-09 Thread Ben Lauwens
Hi Tom

I am interested. I am building a macro mimicking how iterator blocks are 
transformed in a state-machine in C# (as an alternative to Tasks) and this is 
one of the (many) thinks I have to solve. Can you point me to the source? Thanks

Ben

[julia-users] macro: with

2016-09-07 Thread Tom Breloff
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)


[julia-users] Macro with varargs

2015-04-23 Thread Kuba Roth
This is my first  time writing macros in Julia. I've read related docs but 
could not find an example which works with the arbitrary number of arguments.
So in my example below the args... works correctly with string literals but for 
the passed variables it returns their names and not the values. I'm pretty sure 
this is a newbie mistake and much appreciate any comments.
Thank you.

macro echo (args...)
 :(for x in $args
   print(x, " ")
   end)
end

julia> @echo "AAA" "VVV" 1
AAA VVV 1

julia> testB = "BBB"
"BBB"
julia> testC = "CCC"
"CCC"
julia> @echo testB testC
testB testC