Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

autrijus (1505)

  (email not shown publicly)

Journal of autrijus (1505)

Sunday July 31, 2005
01:16 PM

Day 178 (r5932): QuickChecking PIL.

[ #25991 ]
Today I finally put the QuickCheck technology to use, having it generate a large number of PIL expressions and check that invariants hold.

For example, this property declares that untie() accepts any lvalue arguments:

prop_untie :: LV -> Bool
prop_untie x = try_ok (Untie x)

Based on the type signature, when I type test prop_untie in the ghci prompt, QuickCheck will generate 100 of random expressions that can evaluate to a lvalue, run them through Untie, and check that all of them succeeds.

I am gradually converting hand-crafted unit tests into this kind of invariant-based tests. This process prompted me to see the language in a different light: not as a black box with external expectations defined by individual unit tests, but rather a well-behaved system with invariant properties. Of course, such verifiable specification is still not as good as a proof -- but it is much more cheap and cheerful than other test methodologies that I know of.

During the quick checking, a question arises: what is the meaning of untie(&say)? Perl 5 does not have this problem, as &say is a function call there -- you cannot address a function by name. In Perl 6, it seems to me that my &foo is merely a constrained version of scalar variable my Code $foo, and &foo = sub { ... } should work as usual. I have brought this to p6l for discussion.

iblech and I also noticed that function parameter binding and normal variable binding are symmetric:

    sub f ($a, $b) {
        return (c => $a, d => $b)
    ($c, $d) := f(a => $a, b => $b);

Currently the return side is not specified to observe the same rich binding semantics as the parameter side; moreover, named return values are not expressible. We think that it makes sense to unify both representations into the same binding form.

Finally, I have posted a preliminary solution to the dreaded $x = $x + my $x if $x; problem that haunted us during the hackathon. Enjoy!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • The new smoke is online [] [r5930] (compare with r5904 []), showing that PIL2JS passes 57.07% of Pugs' testsuite, with 28 unexpected successes. :)

    You can also browse the testsuite [], compiled to JS.

    FYI, compiling the whole suite to JS took 5min 40s; compiling and running using Spidermonkey's bin/js took 29min (with -j1).

    Test failures are mainly due to

    • &eval, of course, not working,
    • missing implementation of builtins,
    • regexps not (yet) working, and
    • Stevan's MetaModel for JS [] not being integrated yet.