-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cl-letf
in Hy
#1660
Comments
The purpose of Hy's Python does this kind of thing with context managers and the Another option might be to use a
|
I didn't think about it in terms of broader variable scoping and/or binding, but I suppose that could be part of it. However, does that still apply in a situation like the following? > (let [some-dict {"some-key" None}
... (get some-dict "some-key") 1]
... (print some-dict))
File "<input>", line 2, column 6
(get some-dict "some-key") 1]
^------------------------^
HyMacroExpansionError: bind targets must be symbols Another way to state the functionality I'm describing: alter |
If you want to permanently update a target, use If you want to update a target for the duration of a block (and then put it back), use
See also: If you want some kind of lexically-scoped update of a generalized target, then I don't understand what that means. If you want some kind of destructuring, |
Maybe what we need is a |
I wonder if that problem is no reason to fork? It would be hard to change the muscle-memory from (let (...) foo) to (with [x 5] foo) or something like that. But I think not even that would work. What is the goal of hy, it should be a as much as possible lisp with a ptyhon backend? I thought it's just not possible that python has no block scope so you can't implement a lisp like (let) construct, but I just learned aboutd the del() function. So you could compile: (let (foo 5) (bar)) into: foo = 5
bar()
del (foo) I just wonder, because without let I can't take a lisp like language serious. I don't want to programm python code with a bit different parens syntax. |
A library is not a fork. Hy should be as much like Python as possible, but homoiconic with macros and expression-oriented like Lisp, with features mostly taken from Clojure, but also Common Lisp. Python does not have arbitrary block scope, but it does have late-binding lexically-scoped function closures.
|
@spiderbit As already stated above, Hy has a |
that's good to hear, why do I not see it then in the documentation homepage? neither there: nor there: where is it hidden? :D |
@gilch, on a somewhat related note, I came across this thread (and this one, too) a while back when searching for |
Anyway, I think @gilch's diagnosis of why the idea of |
After a macro expansion, I ended up in a situation (this one, to be exact) like the following:
For this situation to work out, it seems like
let
would have to behave like Emacs'cl-letf
.A very related functionality — namely, generalized variables in Emacs — does appear to work in Hy:
That said, is there any place/interest in having an extended
let
that allows this (when reasonable) or a separateletf
?The text was updated successfully, but these errors were encountered: