cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
jthi
Super User

Remove From not working as intended with last items in list

I noticed that Remove From() function isn't working as intended (and its documentation is written wrong in both Scripting Index and JMP Help). It seems to behave irrationally when last element is removed from the list.

 

I have contacted JMP support about this. According to them intended behaviour is as follows (same as I would expect it to be):

The expected behaviour is that Remove From returns the item(s) removed as your example shows for the first 9 items.  Additionally, it modifies the input container by removing the item(s).

I have yet to hear back from them if they know about timeline when this will be fixed and documentation updated. I will report back here if I hear back with timeline.

 

Example and one "workaround" (if I really need same behaviour as Remove From, I will write my own function for it for now):

Names Default To Here(1);
m = 1::10;
 
For Each({item}, m,
       earlier_m = m;
       // Returns: The original source with the items deleted.
       // Doesn't this return deleted list (except when it is last element...)
       removed = Remove From(m, 1);
       Print(Eval Insert("^removed^ removed from ^earlier_m^"));
);
 
// workaround?
m = 1::10;
For Each({item}, m,
       earlier_m = m;
       removed = m[1];
       Remove From(m, 1);
       Print(Eval Insert("^removed^ removed from ^earlier_m^"));
);
-Jarmo
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Remove From not working as intended with last items in list

Thanks for reporting this.  Note that this bug applies to calls to RemoveFrom() used on a vector (matrix), and does not apply to list containers. 

 

Your workaround seems reasonable for vectors.  If you use this workaround on a list, keep in mind that you will create a copy of the first element.  For most types this will be fine - copying an element that references a display box, data table, or platform will just create another symbol referencing the same object.  If the list elements contain items like large matrices or associative arrays, you will be creating a duplicate copy of this object.  This may not have a large noticeable effect either, but the semantics of the workaround are slightly different.

View solution in original post

1 REPLY 1

Re: Remove From not working as intended with last items in list

Thanks for reporting this.  Note that this bug applies to calls to RemoveFrom() used on a vector (matrix), and does not apply to list containers. 

 

Your workaround seems reasonable for vectors.  If you use this workaround on a list, keep in mind that you will create a copy of the first element.  For most types this will be fine - copying an element that references a display box, data table, or platform will just create another symbol referencing the same object.  If the list elements contain items like large matrices or associative arrays, you will be creating a duplicate copy of this object.  This may not have a large noticeable effect either, but the semantics of the workaround are slightly different.