Project

General

Profile

Design #668

Remove keyword "weights"?

Added by Anna Maria Bigatti about 9 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
Parser/Interpreter
Start date:
05 Mar 2015
Due date:
% Done:

100%

Estimated time:
4.01 h
Spent time:

Description

In CoCoA-4 "Weights" was used to set weights in a polynomial ring construction.
Now weights are dealt with in a completely different matter (see manual for NewPolyRing), and it is unlikely that the keyword will be used again.
Should we remove it?


Related issues

Related to CoCoA-5 - Feature #673: Error message: I was expecting...Closed2015-03-11

History

#1 Updated by Anna Maria Bigatti about 9 years ago

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

The problem arose when Claudia Fassino worked with PreprocessPoint, and had trouble getting the value of P.weights, this happened because "weight" is a protecetd keyword (even though unused).

Such record field cannot be created in CoCoA-5, but can be created in BuiltinFunctions.C.
In any case it cannot be accessed in any way, not even P["weights"].
(well, I did find an ugly workaround, so ugly I'm not writing it here ;-)

#2 Updated by Anna Maria Bigatti about 9 years ago

The involved lines are:

Lexer.C:391:            Keyword("Weights", TT_WEIGHTS),
Parser.C:178:    case TT_WEIGHTS: return "\"Weights\"";
Parser.C:1465:                case TT_WEIGHTS:

#3 Updated by John Abbott about 9 years ago

This is trickier than I originally thought.

The way the CoCoA-5 interpreter is designed a keyword is always seen as that keyword even it would make no sense in that context. Many computer languages work this way (FORTRAN is the only exception I know of), so it is probably a good idea.

In principle we could allow records to contain fields whose names are CoCoA-5 keywords; indeed PreprocessPoints does exactly that. Modifying the indexing function would not be hard: we could make rec["weights"] work as expected; it would be harder to make rec.weights work as expected since that would break the rule of a keyword always being seen as a keyword. However, if we were to do that then a printed record containing a field with name weights could not be cut-and-pasted as input -- for that to work we would have to modify parsing of a record which looks to be rather tricky (and would further break the rule about a keyword always being seen as a keyword).

Nevertheless I do find it unnatural/inconvenient that fields in a record are "arbitrarily" forbidden from having certain names.

I suppose the cleanest solution is to stick with the rule that keywords can never be used as identifiers in any context. It has the advantage that it is fairly easy to remember (assuming you have a list of keywords available), and very easy to implement (no need to change the existing code).

I note that the same limitation applies to tags in tagged values; this is probably unnecessary as a tag only ever appears as a string (right?).

I shall try to improve the error message when executing rec["weights"] which is unhelpful in its current form.

#4 Updated by John Abbott about 9 years ago

I should also modify RECORD::setField so that it gives an error if the field name is not a valid identifier for CoCoA-5. This ought to be easy.

Hint: Interpreter.C:2276--2288

Fixing the error messages, as suggested in my previous post, looks to be rather trickier than I had hoped :-(

#5 Updated by John Abbott about 9 years ago

  • % Done changed from 20 to 30
After speaking to Anna by Skype we have decided:
  • Anna will remove the keyword weights (from interpreter and UIs)
  • John will attempt to complete the revision of error messages

#6 Updated by John Abbott about 9 years ago

In Interpreter.H:718 the mem fn setField is declared as virtual; why??

#7 Updated by John Abbott about 9 years ago

  • % Done changed from 30 to 50

At the moment I have implemented setField and setFieldNoCheck; the latter is just the old fn renamed. The new fn needs source code location info in case an error occurs.

I have changed Interpreter.C, BuiltinFunctions.C and BuiltinFunctions-Normaliz.C but found I was undecided whether to call setField or setFieldNoCheck. In the end I used the simple rule: if the field name was a string literal then I called setFieldNoCheck, otherwise I called setField (so the field name would be checked at run time).

I'm not sure this is the most sensible strategy -- it was quick to effect :-)

#8 Updated by John Abbott about 9 years ago

It works... more or less. A["weights"] gives the error I wanted, but A.weights still gives a less helpful error. To rectify this requires changing Parser.H:158; perhaps I'll add a new issue for this as it will probably take some time to do.

#9 Updated by John Abbott almost 9 years ago

  • Target version changed from CoCoA-5.?.? to CoCoA-5.1.2 summer 2015

#10 Updated by Anna Maria Bigatti almost 9 years ago

  • Status changed from In Progress to Feedback
  • % Done changed from 50 to 90

seems effectively done: close this issue?

#11 Updated by Anna Maria Bigatti over 8 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100
  • Estimated time set to 4.01 h

Also available in: Atom PDF