package Exercise::Gen;

use warnings;
use strict;
use Exercise::Gen::Let;
our $VERSION = '0.01';
our ( $debug_frac, $debug_fun);
my $idp=qr{[a-zA-Z_]\w*};
use utf8;

my (@texfields,@texfields_req) ; 
my @_fs= qw(
  title author question sugestion resolution result verify 
  usepackage? obs?);

BEGIN{ 
 @texfields_req = map{        "_$_"} grep { !/\?/} @_fs;
 @texfields     = map{s/\?//; "_$_"}               @_fs;
}

use List::Util qw{shuffle first};
use Data::Dumper;

sub _choice{ my @a=@_; my $i = int(rand(scalar @a)); ($a[$i], $i)}
sub rep  { my ($self,$v)= @_; _repl($v,$self->{ts});} ## FIXme ??

sub myperleval{
  my ($r,$b,$ts)=@_;
  ##print STDERR Dumper($b,$ts);
  ##my $aux=myeval(_repl($b,$ts));
  my $aux=myeval($b);
  if(ref($aux) eq "ARRAY"){ $r->{vals}=$aux }
  else                    { $r->{exp} =$aux }
  "";
}

sub myeval{ my $exp=shift;
  my $v=eval("$exp") // $exp;
  _err(" in eval($exp): $@ in calculation") if $@;
  $v
}
sub _err{ print STDERR "Error: $_[0]\n";$_[0]}
sub _err_die{ print STDERR "Error: $_[0]\n";die();}


__END__

=head1 NAME

Exercise::Gen - Generation of exercises (math, etc)

=head1 VERSION

Version 0.01

=head1 SYNOPSIS

    use Exercise::Gen;
    $n= Exercise::Gen->new("file")

=head1 EXPORT

  $p1= $n->latex()

=head1 SUBROUTINES/METHODS

=head2 read_enun

=head2 proc_geral

=head2 latex

=head2 vals

=head2 function1

=head1 Insides

 Symb-table

   

=head1 AUTHOR

J.Joao, C<< <jj at di.uminho.pt> >>


=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT

Copyright 2011 J.Joao.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut

 self
   ts
     TexElmentes (v,v1,v2)
