You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many languages, like Rust, JavaScript, Java, etc have a variable declaration keyword, maybe let or const or var or something else (like the variable's type).
Not all languages have a declaration keyword! Python and Matlab both declare variables via x = 3 with no preceding let or var or const keywords.
Currently KCL supports let, const and var (they all do the same thing for various historical reasons). According to @jgomez720 the Python-style x = 3 is a more natural syntax for him, as a mechanical engineer. He prefers it to let x = 3 or const x = 3.
So, KCL should probably imitate Python, and remove the variable declaration keywords.
Justification
If KCL had mutation, it'd be important to have an explicit declaration keyword. That way users could tell when a variable comes into being and when it is/is not in scope or is redefined. Without mutation, that isn't as big of a problem for KCL.
Implementation
We want to avoid breaking existing code that uses let or const if possible. Here's a plan for that:
Update the AST node for VariableDeclaration to make the keyword (let/const/var) optional.
Update the parser to allow users to skip the variable declaration keyword
Update the recaster (which is also used as the code formatter) to remove the keyword.
This way, old code (let x = 3) will be accepted and run just fine, but be converted to x = 3 when executed.
The text was updated successfully, but these errors were encountered:
Some folks may wonder why they keyword disappears when auto-formatting their code. Do you have a method of highlighting code to show a warning? If so you can call the keywords out as deprecated.
Sorry for the trouble this may have caused. In the future, we'll try to do things like have auto-migration and lint auto-fix. But it's a lot of work. We're still in the pre-1.0 phase where we're making breaking changes.
Many languages, like Rust, JavaScript, Java, etc have a variable declaration keyword, maybe
let
orconst
orvar
or something else (like the variable's type).Not all languages have a declaration keyword! Python and Matlab both declare variables via
x = 3
with no precedinglet
orvar
orconst
keywords.Currently KCL supports
let
,const
andvar
(they all do the same thing for various historical reasons). According to @jgomez720 the Python-stylex = 3
is a more natural syntax for him, as a mechanical engineer. He prefers it tolet x = 3
orconst x = 3
.So, KCL should probably imitate Python, and remove the variable declaration keywords.
Justification
If KCL had mutation, it'd be important to have an explicit declaration keyword. That way users could tell when a variable comes into being and when it is/is not in scope or is redefined. Without mutation, that isn't as big of a problem for KCL.
Implementation
We want to avoid breaking existing code that uses
let
orconst
if possible. Here's a plan for that:VariableDeclaration
to make the keyword (let/const/var) optional.This way, old code (
let x = 3
) will be accepted and run just fine, but be converted tox = 3
when executed.The text was updated successfully, but these errors were encountered: