3 ms·
do you have any ideas for making it look more like python?
by uryga 6y ago
do you have any ideas for making it look more like python?
- nromiun 6y agoI don't think it is possible to make macros look like the host language without homoiconicity. However the proposal has this in the rationale section: > Python is both expressive and easy to learn; it is widely recognized as the easiest to learn widely-used programming language. However, it is not the most flexible. That title belongs to lisp. If the main purpose of the proposal is to make Python "flexible" like Lisp why not go the extra mile and add lisp syntax as well (like hy)? That will solve the problem of macros and flexibility.
- ddragon 6y agoNon 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.