Compile time check for let

2020-07-23 Thread jibal
> I did try to make sense of his ideas in those diagnostic ways Yeah, sorry, I seem to have missed your comment earlier. > To me, const was always meant to be used for things who represent something > like a physical constant That's just one usage. In a language like Nim, which takes compile-ti

Compile time check for let

2020-07-23 Thread ShalokShalom
Yeah, its the language barrier, although all the people involved in this thread already got the idea right, also cblake. I understand that there are details to the implementation who change the meaning of those things, while I try to keep it simple and understand those things on a practical sid

Compile time check for let

2020-07-23 Thread juancarlospaco
But... a let can have compile-time parts and run-time parts, like when you use `let foo = block:`, that may or may not have `static( )` or even macro code somewhere in between.

Compile time check for let

2020-07-23 Thread cblake
I did try to make sense of his ideas in those diagnostic ways (which I think could add value though maybe not be a high priority), but I guess my description was not to @ShalokShalom's liking. :-(

Compile time check for let

2020-07-23 Thread jibal
It may partially be the language barrier, but your comments are incoherent. You could replace every const with let and it wouldn't affect program behavior unless the variable is used in a when or {.compiletime.} context. And you could replace every let with const as long as the initializer can b

Compile time check for let

2020-07-22 Thread snej
I think you mean that the value could be different each time the `let` is evaluated? In which case we're saying the same thing — it's evaluated at runtime, not compile time. (When something like `let x = ` appears in a proc, there isn't a single variable `x` whose value changes. Instead, ea

Compile time check for let

2020-07-22 Thread ShalokShalom
I mean that let can as an example gain input. The value itself stays the same, but its usage changes. Const will always be used in the same, predictable way, let can be used in unpredictable ways.

Compile time check for let

2020-07-22 Thread snej
> When something does potentially change, I use let I don't understand. A `let` binding cannot change; that's what distinguishes it from `var`. The difference between `let` and `const` is that the latter is evaluated at compile time.

Compile time check for let

2020-07-22 Thread cblake
Alternatively to nimpretty or nimsuggest, there could be a diagnostic message letting code authors just change `var` to `let` or `let` to `const` as they think most helps clarity and their plans for code evolution. E.g., `var-ness unused` or `run-time-ness unused`. I suspect this is the sort of

Compile time check for let

2020-07-22 Thread Araq
The compiler does turn `let` into `const` sometimes behind your back. Maybe you're talking about nimpretty or your editor.

Compile time check for let

2020-07-21 Thread jxy
if you want to roll your own, import macros type MaybeStatic[T] = static[T] | T template constLet[T](id:untyped, v:MaybeStatic[T]) = when v is static: const id = v else: let id = v proc f(x:MaybeStatic[int]) = constLet(y,x) expandMac

Compile time check for let

2020-07-21 Thread ShalokShalom
Yes, and the same for variables who can be changed to **let**. So that it is always clear, what an assignment does.

Compile time check for let

2020-07-21 Thread Yardanico
I think what @ShalokShalom wants is compile-time const inference, so variables which are not changed and can be computed at compile-time are automatically inferred as "const".

Compile time check for let

2020-07-21 Thread juancarlospaco
I dont understand what the problem is, if any.

Compile time check for let

2020-07-21 Thread ShalokShalom
I order const and let according to the distinctive use case. When something does change, let and for things who persist all the same, const. I think it is a good idea, to check (optionally?) if each let interacts in that way, or if let could also be changed into a const. I think that way, it is