Author Topic: vl-some one?  (Read 7446 times)

0 Members and 1 Guest are viewing this topic.

Sdoman

  • Guest
vl-some one?
« on: November 26, 2005, 10:40:10 AM »
Question:

What does the vl-some function do and how would you use it?

I just came across this function and don't understand the help file. Thanks!
 

LE

  • Guest
Re: vl-some one?
« Reply #1 on: November 26, 2005, 10:56:42 AM »
VL-SOME is useful, to find a value and stop without continue evaluating.... [plain-english I think]

i.e.:

- You, have a file with all your project paths
- From that you make a list of paths
- Then you look for the drawing "test.dwg"
- Let say the paths list is of 100 items and "test.dwg" is in the path item 4
- With vl-some we can do the follwing and stop, at the moment the path correspond to your file.

HTH


Code: [Select]
;; projectpaths.txt
;;
;; C:\routines\
;; M:\_standard\3Blocks\04Mason\Stone\
;; C:\test\__AEC\AR\B\ARCH\
;; etc....

;; usage: (file-finder [file name] [extension] [list of paths])
;; return: full path and file name
;;
;; if no extension is provided by default uses: ".dwg"
;;
;; (file-finder
;;   "test"
;;   ".dwg"
;;   '("C:\\routines\\" "M:\\Blocks\\Stone\\" "C:\\test\\"))
;;
;; "C:\\routines\\test.dwg"
;;
(defun file-finder  (FileName Ext OfficePaths)
  (vl-some
    '(lambda (Path)
       (findfile (strcat Path
    (vl-filename-base FileName)
    (cond (Ext)
          (".dwg")))))
    OfficePaths))

Sdoman

  • Guest
Re: vl-some one?
« Reply #2 on: November 26, 2005, 11:18:55 AM »
Thanks LE!  Good example. 

So if I understand correctly, the first argument to vl-some is a test function to be applied to the second argument which is a list of values.  Vl-some passes the first element of the list to the test function and if the result is not-nill then stops.  Otherwise, it passes the next element of the list and so one until the end of the list.

The help file hinted that more then one list could be supplied.  Can you or anyone show an example using two or more lists please?

Thanks!

LE

  • Guest
Re: vl-some one?
« Reply #3 on: November 26, 2005, 11:33:43 AM »
Thanks LE!  Good example. 

So if I understand correctly, the first argument to vl-some is a test function to be applied to the second argument which is a list of values.  Vl-some passes the first element of the list to the test function and if the result is not-nill then stops.  Otherwise, it passes the next element of the list and so one until the end of the list.

The help file hinted that more then one list could be supplied.  Can you or anyone show an example using two or more lists please?

Thanks!

Yes.... I have more functions using vl-some.... I'll tried to post some more.... later

Fatty

  • Guest
Re: vl-some one?
« Reply #4 on: November 26, 2005, 12:34:18 PM »
Quote

Yes.... I have more functions using vl-some.... I'll tried to post some more.... later

I think there are two very interesting themes begin owing to following functions:
'vl-some'
and
'vl-every'
which considerably accelerate processing and sorting of lists that are used
My highest gratitude if you shine this dark side of the Moon

Thank you,

Regards,

Fatty

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vl-some one?
« Reply #5 on: November 26, 2005, 01:22:32 PM »
It's about halting execution as soon as futher processing is superfluous.

Consider these quasi equivalents ...

Code: [Select]
(defun some ( foop lst / result )
    (if (listp foop) (setq foop (eval foop)))
    (vl-catch-all-apply
       '(lambda ( )
            (foreach x lst
                (if (foop x)
                    (progn
                        (setq result t)
                        (exit)
                    )
                )
            )
        )   
    )
    result
)

(defun every ( foop lst / failed )
    (if (listp foop) (setq foop (eval foop)))
    (vl-catch-all-apply
       '(lambda ( )
            (foreach x lst
                (if (null (foop x))
                    (progn
                        (setq failed t)
                        (exit)
                    )
                )
            )
        )   
    )
    (null failed)
)

