[LON-CAPA-cvs] cvs: loncom /homework lonmaxima.pm response.pm

www lon-capa-cvs@mail.lon-capa.org
Mon, 11 Dec 2006 22:02:16 -0000


www		Mon Dec 11 17:02:16 2006 EDT

  Modified files:              
    /loncom/homework	lonmaxima.pm response.pm 
  Log:
  <mathresponse> appears to work, but needs lots of testing
  
  
Index: loncom/homework/lonmaxima.pm
diff -u loncom/homework/lonmaxima.pm:1.6 loncom/homework/lonmaxima.pm:1.7
--- loncom/homework/lonmaxima.pm:1.6	Mon Dec 11 12:37:43 2006
+++ loncom/homework/lonmaxima.pm	Mon Dec 11 17:02:13 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to MAXIMA CAS
 #
-# $Id: lonmaxima.pm,v 1.6 2006/12/11 17:37:43 www Exp $
+# $Id: lonmaxima.pm,v 1.7 2006/12/11 22:02:13 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,18 +68,32 @@
 sub runscript {
     my ($socket,$fullscript)=@_;
     if (&blacklisted($fullscript)) { return 'Error: blacklisted'; }
-    return &maximareply($socket,$fullscript);
+    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,$arguments) = @_;
+    my ($script,$submission,$argument) = @_;
     my $socket=&connect();
-    my $fullscript=$script;
+    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 (split(/\s*\,\s*/,$argument)) {
+	$fullscript.="LONCAPALIST[$argument_index]:$argument_component;\n";
+	$argument_index++;
+    }
+    $fullscript.=$script;
     my $reply=&runscript($socket,$fullscript);
-#    &Apache::lonnet::logthis('Script:'.$fullscript);
-#    &Apache::lonnet::logthis('Sub:'.$submission);
-#    &Apache::lonnet::logthis('Arg:'.$arguments);
-
     &disconnect($socket);
     if ($reply=~/^\s*true\s*$/) { return 'EXACT_ANS'; }
     if ($reply=~/^\s*false\s*/) { return 'INCORRECT'; } 
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.153 loncom/homework/response.pm:1.154
--- loncom/homework/response.pm:1.153	Mon Dec 11 12:37:43 2006
+++ loncom/homework/response.pm	Mon Dec 11 17:02:13 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.153 2006/12/11 17:37:43 www Exp $
+# $Id: response.pm,v 1.154 2006/12/11 22:02:13 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -491,7 +491,13 @@
 	my $args_ref= \%{$safeeval->varglob('LONCAPA::mathresponse_args')};
 	undef(%{ $args_ref });
 	$$args_ref{'cas'}=$token->[2]{'cas'};
-	$$args_ref{'args'}=$token->[2]{'args'};
+        if ($token->[2]{'args'}=~/\$/) {
+	    $$args_ref{'args'}=&Apache::run::run($token->[2]{'args'},$safeeval);
+	} elsif ($token->[2]{'args'}=~/\@/) {
+	    $$args_ref{'args'}=&Apache::run::run('join(",",'.$token->[2]{'args'}.')',$safeeval);
+	} else {
+	    $$args_ref{'args'}=$token->[2]{'args'};
+	}
     } elsif ($target eq 'meta') {
 	$result .= &Apache::response::meta_package_write('mathresponse');
     }