Log Message:
-----------
Allow the perlFunction method to produce functions that return
formulas when not all the variables are used as arguments.
For example:
Formula("x+y")->perlFunction('f',['x']);
$f = f(2);
would produce the equivalent of
$f = Formula("2+y");
Using the substitute method is more efficient, but this now does the
right thing rather than generate error messages.
Modified Files:
--------------
pg/lib:
Parser.pm
Revision Data
-------------
Index: Parser.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Parser.pm,v
retrieving revision 1.50
retrieving revision 1.51
diff -Llib/Parser.pm -Llib/Parser.pm -u -r1.50 -r1.51
--- lib/Parser.pm
+++ lib/Parser.pm
@@ -706,11 +706,15 @@
sub perlFunction {
my $self = shift; my $name = shift || ''; my $vars = shift;
$vars = [sort(keys %{$self->{variables}})] unless $vars;
- my $n = scalar(@{$vars}); my $vnames = '';
+ $vars = [$vars] unless ref($vars) eq 'ARRAY';
+ my $n = scalar(@{$vars}); my $vnames = ''; my %isArg;
if ($n > 0) {
- my @v = (); foreach my $x (@{$vars}) {CORE::push(@v,"\$".$x)}
+ my @v = ();
+ foreach my $x (@{$vars}) {CORE::push(@v,"\$".$x); $isArg{$x} = 1}
$vnames = "my (".join(',',@v).") = \@_;";
}
+ foreach my $x (keys %{$self->{variables}})
+ {$vnames .= "\n my \$$x = main::Formula('$x');" unless $isArg{$x}}
my $context = $self->context;
my $fn = eval
"package main;
|