On Sun, Jul 19 2015, Mark S <[email protected]> wrote:
Second (and relatedly) I am trying to get a better sense of the
need and the utility of macros and meta-programming--what do
they make possible that is otherwise not possible? Also at the
moment for the way that I am going to use Julia, clarity in the
code is a top priority (over fanciness). So if I can write
something that is easier to read (for a novice) then that is an
approach that I prefer to one that is more sophisticated but
also more obscure. One of the things I like about Julia is that
generally it is quite easy to read.
Macros can provide a lot of clarity when designed well; that's one
of the reasons people use them.
Think of macros as a source code transformation, generally this is
done at compile time and ideally it should be orthogonal to
runtime evaluation.
Third I am interested in working with delayed evaluation and was
trying to get a better sense of that also. I'd like to
understand how the macro implementation is better than the
procedural implementation.
You mention that there would be a lot of boilerplate code
without macros . . . . It seemed to me that once you have
delaying and forcing procedures there is not big difference in
delayed evaluation compared to where it is implemented using
macros. I am interested in better understanding your comment
. . . .
Look at Lazy.jl, and see how macros are used. Eg look at the
definition of @lazy, and try manually constructing the expression
that it expands to, I think it will be instructive.
Julia's model for macros follows the Lisp family quite closely,
except, of course, for AST representation. Lisp-family languages
(Scheme, CL) have quite a few good books/resources on macros, but
Julia is relatively young so these are harder to come by. So if
you haven't encountered macros before, the best way to learn might
be looking at well-designed examples and understanding the
details.
Best,
Tamas