in `@macro` context `c` is not iterable, it is a symbol (a literal 'c'). when the horner macro is evaluated, `c` doesn't have a value, just the expression `:c` – this difference is what differentiates a macro from a function.
On Sat, Aug 30, 2014 at 12:02 AM, Don MacMillen <[email protected]> wrote: > Oops typo in last responce, I meant. > > > julia> @horner(.75, c...) > ERROR: unsupported or misplaced expression ... > > julia> > > On Friday, August 29, 2014 9:00:10 PM UTC-7, Don MacMillen wrote: >> >> Ah, well that was perhaps a bad example. My understanding was the >> you could interpolate an interable. Consider then the horner macro >> >> macro horner(x, p...) >> ex = esc(p[end]) >> for i = length(p)-1:-1:1 >> ex = :($(esc(p[i])) + t * $ex) >> end >> Expr(:block, :(t = $(esc(x))), ex) >> end >> >> if I have a vector of constant coefficients, shouldn't I be able to splice >> them into the macro call? >> >> julia> c = [1.:5] >> 5-element Array{Float64,1}: >> 1.0 >> 2.0 >> 3.0 >> 4.0 >> 5.0 >> >> julia> @horner(.x, c...) >> ERROR: syntax: invalid identifier name "." >> >> >> >> On Friday, August 29, 2014 8:45:00 PM UTC-7, Jameson wrote: >>> >>> that would be utterly pointless, since you can already just write: >>> @mymacro(“aaa”, “bbb”, “ccc”) >>> >>> if you are intending to look at values, you should be using a function. >>> a macro is a function but it's also special in that it takes the quoted AST >>> of it’s arguments during parsing, not their values during runtime >>> >>> observe when b... is getting printed: >>> >>> julia> macro mymacro(a,b) >>> println(b) >>> end >>> >>> julia> f() = @mymacro(a,b...) >>> b... >>> f (generic function with 1 method) >>> >>> julia> f() >>> >>> >>> >>> >>> On Fri, Aug 29, 2014 at 9:45 PM, Don MacMillen <[email protected]> >>> wrote: >>> >>>> I meant something like this >>>> >>>> julia> macro mymacro(a,b,c) >>>> println(c) >>>> end >>>> >>>> julia> @mymacro("aaa", ("bbb", "ccc")...) >>>> ERROR: wrong number of arguments >>>> >>>> which works fine for functions >>>> >>>> julia> function myfunc(a,b,c) >>>> println(c) >>>> end >>>> myfunc (generic function with 1 method) >>>> >>>> julia> myfunc("aaa", ("bbb", "ccc")...) >>>> ccc >>>> >>>> >>>> >>>> >>>> On Friday, August 29, 2014 6:02:45 PM UTC-7, Jameson wrote: >>>> >>>>> splicing into a macro works for me: >>>>> >>>>> julia> macro mymacro(a,b) >>>>> println(b) >>>>> end >>>>> >>>>> julia> @mymacro(x, y...) >>>>> y... >>>>> >>>>> >>>>> >>>>> >>>>> On Fri, Aug 29, 2014 at 8:57 PM, Don MacMillen <[email protected]> >>>>> wrote: >>>>> >>>>>> The slides are great. Many thanks for sharing. >>>>>> >>>>>> I do have a question about macros that maybe you can answer. In your >>>>>> nb on >>>>>> metaprogramming you have the horner macro listed and it uses a >>>>>> temporary >>>>>> variable t. But this macro can be written without using a temporary >>>>>> variable. >>>>>> It turns out to be slower (the no temp version) if we are computing a >>>>>> bunch of >>>>>> polynomials with the same coefficients, but is a tiny bit faster if >>>>>> the coefficients >>>>>> are always changing. So are the Expr's cached? Or is something else >>>>>> going on? >>>>>> >>>>>> Also (OK I have two questions) it looks like we cannot splice into a >>>>>> macro call? >>>>>> Ie @mymacro(x, y...) doesn't work? >>>>>> >>>>>> Thanks again. >>>>>> >>>>>> Don >>>>>> >>>>>> >>>>>> On Friday, August 29, 2014 4:08:44 AM UTC-7, Steven G. Johnson wrote: >>>>>>> >>>>>>> I just gave a talk on Julia at EuroSciPy, and managed to escape >>>>>>> alive. :-) >>>>>>> >>>>>>> I think they will post a video at some point, but in the meantime >>>>>>> the slides and IJulia notebooks are posted at: >>>>>>> >>>>>>> https://github.com/stevengj/Julia-EuroSciPy14 >>>>>>> >>>>>>> --SGJ >>>>>>> >>>>>> >>>>> >>>
