[system] / trunk / pg / lib / Parser / Function / numeric2.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/Function/numeric2.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3370 - (download) (as text) (annotate)
Tue Jul 12 22:29:53 2005 UTC (7 years, 10 months ago) by dpvc
File size: 1302 byte(s)
A first pass at making parser error messages localizable.  The
Context()->{error}{msg} hash can be used to specify translations of
the standard messages.  For example,

    Context()->{error}{msg}{'Division by zero'} = "Don't divide by zero, dude!";
    Context()->{error}{msg}{'Function '%s' has too many inputs'} =
        "You passed too many arguments to '%s'";

(I didn't translate into another language, here, but you could do
that, too.)

The msg hash could also be used within answer checkers to make certain
answer messages more appropriate for the given type of expected answer.

    1 #########################################################################
    2 #
    3 #  Implement functions having two real inputs
    4 #
    5 package Parser::Function::numeric2;
    6 use strict; use vars qw(@ISA);
    7 @ISA = qw(Parser::Function);
    8 
    9 #
   10 #  Check for two real-valued arguments
   11 #
   12 sub _check {
   13   my $self = shift;
   14   return if ($self->checkArgCount(2));
   15   if ($self->{params}->[0]->isNumber && $self->{params}->[1]->isNumber &&
   16       !$self->{params}->[0]->isComplex && !$self->{params}->[1]->isComplex) {
   17     $self->{type} = $Value::Type{number};
   18   } else {
   19     $self->Error("Function '%s' has the wrong type of inputs",$self->{name});
   20   }
   21 }
   22 
   23 #
   24 #  Check that the inputs are OK
   25 #
   26 sub _call {
   27   my $self = shift; my $name = shift;
   28   Value::Error("Function '%s' has too many inputs",$name) if scalar(@_) > 2;
   29   Value::Error("Function '%s' has too few inputs",$name) if scalar(@_) < 2;
   30   Value::Error("Function '%s' has the wrong type of inputs",$name)
   31     unless Value::matchNumber($_[0]) && Value::matchNumber($_[1]);
   32   return $self->$name(@_);
   33 }
   34 
   35 #
   36 #  Call the appropriate routine
   37 #
   38 sub _eval {
   39   my $self = shift; my $name = $self->{name};
   40   $self->$name(@_);
   41 }
   42 
   43 #
   44 #  Do the core atan2 call
   45 #
   46 sub atan2 {shift; CORE::atan2($_[0],$_[1])}
   47 
   48 #########################################################################
   49 
   50 1;
   51 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9