@@ -30,11 +30,12 @@ function rand_macro(ex)
3030 namefull = sig. args[2 ] # x::X
3131 @assert namefull. head == :(:: ) # TODO : throw exception
3232
33- sps = Any[] # sub-samplers
33+ # sub-samplers; second argument true forces Val(Inf) for the sampler
34+ sps = Pair{<: Any ,Bool}[]
35+
3436 rng = gensym ()
3537 body = samplerize! (sps, body, argname, rng)
3638 istrivial = isempty (sps)
37- # rand -> Base.rand
3839
3940 exsig = Expr (:call ,
4041 :(Random. rand),
@@ -69,7 +70,7 @@ function rand_macro(ex)
6970
7071 # insert inner samplers
7172 if ! istrivial
72- SP = [Expr (:call , :Sampler , :RNG , esc (x), : n ) for x in sps]
73+ SP = [Expr (:call , :Sampler , :RNG , esc (x), many ? Val {Inf} () : : n ) for (x, many) in sps]
7374 @assert :SP == pop! (sp. args[2 ]. args[2 ]. args[2 ]. args[3 ]. args)
7475 append! (sp. args[2 ]. args[2 ]. args[2 ]. args[3 ]. args, SP)
7576 end
@@ -95,8 +96,9 @@ function samplerize!(sps, ex, name, rng)
9596 end
9697 ex isa Expr || return ex
9798 if ex. head == :call && ex. args[1 ] == :rand
98- # TODO : handle Repetition == Val(Inf) for arrays
99- push! (sps, ex. args[2 ])
99+ # we assume that if rand has more than one arg, we want
100+ # a Val(Inf) sampler (e.g. rand(1:9, 2, 3)
101+ push! (sps, ex. args[2 ] => length (ex. args) > 2 )
100102 i = length (sps)
101103 Expr (:call , :rand , rng, :($ name. data[$ i]), ex. args[3 : end ]. .. )
102104 else
0 commit comments