> > Q1) where to find julia macro tutorials (beyond the standard manual)?
I'm not aware of any tutorials, but there were several JuliaCon talks that are related to some of the nittier details if you are interested [1]. If anything in the manual is unclear or could use more explanation, please do make suggestions. (we're trying to make it accessible for people with no macro background as well as advanced Lispers) Q2) ... improvements You might consider supporting full type declaration syntax, i.e.: @defwithvals type emp age=0 salary=10000 end (Though perhaps this is what Mauro's Parameters.jl package does?) Eventually this will be supported without needing a macro, see: https://github.com/JuliaLang/julia/issues/10146 [1] https://www.youtube.com/watch?v=RYZkHudRTvI&list=PLP8iPy9hna6Sdx4soiGrSefrmOPdUWixM&index=16 https://www.youtube.com/watch?v=xUP3cSKb8sI&list=PLP8iPy9hna6Sdx4soiGrSefrmOPdUWixM&index=62 https://www.youtube.com/watch?v=KAN8zbM659o&list=PLP8iPy9hna6Sdx4soiGrSefrmOPdUWixM&index=55 On Tue, Oct 13, 2015 at 5:18 PM, Tim Menzies <[email protected]> wrote: > this is day3 of julia so pardon dumb questions > > i had some trouble finding tutorials on julia macros. i've read the > textbooks but i suspect there is somewhere else to look (i say that since i > would have thought that the following would exist in standard Julia, but i > could not find it). so, two questions > > Q1) where to find julia macro tutorials (beyond the standard manual)? > > Q2) here's my first julia macro to do something like LISP's defstruct > where i can define a type and its init contents all at one go. comments? > traps for the unwary? improvements? > > # e.g. @def emp age=0 salary=10000 > > # autocreates a constructor emp0 that returns and emp > > # initialized with 0,10000 > > macro has(typename, pairs...) > name = esc(symbol(string(typename,0))) > tmp = esc(symbol("tmp")) > ones = [x.args[1] for x in pairs] > twos = [x.args[2] for x in pairs] > :(type $(typename) > $(ones...) > end; > function $(name)() > $(typename)($(twos...)) > end) > end > > > thanks! > tiim menzies > >
