Author Topic: nth or car?  (Read 4874 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
Re: nth or car?
« Reply #15 on: May 08, 2009, 06:21:24 PM »
gotcha, thanks.
 :lol:
this one should be "Wahoo!" instead of "cheesy", I am thinking...
Never express yourself more clearly than you are able to think.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: nth or car?
« Reply #16 on: May 08, 2009, 06:26:49 PM »
?? weird that you would compare the performance of list and append ??
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nth or car?
« Reply #17 on: May 08, 2009, 10:14:46 PM »
 8-)
curmudgeon used append to get his result & I used list. Made sense in my little world. :-)
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: nth or car?
« Reply #18 on: May 09, 2009, 02:56:32 AM »
Hi all,

list and cons functions are faster than append (no doubt about it) but sometimes append seems to be the best way.

If I don't misunderstand, the goal is to rotate the first item of a list to the end of this list:

(setq lst '(0 1 2 3 4 5 6 7 8 9))
(0 1 2 3 4 5 6 7 8 9) -> (1 2 3 4 5 6 7 8 9 0)

Neither curmudgeon nor CAB given expression do the trick:

(append (cdr lst) (list (list (car lst)))) returns (1 2 3 4 5 6 7 8 9 (0))

(list (cdr lst) (car lst)) returns ((1 2 3 4 5 6 7 8 9) 0)

Right expressions could be:

(append (cdr lst) (list (car lst)))

(reverse (cons (car lst) (reverse (cdr lst))))

which both return (1 2 3 4 5 6 7 8 9 0) and the append expression is faster than the reverse cons reverse one.
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nth or car?
« Reply #19 on: May 09, 2009, 09:06:21 AM »
gile did the "home work" :-)
Thanks
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.

cyberiq

  • Guest
Re: nth or car?
« Reply #20 on: May 12, 2009, 11:31:50 AM »
Hi,

You can find a little extra comments on this issue at the following adress:

http://discussion.autodesk.com/forums/thread.jspa?messageID=6141668&tstart=0

Regards

curmudgeon

  • Newt
  • Posts: 194
Re: nth or car?
« Reply #21 on: May 15, 2009, 03:52:36 PM »
thanks again guys. gile, I have no excuse, what you reported as "right" with the append version is exactly the syntax I had intended to be typing. sorry. horse, I read the thread you supplied entire. the speed tests were also very interesting.
 8-)
Never express yourself more clearly than you are able to think.