3 ms·
Non homoiconic languages (Elixir, Julia) usually use quote/unquote syntax, with quote being a construct that transforms code to AST and unquote evaluates an AST
by ddragon 6y ago
Non homoiconic languages (Elixir, Julia) usually use quote/unquote syntax, with quote being a construct that transforms code to AST and unquote evaluates an AST. For example in elixir:
a = 3
quote do
if unquote(a) > 3 do
6
end
end
Which produces:
{:if, [context: Elixir, import: Kernel],
[{:>, [context: Elixir, import: Kernel], [4, 3]}, [do: 6]]}
In Elixir and Julia the AST is represented by a normal type within the language itself just like Lisp, so the macro can just receive that type, manipulate it with the base language tools or using the special syntax above and return it.
- dragonwriter 6y ago> Non homoiconic languages (Elixir, Julia) usually use quote/unquote syntax So do homoiconic languages; quote/unquote/quasiquote and friends all originate in, or at least are used in, the Lisp family of homoiconic languages. (IIRC, Scheme uses more them than the CL branch of the tree, but both major branches use quote, and the ' abbreviated syntax for it.)
- ddragon 6y agoYes, I ended up writing as if they were different when it's a direct translation, except that quote transforms the visible syntax into a different hidden syntax, which is what makes it non homoiconic.