Examples ...

Code: [Select]
(some
   '(lambda (x) (eq 'str (type x)))
   '("a" "b" 42 "d" "e")
)

And ...

Code: [Select]
(every
   '(lambda (x) (eq 'str (type x)))
   '("a" "b" 42 "d" "e")
)

:)

Edit: Fixed error in 'some' definition.
« Last Edit: November 27, 2005, 08:59:41 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Fatty

  • Guest
Re: vl-some one?
« Reply #6 on: November 26, 2005, 01:53:06 PM »
Hi MP

Undoubtedly, your teacher is the great person, and,
it is true, that you are worthy the teacher
I hope in 20 years I shall reach the same level as you now

Regards,

Fatty

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vl-some one?
« Reply #7 on: November 26, 2005, 01:55:24 PM »
I should have used better examples, maybe these are more illuminating.

Code: [Select]
(some
   '(lambda (x) (print x) (eq 'str (type x)))
   '("a" "b" 42 "d" "e")
)

And ...

Code: [Select]
(every
   '(lambda (x) (print x) (eq 'str (type x)))
   '("a" "b" 42 "d" "e")
)

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

LE

  • Guest
Re: vl-some one?
« Reply #8 on: November 26, 2005, 02:00:45 PM »
Code: [Select]
(defun some  (l / term)
  (mapcar '(lambda (x)
     (if x
       (setq term t)))
  l)
  term)

To verify if a point PT is part of list of points LST

Code: [Select]
(some
    (mapcar '(lambda (x)
       (and (equal (car x) (car pt) 0.0001)
    (equal (cadr x) (cadr pt) 0.0001)
    (equal (caddr x) (caddr pt) 0.0001)))
    lst))

Same as using built-in vl-some function

Code: [Select]
(vl-some '(lambda (x)
       (and (equal (car x) (car pt) 0.0001)
    (equal (cadr x) (cadr pt) 0.0001)
    (equal (caddr x) (caddr pt) 0.0001))) lst)

Sdoman

  • Guest
Re: vl-some one?
« Reply #9 on: November 26, 2005, 02:11:58 PM »
Thanks for the excellent samples and explanations everyone.

As for using vl-some with more than one list, I figure that the test function should be designed to accept the nth element of each list.  Like mapcar:

Code: [Select]
(mapcar '(lambda (x y z) ...do something with x y z...)) (list1) (list2)(list3) )
Fatty:  You are good teacher too! I like reading your comments.
 

LE

  • Guest
Re: vl-some one?
« Reply #10 on: November 26, 2005, 02:17:38 PM »
Steve,

I have not forgot about the list's usage with vl-some.... I am in another channel right now.... [arx]...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vl-some one?
« Reply #11 on: November 26, 2005, 02:17:58 PM »
Hi MP

Undoubtedly, your teacher is the great person, and,
it is true, that you are worthy the teacher
I hope in 20 years I shall reach the same level as you now

Regards,

Fatty

"Necessity is the mother of invention" and "The school of hard knocks is a good teacher".

Thank you Oleg but I am not worthy this praise and I have seen your coding kind sir -- you can hold your own against anyone including me.

:)
« Last Edit: November 26, 2005, 05:07:16 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Fatty

  • Guest
Re: vl-some one?
« Reply #12 on: November 26, 2005, 02:51:17 PM »
Quote
........................

Hi Steve

Thanks for your approval...
Do not confuse me, I am unworthy such awards among greater men, I try to help, but it not each time turns out successfully

Have a good one

Fatty

Fatty

  • Guest
Re: vl-some one?
« Reply #13 on: November 27, 2005, 02:33:06 AM »
I thank you LE and MP for fine examples of functions vl-some and vl-every
It was the nice classical lecture on this theme

Fatty

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vl-some one?
« Reply #14 on: November 27, 2005, 08:57:44 AM »
I don't know if anyone had tried my examples but there was an error in the 'some' definition. It has been corrected. My apologies if this confused anyone.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst