Skip to content

Commit

Permalink
Merge pull request #42 from JuliaLang/sjk/ngenerate
Browse files Browse the repository at this point in the history
Define X_n variables on entry to function generated by nsplat/ngenerate
  • Loading branch information
simonster committed Feb 9, 2015
2 parents 0b4b92a + c2f960e commit 94423b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ngenerate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function _nsplat(prototype, body, varname, T, itersym)
bodyquot = Expr(:quote, body)
newbody = quote
$itersym = length($varsym)
Compat.CompatCartesian.resolvesplats!($bodyquot, $varquot, $itersym)
quote
Base.Cartesian.@nexprs $($itersym) (d->$($(Expr(:quote, symbol(varsym, "_d")))) = $($varquot)[d])
$(Compat.CompatCartesian.resolvesplats!($bodyquot, $varquot, $itersym))
end
end
prototype, newbody
end
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ end
@test size(bitrand(MersenneTwister(), 3, 4)) == (3, 4)
@test size(bitrand(MersenneTwister(), (3, 4))) == (3, 4)
@test rand(Bool) in [false, true]

module CartesianTest
using Base.Cartesian, Compat
@ngenerate N NTuple{N,Int} function f(X::NTuple{N,Int}...)
@ncall N tuple X
end
end

@test CartesianTest.f(1) == (1,)
@test CartesianTest.f(1,2) == (1,2)
@test CartesianTest.f(1,2,3) == (1,2,3)
@test CartesianTest.f(1,2,3,4) == (1,2,3,4)
@test CartesianTest.f(1,2,3,4,5) == (1,2,3,4,5)

0 comments on commit 94423b4

Please sign in to comment.