Needed 1+1, built a functional programming language

(hereticpleb.vercel.app)

27 points | by birdculture 9 hours ago

4 comments

  • winwang 10 minutes ago
    Nice, I like this style of exposition. "Let's do this one thing -> well, shit -> (loop)". Term rewriting (graph reduction as you've said) is evaluation.
  • gnarlouse 1 hour ago
    This reminds me of decades ago when ...wait, I was still writing code like three years ago.
  • gbacon 20 minutes ago
    See also https://perl.plover.com/yak/lambda/ from 1999.

    > Perl Contains the Lambda Calculus

    > (How to write a 163 line program to compute 1+1)

    > Length: 90 minutes

    Prerequisites: None.

  • ancientstraits 1 hour ago
    The "how to implement a hash table" article https://benhoyt.com/writings/hash-table-in-c/ was really helpful for me. I thought that hash tables were something that were basically impossible to make in C, but this showed that it was simpler.
    • dprkh 1 hour ago
      Arrays are hash tables. You can implement a very simple hash table from a tutorial, but can you implement a sophisticated one? What about a concurrent hash table?
      • saghm 58 minutes ago
        Yeah, I'm pretty sure we made hash tables in the first C class I took in college in my second semester freshman year. If you can make a linked list, and then make an array of them, and a function to map keys to array indexes, you have a hash table. Whether it's actually performant is entirely a separate question, but a naive hash table is still a hash table.
        • raddan 16 minutes ago
          Hash tables are awesome. They are both an incredibly simple data structure and a seriously deep rabbit hole. Most of the complexity comes from collision resolution [1], and how you handle resolution largely determines what kind of hash table you have. There are at least dozens of collision resolution approaches. The simplest, and probably the one you implemented in your undergrad C class was open addressing. That’s also what I implemented as an undergrad. But there are many more approaches, some quite a bit more complicated, and many of them let you continue to shave off asymptotic costs when you run collision resolution, or they improve locality for typical lookups, allowing better cache utilization, etc. Hash tables are super fun to play with, and for full effect, you really do need to implement them in something like C.

          I only skimmed the linked article, but I do wonder whether the author ever realized that they needed to think about scope rules. I searched for the word “scope” but never found it. Closures seriously complicate language design and things get painful and counterintuitive unless you use lexical scope (or… you know… you like pain).

          [1] https://en.wikipedia.org/wiki/Hash_table#Collision_resolutio...