openwebwork/pg — pull request #73 by jasongrout (2013-10-23 04:32:59+00:00)
Title: Update AskSage

This introduces several new features and improves the API:

1. An accepted_tos attribute now lets you interact with the official Sage cell server

2. The return value from AskSage is a (reference to a) hash. The hash contains (basically) the contents of the global python WEBWORK variable. This lets you pass back multiple values, somewhat intelligently coded. For example, here is a problem for finding the matrix derivative of a function:

```perl
## Template for calling Sage from within a WebWork pg file

## BEGIN_DESCRIPTION
## Sample problem embedding Sage in WW
## END_DESCRIPTION

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);

###############################################
##
## pg initializations and regular WeBWorK code

Context("Matrix");
Context()->variables->add(u => 'Real');
Context()->variables->add(v => 'Real');
$SageCode1=<true indicates that you agree to the terms of service:
# https://sagecell.sagemath.org/tos.html
$reply = AskSage($SageCode1,{seed=>$problemSeed, accepted_tos=>true});
$F = Formula($reply->{function});
$ans = Matrix($reply->{diff});

Context()->texStrings;
BEGIN_TEXT
Find the total derivative \(Df\) of \[f(u,v)={$F}\]
\{ $ans->ans_array(50)\}
END_TEXT
Context()->normalStrings;
ANS($ans->cmp());
ENDDOCUMENT();
```