Skip to content

Adding the ability to use units with significant figures. #36

Open
pstaabp wants to merge 1 commit into
sigfig-exponential-formfrom
sig-fig-add-partial-credit
Open

Adding the ability to use units with significant figures. #36
pstaabp wants to merge 1 commit into
sigfig-exponential-formfrom
sig-fig-add-partial-credit

Conversation

@pstaabp
Copy link
Copy Markdown
Owner

@pstaabp pstaabp commented Jun 2, 2026

when using the extension with Units context and added a test for units with significant figures.

when using the extension with Units context and added a test for units with significant figures.
@pstaabp
Copy link
Copy Markdown
Owner Author

pstaabp commented Jun 2, 2026

@dpvc Somehow I inadvertently merged the previous one. I just updated the code with your suggestions from #34 and that fixed the error about the missing STRING function, but a couple of other issues popped up:

  • I think that the caller function is not allowed in the safe compartment. I have this error inside of a problem running in WeBWorK:
ERRORS from evaluating PG file:
Error detected while loading [PG]/macros/contexts/contextUnits.pl:
PG_macro_file_eval detected error at line 110 of file [PG]/lib/PGloadfiles.pm
Error detected while loading [PG]/macros/contexts/contextExtensions.pl:
PG_macro_file_eval detected error at line 110 of file [PG]/lib/PGloadfiles.pm
'caller' trapped by operation mask at line 476 of [PG]/macros/contexts/contextExtensions.pl.
  • Also, I thought I had added a test for doing units. It's in the latest commit. Everything passes, except I'm getting errors from the end of the AUTOLOAD function. If I run the significant_figures_units.t file, I get:
	(in cleanup) Can't locate object method "DESTROY" via package "context::Units::BOP::Space" at line 50 of /opt/webwork/pg/lib/Parser/BOP.pm
	(in cleanup) Can't locate object method "DESTROY" via package "context::Units::Parser::Formula" at line 110 of (eval 214)
	(in cleanup) Can't use an undefined value as a HASH reference at (eval 223) line 405.

This doesn't occur within WeBWorK. I see that that WWSafe has a DESTROY sub that may handle it there.

I'm guessing it's trying to call the DESTROY method that doesn't exist in either the base or extending class.

@pstaabp pstaabp changed the title Added a sub AUTOLOAD function to handle errors Adding the ability to use units with significant figures. Jun 2, 2026
@dpvc
Copy link
Copy Markdown

dpvc commented Jun 3, 2026

I think that the caller function is not allowed in the safe compartment.

Well, I suppose it could be added to the list of allowed functions. Alternatively, you can remove it and just use

	die "Can't locate object method \"$method\" via package \"" . ref($self) . "\"\n";

instead. This will mean the location of the call won't be made, but I suppose that's OK. It might be possible to use the output of Value::traceback() to find the needed information, as I think that is allowed to be used in the safe compartment. I suppose a new method like Value::caller() could be added that would give the needed data. (Because the definitions in Value.pm are outside the safe compartment, caller() can be used there.)

As for DESTROY, you could filter that out and not produce a message for it:

	die "Can't locate object method \"$method\" via package \"" . ref($self) . "\"\n"
		unless $method eq 'DESTROY';

@dpvc
Copy link
Copy Markdown

dpvc commented Jun 3, 2026

If you continue to get

(in cleanup) Can't use an undefined value as a HASH reference at (eval 223) line 405.

you may need to add

	return unless $self;

before the line defining my $class;

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