Project

General

Profile

Feature #1541

foreach with ref to list entry?

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

Status:
New
Priority:
Normal
Assignee:
-
Category:
CoCoA-5 function: new
Target version:
Start date:
01 Dec 2020
Due date:
% Done:

0%

Estimated time:
Spent time:

Description

Julian Danner asks whether it would be possible to have a version of foreach which operates on a reference to the list entry.

Currently this does not change L

L := [1,2,3];
foreach X in L do
  if X > 2 then X := 0; endif;
endforeach;

The actual implementation was a list of RECORDs where it made sense to update a field of some of the records.

History

#1 Updated by John Abbott over 3 years ago

If we choose to extend CoCoA-5, there are 2 obvious approaches:
  • modify foreach so that it uses references --- obviously not backward compatible!
  • make a new loop command (e.g. foreachref) --- obviously entails modifying the interpreter significantly

At the moment I am undecided whether the proposal is a good idea. The man page for foreach should make it clear that entries in the original list cannot be modified by changing the value of the loop variable. I have made a first, simple change to the man page.

#2 Updated by John Abbott 3 months ago

Postponing this issue because it requires discussion, and could be tricky/lengthy if we opt to to make the change.
I have made a further minor improvement to the documentation for foreach.

Also available in: Atom PDF