Hacker News new | past | comments | ask | show | jobs | submit login

Which is odd because in every other language that uses let (lisp, scheme, swift, rust, scala/kotlin val, haskell, etc.), let bindings are const and let is synonymous with const.



Let bindings in Lisp are not const. You can use `setf` (among others) to mutate the variable. For instance, this works just fine in Lisp:

  (let ((x 1))
    (print x)  ;; => 1
    (incf x)
    (print x)) ;; => 2
Scheme also allows let bindings to be mutated, but using `set!`.


I assumed scheme and lisp were the same here semantically. Bad assumption on my part. My experience is primarily with scheme.

Similar Rust and Swift allow let bindings to be shadowed but you need to re-declare your intent. You can't just mutate the binding on a whim.


I'm confused, Scheme also permits mutation of let bindings so Lisp and Scheme do have similar semantics here. Neither language provides immutable (const) let bindings. Scheme just makes it more obvious (by convention) when you may have mutation, through function and form names ending in !.


The distinction in my mind was that a variable is something where mutation is allowed naturally without being explicit e.g. var a = 1; a = 2. In Scheme you have to opt in to the mutation by using a ! function set! which in scheme's world is like, in C++, const_cast-ing away the const from a pointer, or, in Java, using reflection to make a final field accessible and modify it. All possible using the languages as specified, but semantically not something you're normally encouraged to do.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: