How can a binding be a constant when symbol can be redefined? #1442
-
|
Hello! I'm reading Janet's docs today to get myself familiar with the language and I stumbled upon this paragraph in the Special section:
It got me confused. How can a def binding be a constant if the symbol itself can be redefined? I'm new to Janet (and LISPs in general), so I might be missing something LISPs do that C-family langs don't, but I couldn't understand these conflicting statements about symbol bindings. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
In the simplest terms: variables bound with You see that when we define our functions Meanwhile, because |
Beta Was this translation helpful? Give feedback.
In the simplest terms: variables bound with
varcan beset, and those bound withdefcannot. Here's a REPL session:You see that when we define our functions
fandg, we close over the variablesconstandnot-const. This means that when we rebind the symbolconst, as inrepl:5, the closed-over variable inside offis unchanged;(f)prints ou…