On Wednesday, October 14, 2015 at 5:53:47 AM UTC-4, Mauro wrote: > > My package https://github.com/mauro3/Parameters.jl does something > similar to your example. So you could have a look at that and get some > inspiration.
Parameters.jl is amazing... so detailed But, i fear, a bridge too far for a newb like me. I promise to return to it in small N months to see if I "grok" it then. -- @timmenzies > > Also xdump and Meta.show_sexpr are your friends in dissecting Expr. > > On Tue, 2015-10-13 at 23:18, Tim Menzies <[email protected] <javascript:>> > 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 >
