\

(How to Write a (Lisp) Interpreter (In Python)) (2010)

80 points - today at 3:36 PM

Source
  • chombier

    today at 4:25 PM

    If you ever wondered how to write a programming language, this is probably the best resource to get started (and then of course Crafting Interpreters).

    See also part 2 https://norvig.com/lispy2.html

    • timonoko

      today at 6:22 PM

      I actually perfected the Norvig Lisp at one time. It has compiler to python and just everything. Those very few here that can actually read code, understand why this project soon exploded into biggest piece of odorous excrement.

      https://github.com/timonoko/nokolis.py

      • zahlman

        today at 3:57 PM

        (how-to in-python (write (interpreter lisp)))

          • consumer451

            today at 4:44 PM

            Yes, but to be fair, you only have a couple minutes to fight the HN title regex.

        • timonoko

          today at 6:03 PM

          One of those exercises that are now just boring, because AI does it better.

          My Lisp from 1975 was actually used in real world and highly lucrative. Gemini could read the source code, but it told that my code was piece of shit and cannot be implemented in 64-bit world without drastic changes, so it made an example. But that version was just too advanced and too complex as a study subject. There are already enuff good Lisps in the world, methinks.

            • Jtsummers

              today at 6:05 PM

              Why did you replace your very similar comment with "--" just to post essentially the same thing again?

                • today at 6:08 PM

                    • today at 6:21 PM

                      • today at 6:11 PM

            • azhenley

              today at 4:09 PM

              Writing a Lisp is one of my favorite projects. I try to do it every year or two, taking a different approach each time.

                • onraglanroad

                  today at 4:49 PM

                  The one where you replaced parentheses with the crying laughing emojis was definitely the worst.

              • tosh

                today at 3:48 PM

                I can't recommend highly enough to implement a simple lisp (or a forth).

                Illuminating experience and it will also help you see (among many other things) the parentheses in a different light.

                  • stdatomic

                    today at 4:08 PM

                    First day of paradigms course in the 2000s and prof says "if your opinion of Scheme is too many parentheses, then you're an idiot."

                    Needless to say that was my opinion and every day I think, more and more, how right he was.

                    (later I did make some gui apps that included scripting and chose s-expr syntax because of how simple it is to implement it)

                      • bananaflag

                        today at 4:23 PM

                        There are two problems with Lisp parentheses in my opinion:

                        1) Humans are not that equipped to handle that level of nesting without some other aid, this is why Lisp code is usually indented.

                        2) Parentheses aren't just about grouping, and this is unintuitive. For example, x is not the same as (x). This is a bit like in set theory where x is not the same as {x}, but parentheses do not look like the kind of sign that would work like that.

                          • jimmypk

                            today at 5:58 PM

                            [dead]

                        • NooneAtAll3

                          today at 4:15 PM

                          main problem isn't brackets themselves - it's that they're too on the right

                          had brackets been displayed as curly braces in C - everything would look much more manageable

                            • phpnode

                              today at 4:37 PM

                              so, instead of

                                  (foo (bar (1 2 3))
                              
                              you'd prefer

                                  {
                                    foo {
                                      bar {
                                        1
                                        2
                                        3
                                      }
                                    }
                                  }
                              
                              is that right?

                                • NooneAtAll3

                                  today at 6:39 PM

                                      ( aar
                                        (bar1 1 2 3)
                                        (bar2 1 2 3)
                                        (bar3 
                                           (car1 2 3)
                                           (car2)
                                           (car3)
                                        )
                                      )
                                  
                                  vs

                                  (aar (bar1 1 2 3) (bar2 1 2 3) (bar3 (car1 2 3)(car2)(car3)))

                                  • irishcoffee

                                    today at 4:57 PM

                                    Emacs vs vim, go!

                                • eska

                                  today at 4:43 PM

                                  I changed my opinion about parens when I stopped formatting like C, and used indent rather than parens to denote blocks. That is, a large amount of them at the end is totally fine.

                      • librasteve

                        today at 4:38 PM

                        or you could just use Raku and its “surprisingly good lisp impression”:

                        https://www.codesections.com/blog/raku-lisp-impression/

                        • urcite_ty_kokos

                          today at 3:51 PM

                          Appreciated the title xD

                          • joshuamorton

                            today at 4:46 PM

                            There are edge cases where this fails, but `def parse(s): return json.loads('['+re.sub('([")])\s*(["(])','\g<1>,\g<2>',re.sub('[^()\s]+','"\g<0>"',s)).replace('(','[').replace(')',']')+']')` is a surprisingly robust lisp parser.

                            • e12e

                              today at 3:55 PM

                              (2010)?

                              • today at 5:08 PM

                                • timonoko

                                  today at 4:46 PM

                                  [flagged]

                                    • genxy

                                      today at 5:10 PM

                                      There is always someone better than you at almost everything you do, this is statistical reality.

                                      If all you care about is the artifact and not the path, there is no reason to do anything.

                                      Use the tool to better yourself, your understanding and push the limits of what is possible. If a Lisp in assembly with GC is now hello world, change what a hard project is.

                                      I see this attitude a lot, and I think it is rooted in a sort of self-centered elitism. Anyone can do it, so why do it? Instead you could have the AI teach you how to implement it yourself with a deep understanding that no human, even if you paid them, would put up with.

                                      But sure, get depressed. But why tho?

                                      • today at 5:57 PM

                                        • tosh

                                          today at 4:59 PM

                                          is learning how to accomplish or understand something boring

                                          just because someone or something else does it better?

                                          • abecedarius

                                            today at 5:45 PM

                                            It's funny, in the 8-bit days a lot of us learned programming for its own sake without much expectation it'd be lucrative. Took ~50 years to get back to that spirit as the default.

                                            • Lyngbakr

                                              today at 5:12 PM

                                              It depends why you're doing it. Are you doing it for the product or the process? (Of course, they're not mutually exclusive.) I do it for the fun of building, in which case AI is irrelevant.

                                              • chamomeal

                                                today at 4:58 PM

                                                I mean it’s still worth doing, even if AI can do it. But I definitely empathize with that bit of AI ennui.

                                            • RedCinnabar

                                              today at 5:07 PM

                                              Man these kind of resources have aged really bad in the age of AI.

                                                • Crespyl

                                                  today at 5:11 PM

                                                  Why would AI make these age worse than, say, libraries or languages becoming obsolete?

                                                  I don't think a good learning resource gets worse just because there's a newer alternative.

                                                    • RedCinnabar

                                                      today at 5:38 PM

                                                      > I don’t think a good learning resource gets worse[...]

                                                      Probably not, but they become irrelevant. The other day I found an old programming book at my parents’ and while it was still a terrific resource, I couldn’t image anyone learning a language from a book nowadays.

                                                      AI is doing the same thing but 100 times effectively than anything else.

                                                  • incanus77

                                                    today at 5:20 PM

                                                    How do you mean “these kind”?

                                                      • RedCinnabar

                                                        today at 5:31 PM

                                                        Blog tutorials, guides, programming books and youtube tutorials. They are completely irrelevant in a time where you have a personal tutor willing to explain every single detail of a subject.

                                                          • macintux

                                                            today at 6:24 PM

                                                            That's like saying your grandfather is irrelevant now that he's spawned children and grandchildren. Good luck to those personal tutors without this source material.

                                                    • jgalt212

                                                      today at 5:09 PM

                                                      How so?