Project

General

Profile

Design #1538

RingElem from string (ReadExpr)

Added by John Abbott over 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Various
Target version:
Start date:
13 Nov 2020
Due date:
% Done:

100%

Estimated time:
1.61 h
Spent time:

Description

What should the following do

RingElem(QQ, "1/-2");

Currently it gives error "unexpected minus".


Related issues

Related to CoCoALib - Design #1529: INPUT questionsClosed2020-10-31

Related to CoCoA-5 - Bug #1537: EmacUI: strange colours, sometimesClosed2020-11-13

Related to CoCoA-5 - Design #1540: Double powerClosed2020-11-16

Related to CoCoALib - Bug #1579: Readexpr/RingElem: unhelpful error message when input is wrongClosed2021-02-23

Related to CoCoALib - Slug #1518: SLUG: Printing PPs with many indetsIn Progress2020-10-23

History

#1 Updated by John Abbott over 3 years ago

#2 Updated by John Abbott over 3 years ago

Similar problem for RingElem(QQ, "2*-3");

#3 Updated by John Abbott over 3 years ago

My personal opinion is that I do not like 1/-2 and 2*-3; they both look like typos to me. Perhaps the user meant 1/x-2 or 2*x-3?
In contrast, with brackets I find it easier to read, and less likely that the user made a typo.

#4 Updated by John Abbott over 3 years ago

  • Related to Bug #1537: EmacUI: strange colours, sometimes added

#5 Updated by John Abbott over 3 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

The input functions are quite messy: not really a coherent design philosophy.

It seems that ReadExpr gives error if there are extra chars after the end of the expr, but ReadExprSemicolon does not complain if there are extra chars after the semicolon.
At the moment my expectation is that a fn which accepts a stream would read the next item on the stream, and leave the input pointer at the first char after the read value.
If the caller wants to ensure that there is nothing else in the stream then this must be written explicitly in the caller's code.

With this design ReadExprSemicolon becomes even simpler to implement.

Maybe there could be ReadJust1Expr which behaves as ReadExpr currently does?

#6 Updated by John Abbott over 3 years ago

#7 Updated by John Abbott about 3 years ago

  • Status changed from In Progress to Resolved
  • Assignee set to John Abbott
  • % Done changed from 10 to 70
I have just checked what the code does (or seems like it should do).
The current impl is:
  • reading from istream keeps going until an "impossible" char is found; error if expr up to that point is incomplete, o/w no error & remaining chars are ready for further input operations
  • reading from string expects the string to contain exactly the right input: trailing non-whitespace chars will trigger an error

#8 Updated by John Abbott about 3 years ago

  • % Done changed from 70 to 80

I have changed the CoCoA-5 parser so that it produces a warning when given input such as 2*-1 or 3/-1. The computation still works, but the warning recomments putting the 2nd arg inside brackets. Also 2*+1 and 3/+1 produce the same warning.

An impromptu test suggests that all works as desired.

#9 Updated by John Abbott about 3 years ago

Should we attempt to produce a better error message for the example given in the original description?
Is it worth it? Is that a good use of our limited resources?

#10 Updated by John Abbott about 3 years ago

  • Related to Bug #1579: Readexpr/RingElem: unhelpful error message when input is wrong added

#11 Updated by John Abbott over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 80 to 100
  • Estimated time set to 1.61 h

#12 Updated by Anna Maria Bigatti 12 months ago

  • Related to Slug #1518: SLUG: Printing PPs with many indets added

Also available in: Atom PDF