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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mypy:
mypy --install-types --ignore-missing-imports --non-interactive mathics

plot-detailed-tests:
MATHICS_CHARACTER_ENCODING="ASCII" MATHICS_PLOT_DETAILED_TESTS="1" $(PYTHON) -m pytest -x $(PYTEST_OPTIONS) test/builtin/drawing/test_plot_detail.py
MATHICS_PLOT_DETAILED_TESTS="1" $(PYTHON) -m pytest -x $(PYTEST_OPTIONS) test/builtin/drawing/test_plot_detail.py

#: Run pytest tests. Use environment variable "PYTEST_OPTIONS" for pytest options
pytest:
Expand All @@ -156,7 +156,7 @@ latex-doctest-data: mathics/builtin/*.py mathics/doc/documentation/*.mdoc mathic

#: Run tests that appear in docstring in the code. Use environment variable "DOCTEST_OPTIONS" for doctest options
doctest:
MATHICS_CHARACTER_ENCODING="ASCII" MATHICS3_SANDBOX=$(MATHICS3_SANDBOX) $(PYTHON) mathics/docpipeline.py $(DOCTEST_OPTIONS)
MATHICS3_SANDBOX=$(MATHICS3_SANDBOX) $(PYTHON) mathics/docpipeline.py $(DOCTEST_OPTIONS)

#: Run tests that appear in docstring in the code, stopping on the first error.
doctest-x:
Expand Down
2 changes: 2 additions & 0 deletions mathics/Data/ExampleData/HelloWorld.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(* An example of a Wolfram Language/Mathics3 program that can be used for testing. *)
"Hello, " <> "World!"
17 changes: 17 additions & 0 deletions mathics/SystemFiles/Formats/WL/Import.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(* ::Package:: *)

(* Note: this is stripped down a lot from what WMA handles. *)

Begin["System`Convert`WLDump`"];


ImportExport`RegisterImport[
"WL", (* WMA mime-type name *)
WLDump`ImportWL (* Default Function name that handles this. *),
{},
"AvailableElements" -> {"Get", "Script"},
"DefaultElement" -> "Get"
];


End[];
2 changes: 1 addition & 1 deletion mathics/builtin/atomic/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class FormatValues(Builtin):

The replacement pattern on the right in the delayed rule is formatted according to the top-level form. To see the rule input, we can use 'InputForm':
>> FormatValues[F] //InputForm
= {HoldPattern[Format[F[x_], OutputForm]] Subscript[x, F]}
= {HoldPattern[Format[F[x_], OutputForm]] :> Subscript[x, F]}
"""

summary_text = (
Expand Down
52 changes: 52 additions & 0 deletions mathics/builtin/fileformats/wlformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
WL File Format

WL and Mathics3 importer
"""

from mathics.core.builtin import Builtin, String
from mathics.core.evaluation import Evaluation
from mathics.eval.fileformats.wlformat import eval_WLImport


class ImportWL(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/format/WL.html</url>

<dl>
<dt>'WLDump`ImportWL[$path$]'
<dd>Read $path$ as a Wolfram package and 'Get' it.
</dl>

This command is hooked into the 'Import' command via \
'SystemFiles/Formats/WL/Import.wl'.

When running this command directly, a list of rules is returned:

>> WLDump`ImportWL["ExampleData/HelloWorld.wl"]
= {Get ⇾ Hello, World!, Script ⇾ Hello, World!}

The left-hand side is a element name that can be provided to 'Import', \
and the right-hand side is the value associated with that element. Here it \
represents the last evaluation value when evaluating the contents of the file.

When an 'Import' is done and the file mentioned is a Mathics3 or a \
Wolfram-Language file, this command is run underneath selecting value of the \
"Get" element:

>> Import["ExampleData/HelloWorld.wl"]
= Hello, World!

All of this is the same as just running a simple 'Get':
>> << "ExampleData/HelloWorld.wl"
= Hello, World!

In sum, the built-in provides the glue to the 'Import' accees mechanism for 'Get'.
"""

context = "WLDump`"
summary_text = "import WL file"

def eval(self, path: String, evaluation: Evaluation):
"WLDump`ImportWL[path_String]"
return eval_WLImport(path, evaluation)
4 changes: 2 additions & 2 deletions mathics/builtin/functional/apply_fns_to_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ class MapAt(Builtin):

Map $f$ onto at the second position of an association:
>> MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, 2]
= <|a -> 1, b -> f[2], c -> 3, d -> 4|>
= <|a 1, b f[2], c 3, d 4|>

Same as above, but select the second-from-the-end position:
>> MapAt[f, <|"a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4|>, -2]
= <|a -> 1, b -> 2, c -> f[3], d -> 4|>
= <|a 1, b 2, c f[3], d 4|>

"""

Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Format(Builtin):
Mathics3 input:

>> Format[{a -> Integrate[F[x], x]}, StandardForm] //InputForm
= Format[{a Integrate[F[x], x]}, StandardForm]
= Format[{a -> Integrate[F[x], x]}, StandardForm]

In WMA, you might not get something that can be used as input.

Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/numbers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Apart(Builtin):
= Sin[1 / (x ^ 2 - y ^ 2)]

>> a == "A" // Apart // InputForm
= a "A"
= a == "A"
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -175,7 +175,7 @@ class Cancel(Builtin):

But it does not touch other expressions:
>> a == "A" // Cancel // InputForm
= a "A"
= a == "A"
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -976,7 +976,7 @@ class Factor(Builtin):

But it does not touch other expressions:
>> a == "A" // Factor // InputForm
= a "A"
= a == "A"
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down
10 changes: 5 additions & 5 deletions mathics/doc/documentation/1-Manual.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1233,15 +1233,15 @@ A dice object shall be displayed as a rectangle with the given number of points
#> Definition[Dice]
= Attributes[Dice] = {Orderless}
.
. Format[Dice[n_Integer ? (1 #1 6&)], MathMLForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize Tiny]]
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], MathMLForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 #1 6&)], OutputForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize Tiny]]
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], OutputForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 #1 6&)], StandardForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize Tiny]]
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], StandardForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 #1 6&)], TeXForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize Tiny]]
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], TeXForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize -> Tiny]]
.
. Format[Dice[n_Integer ? (1 #1 6&)], TraditionalForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize Tiny]]
. Format[Dice[n_Integer ? (1 <= #1 <= 6&)], TraditionalForm] = Block[{p = 0.2, r = 0.05}, Graphics[{EdgeForm[Black], White, Rectangle[], Black, EdgeForm[], If[OddQ[n], Disk[{0.5, 0.5}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{p, p}, r]], If[MemberQ[{2, 3, 4, 5, 6}, n], Disk[{1 - p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{p, 1 - p}, r]], If[MemberQ[{4, 5, 6}, n], Disk[{1 - p, p}, r]], If[n === 6, {Disk[{p, 0.5}, r], Disk[{1 - p, 0.5}, r]}]}, ImageSize -> Tiny]]

The empty series of dice shall be displayed as an empty dice:
>> Format[Dice[]] := Graphics[{EdgeForm[Black], White, Rectangle[]}, ImageSize -> Tiny]
Expand Down
Loading