@@ -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,49 @@ 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
+ Also, Pi *can* be Unprotected and changed, while True, cannot.
656
+
657
+ Also note that ``SymbolConstant`` differs from ``Symbol`` in that
658
+ Symbol has no value field (even when its value happens to be
659
+ representable in Python. Symbols need to go through Definitions
660
+ get a Symbol's current value, based on the current context and the
661
+ state of prior operations on that Symbol/Definition binding.
662
+
663
+ In sum, SymbolConstant is partly like Symbol, and partly like
664
+ Numeric constants.
653
665
"""
654
666
655
- # Dictionary of PredefinedSymbols defined so far.
667
+ # Dictionary of SymbolConstants defined so far.
656
668
# We use this for object uniqueness.
657
- # The key is the PredefinedSymbol object 's name , and the
669
+ # The key is the SymbolConstant 's value , and the
658
670
# diectionary's value is the Mathics object representing that Python value.
659
- _predefined_symbols = {}
671
+ _symbol_constants = {}
660
672
661
673
# We use __new__ here to unsure that two Integer's that have the same value
662
674
# return the same object.
663
675
def __new__ (cls , name , value ):
664
676
665
677
name = ensure_context (name )
666
- self = cls ._predefined_symbols .get (name )
678
+ self = cls ._symbol_constants .get (name )
667
679
if self is None :
668
680
self = super ().__new__ (cls , name )
669
681
self ._value = value
670
682
671
683
# Cache object so we don't allocate again.
672
- self ._predefined_symbols [name ] = self
684
+ self ._symbol_constants [name ] = self
673
685
674
686
# Set a value for self.__hash__() once so that every time
675
687
# it is used this is fast. Note that in contrast to the
@@ -723,10 +735,10 @@ def symbol_set(*symbols: Tuple[Symbol]) -> FrozenSet[Symbol]:
723
735
724
736
# Symbols used in this module.
725
737
726
- # Note, below we are only setting PredefinedSymbol for Symbols which
738
+ # Note, below we are only setting SymbolConstant for Symbols which
727
739
# are both predefined and have the Locked attribute.
728
740
729
- # An experiment using PredefinedSymbol ("Pi") in the Python code and
741
+ # An experiment using SymbolConstant ("Pi") in the Python code and
730
742
# running:
731
743
# {Pi, Unprotect[Pi];Pi=4; Pi, Pi=.; Pi }
732
744
# show that this does not change the output in any way.
@@ -736,9 +748,9 @@ def symbol_set(*symbols: Tuple[Symbol]) -> FrozenSet[Symbol]:
736
748
# more of the below and in systemsymbols
737
749
# PredefineSymbol.
738
750
739
- SymbolFalse = PredefinedSymbol ("System`False" , value = False )
740
- SymbolList = PredefinedSymbol ("System`List" , value = list )
741
- SymbolTrue = PredefinedSymbol ("System`True" , value = True )
751
+ SymbolFalse = SymbolConstant ("System`False" , value = False )
752
+ SymbolList = SymbolConstant ("System`List" , value = list )
753
+ SymbolTrue = SymbolConstant ("System`True" , value = True )
742
754
743
755
SymbolAbs = Symbol ("Abs" )
744
756
SymbolDivide = Symbol ("Divide" )
0 commit comments