Unevaluated
In #58 I tried to fix this issue:
In WMA
In[1]:= F[a, Unevaluated[a]]
Out[1]:=F[a, Unevaluated[a]]
In Mathics
In[1]:= F[a, Unevaluated[a]]
Out[1]:=F[Unevaluated[a], Unevaluated[a]]
This happens because as now Symbols are singletons, the old mechanism of setting a property does not work anymore. In #58, I tried to fix this using a table. However, this does not work in general, if F has the attributes Orderless or Flat, because the order is lost.
This feels more of the kind of confusion we've been having. A Lisp or WL Symbol is unique. In other words the name "a" is unique. What is meant by a in the expression Unevaluated[a] is a symbolic variable (or maybe "symbolic value") whose name is Lisp/WL Symbol a. Note that the a in Unevaluated[a] is no different than the a in a + 5. Both are expressions. The difference is that Unevaluated has a property that indicates for any variable just use its name.
Often people shorten "symbolic variable" to "symbol".
Possibly Mathics' Symbol class should be renamed to Variable or maybe SymbolicValue which consists of a name ("Symbol") and a binding value ("Definition"?) or a indication that the binding is "unbound" . And in the process, a new Symbol class should be added that matches Lisp/WL Symbol in that stricter narrower definition.
Unfortunately the name "Symbol" has been used to mean both the a Symbol name (but SymbolName is another WL function) as well as a symbolic variable/value. Variables can be unbound, or bound. Variables also have a scope attached to them.
@rocky, in WL there are no "symbolic variables" (in the sense of something that has at some point a value), just Symbols, and lists of rules (organized as Definitions) associated with the symbols.
https://www.ibm.com/docs/en/zos/2.3.0?topic=variables-what-is-symbolic-variable https://www.mathworks.com/matlabcentral/answers/320690-what-are-symbolic-variables
@mmatera By "symbolic variable" I mean unbound variable.
An unbound symbol is what Lisp calls a Symbol. And saying a Symbol is unbound implies that a Symbol can be bound. I suspect that this is the missing concept, variable binding, in Mathics.
In WMA, bindings are given through the ownvalues associated with the symbol.
Is it possible in LISP to set something like
In[1]:=a:=1/;x>0;
In[2]:=a:= 0;
In[3]:=a
In[4]:=0
Out[4]=0
In[5]:= x=1; a
Out[5]=1
In that case, how this would work here using that concept?
the getter function for variable "a" would be a lambda function that returns 1 if x is greater than 0.
Is this how #628 works?
Nop. It was just to narrow the idea about what would be here a "bounded variable". #628 avoids to monkey patch a symbol by changing the expression Unevaluated[symb] by a wrapper surrounding symb, which produces the right behavior under sort and flat. I can add a more detailed explanation about how the wrapper works, or add more examples/tests.
Otherwise, just keep this here as a draft, like several other PRs, until we have a clearer picture, and then check against the tests a fix from another approach. The effort here was put in localizing the change just in the method we need to fix in order to get the right behaviour.
Yes, let's keep this as a draft.