Author Topic: Remove-if ... etal  (Read 3775 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Remove-if ... etal
« on: March 12, 2009, 12:02:06 AM »
A sort of challenge ..

(vl-directory-files .... includes  ("." ".." etc if the folder is not a root drive

To remove these strings if existing I tried these

 ... any others ??

Code: [Select]

(defun _test01 ()
  (setq bom:ParentFolder "F:\\WDT-BOM-Data"
        Folders          (vl-remove-if (function (lambda (g) (or (= g ".") (= g ".."))))
                                       (vl-directory-files bom:ParentFolder NIL -1)
                         )
  )
)
(defun _test02 ()
  (setq bom:ParentFolder "F:\\WDT-BOM-Data"
        Folders          (vl-remove ".." (vl-remove "." (vl-directory-files bom:ParentFolder NIL -1)))
  )
 
)
(defun _test03 ()
  (setq bom:ParentFolder "F:\\WDT-BOM-Data"
        Folders          (if (= "." (car (setq Folders (vl-directory-files bom:ParentFolder NIL -1))))
                           (if (= ".." (car (setq Folders (cdr Folders))))
                             (setq Folders (cdr Folders))
                           )
                         )
  )
)


Quote
(benchMark '((_test01) (_test02) (_test03)))
Benchmarking [M.P. 2005] .........Elapsed milliseconds for 64 iteration(s)/ relative Timing :

    (_TEST02).....796 / 1.0845 <slowest>
    (_TEST01).....766 / 1.0436
    (_TEST03).....734 / 1 <fastest>

edit: clumsy and stupid
« Last Edit: March 12, 2009, 12:34:16 AM by kdub@wdt »
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.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #1 on: March 12, 2009, 12:08:37 AM »


... and does anyone know for definite if there is ever only ONE elipsis returned or always either NONE or TWO ??

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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #2 on: March 12, 2009, 12:22:02 AM »
Sorry, I don't know the answer to your last question and I can't run AutoCAD right now to find out.

Untested but what if you use the member function (member g '("." "..")) in _test01 instead of the or construct? It's fewr function calls than the other variants so it might bench faster.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #3 on: March 12, 2009, 12:32:21 AM »


good thought ..  close to the money :)
Code: [Select]
(defun _test04 ()
  (setq bom:ParentFolder "F:\\WDT-BOM-Data"
        Folders          (vl-remove-if (function (lambda (g) (member g '("." "..") )))
                                       (vl-directory-files bom:ParentFolder NIL -1)
                         )
  )
)

Quote
(benchMark '((_test01) (_test02) (_test03) (_test04)))

Benchmarking [M.P. 2005] .........Elapsed milliseconds for 64 iteration(s)/ relative Timing :

    (_TEST04).....797 / 1.0858 <slowest>
    (_TEST03).....781 / 1.064
    (_TEST02).....765 / 1.0422
    (_TEST01).....734 / 1 <fastest>
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #4 on: March 12, 2009, 12:35:56 AM »
Great, the worst. So much for that idea <facepalm>.

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #5 on: March 12, 2009, 12:37:23 AM »
Great, the worst. So much for that idea <facepalm>.





but it's only 'worse' by a poofteenth   :)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #6 on: March 12, 2009, 12:39:43 AM »
Worse by 8.6%. That ain't poofteenth.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #7 on: March 12, 2009, 12:55:15 AM »
If memory serves me you'll always get the "." ".." if the directory location is not the root folder, but I'm assuming vl-directory-files behavior mirrors that of the DOS dir command.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #8 on: March 12, 2009, 01:07:37 AM »
Code: [Select]
(defun _test? ()
    (setq
        bom:ParentFolder "F:\\WDT-BOM-Data"
        Folders          (if (member ".." (setq Folders (vl-directory-files bom:ParentFolder NIL -1)))
                             (cddr Folders)
                             Folders
                         )
    )
)

untested but ... if the "." ".." always appear in the noted order (and always first in the list) then the above should work.
« Last Edit: March 12, 2009, 01:11:28 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #9 on: March 12, 2009, 01:12:47 AM »

Thanks Michael,
I'm doing an animated stepthrough at the moment so I'll try that option as soon as the process is finished.
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #10 on: March 12, 2009, 01:18:21 AM »
You're welcome KB. I gotta crash here pretty quick so I won't see the results 'til tomorrow, but thanks for the opportunity to pitch a few ideas.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Remove-if ... etal
« Reply #11 on: March 12, 2009, 04:55:29 AM »
On the old box at home .....

Code: [Select]

(defun _test01 ()
  (setq bom:ParentFolder "F:\\_Develop"
        Folders          (vl-remove-if (function (lambda (g) (or (= g ".") (= g ".."))))
                                       (vl-directory-files bom:ParentFolder NIL -1)
                         )
  )
)
(defun _test02 ()
  (setq bom:ParentFolder "F:\\_Develop"
        Folders          (vl-remove ".." (vl-remove "." (vl-directory-files bom:ParentFolder NIL -1)))
  )
 
)
(defun _test03 ()
  (setq bom:ParentFolder "F:\\_Develop"
        Folders          (if (= "." (car (setq Folders (vl-directory-files bom:ParentFolder NIL -1))))
                           (if (= ".." (car (setq Folders (cdr Folders))))
                             (setq Folders (cdr Folders))
                           )
                         )
  )
)
(defun _test04 ()
  (setq bom:ParentFolder "F:\\_Develop"
        Folders          (vl-remove-if (function (lambda (g) (member g '("." "..") )))
                                       (vl-directory-files bom:ParentFolder NIL -1)
                         )
  )
)

(defun _test05 ()
    (setq
        bom:ParentFolder "F:\\_Develop"
        Folders          (if (member ".." (setq Folders (vl-directory-files bom:ParentFolder NIL -1)))
                             (cddr Folders)
                             Folders
                         )
    )
)
(defun _test06 ()
    (setq bom:ParentFolder "F:\\_Develop")
    (if (= ".." (cadr (setq Folders (vl-directory-files bom:ParentFolder NIL -1))))
        (setq Folders (cddr Folders))
    )
)

Quote

Benchmarking [M.P. 2005] .............Elapsed milliseconds for 1024 iteration(s)/ relative Timing :

    (_TEST04).....500 / 1.0684 <slowest>
    (_TEST01).....484 / 1.0342
    (_TEST02).....469 / 1.0021
    (_TEST03).....469 / 1.0021
    (_TEST05).....469 / 1.0021
    (_TEST06).....468 / 1 <fastest>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Remove-if ... etal
« Reply #12 on: March 12, 2009, 10:08:18 AM »
:D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Remove-if ... etal
« Reply #13 on: March 12, 2009, 02:19:09 PM »
Kerry,

What kind of speed does this have?

Code: [Select]
(defun subfolders (path / folder fs lst subs)
  (setq fs (vlax-create-object "Scripting.FileSystemObject"))
  (if (and (setq folder (vlax-invoke fs 'getfolder path))
           (setq subs (vlax-get folder 'subfolders))
      )
    (vlax-for sub subs (setq lst (cons (vlax-get sub 'Path) lst)))
  )
  (vlax-release-object fs)
  (reverse lst)
)
(subfolders "C:\\")

Nevermind  :ugly:

    (_TEST03)........1500 / 3.47 <fastest>
    (_TEST05)........1515 / 3.43
    (_TEST02)........1516 / 3.43
    (_TEST06)........1516 / 3.43
    (_TEST01)........1578 / 3.30
    (_TEST04)........1578 / 3.30
    (SUBFOLDERS).....5203 / 1.00 <slowest>
« Last Edit: March 12, 2009, 02:50:31 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Remove-if ... etal
« Reply #14 on: March 12, 2009, 02:36:30 PM »
Code: [Select]
(defun _test07 ()
  (setq bom:ParentFolder "C:\\Program Files")
  (if (> (strlen bom:ParentFolder) 3)
    (cddr (vl-directory-files bom:ParentFolder NIL -1))
    (vl-directory-files bom:ParentFolder NIL -1)
  )
)
03 and 06 do not work for the root