Re: [fricas-devel] Use symbols instead of strings in fmt.spad

2024-05-13 Thread Waldek Hebisch
On Mon, May 13, 2024 at 05:58:01PM +0200, Ralf Hemmecke wrote:
> On 5/12/24 16:01, Waldek Hebisch wrote:
> > OutputForm was designed so that operators are Symbol-s and
> > dealing with operators should use opearations from Symbol.
> > fmt.spad essentially treated operators as strings (they were
> > immediately converted to strings and resto of code used
> > string operations).  The attached patch replaces strings
> > by symbols, alt least in places that I found.
> 
> I do not see any bug/problem in my formatting framework.
> 
> The only thing that is needed from OutputForm is the string representation
> of the operator (and its semantics). It's just a matter of taste whether the
> interface uses String or Symbol. I have chosen String.

It is not only matter of taste.  Symbol is preferable for control
functions, String for pure data.  Operators in OutputForm are
part of control, that is why they are Symbol.  The patch is not
changes places where String-s are just data, those places are
fine and using Symbol there would be wrong.

I am not aware of bugs in formatting framework.  However, using
String in places where Symbol is more appriopriate is a problem.
In particular using String instead of Symbol led to bugs or
inefficiences in other parts of FriCAS.

> I do not like the usage of ' in a .spad file.
> The patch introduces the need for ::Symbol for the third parameter in
> setOperatorHandler!, i.e. makes it less user friendly.

Well, ' works.  And only operators defined in OutputForm make sense
for third parameter to 'setOperatorHandler!', so not being able
to pass a String will help in getting working code.

> I see no benefit of that patch and thus I am strongly against it.

Benefit is mainly to have formatting framework as an example of
good programming style.  As I wrote, confusion between Symbol
and String led to real troubles in the past, so IMO good example
should be careful there.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZkJLGmMGOBm-jxne%40fricas.org.


Re: [fricas-devel] Use symbols instead of strings in fmt.spad

2024-05-13 Thread Ralf Hemmecke

On 5/12/24 16:01, Waldek Hebisch wrote:

OutputForm was designed so that operators are Symbol-s and
dealing with operators should use opearations from Symbol.
fmt.spad essentially treated operators as strings (they were
immediately converted to strings and resto of code used
string operations).  The attached patch replaces strings
by symbols, alt least in places that I found.


I do not see any bug/problem in my formatting framework.

The only thing that is needed from OutputForm is the string 
representation of the operator (and its semantics). It's just a matter 
of taste whether the interface uses String or Symbol. I have chosen String.


I do not like the usage of ' in a .spad file.
The patch introduces the need for ::Symbol for the third parameter in 
setOperatorHandler!, i.e. makes it less user friendly.


I see no benefit of that patch and thus I am strongly against it.

Ralf

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/5ff5b4b9-3dab-43d0-a835-abd961fda92b%40hemmecke.org.


[fricas-devel] Use symbols instead of strings in fmt.spad

2024-05-12 Thread Waldek Hebisch
OutputForm was designed so that operators are Symbol-s and
dealing with operators should use opearations from Symbol.
fmt.spad essentially treated operators as strings (they were
immediately converted to strings and resto of code used
string operations).  The attached patch replaces strings
by symbols, alt least in places that I found.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZkDL0Mt9aAzI5Myl%40fricas.org.
diff --git a/src/algebra/fmt.spad b/src/algebra/fmt.spad
index 25db609f..937cc88f 100644
--- a/src/algebra/fmt.spad
+++ b/src/algebra/fmt.spad
@@ -325,7 +325,7 @@ OutputBox : Exports == Implementation where
 ++ the name of that operator.
 OperatorHandlers(HANDLER: Type): Exports == Implementation where
   Z ==> Integer
-  S ==> String
+  S ==> Symbol
   Exports == with
 new: () -> %
   ++ \spad{new()} creates an empty structure of handlers.
@@ -419,6 +419,7 @@ FormatterCategory: Category == Exports where
   Z   ==> Integer
   N   ==> NonNegativeInteger
   S   ==> String
+  Sy  ==> Symbol
   LE  ==> List E
   BOX ==> OutputBox
   LBOX ==> S -> BOX -- Label box for prologue and epilogue
