grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
124 stars 24 forks source link

leading spaces in OpenMath parser #297

Closed grzegorzmazur closed 4 years ago

grzegorzmazur commented 4 years ago

When converting strings from OpenMath to Yacas, the spaces should be kept. Please consider this example:

OpenMathStringOfSpaces := " " FromString( % )OMRead() OpenMathStringWithLeadingSpaces := " a " FromString( % )OMRead()

In the first case, the empty string is returned instead of the original one, and in the second case the leading spaces are lost.

In> OpenMathStringOfSpaces := " " Out> " " In> FromString( % )OMRead() Out> "" In> OpenMathStringWithLeadingSpaces := " a " Out> " a " In> FromString( % )OMRead() Out> "a " In>

About this, please consider what is said in http://www.catb.org/~esr/writings/taoup/html/ch01s06.html , which is especially relevant for OpenMath, which is intended to be used by computers:

For robustness, designing in tolerance for unusual or extremely bulky inputs is also important. Bearing in mind the Rule of Composition helps; input generated by other programs is notorious for stress-testing software (e.g., the original Unix C compiler reportedly needed small upgrades to cope well with Yacc output). The forms involved often seem useless to humans. For example, accepting empty lists/strings/etc., even in places where a human would seldom or never supply an empty string, avoids having to special-case such situations when generating the input mechanically. -- Henry Spencer One very important tactic for being robust under odd inputs is to avoid having special cases in your code. Bugs often lurk in the code for handling special cases, and in the interactions among parts of the code intended to handle different special cases.