Desperately trying to understand this stuff :-)

Would something like @f2() below work here?

Also works in Julia-0.3.

Can’t figure it out using staged functions (yet?).

Rob J. Goedman
[email protected]


julia> A = (1, 2, 5)
(1,2,5)

julia> macro f1(a,b,c)
         return :($a+$b+$c)
       end

julia> @show @f1(2,4,6);
@f1 2 4 6 = 12

julia> 

julia> B = (3, 6)
(3,6)

julia> macro f2(a, b)
         return :($a + sum($b))
       end

julia> @show @f2(5, B);
@f2 5 B = 14

julia> @show @f2(3, B);
@f2 3 B = 12

julia> versioninfo()
Julia Version 0.4.0-dev+2686
Commit 1548d62* (2015-01-08 15:32 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.1.0)
  CPU: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3


> On Jan 7, 2015, at 8:25 PM, Chi-wei Wang <[email protected]> wrote:
> 
> Any ways to achieve this?
> 
> Jameson於 2015年1月7日星期三UTC-8下午7時32分59秒寫道:
> the declaration `const A = (2,3)` is not part of the macro environment. 
> values are only seen by functions. whereas macros only see the surface 
> syntax. so the arguments to `@f` are the literals `1` and `:(A...)`
> 
> On Wed Jan 07 2015 at 10:04:26 PM Chi-wei Wang <[email protected] 
> <javascript:>> wrote:
> Can ... be applied on macro? I tried this but it didn't compile.
> macro f(a,b,c)
>   return :($a+$b+$c)
> end
> const A = (2,3)
> @f(1, A...)
> 
> 
> 
> Chi-wei Wang於 2015年1月7日星期三UTC-8下午6時45分14秒寫道:
> It works! I missed the varargs section in the doc. Thanks!
> 
> Greg Plowman於 2015年1月7日星期三UTC-8下午5時26分02秒寫道:
> 
> Would the following work?
> 
> const A = (1,2,3)
> f(x::Int, y::Int, z::Int) = x+y+z
> f(A...)
> 
> 
> http://docs.julialang.org/en/release-0.3/manual/functions/#varargs-functions 
> <http://docs.julialang.org/en/release-0.3/manual/functions/#varargs-functions>
> 
> 
> On Thursday, January 8, 2015 11:14:23 AM UTC+11, Chi-wei Wang wrote:
> Hi, everyone. I am trying to achieve the effect like the following C code:
> 
> #define A 1,2,3
> void f(int x, int y, int z) {
> }
> 
> f(A);
> 
> Yet the macro in Julia always returns a single expression. Is it possible to 
> do this?

Reply via email to