‹ BackHN Continuity

Thread

Needed 1+1, built a functional programming language

151 points · 80 comments · birdculture

  1. ancientstraits · · focus · HN ↗
    The &quot;how to implement a hash table&quot; article <a href="https:&#x2F;&#x2F;benhoyt.com&#x2F;writings&#x2F;hash-table-in-c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;benhoyt.com&#x2F;writings&#x2F;hash-table-in-c&#x2F; 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.
    1. fuzztester · · focus · HN ↗
      If hash tables were impossible to make in C, then it would be impossible to make them in Python, because it is a higher level language than C.

      (Almost by definition, anything doable in a higher level language is doable in a lower level language, but not necessarily vice versa. In fact, many higher level languages are themselves written in lower level languages, e.g. Python is written in C.)

      But Python has got dicts built into it, which are nothing but hash tables, and they are almost certainly written in C.

      Google for some videos by Raymond Hettinger about Python dictionaries.

      Or look at the source code of the Python interpreter.

      1. eru · · focus · HN ↗
        &gt; But Python has got dicts built into it, which are nothing but hash tables, and they are almost certainly written in C.

        In CPython they are written in C (at the moment). Other Python implementations are written in other languages.

        &gt; (Almost by definition, anything doable in a higher level language is doable in a lower level language, but not necessarily vice versa. In fact, many higher level languages are themselves written in lower level languages, e.g. Python is written in C.)

        It depends on what you mean by &#x27;anything doable&#x27;. Eg Haskell compilers can in principle do lots of crazy optimisations that a C compiler would not be able to safely do, just because they don&#x27;t have enough information. Even more so for Lean compilers, which can _know_ which of your loops are terminating, instead of making crude assumptions like C compilers.

        Btw, higher level languages being implemented in lower level languages is mostly something for interpreters. Writing a C interpreter in Python is pretty much futile, if you care about speed. But writing a C compiler in Python is perfectly fine. And writing a Python compiler in Python is also fine. Many languages self-host (at least some of) their compilers.

        1. fuzztester · · focus · HN ↗
          &gt;In CPython they are written in C (at the moment). Other Python implementations are written in other languages.

          True. E.g.:

          1. PyPy:

          <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;PyPy" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;PyPy

          &gt;The PyPy interpreter itself is written in a restricted subset of Python called RPython (Restricted Python).

          2. Jython:

          <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Jython" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Jython

          &gt;Implementation language: Python, Java

          The article says the last release of Jython was 2 years ago. I wonder how much it is used these days. It did seem like a good idea when it was first released. I had only tried it out a little at that time.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.