Author Topic: item - list  (Read 2163 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
item - list
« on: June 14, 2016, 01:51:20 PM »
Hello such someone could tell me how I know if an item belongs to a list.

Thanks :smitten:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ronjonp

  • Needs a day job
  • Posts: 7531
Re: item - list
« Reply #1 on: June 14, 2016, 02:02:22 PM »
Look into MEMBER or VL-POSITION

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: item - list
« Reply #2 on: June 14, 2016, 02:51:25 PM »
And ASSOC
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: item - list
« Reply #3 on: June 15, 2016, 07:27:13 PM »
What's the fastest one?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: item - list
« Reply #4 on: June 15, 2016, 07:36:57 PM »
What's the fastest one?

Technically they do slightly different things.
Form should follow function, so what do you want returned ??

If you provide a data list and sample code I will check the relative speed of each test for you.

I'm prepared to wager the difference is considerably smaller than the time it takes most people to find a key on the keyboard.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

mailmaverick

  • Bull Frog
  • Posts: 495
Re: item - list
« Reply #5 on: June 16, 2016, 09:39:18 AM »
Look into MEMBER or VL-POSITION

I have checked, VL-POSITION is certainly faster than MEMBER.
I am surprised how VL functions are faster than innate functions of LISP which are the basic functions since beginning of LISP.
Can anyone explain the reason.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: item - list
« Reply #6 on: June 16, 2016, 10:38:43 AM »
A difference in memory allocation perhaps? Consider that member returns a list containing the item and all items following it, whereas vl-position merely returns an integer indicating the index of the item.

mailmaverick

  • Bull Frog
  • Posts: 495
Re: item - list
« Reply #7 on: June 16, 2016, 10:46:20 AM »
A difference in memory allocation perhaps? Consider that member returns a list containing the item and all items following it, whereas vl-position merely returns an integer indicating the index of the item.

Indeed.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: item - list
« Reply #8 on: June 16, 2016, 11:48:08 AM »
Or if an item is a list at all  TYPE


Code - Auto/Visual Lisp: [Select]
  1. (setq x '(3))
  2.  (=  (Type x) 'LIST)
  3.  

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: item - list
« Reply #9 on: June 16, 2016, 12:54:25 PM »
Look into MEMBER or VL-POSITION

I have checked, VL-POSITION is certainly faster than MEMBER.
I am surprised how VL functions are faster than innate functions of LISP which are the basic functions since beginning of LISP.
Can anyone explain the reason.
This is an old test:
Code: [Select]
(defun Test_vl-position (InLst)
  (foreach ForElm InLst (vl-position ForElm InLst))
)
(defun Test_member (InLst)
  (foreach ForElm InLst (member ForElm InLst))
)
Code: [Select]
(setq alist1 (atoms-family 1))
(setq alist1 (append alist1 alist1 alist1 alist1))
(timerU '(Test_vl-position alist1) 100)
(timerU '(Test_member      alist1) 100)

TEST_VL-POSITION > 100 iterations: 3.68 secs.
TEST_MEMBER      > 100 iterations: 23.44 secs.


(setq alist1 nil) (setq alist '(1 2 3 4 4 5 5 5 6 7 8 9 9 9 9))
(setq alist1 (repeat 500 (setq alist1 (append alist1 alist))))
(timerU '(Test_vl-position alist1) 100)
(timerU '(Test_member      alist1) 100)

TEST_VL-POSITION > 100 iterations: 0.72 secs.
TEST_MEMBER      > 100 iterations: 1.74 secs.