Skip to content

Add flags for context related to partial credit of SigFig problems.#34

Merged
pstaabp merged 0 commit into
sigfig-exponential-formfrom
sig-fig-add-partial-credit
Jun 2, 2026
Merged

Add flags for context related to partial credit of SigFig problems.#34
pstaabp merged 0 commit into
sigfig-exponential-formfrom
sig-fig-add-partial-credit

Conversation

@pstaabp
Copy link
Copy Markdown
Owner

@pstaabp pstaabp commented May 22, 2026

This includes flags for determining if a problem is to check to see if an answer has the correct # of sig figs and/or is close and give partial credit.

@pstaabp pstaabp force-pushed the sig-fig-add-partial-credit branch from 5fdce91 to 12e0598 Compare May 22, 2026 18:40
@pstaabp
Copy link
Copy Markdown
Owner Author

pstaabp commented May 22, 2026

@dpvc Now that I have more time, getting back to this. The code that I have in the PR is to add a couple of flags that allow partial credit if either the student answer matches the correct answer (within tolerance) but the number of sig figs is wrong or the number of sig figs matches and the student answer is incorrect but within tolerance.

We had this working on a different branch before I merged your code about handling the exponential form. I've been testing with the units as:

DOCUMENT();
loadMacros("PGstandard.pl","PGML.pl",'contextSignificantFigures.pl', 'contextUnits.pl');

Context(context::Units::extending('SignificantFigures')->withUnitsFor('length'))->flags->set(tolerance => 1,partial_credit=>0.48);

$ans=Compute('123.0 cm');
BEGIN_PGML
Enter the value [$ans]

[_]{$ans}
END_PGML
ENDDOCUMENT();

Now, I'm getting the following error:

ERRORS from evaluating PG file: Can't locate object method "STRING" via package "context::Units::BOP::Space" 
at line 737 of [PG]/macros/contexts/contextSignificantFigures.pl from within 
 context::SignificantFigures::BOP::space::string called at line 1935 of 
[PG]/macros/contexts/contextUnits.pl from within context::Units::BOP::string
called at line 755 of [PG]/lib/Parser.pm from within Parser::string called at 
line 107 of [PG]/macros/core/Parser.pl from within main::Compute called at line 6 of undefined

This looks like it's calling the new STRING method that you put in, but isn't being handled right with units.

@pstaabp
Copy link
Copy Markdown
Owner Author

pstaabp commented Jun 1, 2026

@dpvc wondering if you have some time to take a look at this?

@dpvc
Copy link
Copy Markdown

dpvc commented Jun 2, 2026

OK, I have been able to track down what is going on. The mechanism for extending a context to have new features without losing the old ones is a complicated one, and the new classes don't actually inherit from the old ones, but have to handle them carefully in order to access the older class methods. The classes that I added to the SignificantFigures context share common functions using a common package that is inherited by all of them. But when the units context extends that, it doesn't inherit the common package, and so doesn't find those methods; STRING() is one of those.

I think I have a fix for that, but it has to be made in the pg/macros/contexts/contextExtension.pl file:

diff --git a/macros/contexts/contextExtensions.pl b/macros/contexts/contextExtensions.pl
index c9f8700d..ea0a6482 100644
--- a/macros/contexts/contextExtensions.pl
+++ b/macros/contexts/contextExtensions.pl
@@ -460,6 +460,23 @@ sub extensionContext {
        return $class;
 }
 
+#
+# Trap any calls to super-class methods that aren't in the overriden
+# class and pass them on to the original class.
+#
+sub AUTOLOAD {
+       our $AUTOLOAD;
+       my $self = shift;
+       my $class = $self->extensionContext;
+       my $method = (split(/::/, $AUTOLOAD))[-1];
+       if (substr($AUTOLOAD, 0, length($class) + 2) eq $class . '::') {
+               my $code = $self->super($method);
+               return &$code($self, @_) if $code;
+       }
+       my ($pkg, $file, $line, $subname) = caller(0);
+       die "Can't locate object method \"$method\" via package \"". ref($self) . '"' . " at line $line of $file\n";
+}
+
 #################################################################################################
 #################################################################################################

This uses the perl AUTOLOAD feature to trap methods that aren't defined, and looks them up in the original class to see if they exist there, and calls them if they do. Otherwise it throws the usual error that you would have received for the missing method.

I think that will do the trick for you, and should male contextExtension more robust as well.

@pstaabp pstaabp merged commit 12e0598 into sigfig-exponential-form Jun 2, 2026
4 of 6 checks passed
@pstaabp
Copy link
Copy Markdown
Owner Author

pstaabp commented Jun 2, 2026

Somehow closed this. I couldn't reopen, so a new version is at #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants