Post Reply 
Editing Bug: occasional write filename into file
11-07-2017, 07:00 PM (This post was last modified: 11-10-2017 10:25 AM by StephenG1CMZ.)
Post: #1
Editing Bug: occasional write filename into file
I have been seeing an occasional bug over the last couple of weeks on Android.

After editing a program, say LIST, I make a backup, selecting More/Save LISTF (appending 1-3 characters after the name).

Then I see an unexpected syntax error (I'm making a good backup, not a random one).

On checking, I see one of my procedures calls is now something like
RETURN mat2LISTF
And has to be changed back to
RETURN mat2list or whatever
In order to correct the syntax error.

So, More/Save and appending character(s) to save to a different file, is changing the text of the procedure name to include the filename. The file is created.

I have only seen this about 4 times over the last couple of weeks, but its only over the last few weeks that I have been editing regularly - for the previous few months usage had been infrequent due to time pressures. It is becoming more frequent.

Also, for a few days editing a 40KB file was getting very sluggish, although this has now returned to normal.

Has anyone else seen this?

(Perhaps I should mention that my 8GB RAM/64GB SD Android phone regularly complains that it has insufficient MB to update applications, in case that is relevant).

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-09-2017, 11:32 PM
Post: #2
RE: Editing Bug: occasional write filename into file
For example, here is a corrupted backup of my list program, V1.
Easy enough to get rid of the syntax error - but if I replace it with the wrong name, it's not a very useful backup.

Code:


 LOCAL CRID:="List API V1.0 © 2017 StephenG1CMZ";

 //Customise
 EXPORT ListShowErrors:=1;//SHOW ERRORS
 EXPORT ListNumericTypes:={DOM_FLOAT-1,DOM_INT-1,DOM_COMPLEX-1,DOM_MATRIX-1};
 //Query: Include COMPLEX,LONGFLOAT,MATRIX?
 //End

 //Forward
 ListCOUNTITEM(LST,ITEM);
 ListCOUNTITEMS(LST,ITEMS);
 ListIsTYPE(LST,TYPES);
 ListREMOVEDUPLICATES(LST);
 ListREMOVEX(LST,POSN);
 ListSORT(LST);

 //NB In main routines (ie not Python)
 //POSN parameter is >=0 (0=LAST)
 //POSN returned is ≥0 (PPL,0=NOTIN)

 //LOCAL SL:=1;
 LOCAL NL:="\n";
 LOCAL EMPTY0:=0;//ADDITIVE
 LOCAL EMPTY1:=1;//MULTIPLICATIVE

//TO REFER TO ListTYPE, USE DOM_LIST-1; MAGIC NUMBER FOR LISTS.

 LOCAL ListANS;//OUTPUT LIST(WHEN NOT RETURNED)
  //Also, useful temporary results 

 //ERR 
 LOCAL NaN:="NaN";
 LOCAL ListErrK:=1;
 LOCAL PyErrK:=3;
 EXPORT ListLastError:=0;
 LOCAL ERRKIND:={"","Error","","Py Error"};
 LOCAL ERRLST:={
  "IndexOutofBoundsException",
  "ListIsEmptyError",
  "ListIsFullError",
  "ListStatisticsError",
  "ItemNotFoundError",
  "ValueError"
 };
 //ERRNO IS ARBITRARY:INDEXES ERRLST
 LOCAL IndexOutOfBoundsException:=1;//List J
 LOCAL ListIsEmptyError:=2;
 LOCAL ListIsFullError:=3;//UNUSED YET
 LOCAL ListStatisticsError:=4;//UNUSED
 LOCAL ItemNotFoundError:=5;//List Py
 LOCAL ValueError:=6; // Py
 
 EXPORT ABOUT()
 BEGIN
  MSGBOX(CRID);
 END;

 TBD()
 BEGIN
  MSGBOX( "List: TBD");
 END;
 
 EXPORT RAISE(ERR,CULPRIT,SEVERITY)
 //Only exported for testing
 BEGIN
  IF ListShowErrors AND SEVERITY>0 THEN
   MSGBOX("List: "+ERRKIND(SEVERITY+1)+NL+ERRLST(ERR)+NL+CULPRIT);
  END;
  ListLastError:=ERR;
 END;

 NAN()
 BEGIN
  RETURN NaN;
 END;

 //MAINLY STANDARD FUNCTIONS

 EXPORT ListΣLIST(LST)
 BEGIN
  RETURN IFTE(SIZE(LST),ΣLIST(LST),EMPTY0); 
 END;

 EXPORT ListΠLIST(LST)
 BEGIN
  LOCAL SZ:=SIZE(LST);
  
  IF SZ>1 THEN RETURN ΠLIST(LST);
  END;
  IF SZ==1 THEN RETURN LST(1);
  END;
  //IF SZ==0 THEN
  RETURN EMPTY1;
  //END;
 END;

 EXPORT ListAFTER(LST,POSN)
 //Slice After POSN:
 //POSN=0 OR LAST:{}
 BEGIN
  LOCAL FRM:=POSN+1;
  RETURN IFTE((POSN==0 OR FRM>SIZE(LST)),{},LST({FRM,SIZE(LST)}));
 END;

 EXPORT ListANDBOOL(LST,LSTBOOL,NewValue)
 //Replace items ANDed out with NULL(NewValue)
 //EG ({"AA","BB"},{0,1},"CHAR(0)") = {"","BB"}//Note the quotes
 //EG ({11,13},{0,1},"12")//NOMORETHAN12
 //RequirementSpec:
 //http://www.hpmuseum.org/forum/thread-5092.html
 //Usage:
 //http://www.hpmuseum.org/forum/thread-5031.html
 //See also:MaskBOOL
 //NULL=NULL
 BEGIN
  //Guard against empty "" giving syn err
  LOCAL MYNULL:=IFTE(NewValue=="","CHAR(0)",NewValue);
  IF SIZE(LST) AND SIZE(LSTBOOL) THEN
   RETURN EXECON("IFTE(&2,&1,"+MYNULL+")",LST,LSTBOOL);
  END;
  RETURN {};
 END;

 EXPORT ListAPPEND(LST,ITEM)
 //APPEND ITEM TO LIST
 //EG L2:=APPEND(L2,3)
 //PPL:L2(0):=3;
 //Py:APPEND(L2,3)
 //NULL: {ITEM}
 // (LST,{ITEMLST}) ADDS 1 ITEM (A LST)
 BEGIN
  RETURN LST(0):=ITEM; 
 END;

 EXPORT ListBEFORE(LST,POSN)
 //Slice Before POSN: 
 //POSN=0: ({1,2},0)={1}
 BEGIN
  LOCAL TOO:=POSN-1;
  IF POSN==0 THEN
    RETURN ListBEFORE(LST,SIZE(LST));
  END;
  RETURN IFTE(TOO>0,LST({1,TOO}),{});
 END;

 EXPORT ListCONCAT(LST1,LST2)
 //CONCATENATE
 BEGIN
  CONCAT(LST1,LST2);
 END;

 EXPORT ListCOUNT (LST,ITEM)
 //COUNT 1 ITEM:FASTEST
  //INTERSECT IS CURRENTLY QUICKER
  //BUT RECHECK AFTER ITERATIVE SOLN IMPL
 BEGIN
  RETURN ListCOUNTITEMS(LST,{ITEM});
 END;

 EXPORT ListCOUNTANYDUPLICATES(LST)
 //Current Implementation yields a sorted LST
 //But might change
 BEGIN
  ListANS:=ListSORT(LST);
  RETURN ListCOUNTANYDUPLICATES_SORTED(ListANS);
 END;

 EXPORT ListCOUNTANYDUPLICATES_SORTED(SortedLST)
 //Count how many duplicates in a sortedlist,Return a REAL INT
 //({1,9,9}=1 dup, {1,2,2,3,3,3}=3 dup)
 BEGIN
  LOCAL II;
  LOCAL DUPCOUNT:=0;
  IF SIZE(SortedLST)>1 THEN
   FOR II FROM 1 TO SIZE(SortedLST)-1 DO
    IF SortedLST(II) ==SortedLST(II+1) THEN
     DUPCOUNT:=DUPCOUNT+1;
    END;//IF
   END;//FOR
   //ELSE:SMALL LISTS HAVE NO DUPLICATES
  END;//IF
  RETURN DUPCOUNT;
 END;
 
 EXPORT ListCOUNTITEM(LST,ITEM)
 //Count Instances of 1 ITEM in LST
 //ITEM MAY BE A LIST COMPRISING 1 ITEM 
 //(USE COUNTITEMS TO SEARCH FOR A LIST OF ITEMS)
 //NULL LST:0
 //NULL ITEM:COUNTED
 
 BEGIN
  LOCAL POSN:=POS(LST,ITEM);
  CASE
   IF POSN==0 THEN RETURN 0; END;
   //IF POSN==SIZE(LST)  THEN RETURN 1; END;
   DEFAULT
    //FOR LISTS WIH MANY DUPLICATES:
    //AN ITERATIVE SOLN WILL BE NEEDED
    RETURN 1+ListCOUNT(ListAFTER(LST,POSN),ITEM);
  END; 
 END;

 EXPORT ListCOUNTITEMS(LST,ITEMS)
 //ITEMS MAY BE 1 ITEM OR A LIST OF SEPARATE ITEMS
 //SO TO COUNT LISTS, CONTAIN THEM IN A LIST
 //EG {1,{},2},{{}}= 1
 //EG {1,2,3},{2,3} = 2
 //EG {1,{2,3}},{2,3} = 0 (TO SEARCH FOR ITEM {2,3} USE COUNT)
 //ITEMS NULL=0
 //THIS VERSION IS QUICKER,BUT PARAMETERS DIFFER
 BEGIN
  RETURN SIZE(INTERSECT(LST,ITEMS));
 END;
 
 EXPORT ListDIFFER2(LST1,LST2)
 //POSITION OF 1st DIFFERENCE
 //FLOAT≠INTEGER
 //SIZE≠SIZE: SZ+1 RETURNED(UNLESS EARLIER DIFFERENCE)
 BEGIN
  LOCAL II:=1;
  LOCAL SZ:=MIN(SIZE(LST1),SIZE(LST2));

  IF EQ(LST1,LST2) THEN
   RETURN 0;
  END;
  //IF SIZE(LST1)≠SIZE(LST2) THEN
  // RETURN −1;
  //END;
  WHILE II≤SZ DO
   IF TYPE(LST1)≠TYPE(LST2) OR LST1(II)≠LST2(II) THEN
    RETURN II;
   END;
   II:=II+1;
  END; 
  RETURN IFTE(SIZE(LST1)>SZ OR SIZE(LST2)>SZ,SZ+1,0);
 END;

 EXPORT ListFIND(LST,ITEM)
  //See http://www.hpmuseum.org/forum/thread-9431.html
 BEGIN 
  LOCAL X,Y;
  LOCAL LSTPOSNS={};

  WHILE X:=POS(LST,ITEM) DO
    LSTPOSNS(0):=(Y:=X+Y);
    LST:=LST({X,SIZE(LST)}+1)
  END;
  RETURN LSTPOSNS;
 END;
 
 EXPORT ListGETLIST(LST,GETLST)
 //Solves Puzzle #32. POSN≥0.
 //POSN>SIZE(LST):EXCEPTION. RETURN {} FOR THAT ITEM
 BEGIN
 LOCAL II;

  IF SIZE(GETLST) THEN
   IF MAX(GETLST)>SIZE(LST) THEN
    RAISE(IndexOutOfBoundsException,"ListGETLIST",ListErrK);
   END;
   //IFTE GUARDS INDEX>SIZE(LST)
   RETURN MAKELIST(IFTE(GETLST(II)>SIZE(LST),{},LST(GETLST(II))),II,1,SIZE(GETLST));
  END;
  RETURN {};//ASKED TO GET NOTHING
 END;

 EXPORT ListHEAD(LST)
 //List HEAD AKA LISP CAR
 //NULL:ERR
 BEGIN
  IF SIZE(LST) THEN
   RETURN LST(1);
  END;
  RAISE(ListIsEmptyError,"HEAD",ListErrK);
  RETURN {};
 END;

 EXPORT ListINDEX(LST,ITEM)
 //Despite the confusing name
 //Simple: Return posn of 1st instance of item
 //NULL: 0
 BEGIN
  RETURN POS(LST,ITEM);
 END;

 EXPORT ListINSERT(LST,POSN,ITEM)
 //INSERT ITEM BEFORE POSN
 //PPL POSN=0 = APPEND
 //Py  POSN=0 = 1ST
 BEGIN
  LOCAL POSNB:=POSN-1;
  LOCAL LSTB:=IFTE(POSN==1,{},LST({1,POSNB}));
  LOCAL LSTA:=LST({POSN,SIZE(LST)});

  IF POSN==0 THEN //IN PPL:
   //IT IS UNCLEAR WHETHER THIS SHOULD APPEND,
   //OR INSERT BEFORE LAST 
   //OPINIONS?
   //TBD();
   RETURN CONCAT(LST,ITEM);
  END;
  RETURN CONCAT(CONCAT(LSTB,ITEM),LSTA);
 END;

 //Query:
 //IsLIST,IsSET ask-Is parameter this
 //IsNUMERIC,IsTYPE ask:Are contents this
 //Change names to clarify?

 EXPORT ListIsLIST(LST)
 //BOOL:Is entire parameter a list
 //In PPL lists and sets both 1
 BEGIN
   RETURN (TYPE(LST)==ListTYPE);
 END;

 EXPORT ListIsNUMERIC(LST)
 //Is list currently numeric
 BEGIN 
  RETURN ListIsTYPE(LST,ListNumericTypes);
 END;

 EXPORT ListIsSET(LST)
 //BOOL:Is LST currently a set (no duplicates)
 //A uniquelist (no duplicates) may be a set
 //NULL:1
 BEGIN
  RETURN NOT(ListCOUNTANYDUPLICATES(LST));
 END;

 EXPORT ListIsSORTEDEQ(LST)
 //Tells whether a list is sorted...inefficiently
 //By sorting it and checking equality
 //(Useful for testing)
 BEGIN
  ListANS:=ListSORT(LST);
  RETURN EQ(ListANS,LST);
 END;
 
 EXPORT ListIsSORTED(LST)
 //Looping until 1st descending will be quicker TBD
 BEGIN
  RETURN ListIsSORTEDEQ(LST);
 END;

 EXPORT ListIsTYPE(LST,TYPES)
 //TYPES: TYPE OR LIST OF TYPES
 //SEE ALSO:IsNUMERIC
 //MAKELIST IS FASTER THAN [FOR,INCREMENT COUNT] 
 BEGIN
  LOCAL II;

  IF TYPE(TYPES)==DOM_FLOAT-1 THEN RETURN IsTYPE(LST,{TYPES});
  END;
 
  IF SIZE(LST) AND SIZE(TYPES) THEN
   ListANS:=MAKELIST(IFTE(POS(TYPES,TYPE(LST(II))),1,0),II,1,SIZE(LST));//List matching types
   RETURN IFTE(ΣLIST(ListANS)==SIZE(LST),1,0); //Count them
  END;
  RAISE(ListIsEmptyError,"ListIsTYPE",1);
  //EMPTY LST: LST ALWAYS INDETERMINATE (GUARD) 
  //EMPTY TYPES: 0>NO MATCHES OR 1>NO REJECTS 
  RETURN 0;//INDETERMINATE
 END;

 EXPORT ListMASKBOOL(LST,LSTBOOL,NewValue)
 //Mask selected values
 //Cf ANDBOOL
 //Here 1 selects replace, not 0
 //NULL=NULL
 BEGIN 
  //Guard against empty "" giving syn err
  LOCAL MYNULL:=IFTE(NewValue=="","CHAR(0)",NewValue);
  IF SIZE(LST) AND SIZE(LSTBOOL) THEN
   RETURN EXECON("IFTE(&2,"+MYNULL+",&1)",LST,LSTBOOL);
  END;
  RETURN {};
  //Equivalent to
  //RETURN ListANDBOOL(LST,NOT(LSTBOOL),NewValue);
 END;

EXPORT ListMAX(LST)
BEGIN
  RETURN IFTE(SIZE(LST),MAX(LST),EMPTY0);
END;

 EXPORT ListMEAN(LST)
 BEGIN
  IF SIZE(LST) THEN
   RETURN mean(LST);
  END;
  RAISE(ListIsEmptyError,"ListMEAN",ListErrK);
  RETURN NAN();
 END;

 EXPORT ListMEAN2(LSTV,LSTF)
 BEGIN
  IF SIZE(LSTV) AND SIZE(LSTF) THEN
   RETURN mean(LSTV,LSTF);
  END;
  RAISE(ListIsEmptyError,"ListMEAN2",ListErrK);
  RETURN NAN();
 END;

 EXPORT ListMEDIAN(LST)
 BEGIN
  IF SIZE(LST) THEN
   RETURN(median(LST));
  END;
  RAISE(ListIsEmptyError,"ListMEDIAN",ListErrK);//(NO MEDIAN)
  RETURN NAN();///
 END;

 EXPORT ListMEDIAN2(LSTV,LSTF)
 BEGIN
  IF SIZE(LSTV) AND SIZE(LSTF) THEN
   RETURN(median(LSTV,LSTF));
  END;
  RAISE(ListIsEmptyError,"ListMEDIAN2",ListErrK);
  RETURN NAN();///
 END;

 EXPORT ListMIN(LST)
 BEGIN
  RETURN IFTE(SIZE(LST),MIN(LST),EMPTY0);
 END;

 EXPORT ListMODE2(LSTV,LSTF)
 //Get MODES of ItemXFrequency Lists
 //Empty=Empty
 BEGIN
  LOCAL II;
  LOCAL MODESLST:={};
  LOCAL MODEPOSNS:={};

  IF SIZE(LSTF) AND SIZE(LSTV) THEN
   //Find MODES
   MODEPOSNS:=ListFIND(LSTF,MAX(LSTF));
  
   FOR II FROM 1 TO SIZE(MODEPOSNS) DO
    MODESLST(II):=LSTV(MODEPOSNS(II));
   END;//FOR
  END;//IF
  RETURN MODESLST;
 END;
 //A FASTER IMPLEMENTATION OF MODE IS AT
 //http://www.hpmuseum.org/forum/thread-9393.html
 EXPORT ListMODE(LST)
 //Get MODES of LST : Empty = Empty
 BEGIN
  //Make uniquelst and count
  ListANS:=ListOCCURRENCES(LST);
  
  RETURN ListMODE2(ListANS(1),ListANS(2));
 END;

 EXPORT ListOCCURRENCES(LST)
 //Given a list
 //Return unique list of occurrences and their occurrence counts as 2 lists
 BEGIN
  LOCAL II;
  LOCAL LSTF:={};
  LOCAL LSTV:=ListREMOVEDUPLICATES(LST);

  FOR II FROM 1 TO SIZE(LSTV) DO
   LSTF(II):=ListCOUNT(LST,LSTV(II));
  END;
  RETURN {LSTV,LSTF};
 END;
//There must be a better name
 EXPORT ListInvOCCUR(LSTV,LSTF)
 //INVERSE OF OCCURRENCES
 //Given V and F yield V,F times
 //NULL=NULL
 //In an OCCURRENCES list V is unique and F>0
 //But We handle V with F=0 and V nonunique
 BEGIN
  LOCAL II,JJ;
  LOCAL LST:={};

  FOR II FROM 1 TO SIZE(LSTV) DO
   IF LSTF(II) THEN //V WITH F>0
    LST:=CONCAT(LST,MAKELIST(LSTV(II),JJ,1,LSTF(II)));
   END;
  END;
 
  RETURN LST;
 END;

 EXPORT ListPOP(LST,POSN)
 //POP POSN OFF LIST
 BEGIN
  LOCAL ITEM;
  IF SIZE(LST) THEN
   ITEM:=LST(IFTE(POSN,POSN,SIZE(LST)));//0=>LAST
   ListANS:=ListREMOVEX(LST,POSN);
  ELSE
   RAISE(ListIsEmptyError,"ListPOP",ListErrK);
   ITEM:={};
   ListANS:={};
  END;   
  //RETURN POPPED ITEM
  //BUT ALSO SAVE SHORTENED LST
  RETURN ITEM;
 END;

 EXPORT ListPOPLAST(LST)
 //POP POSN OFF LIST
 //Py: POP()
 BEGIN
  RETURN ListPOP(LST,SIZE(LST)); 
 END;

 EXPORT ListremoveX(LST,POSN)
 // CAS ALTERNATIVE TO REMOVEX:MAY BE SLOW
 //See 
 //http://www.hpmuseum.org/forum/thread-9406.html and
 //http://www.hpmuseum.org/forum/thread-7987.html?highlight=suppress 
 //NULL=NULL,POSN>SZE=LST
 BEGIN
  IF POSN THEN
   RETURN suppress(LST,POSN);
  END;
  RETURN suppress(LST,SIZE(LST));//0=LAST
 END;

 EXPORT ListREMOVEX(LST,POSN)
 //REMOVE 1 ITEM AT POSN
 //NULL=NULL,POSN>SIZE=LST (NOWT REMOVED)
 BEGIN
  LOCAL LSTB,LSTA;

  IF POSN THEN
   LSTB:=ListBEFORE(LST,POSN);
   LSTA:=ListAFTER (LST,POSN);
   RETURN CONCAT(LSTB,LSTA);
  ELSE
   //PPL: 0=Remove Last Item
   RETURN ListREMOVEX(LST,SIZE(LST));
   //Py: 0=RemoveFirst ie return TAIL
  END;
 END;
 
 EXPORT Listremove(LST,ITEM) 
 //CAS version slower
 //NULL=NULL
 BEGIN
  RETURN remove(ITEM,LST);
 END;

 EXPORT ListREMOVE(LST,ITEM)
 //Remove 1 instance of ITEM
 //NULL=NULL 
 BEGIN
  LOCAL POSN:=POS(LST,ITEM);
  IF POSN THEN
   RETURN ListREMOVEX(LST,POSN);
  END;
  RAISE(ItemNotFoundError,ITEM,0);
  RETURN LST;//NOTHING TO REMOVE
 END;

 EXPORT ListREMOVEDUPLICATES(LST)
 //RESULT WITH DUPLICATES JUST ONCE 
 //Native: Sequence NOT determined but seems same
 //From #21
 BEGIN
  RETURN UNION(LST);
 END;

 EXPORT ListREMOVEDUPLICATESSL(LST)
 //SL
 //My own implementation ensures known list sequence (per original LST)
 BEGIN
  LOCAL II;
  LOCAL ListANS:={};

  FOR II FROM 1 TO SIZE(LST)  DO
   IF POS(ListANS,LST(II))==0 THEN //NOT YET LISTED
    ListANS(0):=LST(II);//ADD ENTRY
   END;
  END;
  RETURN ListANS;//EACH ITEM ONCE
 END;

 EXPORT ListREMOVEITEM(LST,ITEM)
 //ALL INSTANCES.PUZZLE #40.
 BEGIN
  LOCAL II;
  LOCAL FOUND:=ListFIND(LST,ITEM);
  IF SIZE(FOUND) THEN
   ListANS:=LST;
   //Remove from right:earlier posns unchanged
   FOR II FROM SIZE(FOUND) DOWNTO 1 DO
    ListANS:=ListREMOVEX(ListANS,FOUND(II));
   END;
   RETURN ListANS;
  END;//IF
  RETURN LST;//NOTHING REMOVED 
 END;

 EXPORT ListREPLACE(LST,ITEM,ITEM2)
 //Replace instances of ITEM with ITEM2
 BEGIN
  LOCAL II;
  LOCAL FOUND:=ListFIND(LST,ITEM);
  IF SIZE(FOUND) THEN
   ListANS:=LST;
   FOR II FROM 1  TO SIZE(FOUND)  DO
    ListANS(FOUND(II)):=ITEM2;
   END;
  ELSE
   RETURN LST;
  END;
  RETURN ListANS; 
 END;

 EXPORT ListSHUFFLE(LST_NUM)
 //SHUFFLE NUM: SHUFFLE 1..N INDEXES 
 //SHUFFLE LST: SHUFFLE LST
 //N<0:GUARD:UNSHUFFLED INDEX
 //NULL OR 0 OR >10000: NULL 
 BEGIN
  LOCAL II,NUM;
  IF TYPE(LST_NUM)=DOM_FLOAT-1 THEN
   NUM:=IFTE(LST_NUM>10000,0,LST_NUM);
   IF LST_NUM<0 THEN //GUARD NEGATIVES (AVOID CRASH)
    RETURN MAKELIST(II,II,1,ABS(NUM));//UNSHUFFLED
   END;
  END;
  RETURN mat2LIST_1(randperm(LST_NUM));
 END;

 EXPORT ListSLICE(LST,FRM,TOO)
 //RETURN PART OF LIST
 //SYNTAX HINT
 //SUGGEST ALSO IMPL (LST,{2,3})
 //FRM≤TOO:Bad Inputs={}
 BEGIN
  LOCAL TTOO:=IFTE(TOO==0,SIZE(LST),TOO); //TO 0==LAST
  LOCAL TFRM:=IFTE(FRM==0,SIZE(LST),FRM); //FRM 0==LAST
  //MSGBOX("SLICE "+{FRM,TOO});
  IF TFRM>TTOO THEN
    RAISE(IndexOutOfBoundsException,FRM,ListErrK);//Maybe a new error
    RETURN {};
  END; 
  RETURN LST({TFRM,TTOO});
 END;

 EXPORT ListSORT(LST)
 //This implementation uses native SORT
 //On old compilers See known bugs 
 //This will not affect MODE other than changing ordering 
 BEGIN
  RETURN SORT(LST);
 END;

 EXPORT ListTAIL(LST)
 //List TAIL AKA LISP CDR
 //NULL:ERR
 //(SOME USE TAIL=LAST NOT TAIL=CDR)
 BEGIN
  IF SIZE(LST) THEN
   RETURN LST({2,SIZE(LST)});
  END;
  RAISE(ListIsEmptyError,"TAIL",ListErrK);
  RETURN {};
 END;

 EXPORT ListToSET(LST)
 //In addition to making the list like a set
 //wibni we could track those tnat ARE sets
 BEGIN
  RETURN ListREMOVEDUPLICATES(LST);
 END;

 EXPORT ListVERSION()
 BEGIN
  RETURN CRID;
 END;

 // Python names(LC) prefixed Py ()
 // Py  syntax: Lst.append(ITEM) etc 
 // PPL syntax: Lst:=append(Lst,ITEM)
 // Py indexes from 0 but not yet implemented
 // These names are inspired by Py, 
 // but will never provide exact equivalents.
 
 EXPORT Pyappend(LST,ITEM)
 //append a single item
 BEGIN 
  RETURN append(LST,ITEM);//CAS
 END;

 EXPORT Pyclear(LST)
 //Py :ALSO DELETES LIST (cf CAS purge)
 BEGIN 
  RETURN {};
 END;

 EXPORT Pycopy(LST)
 //Py: A shallow copy PPL: simple copy
 BEGIN
  RETURN LST;
 END;

 EXPORT Pycount(LST,ITEM)
 //Py :Count occurences of item
 BEGIN
  RETURN ListCOUNT(LST,ITEM);
 END;

 EXPORT Pyextend(LST,LST2)
 //Py :Concat items in LST2 to LST
 //Query: If listfull, should we add some or none
 //PPL:LST2 may be an item 
 BEGIN
  CONCAT(LST,LST2);
 END;

 EXPORT Pyindex(LST,ITEM)
 //Py :Return index (or ValueErr)

 //TBD START:END LIMIT RANGE SEARCHED WITHOUT CHANGING INDEX
 BEGIN
  LOCAL LX:=ListINDEX(LST,ITEM); 
  IF LX==0 THEN
   RAISE(ValueError,ITEM,PyErrK);//Py:NotFound => an error
  END;
  RETURN LX; 
 END;

 EXPORT Pyinsert(LST,POSN,ITEM)
 //Py :Insert ITEM before POS
 BEGIN
  IF POSN==0 THEN
   TBD();
   CONCAT(ITEM,LST);//Py 0
  END;
  RETURN ListINSERT(LST,POSN,ITEM); 
 END;

 EXPORT Pypop(LST,POSN)
 //Py :Pop item (Posn Omit:Last)
 //PPL:Posn reqd
 BEGIN
  IF POSN==0 THEN
   TBD();
  END;
  RETURN ListPOP(LST,POSN);
 END;

 EXPORT PypopLast(LST)
 //Py :Pop item (Posn Omit:Last)
 //PPL:Twofunctions
 BEGIN
  RETURN ListPOPLAST(LST);
 END;

 EXPORT Pyremove(LST,ITEM)
 //Py :Remove 1st ITEM,ERR IF NONE
 BEGIN
  LOCAL POSN:=POS(LST,ITEM);
  IF POSN THEN
   RETURN ListREMOVEX(LST,POSN);
  END;
  //ELSE NOTHING TO REMOVE
  RAISE(ItemNotFoundError,ITEM,PyErrK);
  RETURN LST;
 END;
 
 EXPORT Pyreverse (LST)
 BEGIN
  RETURN REVERSE(LST);
 END;

 EXPORT Pysort(LST,KeyFunc,RReverse)
 //TBD: KeyFunc: Selects sort key from itapprox()
 BEGIN
  IF TYPE(KeyFunc)==DOM_FLOAT-1 AND KeyFunc==0 THEN
   //0=None=NO FUNC
  ELSE
   TBD();
   RAISE(ValueError,"Pysort",1);//TBD
  END;
  RETURN IFTE(RReverse,SORT(Pyreverse(LST)),SORT(LST));

 END;

EXPORT ListPuzzles()
 //SEE http://www.hpmuseum.org/forum/thread-8209.html?highlight=challenge
 BEGIN
  LOCAL VR;
  LOCAL LST:=MAKELIST("",VR,1,4);//40
  LST(2):="21. ListREMOVEDUPLICATES";
  LST(3):="32. ListGETLIST";
  LST(4):="40. ListREMOVEITEM";
  CHOOSE(VR,"Puzzles",LST);
 END;

 EXPORT ListPythonAnalogues ()
 BEGIN
  LOCAL KK;
  LOCAL PyFuns:={"Pyappend",
   "Pyclear","Pycopy","Pycount",
   "Pyextend",
   "Pyindex","Pyinsert",
   "Pypop","Pypoplast",
   "Pyremove","Pyreverse",
   "Pysort"};
  //Just Listed as a reminder:not Selectable
  CHOOSE(KK,"Py analogues",PyFuns)

 END;

 EXPORT ListStatisticalFunctions()
 BEGIN
  LOCAL KK;
  //Just listed to group these Not choosable
  CHOOSE(KK,"Statistical Functions",
   {"ListMEAN","ListMEAN2",
    "ListMEDIAN","ListMEDIAN2",
    "ListMODE","ListMODE2"});
 END;

 
 EXPORT ListExamples()
 //In real use, use XXX:=List...()
 BEGIN
  LOCAL LL:={1,2,3,4,5,6,7,8,9};
  PRINT();
  PRINT(ListVERSION);
  //PRINT("A");
  PRINT(ListAFTER(LL,2));
  PRINT(ListANDBOOL({1,12},{0,1},"122"));
  PRINT(ListANDBOOL({"AA","BB"},{0,1},"CHAR(0)"));
  PRINT(ListBEFORE(LL,2));
  //PRINT("C");
  PRINT(ListCOUNT({},2));
  PRINT(ListCOUNTANYDUPLICATES_SORTED({}));
  PRINT(ListCOUNTANYDUPLICATES({0,2,2,2}));
  PRINT(ListCOUNTITEM(LL,2));
  PRINT(ListCOUNTITEMS(LL,{2,3}));
  PRINT(ListDIFFER2(LL,CONCAT(LL,2)));
  //PRINT("F");
  PRINT(ListFIND(LL,2));
  PRINT(ListGETLIST(LL,{5,3}));
  PRINT(ListHEAD(LL));
  //PRINT("I");
  PRINT(ListINDEX(LL,2));
  PRINT(ListINSERT(LL,2,4));
  PRINT(ListIsLIST(5));
  PRINT(ListIsNUMERIC({1,2,#3}));
  PRINT(ListIsSET(LL));
  PRINT(ListIsSORTED(LL)); 
  PRINT(ListIsTYPE({"SI"},DOM_STRING-1));
  PRINT(ListMASKBOOL({1,12},{0,1},"122"));
  PRINT(ListMASKBOOL({"AA","BB"},{0,1},"CHAR(0)"));
  PRINT(ListOCCURRENCES(LL));
  PRINT(ListPOP(LL,2));LL:=ListANS;
  PRINT(ListPOPLAST(LL));LL:=ListANS;
  PRINT("R");
  PRINT(ListREMOVEX(LL,2));
  PRINT(ListREMOVE(LL,9));
  PRINT(ListSHUFFLE(−52));
  PRINT(ListSHUFFLE(52));
  PRINT(ListSHUFFLE({"R","G","B"}));
  PRINT(ListSLICE({1,2,3,4},2,3));
  PRINT(ListSORT(LL));
  PRINT(ListTAIL(LL));
  PRINT(ListToSET({1,2,2}));
 
  PRINT(ListMEAN(LL));
  PRINT(ListMEDIAN(LL));
  PRINT(ListMODES({"AC","DC"})); 
 
  PRINT("Exampled");
  //RETURN ListCOUNT({1,2,2,2},2);
 END;

 EXPORT LIST_1()
 BEGIN
  ABOUT();
  //ListExamples();
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-04-2017, 07:35 AM (This post was last modified: 12-04-2017 07:48 AM by StephenG1CMZ.)
Post: #3
RE: Editing Bug: occasional write filename into file
I have also seen this when choosing a new name for the file.
The length of the source code is a factor - I have not seen it happen on small programs.

My Android phone has now started crashing (claiming to be "Updating Firmware", when it actually requires a reboot with power key held pressed whilst usb powered) - so I am confident that this problem is caused by a lack of available storage on my 8GB/64GB Android with only 400 MB/32GB free. The free 32GB being on the SD card, which Android lets you install but not use.

Ideally of course one might hope for an error message instead/as well as saving an approximation of the source code.

I would be wishing for an upgrade from Santa, but even the latest £600 phone only has 64GB internal storage - and seeing how fast it went tbrough 8GB I think upgrading to 16GB is hardly worthwhile.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-04-2017, 03:16 PM
Post: #4
RE: Editing Bug: occasional write filename into file
(12-04-2017 07:35 AM)StephenG1CMZ Wrote:  I would be wishing for an upgrade from Santa, but even the latest £600 phone only has 64GB internal storage - and seeing how fast it went tbrough 8GB I think upgrading to 16GB is hardly worthwhile.

I have 32GB phone (with 29.12GB available to the user):
  • 115 apps instaled ~ 5.41GB
  • Audio files ~ 5.58GB

Still 6.23GB left.

Hope this help a little.

Prime, 15C CE
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)