Skip to content

Commit

Permalink
Start CheckAbort[] builtin function
Browse files Browse the repository at this point in the history
Just basic implementation. Right now, we don't handle options.
  • Loading branch information
rocky committed Oct 1, 2024
1 parent 6aadef6 commit fba240c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGES
New Builtins
++++++++++++

* ``CheckAbort``
* ``SetEnvironment``

Compatibility
Expand All @@ -22,9 +23,9 @@ Operator precedence has been gone over and is picked up in tables from the Mathi
Performance
-----------

* `Blank*` patterns without arguments are now singletons.
* ``Blank*`` patterns without arguments are now singletons.



7.0.0
-----

Expand Down
30 changes: 30 additions & 0 deletions mathics/builtin/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ def eval_with_form_and_fn(self, expr, form, f, evaluation):
return ret


class CheckAbort(Builtin):
"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/CheckAbort.html</url>
<dl>
<dt>'CheckAbort[$expr$, $failexpr$]'
<dd>evaluates $expr$, returning $failexpr$ if an abort occurs.
</dl>
>> CheckAbort[Abort[]; 1, 2] + x
= 2 + x
>> CheckAbort[1, 2] + x
= 1 + x
"""

attributes = A_HOLD_ALL | A_PROTECTED

summary_text = "catch an Abort[] exception"

def eval(self, expr, failexpr, evaluation):
"CheckAbort[expr_, failexpr_]"

try:
return expr.evaluate(evaluation)
except AbortInterrupt:
return failexpr


class CompoundExpression(BinaryOperator):
"""
<url>:WMA link:
Expand Down

0 comments on commit fba240c

Please sign in to comment.