Skip to content

Commit

Permalink
More formatting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jan 9, 2018
1 parent 949dd6e commit 0489bb1
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
8 changes: 4 additions & 4 deletions expreduce/builtin_comparison.go
Expand Up @@ -54,7 +54,7 @@ func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Equal",
toString: func(this *Expression, params ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " == ", "", true, "", "", params)
return ToStringInfixAdvanced(this.Parts[1:], " == ", "System`Equal", false, "", "", params)
},
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
if len(this.Parts) < 1 {
Expand All @@ -78,7 +78,7 @@ func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "Unequal",
toString: func(this *Expression, params ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " != ", "", true, "", "", params)
return ToStringInfixAdvanced(this.Parts[1:], " != ", "System`Unequal", false, "", "", params)
},
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
if len(this.Parts) != 3 {
Expand All @@ -100,7 +100,7 @@ func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "SameQ",
toString: func(this *Expression, params ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " === ", "", true, "", "", params)
return ToStringInfixAdvanced(this.Parts[1:], " === ", "System`SameQ", false, "", "", params)
},
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
if len(this.Parts) < 1 {
Expand All @@ -121,7 +121,7 @@ func getComparisonDefinitions() (defs []Definition) {
defs = append(defs, Definition{
Name: "UnsameQ",
toString: func(this *Expression, params ToStringParams) (bool, string) {
return ToStringInfixAdvanced(this.Parts[1:], " =!= ", "", true, "", "", params)
return ToStringInfixAdvanced(this.Parts[1:], " =!= ", "System`UnsameQ", false, "", "", params)
},
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
if len(this.Parts) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion expreduce/builtin_string.go
Expand Up @@ -20,7 +20,7 @@ func GetStringDefinitions() (defs []Definition) {
}

context, contextPath := ActualStringFormArgs(es)
return NewString(this.Parts[1].StringForm(ToStringParams{form: formAsSymbol.Name[7:], context: context, contextPath: contextPath}))
return NewString(this.Parts[1].StringForm(ToStringParams{form: formAsSymbol.Name[7:], context: context, contextPath: contextPath, previousHead: "<TOPLEVEL>"}))
},
})
defs = append(defs, Definition{
Expand Down
4 changes: 2 additions & 2 deletions expreduce/builtin_system.go
Expand Up @@ -377,7 +377,7 @@ func GetSystemDefinitions() (defs []Definition) {
if len(this.Parts) != 3 {
return false, ""
}
return ToStringInfixAdvanced(this.Parts[1:], " = ", "", true, "(", ")", params)
return ToStringInfixAdvanced(this.Parts[1:], " = ", "System`Set", false, "(", ")", params)
},
Bootstrap: true,
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
Expand Down Expand Up @@ -425,7 +425,7 @@ func GetSystemDefinitions() (defs []Definition) {
if len(this.Parts) != 3 {
return false, ""
}
return ToStringInfixAdvanced(this.Parts[1:], " := ", "", true, "(", ")", params)
return ToStringInfixAdvanced(this.Parts[1:], " := ", "System`SetDelayed", false, "", "", params)
},
Bootstrap: true,
legacyEvalFn: func(this *Expression, es *EvalState) Ex {
Expand Down
4 changes: 2 additions & 2 deletions expreduce/interp_test.go
Expand Up @@ -67,6 +67,6 @@ func TestInterp(t *testing.T) {
// Test newline handling
assert.Equal(t, "CompoundExpression[a, b]", Interp("a;b\n", es).String())
//assert.Equal(t, "Sequence[a, b]", Interp("a\nb\n", es).String())
assert.Equal(t, "(c) = ((a*b))", Interp("c = (a\nb)\n", es).String())
assert.Equal(t, "(c) = ((a*b))", Interp("c = (a\n\nb)\n", es).String())
assert.Equal(t, "((c = a*b))", Interp("c = (a\nb)\n", es).String())
assert.Equal(t, "((c = a*b))", Interp("c = (a\n\nb)\n", es).String())
}
12 changes: 6 additions & 6 deletions expreduce/resources.go

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions expreduce/resources/comparison.m
Expand Up @@ -21,7 +21,7 @@
EComment["Expressions known to be equal will evaluate to True:"],
EStringTest["True", "9*x==x*9"],
EComment["Sometimes expressions may or may not be equal, or Expreduce does not know how to test for equality. In these cases, the statement will remain unevaluated:"],
EStringTest["((9*x)) == ((10*x))", "9*x==x*10"],
EStringTest["(9*x == 10*x)", "9*x==x*10"],
EComment["Equal considers Integers and Reals that are close enough to be equal:"],
EStringTest["5", "tmp=5"],
EStringTest["True", "tmp==5"],
Expand All @@ -42,33 +42,33 @@
EStringTest["True", "5==tmp"],
EStringTest["False", "tmp==6"],
EStringTest["False", "6==tmp"],
EStringTest["(a) == (b)", "a==b"],
EStringTest["(a == b)", "a==b"],
EStringTest["True", "a==a"],
EStringTest["(a) == (2)", "a==2"],
EStringTest["(2) == (a)", "2==a"],
EStringTest["(2) == ((a + b))", "2==a+b"],
EStringTest["(2.) == (a)", "2.==a"],
EStringTest["(2^k) == (a)", "2^k==a"],
EStringTest["(2^k) == (2^a)", "2^k==2^a"],
EStringTest["(2^k) == ((2 + k))", "2^k==k+2"],
EStringTest["(k) == ((2*k))", "k==2*k"],
EStringTest["((2*k)) == (k)", "2*k==k"],
EStringTest["(a == 2)", "a==2"],
EStringTest["(2 == a)", "2==a"],
EStringTest["(2 == a + b)", "2==a+b"],
EStringTest["(2. == a)", "2.==a"],
EStringTest["(2^k == a)", "2^k==a"],
EStringTest["(2^k == 2^a)", "2^k==2^a"],
EStringTest["(2^k == 2 + k)", "2^k==k+2"],
EStringTest["(k == 2*k)", "k==2*k"],
EStringTest["(2*k == k)", "2*k==k"],
EStringTest["True", "1+1==2"],
EStringTest["(y) == ((b + m*x))", "y==m*x+b"],
EStringTest["(y == b + m*x)", "y==m*x+b"],
EStringTest["True", "1==1."],
EStringTest["True", "1.==1"],
EStringTest["True", "(x==2)==(x==2)"],
EStringTest["True", "(x==2.)==(x==2)"],
EStringTest["True", "(x===2.)==(x===2)"],
EStringTest["(If[(xx) == (3), yy, zz]) == (If[(xx) == (2), yy, zz])", "If[xx == 3, yy, zz] == If[xx == 2, yy, zz]"],
EStringTest["(If[xx == 3, yy, zz] == If[xx == 2, yy, zz])", "If[xx == 3, yy, zz] == If[xx == 2, yy, zz]"],
EStringTest["True", "(1 == 2) == (2 == 3)"],
EStringTest["False", "(1 == 2) == (2 == 2)"],
ESameTest[True, foo[x == 2, y, x] == foo[x == 2, y, x]],
ESameTest[True, foo[x == 2, y, x] == foo[x == 2., y, x]],
ESameTest[foo[x == 2, y, x] == foo[x == 2., y, y], foo[x == 2, y, x] == foo[x == 2., y, y]],
ESameTest[foo[x == 2, y, x] == bar[x == 2, y, x], foo[x == 2, y, x] == bar[x == 2, y, x]],
EStringTest["(foo[x, y, z]) == (foo[x, y])", "foo[x, y, z] == foo[x, y]"],
EStringTest["(foo[x, y, z]) == (foo[x, y, 1])", "foo[x, y, z] == foo[x, y, 1]"],
EStringTest["(foo[x, y, z] == foo[x, y])", "foo[x, y, z] == foo[x, y]"],
EStringTest["(foo[x, y, z] == foo[x, y, 1])", "foo[x, y, z] == foo[x, y, 1]"],
ESameTest[True, foo[x, y, 1] == foo[x, y, 1]],
ESameTest[True, foo[x, y, 1.] == foo[x, y, 1]],
ESameTest[True, Equal[test]],
Expand All @@ -83,7 +83,7 @@
EComment["Expressions known to be unequal will evaluate to True:"],
EStringTest["True", "9 != 8"],
EComment["Sometimes expressions may or may not be unequal, or Expreduce does not know how to test for inequality. In these cases, the statement will remain unevaluated:"],
EStringTest["((9*x)) != ((10*x))", "9*x != x*10"],
EStringTest["(9*x != 10*x)", "9*x != x*10"],
EComment["Unequal considers Integers and Reals that are close enough to be equal:"],
EStringTest["5", "tmp=5"],
EStringTest["False", "tmp != 5"],
Expand Down
4 changes: 2 additions & 2 deletions expreduce/resources/expression.m
Expand Up @@ -98,8 +98,8 @@
Attributes[HoldForm] = {HoldAll, Protected};
Tests`HoldForm = {
ESimpleExamples[
EStringTest["5^3", "HoldForm[Power[5, 3]]"],
EStringTest["5.^3.", "HoldForm[Power[5., 3.]]"]
EStringTest["(5^3)", "HoldForm[Power[5, 3]]"],
EStringTest["(5.^3.)", "HoldForm[Power[5., 3.]]"]
]
};

Expand Down
2 changes: 1 addition & 1 deletion expreduce/resources/string.m
Expand Up @@ -34,7 +34,7 @@
Attributes[Infix] = {Protected};
Tests`Infix = {
ESimpleExamples[
ESameTest["(bar|fuzz|zip)", Infix[foo[Global`bar, Global`fuzz, Global`zip], "|"] // ToString]
ESameTest["bar|fuzz|zip", Infix[foo[Global`bar, Global`fuzz, Global`zip], "|"] // ToString]
]
};

Expand Down
7 changes: 7 additions & 0 deletions expreduce/string.go
Expand Up @@ -78,6 +78,10 @@ func ToStringInfixAdvanced(parts []Ex, delim string, thisHead string, surroundEa
return false, ""
}
var buffer bytes.Buffer
addParens := needsParens(thisHead, params.previousHead)
if addParens {
buffer.WriteString("(")
}
if !surroundEachArg {
buffer.WriteString(start)
}
Expand All @@ -102,6 +106,9 @@ func ToStringInfixAdvanced(parts []Ex, delim string, thisHead string, surroundEa
if !surroundEachArg {
buffer.WriteString(end)
}
if addParens {
buffer.WriteString(")")
}
return true, buffer.String()
}

Expand Down

0 comments on commit 0489bb1

Please sign in to comment.