| ▲ | Making a Python interpreter in 1024 bytes(austinhenley.com) |
| 63 points by azhenley 2 hours ago | 22 comments |
| |
|
| ▲ | teddyh an hour ago | parent | next [-] |
| For those who actually need something like this in production, there is Snek: <https://sneklang.org/> “Snek is a tiny embeddable language targeting processors with only a few kB of flash and ram.” |
| |
| ▲ | jrdres 22 minutes ago | parent [-] | | Yes, but compiling or modifying Snek from source is very challenging. I wish it was one single C file for an example base like Posix, instead of many files for many platforms plus a custom parser in Python (Lola). |
|
|
| ▲ | anitil 27 minutes ago | parent | prev | next [-] |
| This is really cool! It's so fun to see what you can achieve and what's optional. I have seen the 'single character variable' limitation in some other minilangs before, but using the source itself as the target of function calls and loops is new to me. It does make a lot of sense but I wouldn't have thought of that. |
|
| ▲ | tempodox an hour ago | parent | prev | next [-] |
| This seems to be in the same spirit as Justine Tunney's SectorLISP. Very cool. https://justine.lol/sectorlisp/ |
| |
|
| ▲ | hankbond an hour ago | parent | prev | next [-] |
| Good use of free will and well-written. Very nice walkthrough austin! |
|
| ▲ | TZubiri 2 hours ago | parent | prev | next [-] |
| A lot of criticism of python often mentions the whitespace as lexical scope tokens, and that criticism is usually posited by users of the language. As implementer of an interpreter, did you feel that whitespace for lexical scoping made the job of writing the lexer significantly more complex? |
| |
| ▲ | nomel 2 hours ago | parent | next [-] | | And, there are multiple white space symbols! <space><space><tab><space> is different than <space><tab><space><space> So you also have to track the actual sequence of counts of white space used for each level, rather than just a simple count. | | |
| ▲ | rmunn an hour ago | parent | next [-] | | Or you just forbid mixing spaces and tabs in the same indentation sequence, the way most whitespace-sensitive languages seem to end up doing. Or you make a slightly more reasonable rule: spaces may follow tabs, but no tabs may follow a space. That's at least unambiguous. | | |
| ▲ | fc417fc802 an hour ago | parent [-] | | But it also feels arbitrary and annoyingly restrictive. On top of that there are at least 25 whitespace codepoints in UTF. Should your language really be opinionated about when, where, and in what order (for example) the "mongolian vowel separator" appears? | | |
| ▲ | rmunn 3 minutes ago | parent | next [-] | | I mean, obviously that one should only appear within Mongolian text and not within indentation. To state explicitly what should be implicitly obvious, there is no valid reason (that I'm aware of, I welcome any non-facetious correction) to use any character except U+0009 and U+0020 within indentation. Horizontal Record Separator? Zero-width joiner? Language-specific whitespace characters like your example? All make sense within human text, but in programming, they should be eschewed in favor of the characters that can be typed in every single keyboard layout in the world. Even languages that don't put spaces between words, such as Thai, still put spaces between sentences (or comma phrases) and therefore keep the space bar in their keyboard layout. And since mixing tabs and spaces (even between lines, where some lines are tab-indented and some are space-indented) creates problems for whitespace-sensitive langauge, there's a reason why every whitespace-sensitive language I'm aware of has tended to either outright forbid, or at least discourage, U+0009 and its ambiguous meaning (since its meaning isn't clear until you know people's editor configurations, which are usually not available to the validation code running in CI or on other people's machines). | |
| ▲ | Mogzol 19 minutes ago | parent | prev [-] | | > and annoyingly restrictive How so? In what scenario would you ever need to use a sequence like <tab><space><tab> in indentation in your source code? Let alone using esoteric Unicode whitespace characters for indentation. I think it is perfectly reasonable for the language to make the restriction that indentation must be either all tabs, tabs followed by spaces, or all spaces. |
|
| |
| ▲ | jubilanti an hour ago | parent | prev | next [-] | | > <space><space><tab><space> is different than <space><tab><space><space> in my view, both are the same, both `is` (or ===) an IndentationError raise | |
| ▲ | fc417fc802 an hour ago | parent | prev | next [-] | | It's just a stack containing strings at the end of the day. Really not a big deal. | | |
| ▲ | TZubiri 22 minutes ago | parent [-] | | Right, pointers to strings but yeah. Essentially the whitespace count specifies the stack depth at which a line is to be executed. A decrease in stack depth means all superior levels are terminated. Doesn't affect function call stacks though. |
| |
| ▲ | TZubiri 29 minutes ago | parent | prev [-] | | For a 1024 byte implementation (and even way more complex impl.) You would just force one whitespace char, and definitely no mixing. |
| |
| ▲ | zephen 31 minutes ago | parent | prev [-] | | > that criticism is usually posited by users of the language. Uhhh, no. Sure, it's posited by people who feel they are are forced to use it, but it's basically unlearning other syntax. Here's a study about people with no experience. They do better with python: https://www.researchgate.net/publication/262256894_An_Empiri... When the scala language made whitespace optional, it was very divisive, but now it's extremely well accepted. | | |
| ▲ | TZubiri 26 minutes ago | parent [-] | | I meant users of languages ( application programmers) as opposed to compiler programmers, not python programmers specifically, so I'm including devs that use other languages and see in python a tool that they would consume. |
|
|
|
| ▲ | ni5arga 2 hours ago | parent | prev | next [-] |
| the blog post is pretty well-written! loved how he wrote about the the code-golfing part. |
|
| ▲ | Scubabear68 an hour ago | parent | prev [-] |
| I was very disappointed that this is “interpreting” some tiny made up language. This is not Python, or even within three orders of magnitude of Python. |
| |
| ▲ | SPBS an hour ago | parent [-] | | It’s true, the title should have said “Python-like” | | |
|