Permalink
Browse files

[lazy.t] make much more realisitic

* if you want to carry stuff around without evaluating, you need binding
* passing stuff to routines type-checks, thus cannot be lazy
  • Loading branch information...
1 parent cb86fc4 commit a2275c3d4c03bb99ddf50814dcdcf3d0a491e6f8 @moritz moritz committed May 16, 2012
Showing with 5 additions and 18 deletions.
  1. +5 −18 S04-statements/lazy.t
View
@@ -4,12 +4,12 @@ use Test;
# L<S04/Other C<do>-like forms/lazy>
-plan 15;
+plan 12;
{
my $was_in_lazy;
- my $var = lazy { $was_in_lazy++; 42 };
+ my $var := lazy { $was_in_lazy++; 42 };
ok !$was_in_lazy, 'our lazy block wasn\'t yet executed (1)';
@@ -20,37 +20,24 @@ plan 15;
is $was_in_lazy, 1, 'our lazy block was not executed again';
}
-# Same, but passing the lazy value around before accessing it:
-{
- my $was_in_lazy;
-
- my $var = lazy { $was_in_lazy++; 42 };
- my $sub = -> Num $v, Bool $access { $access and +$v };
-
- ok !$was_in_lazy, 'our lazy block wasn\'t yet executed (2)';
- $sub($var, 0);
- ok !$was_in_lazy, 'our lazy block has still not been executed';
- $sub($var, 1);
- ok $was_in_lazy, 'our lazy block has been executed now';
-}
-
# dies_ok/lives_ok tests:
{
my $was_in_lazy;
- my $lazy = lazy { $was_in_lazy++; 42 };
+ my $lazy := lazy { $was_in_lazy++; 42 };
lives_ok { $lazy = 23 }, "reassigning our var containing a lazy worked (1)";
is $lazy, 23, "reassigning our var containing a lazy worked (2)";
ok !$was_in_lazy, "reassigning our var containing a lazy worked (3)";
}
{
my $was_in_lazy;
- my $lazy = lazy { $was_in_lazy++; 42 };
+ my $lazy := lazy { $was_in_lazy++; 42 };
lives_ok { $lazy := 23 }, "rebinding our var containing a lazy worked (1)";
is $lazy, 23, "rebinding our var containing a lazy worked (2)";
ok !$was_in_lazy, "rebinding our var containing a lazy worked (3)";
}
+#?rakudo todo 'why ever not?'
{
dies_ok { (lazy { 42 }) = 23 },
"directly assigning to a lazy var does not work";

0 comments on commit a2275c3

Please sign in to comment.