#!/usr/bin/env perl

use strict; use warnings FATAL => 'uninitialized';


use strict; use warnings; use warnings FATAL => 'uninitialized';
use Function::Parameters qw(:strict);
#use Sub::Call::Tail;

# find modules from functional-perl working directory (not installed)
use Cwd 'abs_path';
our ($mydir, $myname); BEGIN {
    my $location= (-l $0) ? abs_path ($0) : $0;
    $location=~ /(.*?)([^\/]+?)_?\z/s or die "?";
    ($mydir, $myname)=($1,$2);
}
use lib "$mydir/../lib";



sub sumofsquares {
    my ($from, $to)=@_;
    my $tot=0;
    for (my $i= $from; $i<=$to; $i++) {
        $tot+= $i * $i;
    }
    $tot
}


sub Gsumofsquares {
    my ($from, $to)=@_;
    my $tot=0;
    my $i=$from;
  test:
    goto calculate if $i <= $to;
    return $tot;
  calculate:
    $tot+= $i * $i;
    $i++;
    goto test;
}


use Chj::TEST ":all";

TEST {
    [
     map { [ sumofsquares (@$_), Gsumofsquares (@$_) ] }
     ([0,4],
      [1,5],
      [3,7],
      [-2,4])
    ]
}
  [[30, 30], [55, 55], [135, 135], [35, 35]];


use FP::Repl; repl;
