Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sigilless class attribute

Although you can actually itemize any kind of data structure to fit it into a scalar variable, sigilless variables might have some intrinsic value, since they are actually shapeless, to be used as class attributes. However, there seems to be no way to do so, has \.a does not work, has .\a either. A has $!a can probably cover most of what we could achieve with sigilless variables, but would there be an actual way to use them as attributes?

like image 774
jjmerelo Avatar asked Dec 22 '22 20:12

jjmerelo


1 Answers

There's currently no way to have a sigilless attribute. It's also not, so far as I'm aware, currently under active consideration for inclusion in a future Raku version. The most obvious design considerations, were it to be proposed, would be:

  1. The semantics of my \foo = ... are single static assignment. It's quite clear what that means on a lexically scoped symbol. It's less clear what it would mean in a class declaration, and how it would interact with the instantiation workflow. For example, there'd be no equivalent of the :$!foo signature syntax that can be convenient in BUILD/TWEAK.
  2. The use of a twigil implies that it follows a sigil. The twigils without that are potentially ambiguous, depending on context. Further, it'd be odd to allow the . case only for the purpose of declaring that we want a sigilless attribute to get an accessor.
  3. It would break the rule that you can always find access to the instance state by looking for a ! twigil, which would be a pity.
like image 62
Jonathan Worthington Avatar answered Jan 08 '23 13:01

Jonathan Worthington