Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,25 @@ def is_builtin(var):


# FIXME: redo using importlib since that is probably less fragile.
exclude_files = set(("files", "codetables", "base", "importexport", "colors"))
exclude_files = set(("codetables", "base"))
module_names = [
f for f in __py_files__ if re.match("^[a-z0-9]+$", f) if f not in exclude_files
]

if ENABLE_FILES_MODULE:
module_names += ["files", "importexport"]

modules = []
import_builtins(module_names)

_builtins = []
builtins_by_module = {}

for subdir in ("drawing", "numbers", "specialfns",):
disable_file_module_names = [] if ENABLE_FILES_MODULE else ["files_io.files", "files_io.importexport"]

for subdir in ("drawing", "files_io", "numbers", "specialfns",):
import_name = f"{__name__}.{subdir}"

if import_name in disable_file_module_names:
continue

builtin_module = importlib.import_module(import_name)
submodule_names = [
modname
Expand Down
139 changes: 0 additions & 139 deletions mathics/builtin/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,145 +317,6 @@ class Sequence(Builtin):
"""


class Line(Builtin):
"""
<dl>
<dt>'$Line'
<dd>holds the current input line number.
</dl>
>> $Line
= 1
>> $Line
= 2
>> $Line = 12;
>> 2 * 5
= 10
>> Out[13]
= 10
>> $Line = -1;
: Non-negative integer expected.
"""

name = "$Line"


class HistoryLength(Builtin):
"""
<dl>
<dt>'$HistoryLength'
<dd>specifies the maximum number of 'In' and 'Out' entries.
</dl>
>> $HistoryLength
= 100
>> $HistoryLength = 1;
>> 42
= 42
>> %
= 42
>> %%
= %3
>> $HistoryLength = 0;
>> 42
= 42
>> %
= %7
"""

name = "$HistoryLength"

rules = {
"$HistoryLength": "100",
}


class In(Builtin):
"""
<dl>
<dt>'In[$k$]'
<dd>gives the $k$th line of input.
</dl>
>> x = 1
= 1
>> x = x + 1
= 2
>> Do[In[2], {3}]
>> x
= 5
>> In[-1]
= 5
>> Definition[In]
= Attributes[In] = {Listable, Protected}
.
. In[6] = Definition[In]
.
. In[5] = In[-1]
.
. In[4] = x
.
. In[3] = Do[In[2], {3}]
.
. In[2] = x = x + 1
.
. In[1] = x = 1
"""

attributes = ("Listable", "Protected")

rules = {
"In[k_Integer?Negative]": "In[$Line + k]",
}


class Out(Builtin):
"""
<dl>
<dt>'Out[$k$]'
<dt>'%$k$'
<dd>gives the result of the $k$th input line.
<dt>'%', '%%', etc.
<dd>gives the result of the previous input line, of the line before the previous input line, etc.
</dl>

>> 42
= 42
>> %
= 42
>> 43;
>> %
= 43
>> 44
= 44
>> %1
= 42
>> %%
= 44
>> Hold[Out[-1]]
= Hold[%]
>> Hold[%4]
= Hold[%4]
>> Out[0]
= Out[0]

#> 10
= 10
#> Out[-1] + 1
= 11
#> Out[] + 1
= 12
"""

attributes = ("Listable", "Protected")

rules = {
"Out[k_Integer?Negative]": "Out[$Line + k]",
"Out[]": "Out[$Line - 1]",
"MakeBoxes[Out[k_Integer?((-10 <= # < 0)&)],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'StringJoin[ConstantArray["%%", -k]]',
"MakeBoxes[Out[k_Integer?Positive],"
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'"%%" <> ToString[k]',
}


class Quit(Builtin):
"""
<dl>
Expand Down
3 changes: 3 additions & 0 deletions mathics/builtin/files_io/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Input/Output, Files, and Filesystem
"""
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)

from mathics.builtin.base import Builtin, Predefined
from mathics.builtin.files import (
from mathics.builtin.files_io.files import (
DIRECTORY_STACK,
INITIAL_DIR, # noqa is used via global
mathics_open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
get_option,
)

from .pymimesniffer import magic
from mathics.builtin.pymimesniffer import magic
import mimetypes
import sys
from itertools import chain
Expand Down
Loading