hylang / hy

A dialect of Lisp that's embedded in Python
http://hylang.org
Other
4.85k stars 369 forks source link

When doing a setv, magic (nonlocal) if the symbol is in a parent node's assignment place #817

Closed paultag closed 2 years ago

paultag commented 9 years ago

When doing a setv, magic (nonlocal) if the symbol is in a parent node's assignment place

I have no idea if this is doable. Like, at all.

Perhaps it's doable if we work out "Assignment" operators, and store names in parent scopes in the Hy Result object?

refi64 commented 9 years ago

Heh, I actually tried this once in Python 2 and 3. The main issues stemmed from two things:

  1. Sometimes you actually don't want a variable to be nonlocal.
  2. Being a dynamic language, Python makes it a pain to do analysis like this. It's definitely possible, but there are many, many corner cases.
paultag commented 9 years ago

:+1: my vague emotions as well

Kodiologist commented 5 years ago

While we may in the future implement a special operator that does something like this, I hope we can agree that ordinary Python assignment should continue to be available, whether it's named setv or something else.

Kodiologist commented 2 years ago

Yeah, we might add a feature sort of like this, but trying to make the default semantics different from Python's is probably not wise.