News for hackers. Stuff that matters.
Re:Improving Programming Language Performance by alpaca128 on Sunday December 10, 2023 @04:06AM (#38590253)
The scope is clearly defined by the parentheses, though if you're not used to Lisp syntax that can be confusing at first.

    (let n 12)                 =>  let n = 12;
    (let res (square a))       =>  let res = a*a;
    (let mod3 (eq 0 (% i 3)))  =>  let mod3 = (0 == i % 3);
Re:Improving Programming Language Performance by trealira on Sunday December 10, 2023 @04:22AM (#38590315)
In Lisp, "let" is only used for binding the variable, and it comes with a scope.

  (let ((a 1)
        (b 2))
    (+ a b))
It's closer to the ML version of let, which works like this:

  let
      val a = 1
      val b = 2
  in
      a + b
  end
You can sequence expressions for side effects, as well.

  (let ((a 1)
        (b 2))
    (incf a)
    (do-it a b)
    (+ a b))
Re:Improving Programming Language Performance by zoren on Sunday December 10, 2023 @04:13AM (#38590286)
In other lisps a let form has a body that the binding(s) range over and they are not available outside. As in `(let n 12 (+ n n))` here n wouldn't be accessible after. You have `(def name 5)` for making definitions that are readable outsude.
Re:Improving Programming Language Performance by nequo on Sunday December 10, 2023 @10:40AM (#38592246)
Those lets in TFA seem more like Lisp’s setq rather than let. A let expression would bind values to names only within the scope of (let …) itself. The lets in TFA and in your examples have side effects. You reference the bound values outside of (let …).
Re:Improving Programming Language Performance by aidenn0 on Sunday December 10, 2023 @12:01PM (#38592958)
> The scope is clearly defined by the parentheses, though if you're not used to Lisp syntax that can be confusing at first.

The scope is clearly not defined by the parentheses, and I've been programming in Common Lisp for 25 years, so I'm pretty used to Lisp syntax.

A sibling comment suggests it comes from the JavaScript let (which did not exist when I learned JavaScript; it wasn't introduced until 1.7), which is scoped to the containing lexical block, rather than a block introduced by the let form itself.