--- loncom/homework/lonmaxima.pm 2006/06/13 14:57:54 1.5 +++ loncom/homework/lonmaxima.pm 2006/12/15 21:10:13 1.8 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Interface routines to MAXIMA CAS # -# $Id: lonmaxima.pm,v 1.5 2006/06/13 14:57:54 albertel Exp $ +# $Id: lonmaxima.pm,v 1.8 2006/12/15 21:10:13 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -65,6 +65,41 @@ sub blacklisted { return 0; } +sub runscript { + my ($socket,$fullscript)=@_; + if (&blacklisted($fullscript)) { return 'Error: blacklisted'; } + my $reply; + $fullscript=~s/[\n\r\l]//gs; + foreach my $line (split(/\;/s,$fullscript)) { + if ($line=~/\w/) { $reply=&maximareply($socket,$line.";\n"); } + if ($reply=~/^Error\:/) { return $reply; } + } + $reply=~s/\W//gs; + return $reply; +} + +sub maxima_run { + my ($script,$submission,$argument) = @_; + my $socket=&connect(); + my $fullscript=''; + my $submission_index=1; + foreach my $submission_component (split(/\s*\,\s*/,$submission)) { + $fullscript.="RESPONSE[$submission_index]:$submission_component;\n"; + $submission_index++; + } + my $argument_index=1; + foreach my $argument_component (@{$argument}) { + $fullscript.="LONCAPALIST[$argument_index]:$argument_component;\n"; + $argument_index++; + } + $fullscript.=$script; + my $reply=&runscript($socket,$fullscript); + &disconnect($socket); + if ($reply=~/^\s*true\s*$/) { return 'EXACT_ANS'; } + if ($reply=~/^\s*false\s*/) { return 'INCORRECT'; } + return 'BAD_FORMULA'; +} + sub compareterms { my ($socket,$terma,$termb)=@_; my $difference=$terma.'-'.$termb;