Course of Raku / Advanced / Operators / Traits and pragmas 🆕 / Exercises / Relaxing strict
Solution: Relaxing strict
Here is a possible solution to the task.
Code
no strict;
$a = 10;
$b = 20;
say $a + $b;🦋 You can find the source code in the file no-strict.raku.
Output
30Comments
no strictswitches off the requirement that variables be declared, so$aand$bmay be assigned without amy. Under the defaultstrict, each of those lines would be a compile-time error.Once assigned, the variables behave normally, so
$a + $bis30. The relaxation is lexical — it lasts only to the end of the scope whereno strictappears.This is a demonstration, not a recommended practice:
strictis on by default for a good reason — it catches typos in variable names at compile time. In real code, keep it on and declare your variables withmy.
Course navigation
← Relaxing strict | Control flow →