%mathpiper,def="",public="todo"

/*
 * TODO This was an experiment to try to get to using a new ForEach that works the
 * same on lists and arrays. For some odd reason all sorts of places in the scripts
 * break if we use this version of ForEach. We need to look into this still! I want
 * a ForEach that works on lists as well as arrays.

Macro()(ForEachRest(i,L,B));

LocalSymbols(foreachtail)
[
  10 # ForEachRest(_i,L_IsFunction,_B) <--
  [
    Local(foreachtail);
    Local(@i);
    Bind(foreachtail,@L);
    While(Not(IsEqual(foreachtail,{})))
    [
      Bind(@i,First(foreachtail));
      @B;
      Bind(foreachtail,Rest(foreachtail));
    ];
  ];
];

LocalSymbols(index,nr)
[
  20 # ForEachRest(_i,_A,_B)_(   And(
            IsEqual(IsGeneric(A),True),
            IsEqual(GenericTypeName(A),"Array")
            )) <--
  [
    Local(index,nr);
    Local(@i);
    Bind(index,1);
    Bind(nr,Length(@A));
    While(index<=nr)
    [
      Bind(@i,(@A)[index]);
      @B;
      Bind(index,AddN(index,1));
    ];
  ];
];

Macro()(ForEach(i,L)(B));

LocalSymbols(itm,lst,bd)
[
  (ForEach(_i,_L)(_B)) <--
  [
    Local(itm,lst,bd);
//CurrentFile(),CurrentLine(),,Hold(@B)
//Echo(CurrentFile(),CurrentLine());
// Echo("ForEach(",Hold(@i),", ",Hold(@L),", ) ");
    itm:=Hold(@i);
    lst:= (@L);
    bd:=Hold(@B);
//Echo("1...",itm);
    `ForEachRest(@itm,@lst,@bd);
  ];
];
*/

%/mathpiper