Skip to content

Commit 82cb590

Browse files
committed
Remove Symbo("Null"). Get ready for release 1.1.1
1 parent 2b545d7 commit 82cb590

File tree

5 files changed

+69
-52
lines changed

5 files changed

+69
-52
lines changed

CHANGES.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Mathics Packages added:
2222
- ``DiscreteMath`CombinatoricaV0.9`` and
2323
``DiscreteMath`CombinatoricaV0.6``. V0.9 covers Steven Skiena's older "Implementing Discrete Mathematics: Combinatorics and Graph Theory" book.
2424

25-
If you have a package that you would like included in the distribution, and it works with Mathics, please contact us.
26-
25+
If you have a package that you would like included in the distribution, and it works with Mathics, please contact us. Rubi may appear in a future release.
2726

2827

2928
New builtins:
@@ -41,13 +40,15 @@ New builtins:
4140

4241
- Workaround for ``Compile`` so it accepts functions ##1026
4342
- Add ``Trace`` option to ``Get``. ``Get["fn", Trace->True]`` will show lines as they are read.
44-
- Add bool for ``from_python``
43+
- Convert to/from Boolean types properly in ``from_python``, ``to_python``. Previously they were 0, and 1.
4544
- Extend ``DeleteCases`` to accept a levelspec parameter.
4645
- Set Evaluation#exc_result to capture ``Aborted``, ``Timeout``, ``Overflow1``, etc.
4746
- ``ImageData`` changed to get bits {0,1} not bools.
4847
- add tokenizer symbols for <-> and -> and the unicode versions of those.
4948
- fix ``Needs``
5049
- ``System`$InputFileName`` is now set inside ``Needs`` and ``Get``
50+
- Install shell scripts ``dmathicserver``, ``dmathicsscript``, and ``dmathics`` to simplify running docker
51+
- adjust $InputFileName inside ``Get`` and ``Needs``.
5152

5253
1.1.0
5354
-----

mathics/builtin/arithmetic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Rational,
3232
Real,
3333
Symbol,
34+
SymbolNull,
3435
Complex,
3536
String,
3637
SymbolTrue,
@@ -916,7 +917,7 @@ def apply_check(self, x, y, evaluation):
916917
return Symbol("ComplexInfinity")
917918

918919
result = self.apply(Expression("Sequence", x, y), evaluation)
919-
if result is None or result != Symbol("Null"):
920+
if result is None or result != SymbolNull:
920921
return result
921922

922923

mathics/builtin/attributes.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from mathics.builtin.base import Predefined, Builtin
1313
from mathics.builtin.evaluation import Sequence
14-
from mathics.core.expression import Expression, Symbol, String
14+
from mathics.core.expression import Expression, Symbol, SymbolNull, String
1515
from mathics.builtin.assignment import get_symbol_list
1616

1717

@@ -46,16 +46,16 @@ class Attributes(Builtin):
4646
= {Listable}
4747
"""
4848

49-
attributes = ('HoldAll', 'Listable')
49+
attributes = ("HoldAll", "Listable")
5050

5151
def apply(self, expr, evaluation):
52-
'Attributes[expr_]'
52+
"Attributes[expr_]"
5353

5454
name = expr.get_lookup_name()
5555
attributes = list(evaluation.definitions.get_attributes(name))
5656
attributes.sort()
5757
attr = [Symbol(attribute) for attribute in attributes]
58-
return Expression('List', *attr)
58+
return Expression("List", *attr)
5959

6060

6161
class SetAttributes(Builtin):
@@ -75,26 +75,28 @@ class SetAttributes(Builtin):
7575
= {Flat, Orderless}
7676
"""
7777

78-
attributes = ('HoldFirst',)
78+
attributes = ("HoldFirst",)
7979

8080
def apply(self, symbols, attributes, evaluation):
81-
'SetAttributes[symbols_, attributes_]'
81+
"SetAttributes[symbols_, attributes_]"
8282

83-
symbols = get_symbol_list(symbols, lambda item: evaluation.message(
84-
'SetAttributes', 'sym', item, 1))
83+
symbols = get_symbol_list(
84+
symbols, lambda item: evaluation.message("SetAttributes", "sym", item, 1)
85+
)
8586
if symbols is None:
8687
return
87-
values = get_symbol_list(attributes, lambda item: evaluation.message(
88-
'SetAttributes', 'sym', item, 2))
88+
values = get_symbol_list(
89+
attributes, lambda item: evaluation.message("SetAttributes", "sym", item, 2)
90+
)
8991
if values is None:
9092
return
9193
for symbol in symbols:
92-
if 'System`Locked' in evaluation.definitions.get_attributes(symbol):
93-
evaluation.message('SetAttributes', 'locked', Symbol(symbol))
94+
if "System`Locked" in evaluation.definitions.get_attributes(symbol):
95+
evaluation.message("SetAttributes", "locked", Symbol(symbol))
9496
else:
9597
for value in values:
9698
evaluation.definitions.set_attribute(symbol, value)
97-
return Symbol('Null')
99+
return SymbolNull
98100

