Post Reply 
newRPL - Updated to build 1510 [official build remains at 1487]
07-23-2023, 11:54 AM
Post: #290
RE: newRPL - Updated to build 1510 [official build remains at 1487]
(07-22-2023 10:55 PM)Gilles Wrote:  I spent some time tonight starting a ListExt library in newRPL.
For documentation and usage, see : https://www.hpcalc.org/details/7971
It's a partial implementation for now. It's very fast because newRPL is very fast especially with the processing of lists. The rest will follow soon enough when I have time next week and will be integrated into a newRPL library with menu and on line help.
Code:
@====================================================================
@  List Extension for newRPL v0.01, Le 22/07/23 
@  Use the same commands and syntax as :
@   https://www.hpcalc.org/details/7971
@--------------------------------------------------------------------
 LSEQ   
  « → a  
   « CASE 
      'a≥1'  THEN  1 a FOR 'n' n NEXT a →LIST END
      'a≤-1' THEN -1 a FOR 'n' n -1 STEP a NEG →LIST END
      {} 
     END   
   » 
  »
@--------------------------------------------------------------------
 LSEQR   
  « → a b  
   « IF 'a≤b' THEN 
      a b FOR 'n' n NEXT 
     ELSE 
      a b FOR 'n' n -1 STEP 
     END 
     a b - ABS 1 + →LIST
   »
  »
@--------------------------------------------------------------------
 LMRPT
  « → List a  
   « {}
     IF 'a≥1' THEN 1 a START List ADD NEXT END    
   » 
  »
@--------------------------------------------------------------------
 LDDUP
  « 
   REVLIST OBJ→ {}
   1 ROT START
    IF SWAP DUP2 POS THEN DROP ELSE ADD END
   NEXT 
  » 
@--------------------------------------------------------------------
 LASEQ
  « → dép diff nbr 
   « 
    CASE 
     nbr 0 == THEN {} END
     nbr 1 == THEN dép 1 →LIST END
     dép 
     2 nbr START DUP diff + NEXT
     nbr →LIST
    END
   »
  » 
@--------------------------------------------------------------------
 LPOP « DUP HEAD SWAP TAIL SWAP »
@--------------------------------------------------------------------
 LPOPR « DUP HEAD SWAP TAIL »
@--------------------------------------------------------------------
 LPUSH  « IF DUP {} SAME THEN 1 →LIST END SWAP ADD »
@--------------------------------------------------------------------
 LPICK
  « SWAP → List « « List SWAP GET » MAP » »
@--------------------------------------------------------------------
 LREPL
  « ROT → List « 2 « 'List' UNROT REPL » DOLIST DROP List » »
@--------------------------------------------------------------------
 LRMOV
  « → List r 
   « IF r TYPE 10 == THEN
      List 1 r 1 - SUB
      List r 1 + List SIZE SUB
      ADD 
     ELSE
      IF r SIZE THEN
       r LDDUP SORT REVLIST
       1
       « → ri 
        « List 1 ri 1 - SUB 
          List ri 1 + List SIZE SUB
          ADD 'List' STO
        » 
       » 
       DOSUBS DROP List    
      END   
     END 
   » 
  »
@--------------------------------------------------------------------
 LFRST  « 1 SWAP SUB »
@--------------------------------------------------------------------
 LLAST « OVER SIZE DUP ROT - 1 + SWAP SUB »
@--------------------------------------------------------------------
 LRCL  « IF DUP SIZE THEN RCL END »
@--------------------------------------------------------------------
 LROLL « DUP SIZE → List s « List 1 LLAST List s 1 - LFRST ADD » »
@--------------------------------------------------------------------
 LRLLD « DUP TAIL SWAP HEAD ADD »
@--------------------------------------------------------------------
 LZIP
  « OBJ→ DUP 'nl' LSTO « nl →LIST » DOLIST »
@--------------------------------------------------------------------
 LFILT  
  « → Filter 
    « 1 « IF DUP Filter NOT THEN DROP END » DOSUBS »
  » 
@--------------------------------------------------------------------
 NL→I
  « « →STR + » STREAM STR→ » 
@--------------------------------------------------------------------
 I→NL
  « ABS .5 + IP DUP XPON → n s  
   « IF 's≥0' THEN s 0 FOR 'a' n a a DIGITS -1 STEP
     ELSE 0 0 's' STO END
     s 1 + →LIST     
   » 
  »  
@------------------------------------------------------------------- 
 LROT
   « OVER SIZE → List a s  
    « CASE 
       'a>0' THEN List a LLAST List s a - LFRST  ADD END
       'a<0' THEN 'a' SNEG List s a - LLAST List a LFRST ADD END 
       List
      END   
    »
   »
@------------------------------------------------------------------- 
 LSWAP  
   « →  a b 
    « DUP a GET
      OVER b GET
      UNROT b SWAP PUT
      SWAP a SWAP PUT
    »
   »
@ This version is 2.6 time slower :
@  « → List a b 
@   « 'List(a)' →NUM 'List(b)' →NUM 'List(a)' STO  'List(b)' STO
@      List     
@   »
@  »

@------------------------------------------------------------------- 
 LUNION
  « ADD LDDUP »
@-------------------------------------------------------------------
 LINTR
  « → Lst2
   « « IF DUP Lst2 SWAP POS NOT THEN DROP END » MAP »
  »
@------------------------------------------------------------------- 
@ .... A suivre  !!!


this example returns the list of numbers from 1 to 1000 not divisible by 7 :
Code:
1000 LSEQ « 7 MOD » LFLTR

List of the 69 numbers <1000 with sum on digits is 11 :
Code:
999 LSEQ « I→NL ΣLIST 11 == » LFLTR

This is great! I can recommend a few things:
1) You can use CRLIB to create a user library to publish. Wiki-How to create user libraries
2) If plain text is your preferred format, you can use PACKDIR to convert and entire directory to user readable and editable text. It can be copy/pasted into the calc, compiled and stored into a variable with STO so it's a simple way to distribute an entire folder tree.
3) You can make those comments permanent with @@ so users can compile while preserving the helpful comments in the code
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Navigating through sub-menus - Gilles - 05-13-2023, 11:31 AM
RE: newRPL - Updated to build 1510 [official build remains at 1487] - Claudio L. - 07-23-2023 11:54 AM
It's a mystery to me... - Klaus - 11-27-2023, 12:24 PM



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