-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
base: develop
Are you sure you want to change the base?
Conversation
e04a0da
to
34a3322
Compare
There was a problem hiding this 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.
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. |
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. |
There was a problem hiding this 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.
Sorry, the comments about the |
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
Co-authored-by: Glenn Rice <[email protected]>
This PR adds the file
contextExtensions.pl
to themacros/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 newcontextUnits.pl
and an updatedcontextFraction.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.