GithubHelp home page GithubHelp logo

Comments (8)

drgrice1 avatar drgrice1 commented on August 20, 2024 1

Actually, looking closer it seems that this is due to #518, and not #526. The branch of code that is called when the currency set method is called is there. Since $update = 1 is set here and thus the SUPER update method is called, perhaps the correct fix is to remove line 339 of contextCurrency.pl.

from pg.

drdrew42 avatar drdrew42 commented on August 20, 2024

I have my suspicions that this arises from changes made to Value::Context::Data::set in #526

Currency::set calls SUPER::set (Value::Context::Data::set) and follows with Currency::update, but by the time we get to Currency::update, the old operator has already been removed since Value::Context::Data::set now sets $update = 1. We then get this error from Currency::update attempting to redefine an operator that's already been removed.

from pg.

drgrice1 avatar drgrice1 commented on August 20, 2024

Commenting out line 339 of contextCurrency.pl (the update call in the Currency::Context::currency::set method) fixes the problem. Probably not in a proper way though, but the problem works then. This seems to confirm that @drdrew42 is correct in his assessment.

from pg.

drdrew42 avatar drdrew42 commented on August 20, 2024

No, I think the solution should be the removal of these lines from Currency::update

$operators->redefine($data->{symbol}, from => $context, using => $self->{symbol});
$operators->remove($self->{symbol});

perhaps even removing that entire conditional, since we can trust the parent to handle the symbol updates.

Edit: I agree with pointing at #518 as the culprit, but not the means of redress.

from pg.

drgrice1 avatar drgrice1 commented on August 20, 2024

Testing this it seems that my suggestion of removing line 339 (which means the entire set override method should be removed) works. Testing the suggestion to remove lines 385 and 386 of the update method does not. Test with the following MWE modified from @Alex-Jordan's previous example:

DOCUMENT();
loadMacros(qw(PGstandard.pl PGML.pl contextCurrency.pl));

Context('Currency')->currency->set(symbol => '!');
$a = Currency(1000);

BEGIN_PGML
Enter [`[$a]`].

[_]{$a}
END_PGML

ENDDOCUMENT();

Although the problem loads with both changes without error, student answers do not work correctly with @drdrew42's suggestion. If you enter !1000 with my proposed change, the answer is marked correct and displayed in the preview as !1000. However, with @drdrew42's suggestion it is marked incorrect. If you enter $1000 with my proposed change, it is marked incorrect and displayed in the preview as $1000 as it should be. However, with @drdrew42's proposal, it is marked correct and it is displayed in the preview as !1000.

from pg.

drdrew42 avatar drdrew42 commented on August 20, 2024

Confirmed, thanks for digging deeper -- I ran out of time to keep going on this yesterday. Here is what I've found with the removal of line 339.

As described in the POD for this context:

Context()->currency->set(symbol=>'euro'); # accepts '12 euro'

The associativity does not get set to "right" during this transaction, and so "12 euro" is incorrect with message: "There should be a number after 'euro'", and the Currency object is rendered as "euro 12". (Looking at the code, it seems that this never worked as described in the POD.)

Context()->currency->set(symbol=>'euro', associativity => "right") does set the associativity (for both display and submitted answers) so perhaps it is reasonable to update the POD rather than fix the implementation.

However (again following the POD):

Context()->currency->set(symbol=>'euro');
Context()->currency->setSymbol(euro=>{associativity=>"right"});

does accept "12 euro" as correct, and "euro 12" as incorrect, but does not set the display of "euro" to the right and instead displays "euro 12".

from pg.

drgrice1 avatar drgrice1 commented on August 20, 2024

I saw that with the "euro" symbol as well. I am not sure if that ever worked or not, but that also needs to be fixed. I don't think it is related to this issue though.

from pg.

pstaabp avatar pstaabp commented on August 20, 2024

Fixed with #839

from pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.