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

Reply via email to