~sircmpwn/hare-users

3 3

Why can a constant be reassigned?

Details
Message ID
<9d967335353da10c7e20b9ebb79439c7946189c7.camel@javiljoen.net>
DKIM signature
missing
Download raw message
Hello,

I'm going through the Introduction to Hare tutorial, and in the section
on variables and constants[0], I changed the example to see what would
happen if I try to assign to a const, e.g.:

    use fmt;

    export fn main() void = {
    	const i: int = 1, j: int = 2;
    	j = i;
    	fmt::printfln("i = {}, j = {}", i, j)!;
    };

I was expecting a compiler error, but it just prints "i = 1, j = 1".
(I get the same result when declaring `i` and `j` on separate lines,
and when using a different type, such as strings.)

Have I misunderstood the difference between `let` and `const`?
Or is it just that the distinction is not enforced by the compiler?


---

Compiler versions:
harec dev+b4dd427
hare dev+b35f4bc1

[0]:
https://harelang.org/tutorials/introduction/#using-const--let-to-define-variables
Details
Message ID
<CXA8UQ4JPFC3.H6VB8IAAL0C9@taiga>
In-Reply-To
<9d967335353da10c7e20b9ebb79439c7946189c7.camel@javiljoen.net> (view parent)
DKIM signature
missing
Download raw message
Constants are not fully implemented yet.
Details
Message ID
<CXA9WH8AFN25.1215BU4O937PA@notmylaptop>
In-Reply-To
<9d967335353da10c7e20b9ebb79439c7946189c7.camel@javiljoen.net> (view parent)
DKIM signature
missing
Download raw message
There are plans to do an overhaul of mutability semantics in Hare, which
is why this bug hasn't yet been fixed. But you're correct that you
shouldn't be able to reassign it.
Details
Message ID
<d74e5e86c49b29d70ab9a660061dab4f077a5366.camel@javiljoen.net>
In-Reply-To
<CXA9WH8AFN25.1215BU4O937PA@notmylaptop> (view parent)
DKIM signature
missing
Download raw message
I see. Thank you both for clarifying!
Reply to thread Export thread (mbox)