Works! I placed it in a freshly made juliarc.jl. Thanks!
On Sunday, September 14, 2014 10:35:58 AM UTC+10, Patrick O'Leary wrote: > > On Saturday, September 13, 2014 11:06:25 AM UTC-5, Isaiah wrote: >> >> Macros are useful for this sort of thing. >> > > I'm on an isexpr() evangelism mission. Also going to use if statements for > additional exposition. > > using Base.Meta > macro allconst(args...) > exp = Expr(:block) > if isexpr(args[1], :block) > for a in args[1].args > if isexpr(a, :(=)) > push!(exp.args, Expr(:const, Base.esc(a))) > end > end > end > exp > end > > > >> >> ``` >> macro allconst(args...) >> exp = Expr(:block) >> args[1].head == :block && for a in args[1].args >> a.head == :(=) && push!(exp.args, Expr(:const, Base.esc(a) >> )) >> end >> exp >> end >> >> @allconst begin >> a = 1 >> b = 2 >> end >> ``` >> >> (see the Metaprogramming section in the manual for more information) >> >> On Sat, Sep 13, 2014 at 8:37 AM, Yakir Gagnon <12.y...@gmail.com >> <javascript:>> wrote: >> >>> I often define a bunch of constants at the beginning of a program. >>> Wouldn't it be nice if we could start an environment of constants to avoid >>> writing `const` before every one of the rows at the beginning of a program? >>> Kind of like: >>> ```Julia >>> begin const >>> a = 1 >>> b = 2 >>> c = "neverChange" >>> end >>> ``` >>> instead of: >>> ```Julia >>> const a = 1 >>> const b = 2 >>> const c = "neverChange" >>> ``` >>> >> >>