TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kdub_nz on February 02, 2022, 02:24:01 PM

Title: List Indexing and Slicing.
Post by: kdub_nz on February 02, 2022, 02:24:01 PM
Was reminded by the current challenges how often I've thought how nice it would be to have
list Indexing and Slicing based on the index location:
eg:
https://railsware.com/blog/python-for-machine-learning-indexing-and-slicing-for-lists-tuples-strings-and-other-sequential-types/
Code - Python: [Select]
  1. >>> nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]
  2. >>> nums[0:4]
  3. [10, 20, 30, 40]
  4.  
  5. >>> nums[::2]
  6. [10, 30, 50, 70, 90]
  7.  
  8. >>> some_nums = nums[2:7]
  9. >>> some_nums
  10. [30, 40, 50, 60, 70]
  11.  
  12. >>> nums[-3:]
  13. [70, 80, 90]
  14.  

anyone played with this concept ??
Title: Re: List Indexing and Slicing.
Post by: JohnK on February 02, 2022, 03:40:40 PM
Reminds me so much of arrays. :) And so far, we have covered a few of those. In the "challenge queue" we have a few challenges that, combined, will give a bit more `array like' flavor. Great link.

Two of the items I miss most, from other languages, are pointers and arrays.
Title: Re: List Indexing and Slicing.
Post by: d2010 on February 03, 2022, 02:27:12 PM
Was reminded by the current challenges how often I've thought how nice it would be to have
list Indexing and Slicing based on the index location:
eg:
The main problem is = I not found fast index, because, I feel
assoc(1,list(...)) is too slow.
If you need then I need help, together can emulate JavaIndexer inside
or MoreMathematicallyLisp inside
Code: [Select]
(defun dfn_view_pnts(ljfour / $rr a b c d e f x)
/*c2s: b=getvar("VIEWSIZE"),
       $rr=getvar("SCREENSIZE"),
       c=car($rr),
       d=cadr($rr),
       a=b*c/d,
       x=getvar(_T("VIEWCTR")),
       x=trans(x,1,2);
       c=list( car(x)-(a/2.0),cadr(x)-(b/2.0),0.0),
       d=list( car(x)+(a/2.0),cadr(x)+(b/2.0),0.0),
       c=trans(c,2,1),
       d=trans(d,2,1),
       $rr=(ljfour)?list(c,list(car(c),cadr(d),0.0),list(cadr(c),car(d),0.0),d):
           (ljfour==4)?list(c,list(car(c),cadr(d),0.0),list(cadr(c),car(d),0.0),d):
           list(c,d);
*/
$rr)