Julia macros can handle variables and literals differently?

Hello Julia friends,

Why is this

using HDF5, JLD
  s = "It would take me 48 hours to recompute this."
  filename_no_ext = "eric_demo_file"
  @save filename_no_ext
  readdir()
  @load "eric_demo_file"

      

to evaluate differently from this?

using HDF5, JLD
  s = "It would take me 48 hours to recompute this."
  filename_no_ext = "eric_demo_file"
  @save filename_no_ext
  readdir()
  @load filename_no_ext

      

+3


source to share


1 answer


Macros are very different beasts compared to functions. One difference is that they don't evaluate their arguments: http://docs.julialang.org/en/latest/manual/metaprogramming/#macro-invocation

It is important to emphasize that macros receive their arguments as expressions, literals, or symbols.



To see the implications, compare the two outputs (left as an exercise):

julia> macroexpand(:(@load filename_no_ext))

julia> macroexpand(:(@load "eric_demo_file"))

      

+3


source







All Articles