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

1

5

[EDIT: closed in favor of https://mcmap.net/q/1507233/-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.)

Gastroenterostomy answered 3/9, 2021 at 18:51 Comment(1)
cf a comment I wrote discussing some of the darker truths about [the Satanic Sons of Beelzebub: "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.Distil
H
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].

Halvah answered 3/9, 2021 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.