@@ -1330,8 +1331,8 @@ of a \spad{ROW} operator without the wrapping \spad{MATRIX} operator.
 opex: E := operator a2
 not symbol? opex => -1 -- error "second argument no symbol"
 
-o2 := string symbol opex
-o2 ~= "PAREN" => -1 -- error "second argument no PAREN"
+o2 := symbol(opex)
+o2 ~= 'PAREN => -1 -- error "second argument no PAREN"
 
 #(aa2 := arguments a2) > 1 => -1 -- error "second argument too long"
 
@@ -1375,8 +1376,8 @@ of a \spad{ROW} operator without the wrapping \spad{MATRIX} operator.
 formatInteger(n: Z): BOX == box convert n
 formatFloat(s: String): BOX == box s
 formatString(s: S): BOX == box s
-formatSymbol(s: S): BOX == box s
-formatFunctionSymbol(s: S): BOX == box s
+formatSymbol(s : S): BOX == box(s)
+formatFunctionSymbol(s: S): BOX == box(s)
 formatFunction(b: BOX, args: LE): BOX ==
 m: Z := minPrecedence()
 a: BOX := nary(", ", maxPrecedence(), formatExpression m)(m, args)
@@ -1398,10 +1399,10 @@ of a \spad{ROW} operator without the wrapping \spad{MATRIX} operator.
 not symbol? expr => box "[[BAD OUTPUTFORM]]"
 -- We've got a symbol here.
 -- We are in the nullary case.
-str: S := string symbol expr
-knownHandler?(operatorData, 0, str) =>
-handler(operatorData, 0, str)(prec, empty()$LE)
-formatSymbol str
+sy : Sy := symbol expr
+knownHandler?(operatorData, 0, sy) =>
+handler(operatorData, 0, sy)(prec, empty()$LE)
+formatSymbol(string(sy))
 
 -- now we take apart a list
 opex: E := operator expr
@@ -1410,7 +1411,7 @@ of a \spad{ROW} operator without the wrapping \spad{MATRIX} operator.
 formatFunction(formatExpression(opex, minPrecedence()), args)
 
 nargs: Z := #args
-op: S := string symbol opex
+op : Sy := symbol(opex)
 
 knownHandler?(operatorData, nargs, op) =>
 handler(operatorData, nargs, op)(prec, args)
@@ -1421,7 +1422,7 @@ of a \spad{ROW} operator without the wrapping \spad{MATRIX} operator.
 
 -- We format as a function with function name op and argument
 -- give by args.
-formatFunction(formatFunctionSymbol op, args)
+formatFunction(formatFunctionSymbol(string(op)), args)
 
 formatExpression(expr: E): BOX == formatExpression(expr, minPrecedence())
 
diff --git a/src/algebra/fmt1d.spad b/src/algebra/fmt1d.spad
index d0a1c17d..140e730a 100644
--- a/src/algebra/fmt1d.spad
+++ b/src/algebra/fmt1d.spad
@@ -371,7 +371,7 @@ data structure.
 PAREN p ==> bracket("(", ")", FE p)
 PAREN2(p1, p2) ==> bracket("(", ")", infix(", ", MAX, FE MIN, FE MIN))
 
-o(n, op, hdl) ==> setHandler!(oh, n, op, hdl)
+o(n, op, hdl) ==> setHandler!(oh, n, op::Symbol, hdl)
 
 o(0, "NOTHING", nothing())
 o(0, "%pi", formatConstant "%pi")
diff --git a/src/algebra/fmt2d.spad b/src/algebra/fmt2d.spad
index 72102380..2f4ac719 100644
--- a/src/algebra/fmt2d.spad
+++ b/src/algebra/fmt2d.spad
@@ -453,7 +453,7 @@ data structure.
 PAREN p ==> bracket("(", ")", FE p)
 PAREN2(p1, p2) ==> bracket("(", ")", infix(", ", MAX, FE MIN, FE MIN))
 
-o(n, op, hdl) ==> setHandler!(oh, n, op, hdl)
+o(n, op, hdl) ==> setHandler!(oh, n, op::Symbol, hdl)
 
 o(0, "NOTHING", nothing())
 o(0, "%pi", formatConstant "%pi")
diff --git a/src/al