Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. """
  2. @def
  3.  
  4. Macro used to create sections of code that can
  5. be copy/pasted into other code
  6. """
  7. macro def(name, definition)
  8. return quote
  9. macro $(esc(name))()
  10. esc($(Expr(:quote, definition)))
  11. end
  12. end
  13. end
  14.  
  15. # Example of macro that adds some default fields
  16. @def add_default_fields begin
  17. name::String
  18. size::Int
  19. end
  20.  
  21. # Object that has fields from add_default_fields copy/pasted into it
  22. struct Thing1
  23. @add_default_fields
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement