<commit_before>#!/usr/bin/env perl6

constant $root = $?FILE.IO.parent.parent;
use lib $root.child: 'lib';
use lib $root.child('blib').child: 'lib';

use Inline::Lua;

sub perlintsum (int $c) {
    my int $n = 0;
    loop (my int $i = 1; $i <= $c; $i = $i + 1) {
        $n = $n + $i;
    }
    $n;
};

sub perlnumsum (num $c) {
    my num $n = 0e0;
    loop (my num $i = 1e0; $i <= $c; $i = $i + 1e0) {
        $n = $n + $i;
    }
    $n;
};

my &luasum = Inline::Lua.new(:!auto).run: Q:to/ENDLUA/;
    function sum (c)
        local n = 0
        for i = 1, c do
            n = n + i
        end

        return n
    end

    return sum
ENDLUA

my %t;

my $i = @*ARGS ?? +@*ARGS[0] !! 1;

say "lua...";
%t<lua>.push: now;
say luasum $i;
%t<lua>.push: now;

say "perlint...";
%t<perlint>.push: now;
say perlintsum $i.Int;
%t<perlint>.push: now;

say "perlnum...";
%t<perlnum>.push: now;
say perlnumsum $i.Num;
%t<perlnum>.push: now;

say '';
for %t {
    say "$_.key(): { [R-] |@(.value) }";
}
<commit_msg>A couple revisions to the sum example<commit_after>#!/usr/bin/env perl6

constant $root = $?FILE.IO.parent.parent;
use lib $root.child: 'lib';
use lib $root.child('blib').child: 'lib';

use Inline::Lua;

sub perlintsum (int $c) {
    my int $n = 0;
    loop (my int $i = 1; $i <= $c; $i = $i + 1) {
        $n = $n + $i;
    }
    $n;
};

sub perlnumsum (num $c) {
    my num $n = 0e0;
    loop (my num $i = 1e0; $i <= $c; $i = $i + 1e0) {
        $n = $n + $i;
    }
    $n;
};

sub perlnum64sum (num64 $c) {
    my num64 $n = 0e0;
    loop (my num64 $i = 1e0; $i <= $c; $i = $i + 1e0) {
        $n = $n + $i;
    }
    $n;
};

my &luasum = Inline::Lua.new(:!auto).run: Q:to/ENDLUA/;
    function sum (c)
        local n = 0
        for i = 1, c do
            n = n + i
        end

        return n
    end

    return sum
ENDLUA

my %t;

my $i = @*ARGS ?? +@*ARGS[0] !! 1e7;

say "lua...";
%t<lua>.push: now;
say luasum $i;
%t<lua>.push: now;

say "perlint...";
%t<perlint>.push: now;
say perlintsum $i.Int;
%t<perlint>.push: now;

say "perlnum...";
%t<perlnum>.push: now;
say perlnumsum $i.Num;
%t<perlnum>.push: now;

say "perlnum64...";
%t<perlnum64>.push: now;
say perlnum64sum $i.Num;
%t<perlnum64>.push: now;

say '';
for %t {
    say "$_.key(): { [R-] |@(.value) }";
}

{'fraction_non_alphanumeric': 0.22105723023154217, 'fraction_numerical': 0.022280471821756225, 'mean_word_length': 2.220815752461322, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2681094', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1058, 'n_words': 287}