99101

100102
class ClearAttributes(Builtin):
@@ -116,26 +118,29 @@ class ClearAttributes(Builtin):
116118
= {}
117119
"""
118120

119-
attributes = ('HoldFirst',)
121+
attributes = ("HoldFirst",)
120122

121123
def apply(self, symbols, attributes, evaluation):
122-
'ClearAttributes[symbols_, attributes_]'
124+
"ClearAttributes[symbols_, attributes_]"
123125

124-
symbols = get_symbol_list(symbols, lambda item: evaluation.message(
125-
'ClearAttributes', 'sym', item, 1))
126+
symbols = get_symbol_list(
127+
symbols, lambda item: evaluation.message("ClearAttributes", "sym", item, 1)
128+
)
126129
if symbols is None:
127130
return
128-
values = get_symbol_list(attributes, lambda item: evaluation.message(
129-
'ClearAttributes', 'sym', item, 2))
131+
values = get_symbol_list(
132+
attributes,
133+
lambda item: evaluation.message("ClearAttributes", "sym", item, 2),
134+
)
130135
if values is None:
131136
return
132137
for symbol in symbols:
133-
if 'System`Locked' in evaluation.definitions.get_attributes(symbol):
134-
evaluation.message('ClearAttributes', 'locked', Symbol(symbol))
138+
if "System`Locked" in evaluation.definitions.get_attributes(symbol):
139+
evaluation.message("ClearAttributes", "locked", Symbol(symbol))
135140
else:
136141
for value in values:
137142
evaluation.definitions.clear_attribute(symbol, value)
138-
return Symbol('Null')
143+
return SymbolNull
139144

140145

141146
class Protect(Builtin):
@@ -156,9 +161,9 @@ class Protect(Builtin):
156161
= {1, 2, 3}
157162
"""
158163

159-
attributes = ('HoldAll',)
164+
attributes = ("HoldAll",)
160165
messages = {
161-
'ssym': "`1` is not a symbol or a string.",
166+
"ssym": "`1` is not a symbol or a string.",
162167
}
163168

164169
def apply(self, symbols, evaluation):
@@ -174,28 +179,32 @@ def apply(self, symbols, evaluation):
174179
if symbols.get_head_name() in ("System`Sequence", "System`List"):
175180
symbols = symbols.get_leaves()
176181
else:
177-
evaluation.message('Protect', 'ssym', symbols)
178-
return Symbol("Null")
179-
182+
evaluation.message("Protect", "ssym", symbols)
183+
return SymbolNull
184+
180185
for symbol in symbols:
181186
if isinstance(symbol, Symbol):
182187
items.append(symbol)
183188
else:
184189
pattern = symbol.get_string_value()
185-
if not pattern or pattern=="":
186-
evaluation.message('Protect', 'ssym', symbol)
190+
if not pattern or pattern == "":
191+
evaluation.message("Protect", "ssym", symbol)
187192
continue
188193

189194
if pattern[0] == "`":
190195
pattern = evaluation.definitions.get_current_context() + pattern[1:]
191196
names = evaluation.definitions.get_matching_names(pattern)
192197
for defn in names:
193198
symbol = Symbol(defn)
194-
if not 'System`Locked' in evaluation.definitions.get_attributes(defn):
199+
if not "System`Locked" in evaluation.definitions.get_attributes(
200+
defn
201+
):
195202
items.append(symbol)
196203

197-
Expression("SetAttributes", Expression("List", *items), protected).evaluate(evaluation)
198-
return Symbol('Null')
204+
Expression("SetAttributes", Expression("List", *items), protected).evaluate(
205+
evaluation
206+
)
207+
return SymbolNull
199208

200209

201210
class Unprotect(Builtin):
@@ -209,20 +218,20 @@ class Unprotect(Builtin):
209218
</dl>
210219
"""
211220

212-
attributes = ('HoldAll',)
221+
attributes = ("HoldAll",)
213222
messages = {
214-
'ssym': "`1` is not a symbol or a string.",
223+
"ssym": "`1` is not a symbol or a string.",
215224
}
216225

217226
def apply(self, symbols, evaluation):
218227
"Unprotect[symbols___]"
219228
protected = Symbol("System`Protected")
220229
items = []
221-
if isinstance(symbols ,Symbol):
230+
if isinstance(symbols, Symbol):
222231
symbols = [symbols]
223232
elif isinstance(symbols, Expression):
224233
symbols = symbols.get_leaves()
225-
elif isinstance(symbols ,String):
234+
elif isinstance(symbols, String):
226235
symbols = [symbols]
227236
else:
228237
symbols = symbols.get_sequence()
@@ -232,20 +241,24 @@ def apply(self, symbols, evaluation):
232241
items.append(symbol)
233242
else:
234243
pattern = symbol.get_string_value()
235-
if not pattern or pattern=="":
236-
evaluation.message('Unprotect', 'ssym', symbol)
244+
if not pattern or pattern == "":
245+
evaluation.message("Unprotect", "ssym", symbol)
237246
continue
238247

239248
if pattern[0] == "`":
240249
pattern = evaluation.definitions.get_current_context() + pattern[1:]
241250
names = evaluation.definitions.get_matching_names(pattern)
242251
for defn in names:
243252
symbol = Symbol(defn)
244-
if not 'System`Locked' in evaluation.definitions.get_attributes(defn):
253+
if not "System`Locked" in evaluation.definitions.get_attributes(
254+
defn
255+
):
245256
items.append(symbol)
246257

247-
Expression("ClearAttributes", Expression("List", *items), protected).evaluate(evaluation)
248-
return Symbol('Null')
258+
Expression("ClearAttributes", Expression("List", *items), protected).evaluate(
259+
evaluation
260+
)
261+
return SymbolNull
249262

250263

251264
class Protected(Predefined):

mathics/builtin/image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Real,
1414
MachineReal,
1515
Symbol,
16+
SymbolNull,
1617
from_python,
1718
)
1819
from mathics.builtin.colors import (
@@ -242,7 +243,7 @@ def apply(self, path, expr, opts, evaluation):
242243
"""ImageExport[path_?StringQ, expr_, opts___]"""
243244
if isinstance(expr, Image):
244245
expr.pil().save(path.get_string_value())
245-
return Symbol("Null")
246+
return SymbolNull
246247
else:
247248
return evaluation.message("ImageExport", "noimage")
248249

mathics/builtin/structure.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
Expression,
1414
String,
1515
Symbol,
16-
SymbolTrue,
16+
SymbolNull,
1717
SymbolFalse,
18+
SymbolTrue,
1819
Integer,
1920
Rational,
2021
strip_context,
@@ -291,9 +292,9 @@ def apply(self, p1, p2, evaluation):
291292
"PatternsOrderedQ[p1_, p2_]"
292293

293294
if p1.get_sort_key(True) <= p2.get_sort_key(True):
294-
return Symbol("True")
295+
return SymbolTrue
295296
else:
296-
return Symbol("False")
297+
return SymbolFalse
297298

298299

299300
class OrderedQ(Builtin):
@@ -314,9 +315,9 @@ def apply(self, e1, e2, evaluation):
314315
"OrderedQ[e1_, e2_]"
315316

316317
if e1 <= e2:
317-
return Symbol("True")
318+
return SymbolTrue
318319
else:
319-
return Symbol("False")
320+
return SymbolFalse
320321

321322

322323
class Order(Builtin):
@@ -657,7 +658,7 @@ def callback(level):
657658
heads = self.get_option(options, "Heads", evaluation).is_true()
658659
result, depth = walk_levels(expr, start, stop, heads=heads, callback=callback)
659660

660-
return Symbol("Null")
661+
return SymbolNull
661662

662663

663664
class MapIndexed(Builtin):

0 commit comments

Comments
 (0)