#!/usr/bin/perl
#
# eg1: list test program, without List:: prefixes
#

use strict;
use warnings;
use List;

die "Usage: eg1 wordfile [wordfile...]\n" unless @ARGV;

$List::as_string_limit = 5;		       # show no more than 5 elements

# make a list of every lowercased word in every file
my $wordlist = nil();
while( my $line = <> )			       # for every line in every file
{
	chomp $line;
	$line =~ s/^\s+//;		       # remove leading..
	$line =~ s/\s+$//;		       # .. and trailing whitespace
	next unless $line;		       # skip empty lines
	$line = lc($line);		       # lower case
	my @wd = split( /\s+/, $line );	       # foreach word in line
	foreach my $word (@wd)
	{
		$wordlist = cons( $word, $wordlist );
	}
}
$wordlist = rev( $wordlist );	               # reverse wordlist

my $len = len( $wordlist );	               # print length of wordlist
print "len(list) = $len\n";

my $str = List::as_string( $wordlist );	       # print the wordlist
print "list using default limit 5 = $str\n";

$str = List::as_string( $wordlist, 7 );	       # with limit 7
print "list using call limit 7    = $str\n";

$str = List::as_string( $wordlist, 20 );       # with limit 20
print "list using call limit 20   = $str\n";
