5

[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.)

codesections
  • 8,900
  • 16
  • 50
  • cf [a comment I wrote discussing some of the darker truths about [the Satanic Sons of Beelzebub](https://www.reddit.com/r/rakulang/comments/kdq9uk/differences_between_sigilless_and_sigilled/gg6u8ll/): "Sigilless variables ... appear to be, at least in a PL and/or compiler maturity sense, second class citizens. ... sigilless variables are not (yet?) as clean as SSAs, and so SSB begins to take on a grade B rather than grade A aspect". Right now what you've shown in this Q smashed my mental model, even of SSBs let alone SSAs. – raiph Sep 03 '21 at 22:05

1 Answers1

4

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].

librasteve
  • 6,832
  • 8
  • 30