#Are operators and keywords functions?
17 messages · Page 1 of 1 (latest)
Yes
Well, many keywords are macros but if it's easier for the time being think of them as functions and it will make the most sense to you.
Could you elaborate? I'll hit the topic someday but I'm so curious. You mean, macros are not functions?
Macros are like a meta function.
Wow ok, meta-functions
You can use them to build functions and otherwise inject code into the AST.
It's similar to macros in Lisp if you've ever done Lisp.
I'm only from JS but that makes sense, thank you @tranquil bough! Elixir is so much fun and community makes it better
If you made a code generator that spit out js that's the equivalent of macros.
I'm sure you've worked with some sort of framework that built html on the fly. That's what a macro can do with Elixir code.
Ooh I see, so it's code that writes code, and it mainly writes functions since Elixir is functional, that's exciting!
macros are functions that operate on AST
you can check out https://astexplorer.net/ to get an idea of what ASTs look like in different languages, there's a Javascript AST generator here too.
An online AST explorer.
In Elixir you can very easily get an AST by adding 'quote'/'unquote' around a block of code (it's really nice, like in JS you have to npm install a library to turn your JS code into AST)
a 'macro' in Elixir is like a function that takes in some Elixir code you wrote, uses 'quote'/'unquote' to turn that Elixir code into an AST, then reorganizes that AST and writes it back out as Elixir code
there's https://ast.ninja/ for elixir