Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should sigilless "variables" with type constraints be re-bindable? [duplicate]

[EDIT: closed in favor of https://stackoverflow.com/questions/69231506/what-are-the-rules-for-re-binding, which I formulated after more clearly understanding what I was trying to ask in this question.]

My understanding from Is there a purpose or benefit in prohibiting sigilless variables from rebinding? was a symbol declared without a sigil could never be rebound. Quoting from that answer:

Yes, [the current behavior is] certainly by design, and - like most things in [Raku] design - it's this way for more than one reason.… It was decided to make the sigilless symbol form a "static single assignment" syntax…. There were various reasons for this, including… enhancing program readability by having a form that lets the reader know that the symbol will never be rebound to a new value

(emphasis added.)

Given that, I was very surprised to see by the code below:

my Int \b = 8;
say "{b*b}"; # OUTPUT: «64»

b := 4;
say "{b*b}"; # OUTPUT: «16»

That is, when b is declared without a sigil but with an Int type constraint, it can be rebound – unlike when it lacks that type constraint. Is this behavior a bug, or is it correct?

If it is, how does it fit in with the design considerations mentioned in the answer linked above?

(See also this Raku/doc issue thread on GitHub for a discussion of this behavior and whether it's intentional.)

like image 692
codesections Avatar asked Sep 03 '21 18:09

codesections


1 Answers

It's a bug.

[no language should sometimes prohibit sigilless variables from rebinding depending on whether a or which type is specified in the declaration].

like image 59
p6steve Avatar answered Oct 18 '22 22:10

p6steve