Project

General

Profile

Bug #444

Not keyword/operator

Added by John Abbott about 10 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Immediate
Assignee:
Category:
Cleaning
Target version:
Start date:
19 Feb 2014
Due date:
% Done:

100%

Estimated time:
3.50 h
Spent time:

Description

The Not operator behaves differently from C4.

In C4 you could write If Not 1 IsIn I Then ...

In C5 this is interpreted as If Not(1) IsIn I Then ...
which gives a run-time error saying that 1 is not a boolean!

Is this a bug?


Related issues

Related to CoCoA-5 - Support #488: CoCoAManual: Help page for porting old C4 code to C5Closed2014-03-21

History

#1 Updated by John Abbott about 10 years ago

  • Target version set to CoCoA-5.0.9

I have just grepped through the C5 packages and there are several places where the operator Not is incorrectly applied!

I'm now wondering whether it might not be better to eliminate it as a keyword, and just define a function instead (requiring use of brackets whenever it is called). Such a change would make some uses uglier: If Not(IsInteger(arg))

Since we are using it incorrectly, it does seem like poor design...well, I suppose our minds have been "polluted" by C4 language :-)

If we want to keep a "logical negation" operator, maybe there's a better syntax?

#2 Updated by Anna Maria Bigatti about 10 years ago

John Abbott wrote:

I have just grepped through the C5 packages and there are several places where the operator Not is incorrectly applied!

how embarrassing...

I'm now wondering whether it might not be better to eliminate it as a keyword, and just define a function instead (requiring use of brackets whenever it is called). Such a change would make some uses uglier: If Not(IsInteger(arg))

uglier but clearer... I like it. I think I tend to write If (Not IsInteger(arg)) anyway.

#3 Updated by John Abbott about 10 years ago

I've just noticed a real howler in hilop.cpkg5

Define ListOfRingElems(L, R)
  Return Not False IsIn [RingEnv(E) = R | E In L];
EndDefine;

The critical line will not produce a run-time error (or warning); it is interpreted as:

Define ListOfRingElems(L, R)
  Return True IsIn [RingEnv(E) = R | E In L];
EndDefine;

which is very different from the original programmer's intention, I imagine!

#4 Updated by John Abbott about 10 years ago

  • Priority changed from Normal to Immediate
  • % Done changed from 0 to 10

A moment's refection about the above howler has put me in panic mode; how come anything works in CoCoA-5???

Should there be a new operator IsNotIn? Well, perhaps this should be decided after looking at the current C5 packages

#5 Updated by Anna Maria Bigatti about 10 years ago

John Abbott wrote:

I've just noticed a real howler in hilop.cpkg5
[...]
which is very different from the original programmer's intention, I imagine!

Ouch. Anyway that function is not called and should be quickly removed without any further publicity ;-)
Should I do it?

#6 Updated by John Abbott about 10 years ago

  • % Done changed from 10 to 20

There seems to be no doubt that the current Not operator is problematic: even we, the C5 designers, find it "dangerous". So we should work towards its replacement by a true function (built-in for speed).

Step 1: edit all cpkg5 files so that Not is applied as if it were a function (this should not break any code); also replace Not by not.
Step 2: implement built-in fn called not, and remove the keyword Not (this should not break any code)
Step 3: revise the CoCoA manual

#7 Updated by John Abbott about 10 years ago

Stage 1 done. About to check in!

#8 Updated by John Abbott about 10 years ago

  • % Done changed from 20 to 40

Done stage 2. All C5 tests pass. Checked in.

NB old code for Not operator has only been commented out for now.
I'll delete it shortly (if I remember).

#9 Updated by John Abbott about 10 years ago

  • % Done changed from 40 to 50

Old code has been deleted (not yet CVSed though). All still works.

ANNA will fix the manual; perhaps separate man page for not,and,or into two pages?

#10 Updated by John Abbott about 10 years ago

  • Category set to Cleaning
  • Status changed from New to Feedback
  • Assignee set to John Abbott
  • % Done changed from 50 to 90

JAA has revised the manual page for the logical operators.

#11 Updated by John Abbott about 10 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

No problems have arisen in 2 weeks, so I'm closing this issue.

#12 Updated by Anna Maria Bigatti about 10 years ago

(a problem has arisen ;-)
added Not, NOT in BackwardCompatible

#13 Updated by Anna Maria Bigatti almost 10 years ago

  • Estimated time set to 3.50 h

Also available in: Atom PDF