Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the last miscellaneous "list" functions to more appropriate sections #782

Merged
merged 1 commit into from
Feb 9, 2023
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
2 changes: 1 addition & 1 deletion mathics/builtin/functional/apply_fns_to_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Iterable

from mathics.builtin.base import BinaryOperator, Builtin
from mathics.builtin.lists import List
from mathics.builtin.list.constructing import List
from mathics.core.atoms import Integer
from mathics.core.convert.expression import to_mathics_list
from mathics.core.evaluation import Evaluation
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

from mathics.builtin.base import BinaryOperator, Builtin, Operator
from mathics.builtin.box.layout import GridBox, RowBox, to_boxes
from mathics.builtin.lists import list_boxes
from mathics.builtin.makeboxes import MakeBoxes
from mathics.builtin.options import options_to_rules
from mathics.core.atoms import Real, String
from mathics.core.expression import Evaluation, Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Symbol
from mathics.core.systemsymbols import SymbolMakeBoxes
from mathics.eval.lists import list_boxes
from mathics.eval.makeboxes import format_element

SymbolSubscriptBox = Symbol("System`SubscriptBox")
Expand Down
6 changes: 4 additions & 2 deletions mathics/builtin/list/associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@

from mathics.builtin.base import Builtin, Test
from mathics.builtin.box.layout import RowBox
from mathics.builtin.lists import list_boxes
from mathics.core.atoms import Integer
from mathics.core.attributes import A_HOLD_ALL_COMPLETE, A_PROTECTED
from mathics.core.convert.expression import to_mathics_list
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.symbols import Symbol, SymbolTrue
from mathics.core.systemsymbols import SymbolAssociation, SymbolMakeBoxes, SymbolMissing
from mathics.eval.lists import list_boxes


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

<dl>
<dt>'Association[$key1$ -> $val1$, $key2$ -> $val2$, ...]'
Expand Down
44 changes: 42 additions & 2 deletions mathics/builtin/list/constructing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from itertools import permutations

from mathics.builtin.base import Builtin, IterationFunction, Pattern
from mathics.builtin.box.layout import RowBox
from mathics.core.atoms import Integer
from mathics.core.attributes import A_HOLD_FIRST, A_LISTABLE, A_PROTECTED
from mathics.core.attributes import A_HOLD_FIRST, A_LISTABLE, A_LOCKED, A_PROTECTED
from mathics.core.convert.expression import to_expression
from mathics.core.convert.sympy import from_sympy
from mathics.core.element import ElementsProperties
Expand All @@ -21,7 +22,7 @@
from mathics.core.list import ListExpression
from mathics.core.symbols import Atom
from mathics.core.systemsymbols import SymbolNormal
from mathics.eval.lists import get_tuples
from mathics.eval.lists import get_tuples, list_boxes


class Array(Builtin):
Expand Down Expand Up @@ -141,6 +142,45 @@ class ConstantArray(Builtin):
}


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

<dl>
<dt>'List[$e1$, $e2$, ..., $ei$]'
<dt>'{$e1$, $e2$, ..., $ei$}'
<dd>represents a list containing the elements $e1$...$ei$.
</dl>

'List' is the head of lists:
>> Head[{1, 2, 3}]
= List

Lists can be nested:
>> {{a, b, {c, d}}}
= {{a, b, {c, d}}}
"""

attributes = A_LOCKED | A_PROTECTED
summary_text = "form a list"

def eval(self, elements, evaluation):
"""List[elements___]"""
# Pick out the elements part of the parameter elements;
# we we will call that `elements_part_of_elements__`.
# Note that the parameter elements may be wrapped in a Sequence[]
# so remove that if when it is present.
elements_part_of_elements__ = elements.get_sequence()
return ListExpression(*elements_part_of_elements__)

def eval_makeboxes(self, items, f, evaluation):
"""MakeBoxes[{items___},
f:StandardForm|TraditionalForm|OutputForm|InputForm|FullForm]"""

items = items.get_sequence()
return RowBox(*list_boxes(items, f, evaluation, "{", "}"))


class Normal(Builtin):
"""
<url>
Expand Down
16 changes: 10 additions & 6 deletions mathics/builtin/list/eol.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from mathics.builtin.base import BinaryOperator, Builtin
from mathics.builtin.box.layout import RowBox
from mathics.builtin.lists import list_boxes
from mathics.core.atoms import Integer, Integer0, Integer1, String
from mathics.core.attributes import (
A_HOLD_FIRST,
Expand Down Expand Up @@ -44,7 +43,7 @@
SymbolSequence,
SymbolSet,
)
from mathics.eval.lists import delete_one, delete_rec
from mathics.eval.lists import delete_one, delete_rec, list_boxes
from mathics.eval.parts import (
_drop_span_selector,
_take_span_selector,
Expand Down Expand Up @@ -1276,15 +1275,18 @@ class Position(Builtin):
>> Position[{1, 2, 2, 1, 2, 3, 2}, 2]
= {{2}, {3}, {5}, {7}}

Find positions upto 3 levels deep
Find positions upto 3 levels deep:

>> Position[{1 + Sin[x], x, (Tan[x] - y)^2}, x, 3]
= {{1, 2, 1}, {2}}

Find all powers of x
Find all powers of x:

>> Position[{1 + x^2, x y ^ 2, 4 y, x ^ z}, x^_]
= {{1, 2}, {4}}

Use Position as an operator
Use Position as an operator:

>> Position[_Integer][{1.5, 2, 2.5}]
= {{2}}
"""
Expand Down Expand Up @@ -1327,7 +1329,9 @@ def callback(level, pos):

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

<dl>
<dt>'Prepend[$expr$, $item$]'
Expand Down
100 changes: 0 additions & 100 deletions mathics/builtin/lists.py

This file was deleted.

2 changes: 1 addition & 1 deletion mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
PatternObject,
PostfixOperator,
)
from mathics.builtin.lists import InvalidLevelspecError
from mathics.core.atoms import Integer, Number, Rational, Real, String
from mathics.core.attributes import (
A_HOLD_ALL,
Expand All @@ -60,6 +59,7 @@
)
from mathics.core.element import EvalMixin
from mathics.core.evaluation import Evaluation
from mathics.core.exceptions import InvalidLevelspecError
from mathics.core.expression import Expression, SymbolVerbatim
from mathics.core.list import ListExpression
from mathics.core.pattern import Pattern, StopGenerator
Expand Down
Loading