@@ -336,7 +336,7 @@ class Symbol(Atom, NumericOperators, EvalMixin):
336
336
337
337
All Symbols have a name that can be converted to string.
338
338
339
- A Variable Symbol is a ``Symbol``` that is associated with a
339
+ A Variable Symbol is a ``Symbol`` that is associated with a
340
340
``Definition`` that has an ``OwnValue`` that determines its
341
341
evaluation value.
342
342
@@ -348,7 +348,7 @@ class Symbol(Atom, NumericOperators, EvalMixin):
348
348
a constant value that cannot change. System`True and System`False
349
349
are like this.
350
350
351
- These however are in class PredefinedSymbol . See that class for
351
+ These however are in class SymbolConstant . See that class for
352
352
more information.
353
353
354
354
Symbol acts like Python's intern() built-in function or Lisp's
@@ -379,7 +379,7 @@ def __new__(cls, name: str, sympy_dummy=None):
379
379
Allocate an object ensuring that for a given ``name`` and ``cls`` we get back the same object,
380
380
id(object) is the same and its object.__hash__() is the same.
381
381
382
- PredefinedSymbol 's like System`True and System`False set
382
+ SymbolConstant 's like System`True and System`False set
383
383
``value`` to something other than ``None``.
384
384
385
385
"""
@@ -639,37 +639,48 @@ def to_sympy(self, **kwargs):
639
639
return builtin .to_sympy (self , ** kwargs )
640
640
641
641
642
- class PredefinedSymbol (Symbol ):
642
+ class SymbolConstant (Symbol ):
643
643
"""
644
- A Predefined Symbol is a Constant Symbol of the Mathics system whose value can't
645
- be changed.
644
+ A Symbol Constant is Symbol of the Mathics system whose value can't
645
+ be changed and has a corresponding Python representation .
646
646
647
- Therefore, like say, an Integer constant, we don't need to go
648
- through Definitions to get its value.
647
+ Therefore, like an `` Integer`` constant such as ``Integer0`` , we don't
648
+ need to go through `` Definitions`` to get its Python-equivalent value.
649
649
650
- As we do in numeric constants, a PredefinedSymbols Python-equivalent value not its string name
651
- but to its Python-equivalent value. For example for the predefined System`True we
652
- we can set its value to the Python ``True`` value.
650
+ For example for the ``SymbolConstant`` ``System`True``, has its
651
+ value set to the Python ``True`` value.
652
+
653
+ Note this is not the same thing as a Symbolic Constant like ``Pi``,
654
+ which doesn't have an (exact) Python equivalent representation.
655
+
656
+ Also note that ``SymbolConstant`` differs from ``Symbol`` in that
657
+ Symbol has no value field (even when its value happens to be
658
+ representable in Python. Symbols need to go through Definitions
659
+ get a Symbol's current value, based on the current context and the
660
+ state of prior operations on that Symbol/Definition binding.
661
+
662
+ In sum, SymbolConstant is partly like Symbol, and partly like
663
+ Numeric constants.
653
664
"""
654
665
655
- # Dictionary of PredefinedSymbols defined so far.
666
+ # Dictionary of SymbolConstants defined so far.
656
667
# We use this for object uniqueness.
657
- # The key is the PredefinedSymbol object 's name , and the
668
+ # The key is the SymbolConstant 's value , and the
658
669
# diectionary's value is the Mathics object representing that Python value.
659
- _predefined_symbols = {}
670
+ _symbol_constants = {}
660
671
661
672
# We use __new__ here to unsure that two Integer's that have the same value
662
673
# return the same object.
663
674
def __new__ (cls , name , value ):
664
675
665
676
name = ensure_context (name )
666
- self = cls ._predefined_symbols .get (name )
677
+ self = cls ._symbol_constants .get (name )
667
678
if self is None :
668
679
self = super ().__new__ (cls , name )
669
680
self ._value = value
670
681
671
682
# Cache object so we don't allocate again.
672
- self ._predefined_symbols [name ] = self
683
+ self ._symbol_constants [name ] = self
673
684
674
685
# Set a value for self.__hash__() once so that every time
675
686
# it is used this is fast. Note that in contrast to the
@@ -723,10 +734,10 @@ def symbol_set(*symbols: Tuple[Symbol]) -> FrozenSet[Symbol]:
723
734
724
735
# Symbols used in this module.
725
736
726
- # Note, below we are only setting PredefinedSymbol for Symbols which
737
+ # Note, below we are only setting SymbolConstant for Symbols which
727
738
# are both predefined and have the Locked attribute.
728
739
729
- # An experiment using PredefinedSymbol ("Pi") in the Python code and
740
+ # An experiment using SymbolConstant ("Pi") in the Python code and
730
741
# running:
731
742
# {Pi, Unprotect[Pi];Pi=4; Pi, Pi=.; Pi }
732
743
# show that this does not change the output in any way.
@@ -736,9 +747,9 @@ def symbol_set(*symbols: Tuple[Symbol]) -> FrozenSet[Symbol]:
736
747
# more of the below and in systemsymbols
737
748
# PredefineSymbol.
738
749
739
- SymbolFalse = PredefinedSymbol ("System`False" , value = False )
740
- SymbolList = PredefinedSymbol ("System`List" , value = list )
741
- SymbolTrue = PredefinedSymbol ("System`True" , value = True )
750
+ SymbolFalse = SymbolConstant ("System`False" , value = False )
751
+ SymbolList = SymbolConstant ("System`List" , value = list )
752
+ SymbolTrue = SymbolConstant ("System`True" , value = True )
742
753
743
754
SymbolAbs = Symbol ("Abs" )
744
755
SymbolDivide = Symbol ("Divide" )
0 commit comments