Skip to content

Commit 5db838b

Browse files
authored
Merge pull request #2590 from Kodiologist/letw
Warn that `let` is complex in the manual
2 parents 4604638 + ce29871 commit 5db838b

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

NEWS.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Removals
1010
* `(fn/a …)` is now `(fn :async …)`.
1111
* `(with/a […] …)` is now `(with [:async …] …)`.
1212

13-
* As with `for`, `:async` must precede each name to be bound
14-
asynchronously, because you can mix synchronous and asynchronous
15-
types.
13+
* As with `for`, `:async` must precede each name to be bound
14+
asynchronously, because you can mix synchronous and asynchronous
15+
types.
1616

1717
* `(yield-from …)` is now `(yield :from …)`.
1818

docs/api.rst

+13-4
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,19 @@ Assignment, mutation, and annotation
274274

275275
.. hy:macro:: (let [bindings #* body])
276276
277-
``let`` creates local variables with lexically scoped names. This form takes a
278-
list of binding pairs followed by a ``body`` which gets executed. A let-bound
279-
name ceases to refer to that local outside the ``let`` form, but arguments in
280-
nested functions, and bindings in nested ``let`` forms, can shadow these names. ::
277+
``let`` is a macro for simulating traditional block scoping as seen in other
278+
Lisps. Since it coexists with ordinary Python scoping, its consequences can
279+
be complex, so it's wise to get a solid understanding of Python scoping
280+
before you use it. Beginners to Python should note particularly that
281+
:hy:func:`setv` inside a function or class typically creates a local
282+
variable, so ``let`` isn't required for local variables or closures as it is
283+
in many other Lisps.
284+
285+
That disclaimer aside, ``let`` creates local variables with lexically scoped
286+
names. The macro takes a list of binding pairs followed by a ``body`` which
287+
gets executed. A let-bound name ceases to refer to that local outside the
288+
``let`` form, but arguments in nested functions, and bindings in nested
289+
``let`` forms, can shadow these names. ::
281290

282291
(let [x 5 y 6] ; Create `x` and `y`
283292
(print x y) ; => 5 6

0 commit comments

Comments
 (0)