From: dpvc v. a. <we...@ma...> - 2008-10-14 12:47:43
|
Log Message: ----------- BACKPORT: changes from 1.51 and 1.52: 1.52: The copy() method now does not copy values listed by the noinherit() method (e.g., correct_ans, test_values, etc). This resolves bug #1528. 1.51: 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. Tags: ---- rel-2-4-patches Modified Files: -------------- pg/lib: Parser.pm Revision Data ------------- Index: Parser.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser.pm,v retrieving revision 1.32.2.2.2.1 retrieving revision 1.32.2.2.2.2 diff -Llib/Parser.pm -Llib/Parser.pm -u -r1.32.2.2.2.1 -r1.32.2.2.2.2 --- lib/Parser.pm +++ lib/Parser.pm @@ -72,6 +72,7 @@ sub copy { my $self = shift; my $copy = bless {%{$self}}, ref($self); + foreach my $id (Value::Formula::noinherit($self)) {delete $copy->{$id}} $copy->{tree} = $self->{tree}->copy($copy); foreach my $id (keys %{$self}) { $copy->{$id} = {%{$self->{$id}}} if ref($self->{$id}) eq 'HASH'; @@ -706,11 +707,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; |