Skip to content
46 changes: 0 additions & 46 deletions mathics/builtin/assignments/upvalues.py

This file was deleted.

2 changes: 2 additions & 0 deletions mathics/builtin/atomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
Atomic Elements of Expressions

Expressions are ultimately built from a small number of distinct types of atomic elements.

See also <url>:Symbols:/doc/reference-of-built-in-symbols/symbols/</url>.
"""
40 changes: 19 additions & 21 deletions mathics/builtin/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
A_LOCKED,
A_PROTECTED,
attribute_string_to_number,
attributes_bitset_to_list,
)
from mathics.core.builtin import Builtin, Predefined
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.symbols import Symbol, SymbolNull
from mathics.core.systemsymbols import (
SymbolClearAttributes,
SymbolProtected,
SymbolSetAttributes,
)
from mathics.eval.attributes import eval_Attributes

# This tells documentation how to sort this module
sort_order = "mathics.builtin.definition-attributes"

SymbolClearAttributes = Symbol("ClearAttributes")
SymbolSetAttributes = Symbol("SetAttributes")
SymbolProtected = Symbol("Protected")


class Attributes(Builtin):
"""
Expand Down Expand Up @@ -89,16 +90,7 @@ class Attributes(Builtin):

def eval(self, expr, evaluation):
"Attributes[expr_]"

if isinstance(expr, String):
expr = Symbol(expr.value)
name = expr.get_lookup_name()

attributes = attributes_bitset_to_list(
evaluation.definitions.get_attributes(name)
)
attributes_symbols = [Symbol(attribute) for attribute in attributes]
return ListExpression(*attributes_symbols)
return eval_Attributes(expr, evaluation)


class ClearAttributes(Builtin):
Expand Down Expand Up @@ -780,12 +772,18 @@ def eval(self, symbols, evaluation):
names = evaluation.definitions.get_matching_names(pattern)
for defn in names:
symbol = Symbol(defn)
if not A_LOCKED & evaluation.definitions.get_attributes(defn):
attributes = evaluation.definitions.get_attributes(defn)
if not A_LOCKED & attributes:
items.append(symbol)

Expression(
SymbolClearAttributes,
ListExpression(*items),
protected,
).evaluate(evaluation)
changed_list = ListExpression(*items)
if items:
Expression(
SymbolClearAttributes,
changed_list,
protected,
).evaluate(evaluation)

# FIXME this is wrong we should return those attributes that got changed only.
# return changed_list
return SymbolNull
22 changes: 3 additions & 19 deletions mathics/builtin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"""
from typing import Callable, Optional

from mathics.builtin.image.base import Image
from mathics.core.atoms import Integer1, String
from mathics.core.builtin import Builtin, Predefined, Test, get_option
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.parser import parse_builtin_rule
from mathics.core.symbols import Symbol, SymbolList, ensure_context, strip_context
from mathics.core.systemsymbols import SymbolDefault, SymbolRule, SymbolRuleDelayed
from mathics.core.systemsymbols import SymbolDefault, SymbolRule
from mathics.eval.options import eval_Options
from mathics.eval.patterns import Matcher, get_default_value


Expand Down Expand Up @@ -358,23 +358,7 @@ class Options(Builtin):

def eval(self, f, evaluation):
"Options[f_]"

name = f.get_name()
if not name:
if isinstance(f, Image):
# FIXME ColorSpace, MetaInformation
options = f.metadata
else:
evaluation.message("Options", "sym", f, Integer1)
return
else:
options = evaluation.definitions.get_options(name)
result = []
for option, value in sorted(options.items(), key=lambda item: item[0]):
# Don't use HoldPattern, since the returned List should be
# assignable to Options again!
result.append(Expression(SymbolRuleDelayed, Symbol(option), value))
return ListExpression(*result)
return eval_Options(f, evaluation)


class OptionValue(Builtin):
Expand Down
9 changes: 9 additions & 0 deletions mathics/builtin/symbol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
"""
Symbols

Symbols are the atoms of symbolic data. A symbol has a unique name, exists in a Language context or namespace, \
and can have a variety of types of values and attributes.

Expressions are built from a small number of distinct types of atomic elements.
"""
Loading
Loading