Author Topic: Divide List  (Read 5121 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Divide List
« Reply #15 on: June 06, 2009, 03:43:57 PM »
Michael, could the speed not be improved by adding a simple:

Code: [Select]
(DivideList
           '(1 2 3 4 5 6 7 8 9)
           [color=red](function[/color] (lambda (x) (zerop (rem x 3))))
        )
    )

Significantly:

Code: [Select]
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (_SUBDIVIDE (QUOTE (1 2 3 4 5 6 7 8 ...).....1466 / 1.16 <fastest>
    (DIVIDELIST (QUOTE (1 2 3 4 5 6 7 8 ...).....1700 / 1.00 <slowest> [color=green];; (function (lambda ...)) form[/color]

Still prefer the non quoted form myself. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Divide List
« Reply #16 on: June 06, 2009, 07:49:50 PM »
I only mentioned it 'cause I saw VovKa say a bit about using it in another thread on here...   ^-^

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Divide List
« Reply #17 on: June 08, 2009, 09:20:03 AM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Divide List
« Reply #18 on: June 08, 2009, 04:50:23 PM »
someone needs a recursion?
Code: [Select]
(defun test (lst fun)
  (if lst
    ((lambda (rest)
       (if (fun (car lst))
(list (cons (car lst) (car rest)) (cadr rest))
(list (car rest) (cons (car lst) (cadr rest)))
       )
     )
      (test (cdr lst) fun)
    )
    '(nil nil)
  )
)
;;;(test '(1 2 3 4 5 6 7 8 9) (lambda (x) (zerop (rem x 3))))

WARNING!
It is slow...

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Divide List
« Reply #19 on: June 08, 2009, 06:59:14 PM »
I'm not sure if I am correct in my thinking, but I always try to limit my use of recursive methods to very small tasks, like, for example (something I got from Gile a think...):

Code: [Select]
(defun lst->pt (lst)
  (if lst
    (cons (list (car lst) (cadr lst) (caddr lst))
          (lst->pt (cdddr lst)))))

As I've heard that recursive methods have a limit that is the stack memory.