Could we brainstorm a handful of metaprogramming examples/exercises/challenges?
- practical or absurd, both welcome
- with or without solutions, both welcome
- support explanations welcome
The idea is ‘Learning through Doing’.
Here is an example (Thanks @fcard):
# Write a 'swap_args' macro that reverses operands for simple # `<a> <op> <b>` expressions, so ` @swap_args(2/3)` gives 1.5 i.e. 3/2 macro swap_args(e) e.args[2:3] = e.args[3:-1:2] e end @swap_args(2/3) 1.50
I will write up a compendium over the next few days and link it at the top of the WikiBook metaprogramming page: https://en.wikibooks.org/wiki/Introducing_Julia/Metaprogramming.
(EDIT:) Looks like we’re getting a good mix of difficulty levels!