←back to thread

160 points leontrolski | 2 comments | | HN request time: 0.001s | source
Show context
Y_Y ◴[] No.41887424[source]
If only there was a language that let you modify the interpreter on the fly so you could do this as part of normal execution...
replies(4): >>41887458 #>>41887499 #>>41887640 #>>41888996 #
BiteCode_dev ◴[] No.41887458[source]
Python can actually do this using "# coding:", albeit less elegantly than lisp.

I would say it's a good thing, I don't want to see a hundred of half baked, badly tested and vaguely document DSL with no decent tooling support.

replies(2): >>41887507 #>>41887939 #
develatio ◴[] No.41887507[source]
Can you provide some more info / links regarding the “# coding:” feature? I wasn’t able to find anything.
replies(4): >>41887621 #>>41887770 #>>41887778 #>>41887841 #
1. klibertp ◴[] No.41887770[source]
If you place `# coding: utf-8` on the first line of a Python script, it'll try to interpret the raw bytes contained later in the file by passing them through a relevant codec[1]. Since the codec receives the raw source and transforms it before any interpretation happens, you can (here's the point I'm starting to guess) supply a codec that parses the code, transforms the AST, and dumps it back to the source for execution. It would be similar to how "parse transforms" work in Erlang, though there you're handed AST and not bytes.

[1] https://docs.python.org/3/library/codecs.html

replies(1): >>41888833 #
2. zahlman ◴[] No.41888833[source]
>how "parse transforms" work in Erlang, though there you're handed AST and not bytes.

Oh, I didn't know about this. Was thinking about doing something similar in my own language, so I'll have to check that out.