What's the difference between $?CLASS and ::?CLASS
Asked Answered
N

1

8

The Raku docs describe ::?CLASS as a compile-time variable that answers "Which class am I in?". Then, a couple of paragraphs later, it mentions $?CLASS, and says that it answers "Which class am I in? (as variable)".

What's the difference between these two variables? They often seem to contain the same value – do they always? Or are there differences I haven't observed?

Nidorf answered 23/2, 2022 at 18:5 Comment(1)
Try doing class A { method foo($?CLASS:D:) { } } :-)Greater
S
8

These two forms of compile-time variables are different syntactically.

The syntactic form ::?foo may be used as, and will be evaluated as:

  • A term (just like a variable such as $?foo).

  • A type constraint (unlike a variable such as $?foo).

Sinclair answered 23/2, 2022 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.