HNHacker News
TopNewBestAskShowJobs

Kodiologist

292 karma · joined May 3, 2022

http://arfer.net
submissionscomments
Kodiologist··on Why Hy?
In some other Lisps, yes, but Python has its own idea of how function scoping works that generally isn't what you'd want with `let`. For example, in

    (let [a 1]
      (defn foo []
        (setv a 2))
      (foo)
      (print a))
you probably `2` to be printed, but the seeming equivalent Python code

    a = 1
    def foo():
        a = 2
    foo()
    print(a)
prints `1`. Python interprets the assignment as declaring a new local variable. Frankly, Python got scoping wrong (in its quest to eliminate declarations), but here we are. So `let` needs to work around this somehow. The current implementation implicitly adds `global a` or `nonlocal a` as appropriate. (Actually, the name `a` is also mangled so that any references to `a` outside the `let` refer to a different variable.)
Kodiologist··on Why Hy?
Hy has closures. They work just like Python's.

(Common Lisp is super cool, though. Perhaps one day Hy will be as cool.)

Kodiologist··on Why Hy?
Even with PyPy, or Python libraries that are themselves written in C?
Kodiologist··on Why Hy?
It's been implemented, found to be subtly broken, and re-implemented a number of times. Ultimately trying to impose a different model of scoping on top of Python's scoping is living in a state of sin; thus the difficulties. The status quo is an apparently working `let` due to a truly heroic effort by Sunjay Cauligi ( https://github.com/hylang/hy/pull/2125 ). You're encouraged to try to find bugs in it.

In truth, I've never understood the fuss about `let`. It's taken a huge amount of Hy development effort, but it adds very little. Python's native scoping works well in the large majority of cases, and in tricky cases, I'd rather use `nonlocal` or `global` explicitly so I'm sure what's happening at the level of Python semantics. I suspect that people who heard that previous versions of Hy were missing `let` assumed that some other feature (such as nested lexical scopes) was also missing that has actually always been there.

Kodiologist··on Why Hy?
I'm not familiar with such a feature, but you can certainly run a Hy program and edit its state in the REPL at the same time, if that suffices.
← PreviousPage 2 of 2