Julia: How do I create a macro that returns its argument? -


my question quite similar this one, difference. want create macro (or whatever) behaves way:

julia> @my-macro x + 2 :(x + 2) 

(note x + 2 not enclosed in quotes). there in julia? , if there not, how do it? (please, give detailed explanation why works.)

the input expression macro needs quoted because macro returns expression, evaluated, while expression itself, hence need quoting. quoting can done as:

macro mymacro(ex)     expr(:quote,ex) # creates expression looks :(:(x + 2)) end e=@mymacro x + 2 #returns :(x + 2) 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -