Skip to content

Commit 53c511f

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix_definition_autoload_to_builtin
2 parents fa423e3 + de264b8 commit 53c511f

5 files changed

Lines changed: 56 additions & 12 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ New Builtins
1717
#. ``Curl`` (2-D and 3-D vector forms only)
1818
#. ``Kurtosis``
1919
#. ``PauliMatrix``
20+
#. ``Remove``
2021
#. ``SetOptions``
2122
#. ``SixJSymbol``
2223
#. ``Skewness``

SYMBOLS_MANIFEST.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ System`RegularExpression
831831
System`RegularPolygon
832832
System`RegularPolygonBox
833833
System`ReleaseHold
834+
System`Remove
834835
System`RemoveDiacritics
835836
System`RenameDirectory
836837
System`RenameFile
@@ -877,6 +878,7 @@ System`SetAttributes
877878
System`SetDelayed
878879
System`SetDirectory
879880
System`SetFileDate
881+
System`SetOptions
880882
System`SetStreamPosition
881883
System`Share
882884
System`Sharpen

mathics/builtin/assignments/clear.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
class Clear(Builtin):
4141
"""
42+
<url>
43+
:WMA link:
44+
https://reference.wolfram.com/language/ref/Clear.html</url>
45+
4246
<dl>
4347
<dt>'Clear[$symb1$, $symb2$, ...]'
4448
<dd>clears all values of the given symbols. The arguments can also be given as strings containing symbol names.
@@ -77,7 +81,6 @@ class Clear(Builtin):
7781
allow_locked = True
7882
attributes = A_HOLD_ALL | A_PROTECTED
7983
messages = {
80-
"ssym": "`1` is not a symbol or a string.",
8184
"spsym": "Special symbol `1` cannot be cleared.",
8285
}
8386
summary_text = "clear all values associated with the LHS or symbol"
@@ -135,6 +138,10 @@ def apply(self, symbols, evaluation):
135138

136139
class ClearAll(Clear):
137140
"""
141+
<url>
142+
:WMA link:
143+
https://reference.wolfram.com/language/ref/ClearAll.html</url>
144+
138145
<dl>
139146
<dt>'ClearAll[$symb1$, $symb2$, ...]'
140147
<dd>clears all values, attributes, messages and options associated with the given symbols.
@@ -167,12 +174,50 @@ def do_clear(self, definition):
167174
definition.defaultvalues = []
168175

169176

177+
class Remove(Builtin):
178+
"""
179+
<url>
180+
:WMA link:
181+
https://reference.wolfram.com/language/ref/Remove.html</url>
182+
183+
<dl>
184+
<dt>'Remove[$x$]'
185+
<dd>removes the definition associated to $x$.
186+
</dl>
187+
>> a := 2
188+
>> Names["Global`a"]
189+
= {a}
190+
>> Remove[a]
191+
>> Names["Global`a"]
192+
= {}
193+
"""
194+
195+
attributes = A_HOLD_ALL | A_LOCKED | A_PROTECTED
196+
197+
precedence = 670
198+
summary_text = "remove the definition of a symbol"
199+
200+
def eval(self, symb, evaluation):
201+
"""Remove[symb_]"""
202+
if isinstance(symb, Symbol):
203+
evaluation.definitions.reset_user_definition(symb.name)
204+
elif isinstance(symb, String):
205+
evaluation.definitions.reset_user_definition(symb.value)
206+
else:
207+
evaluation.message(self.get_name(), "ssym", symb)
208+
return SymbolNull
209+
210+
170211
class Unset(PostfixOperator):
171212
"""
213+
<url>
214+
:WMA link:
215+
https://reference.wolfram.com/language/ref/Unset.html</url>
216+
172217
<dl>
173-
<dt>'Unset[$x$]'
174-
<dt>'$x$=.'
175-
<dd>removes any value belonging to $x$.
218+
<dt>'Unset[$x$]'
219+
<dt>'$x$=.'
220+
<dd>removes any value belonging to $x$.
176221
</dl>
177222
>> a = 2
178223
= 2

mathics/builtin/attributes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ class Protect(Builtin):
205205
"""
206206

207207
attributes = A_HOLD_ALL | A_PROTECTED
208-
messages = {
209-
"ssym": "`1` is not a symbol or a string.",
210-
}
211208
summary_text = "protect a symbol against redefinitions"
212209

213210
def apply(self, symbols, evaluation):
@@ -261,9 +258,6 @@ class Unprotect(Builtin):
261258
"""
262259

263260
attributes = A_HOLD_ALL | A_PROTECTED
264-
messages = {
265-
"ssym": "`1` is not a symbol or a string.",
266-
}
267261
summary_text = "remove protection against redefinitions"
268262

269263
def apply(self, symbols, evaluation):

mathics/builtin/messages.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ class General(Builtin):
603603
"argtu": ("`1` called with 1 argument; `2` or `3` arguments are expected."),
604604
"base": "Requested base `1` in `2` should be between 2 and `3`.",
605605
"boxfmt": "`1` is not a box formatting type.",
606+
"charcode": "The character encoding `1` is not supported. Use $CharacterEncodings to list supported encodings.",
606607
"color": "`1` is not a valid color or gray-level specification.",
607608
"cxt": "`1` is not a valid context name.",
608609
"divz": "The argument `1` should be nonzero.",
@@ -645,18 +646,19 @@ class General(Builtin):
645646
"setp": "Part assignment to `1` could not be made",
646647
"setps": "`1` in the part assignment is not a symbol.",
647648
"span": "`1` is not a valid Span specification.",
649+
"ssym": "`1` is not a symbol or a string.",
648650
"stream": "`1` is not string, InputStream[], or OutputStream[]",
649651
"string": "String expected.",
650652
"sym": "Argument `1` at position `2` is expected to be a symbol.",
651653
"tag": "Rule for `1` can only be attached to `2`.",
652654
"take": "Cannot take positions `1` through `2` in `3`.",
655+
"ucdec": "An invalid unicode sequence was encountered and ignored.",
653656
"vrule": (
654657
"Cannot set `1` to `2`, " "which is not a valid list of replacement rules."
655658
),
656659
"write": "Tag `1` in `2` is Protected.",
657660
"wrsym": "Symbol `1` is Protected.",
658-
"ucdec": "An invalid unicode sequence was encountered and ignored.",
659-
"charcode": "The character encoding `1` is not supported. Use $CharacterEncodings to list supported encodings.",
661+
# TODO: someone please explain why these are different...
660662
# Self-defined messages
661663
"rep": "`1` is not a valid replacement rule.",
662664
"options": "`1` is not a valid list of option rules.",

0 commit comments

Comments
 (0)