-
Notifications
You must be signed in to change notification settings - Fork 161
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
Make "last" (and similar variables) read-only #3226
Conversation
876de7c
to
3a49038
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.
Thank you, this seems like a very sensible thing to me. However, I have various nitpicks.
lib/demo.g
Outdated
last := result[2]; | ||
UpdateStat("last3", last2); | ||
UpdateStat("last2", last); | ||
UpdateStat("last", result[2]); |
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.
Since you are touching this code anyway, perhaps you'd also be willing to teach it to update memory_allocated
, too? Also perfectly fine if you don't want to, of course!
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've never actually used this code, and don't even know how it should be used, so I'd prefer to leave it. I've just noticed it has no tests, no documentation, and isn't linked to from anywhere?
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.
It is used like this: you take a file and put a bunch of inputs in it, each on its own line. Then you run Demonstration
on this; whenever you press a key, the next input line is read and executed. The result then looks something like this (where each demo>
appeared only after a key was pressed):
gap> Demonstration("demo.g");
Start of demonstration.
demo> 1+1;
2
demo> Factorial(10);
3628800
demo>
End of demonstration.
gap>
Updating last, last2, etc. only is of interest if the demo code references them. So if one wants to write a demo that showcases those, and also memory_allocated
, then it'd be nice to have memory_allocated
. But this is nothing this PR needs to do.
I've long wanted to give this code some love, and improve it; e.g. instead of always going to the next command upon any key press, I think only "return" on an empty line should do that; otherwise, it'd be nice if one could show the next command w/o executing it, and also edit it; and other stuff. I think other people implemented such demo modes for other languages, and they can be very useful for classes, presentations during talks etc.
95c36c5
to
7d491bc
Compare
I think all issues are now fixed. |
7d491bc
to
5c8e413
Compare
Codecov Report
@@ Coverage Diff @@
## master #3226 +/- ##
==========================================
- Coverage 84.75% 84.75% -0.01%
==========================================
Files 689 689
Lines 336391 336411 +20
==========================================
+ Hits 285107 285116 +9
- Misses 51284 51295 +11
|
A very subtle mistake in GAP is for users to use the variables 'last' or 'time', as GAP automatically rewrites these variables after every statement. Add a special function 'UpdateStat' for changing these variables, so we can disable 'last := x;'
5c8e413
to
c5b6027
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.
Perfect, thanks! I am waiting with the merge a bit, so that the PR adding C++ coverage support can finish first, as otherwise codecov will probably once again be super confused about what it displays sigh
Fixes #338 ( mentioned here so it will get closed) |
That doesn't work, you have to add the "fixes" to the PR description |
This stops users writing to
last
,time
, and some other variables, by making them read-only.It adds a method to write to these variables,
UpdateStat
, mainly for use indemo.g
.I realise this might break some code. However, I did have someone had a had-to-track down bug where they were using
last
as a variable themselves, and were then confused when they got stupid answers out, so I think it is worth changing.