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

Fix ldots #993

Merged
merged 7 commits into from
Oct 31, 2020
Merged

Fix ldots #993

merged 7 commits into from
Oct 31, 2020

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Oct 27, 2020

This PR fixes the behavior of Repeated and RepeatedNull and introduce catch exceptions for wrong formatted patterns.
Import@"https://raw.githubusercontent.com/jkuczm/MathematicaCellsToTeX/master/NoInstall.m"
now still does not loads, but at least do not kill the interpreter...

@rocky please have a look at this.

@mmatera mmatera requested review from GarkGarcia and rocky October 27, 2020 13:53
@rocky
Copy link
Member

rocky commented Oct 27, 2020

@mmatera Thanks for doing this. I'll look at Wednesday night.

),"...",170))
else:
return Expression("System`HoldForm",expr)

Copy link
Member

Choose a reason for hiding this comment

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

An interesting way to handle this.

I suspect there is a better way, but I don't know what it is.

And as you have said it doesn't fully address the problem of

In[1] = a...
Out[1] = a...

But this is an improvement.

Copy link
Member

@rocky rocky left a comment

Choose a reason for hiding this comment

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

Let's go with this for now. It is an improvement even if it is not ideal or elegant.

We can always come back and revise as needed.

Again, thanks for doing.

I am assuming this gets us closer to handling more imports which would be super..

@@ -206,6 +206,8 @@ def apply_levelspec(self, expr, rules, ls, evaluation, options):
return result
except InvalidLevelspecError:
evaluation.message('General', 'level', ls)
except PatternError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to extract e in here.

return result
result, applied = expr.apply_rules(rules, evaluation)
return result
except PatternError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before.

@@ -309,8 +314,12 @@ class ReplaceRepeated(BinaryOperator):

def apply_list(self, expr, rules, evaluation):
'ReplaceRepeated[expr_, rules_]'
try:
rules, ret = create_rules(rules, expr, 'ReplaceRepeated', evaluation)
except PatternError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before.

try:
rules, ret = create_rules(
rules, expr, 'ReplaceList', evaluation, extra_args=[max])
except PatternError as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before.

@@ -1114,7 +1127,8 @@ def init(self, expr, min=1):
self.min = min
if len(expr.leaves) == 2:
leaf_1 = expr.leaves[1]
if (leaf_1.has_form('List', 1, 2) and all(leaf.get_int_value() for leaf in leaf_1.leaves)):
allnumbers = all(not (leaf.get_int_value() is None) for leaf in leaf_1.get_leaves())
if (leaf_1.has_form('List', 1, 2) and allnumbers ):
Copy link
Contributor

Choose a reason for hiding this comment

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

There's not need for the parenthesis in this condition.

@@ -1114,7 +1127,8 @@ def init(self, expr, min=1):
self.min = min
if len(expr.leaves) == 2:
leaf_1 = expr.leaves[1]
if (leaf_1.has_form('List', 1, 2) and all(leaf.get_int_value() for leaf in leaf_1.leaves)):
allnumbers = all(not (leaf.get_int_value() is None) for leaf in leaf_1.get_leaves())
Copy link
Contributor

Choose a reason for hiding this comment

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

leaf.get_int_value() is not None is more idiomatic than not (leaf.get_int_value() is None)

@GarkGarcia GarkGarcia added the bug label Oct 29, 2020
@GarkGarcia GarkGarcia changed the title Fixldots Fix ldots Oct 29, 2020
@mmatera mmatera merged commit d1d3b43 into master Oct 31, 2020
@mmatera mmatera deleted the fixldots branch October 31, 2020 03:00
@rocky
Copy link
Member

rocky commented Oct 31, 2020

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants