Skip to content

Commit 2b545d7

Browse files
authored
Merge pull request #1015 from mathics/fixneeds
Fixneeds
2 parents 21d25fe + 3f8d244 commit 2b545d7

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

mathics/builtin/attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ def apply(self, symbols, evaluation):
166166
protected = Symbol("System`Protected")
167167
items = []
168168

169-
if isinstance(symbols ,Symbol):
169+
if isinstance(symbols, Symbol):
170170
symbols = [symbols]
171171
elif isinstance(symbols, String):
172172
symbols = [symbols]
173173
elif isinstance(symbols, Expression):
174174
if symbols.get_head_name() in ("System`Sequence", "System`List"):
175175
symbols = symbols.get_leaves()
176176
else:
177-
evaluation.message('Protect', 'ssym', symbol)
177+
evaluation.message('Protect', 'ssym', symbols)
178178
return Symbol("Null")
179179

180180
for symbol in symbols:

mathics/builtin/exptrig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
"""
4+
r"""
55
Exponential, Trigonometric and Hyperbolic Functions
66
77
\Mathics basically supports all important trigonometric and hyperbolic functions.

mathics/builtin/files.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,7 +3692,7 @@ def apply_name(self, name, evaluation):
36923692

36933693

36943694
class Compress(Builtin):
3695-
"""
3695+
u"""
36963696
<dl>
36973697
<dt>'Compress[$expr$]'
36983698
<dd>gives a compressed string representation of $expr$.
@@ -4800,7 +4800,6 @@ def apply(self, pathname, evaluation):
48004800
return SymbolTrue
48014801
return SymbolFalse
48024802

4803-
48044803
class Needs(Builtin):
48054804
"""
48064805
<dl>
@@ -4912,18 +4911,34 @@ class Needs(Builtin):
49124911
}
49134912

49144913
def apply(self, context, evaluation):
4915-
"Needs[context_String]"
4916-
4917-
if not valid_context_name(context.get_string_value()):
4918-
evaluation.message("Needs", "ctx", Expression("Needs", context), 1, "`")
4914+
'Needs[context_String]'
4915+
contextstr = context.get_string_value()
4916+
if contextstr == "":
4917+
return SymbolNull
4918+
if contextstr[0]=="`":
4919+
curr_ctxt = evaluation.definitions.get_current_context()
4920+
contextstr = curr_ctxt + contextstr[1:]
4921+
context = String(contextstr)
4922+
4923+
if not valid_context_name(contextstr):
4924+
evaluation.message('Needs', 'ctx', Expression(
4925+
'Needs', context), 1, '`')
49194926
return
49204927
test_loaded = Expression("MemberQ", Symbol("$Packages"), context)
49214928
test_loaded = test_loaded.evaluate(evaluation)
49224929
if test_loaded.is_true():
49234930
# Already loaded
49244931
return SymbolNull
49254932

4926-
result = Expression("Get", context).evaluate(evaluation)
4933+
# TODO: Look why this rises the message
4934+
# "Select::normal: Nonatomic expression expected."
4935+
already_loaded = Expression('MemberQ',
4936+
Symbol('System`$Packages'), context)
4937+
already_loaded = already_loaded.evaluate(evaluation).is_true()
4938+
if already_loaded:
4939+
return SymbolNull
4940+
4941+
result = Expression('Get', context).evaluate(evaluation)
49274942

49284943
if result == Symbol("$Failed"):
49294944
evaluation.message("Needs", "nocont", context)

mathics/builtin/scoping.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class With(Builtin):
7575
Use 'With' to insert values into held expressions
7676
>> With[{x=y}, Hold[x]]
7777
= Hold[y]
78-
78+
7979
>> Table[With[{i=j}, Hold[i]],{j,1,4}]
8080
= {Hold[1], Hold[2], Hold[3], Hold[4]}
8181
>> x=5; With[{x=x}, Hold[x]]
@@ -465,7 +465,6 @@ class Contexts(Builtin):
465465
## this assignment makes sure that a definition in Global` exists
466466
>> x = 5;
467467
X> Contexts[] // InputForm
468-
469468
"""
470469

471470
def apply(self, evaluation):

mathics/builtin/system.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,13 @@ class Packages(Predefined):
230230
</dl>
231231
232232
X> $Packages
233-
= {CombinatoricaOld,ImportExport,Internal,System,XML}
234-
#> MemberQ[$Packages, "System"]
233+
= {ImportExport`,XML`,Internal`,System`,Global`}
234+
#> MemberQ[$Packages, "System`"]
235235
= True
236236
"""
237237

238238
name = "$Packages"
239-
240-
def evaluate(self, evaluation):
241-
return Expression(
242-
"List",
243-
*(String(name) for name in evaluation.definitions.get_package_names()),
244-
)
239+
rules = {'$Packages': '{"ImportExport`", "XML`","Internal`", "System`", "Global`"}',}
245240

246241

247242
class ParentProcessID(Predefined):

mathics/core/definitions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,13 @@ def lookup_name(self, name) -> str:
389389
return with_context
390390

391391
def get_package_names(self) -> typing.List[str]:
392-
return sorted({name.split("`")[0] for name in self.get_names()})
392+
packages = self.get_ownvalue("System`$Packages")
393+
packages = packages.replace
394+
assert packages.has_form("System`List", None)
395+
packages = [c.get_string_value() for c in packages.leaves]
396+
return packages
397+
398+
#return sorted({name.split("`")[0] for name in self.get_names()})
393399

394400
def shorten_name(self, name_with_ctx) -> str:
395401
if "`" not in name_with_ctx:

0 commit comments

Comments
 (0)