Project

General

Profile

Design #364

Incr command/function

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

Status:
Closed
Priority:
Normal
Assignee:
Category:
Parser/Interpreter
Target version:
Start date:
03 Jun 2013
Due date:
% Done:

100%

Estimated time:
1.00 h
Spent time:

Description

I would like to have a command for incrementing a counter; and probably another for decrementing.

So instead of writing

IterCounter := IterCounter+1;

one could simply write
incr IterCounter;

What names should the commands have? incr and decr, or maybe increment and decrement.

The command could insist that the value to be incremented is an integer (o/w error).

The following CoCoA fn could achieve most of what I have in mind:

Define incr(ref N)
  If Type(N) <> INT Then error("incr: value  must be integer"); EndIf;
  N := N+1;
EndDefine;

Maybe we should add the function (secretly?); and consider adding a command only if the function proves to be too slow?

Comments? Opinions?


Related issues

Related to CoCoA-5 - Feature #504: New operators: += -= *= /=In Progress2014-04-02

Related to CoCoA-5 - Feature #518: incr/decr functions: to be used in packagesClosed2014-04-03

Related to CoCoA-5 - Slug #1275: incr and decr are slowNew2019-04-29

History

#1 Updated by Anna Maria Bigatti almost 11 years ago

  • Category set to Parser/Interpreter
  • Target version set to CoCoA-5.1.0 Easter14

#2 Updated by John Abbott about 10 years ago

  • Status changed from New to Resolved
  • Assignee set to John Abbott
  • Target version changed from CoCoA-5.1.0 Easter14 to CoCoA-5.0.9
  • % Done changed from 0 to 50

Placing defns of incr and decr in NotBuiltin.
JAA will add doc.

#3 Updated by John Abbott about 10 years ago

  • Status changed from Resolved to Feedback
  • % Done changed from 50 to 90

Written documentation.

The only negative aspect is that the user must write ref before the arg;
if we define commands then ref will no longer be needed.

#4 Updated by John Abbott about 10 years ago

Using fgrep "+1;" *.cpkg5 produced about 30 lines which could be modified to use incr or decr.

Let's try in one file, and compare before and after to see what we think.
[not now, it's too late!]

#5 Updated by Anna Maria Bigatti about 10 years ago

  • Subject changed from Incr command to Incr command/function

#6 Updated by Anna Maria Bigatti about 10 years ago

  • Estimated time set to 1.00 h

#7 Updated by Anna Maria Bigatti about 10 years ago

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

John Abbott wrote:

Using fgrep "+1;" *.cpkg5 produced about 30 lines which could be modified to use incr or decr.

Let's try in one file, and compare before and after to see what we think.
[not now, it's too late!]

Made new issue #518 for applying incr in packages.
Closing this one for 5.0.9

#8 Updated by John Abbott almost 5 years ago

  • Related to Slug #1275: incr and decr are slow added

Also available in: Atom PDF