Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new contextExtensions.pl framework for extending contexts #1106

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Aug 29, 2024

This PR adds the file contextExtensions.pl to the macros/contexts directory. It implements a framework for extending existing contexts to add new features, like units or fractions. I will be making two more PRs for a new contextUnits.pl and an updated contextFraction.pl that rely on this framework.

The contextExtensions.pl file abstracts the functionality needed in order to handle replacing a context's classes while still being able to call the original class methods so that you don't lose the old functionality when you override the class used by an operator or function, or when you replace a Value or Parser object class. There is quite a bit of documentation in the comments and POD section, which I will not repeat here, but this introduces a new paradigm for modifying a context that allows features like units to be added to any existing context.

The coming units and fraction PRs will illustrate how this file is used.

@dpvc dpvc added the Enhancement enhances the software label Sep 1, 2024
Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't directly toyed with this yet other than via the contextUnits.pl macro, but I will go ahead and approve it in any case.

@somiaj
Copy link
Contributor

somiaj commented Sep 16, 2024

Any reason a lot of the base method comments (which are very detailed by the way, thanks) are not in POD? To me this would also make the descriptions readable in the rendered POD that is included with a webwork2 install.

@dpvc
Copy link
Member Author

dpvc commented Sep 17, 2024

Any reason a lot of the base method comments (which are very detailed by the way, thanks) are not in POD?

Two reasons: first, I don't know POD syntax very well, and didn't want to take time to figure it out, particularly how one should handle classes and their methods in a way that makes the connection clear (as opposed to just functions being defined in a macro file).

Second, because this file is really only a support file for building other contexts, which is not something that most problem authors do (where I think POD documentation is most important), and so is only for more advanced programmers, I would expect them to need to look at the code while they are using the extension package, and I think comments are easier to read when looking at the code than POD documentation source.

But if anyone wants to convert to POD, that is OK with me.

Copy link
Member

@drgrice1 drgrice1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was toying with using this, and saw several typos in the comments which I have noted.

Also, I was experimenting with using this in some problems that I have that already sort of do this. In those problems I had previously used Context('Fraction') and then called Context()->parens->set('(' => { type => 'Point' }). That worked for my purposes. Of course with this, calling Context(context::Fraction::extending('Point')) is probably better.

Anyway, one thing that frequently occurs on this problem is that when a coordinate of the point is supposed to be 5/2, a student will answer 2 1/2. I generally don't approve of mixed number usage for coordinates of points, but I guess it is correct. So I experimented with this to see if simply adding the allowMixedNumbers => 1 flag would work. Upon entering (2 1/2, -1) for the answer, I get the message "Coordinate of Point can't be a Fraction", so it doesn't work as I had thought it would. It seems that the signedNumber pattern is the problem, and perhaps should be extended in the case that the allowMixedNumbers flag is set to include mixed numbers.

On a related note, I noted that if I add the studentsMustReduceFractions flag, and enter (10/4, -1), that is still counted correct.

macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
macros/contexts/contextExtensions.pl Outdated Show resolved Hide resolved
@drgrice1
Copy link
Member

Sorry, the comments about the Fraction context probably should have been made in #1108.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement enhances the software
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants