(vl-every (function... vss (vl-some ~(function...

Discussion in 'AutoCAD' started by David Kozina, Jul 21, 2004.

  1. David Kozina

    David Kozina Guest

    Does anyone know if there are performance issues with vl-every compared with
    vl-some?

    If I understand the help files correctly, (vl-every tests all the elements
    in a list, and afterwards tells you what it found, whereas (vl-some stops as
    soon as a test returns T.

    Would this indicate that a test using vl-every ought to be avoided when
    possible and would be better replaced with an opposite test using vl-some?

    I am trying to determine if a list is composed of strings.
    I have a function 'djkStringP that returns T if the argument is a 'STR type,
    nil otherwise.

    In this case, would it be better to use:

    (vl-every
    '(lambda (ele)
    (djkStringP ele)
    )
    _lst
    )

    OR:

    (vl-some
    '(lambda (ele)
    (not (djkStringP ele))
    )
    )
    _lst
    )

    OR would something else be even better?

    Any suggestions? Comments regarding this issue?

    Best regards,
    David Kozina
     
    David Kozina, Jul 21, 2004
    #1
  2. David Kozina

    David Kozina Guest

    Curses! foiled again! Logic problems always seem to mess up my mind. :)
    How 'bout:

    (not
    (vl-some
    '(lambda (ele)
    (not (djkStringP ele))
    )
    _lst
    )
    )
     
    David Kozina, Jul 21, 2004
    #2
  3. David - I was wondering about this too - so I tried out this code:

    (defun c:tmp ( / lst)
    ;(setq lst (list 0 1 2 3 4 5 "6" 7 8 9 10))
    ;(setq lst nil)
    (setq lst (list "0" "1" "2" "3" "4" "5" 6 "7" "8" "9" "10"))
    (princ "\nvl-every: ")
    (princ
    (vl-every '(lambda (at)
    (princ "\n")
    (princ at)
    (numberp at)
    )
    lst
    )
    )
    (princ "\nvl-some: ")
    (princ
    (vl-some '(lambda (at)
    (princ "\n")
    (princ at)
    (numberp at)
    )
    lst
    )
    )
    (princ))

    For the first list:

    vl-every:
    0
    1
    2
    3
    4
    5
    6nil
    vl-some:
    0T

    for the third:

    vl-every:
    0nil
    vl-some:
    0
    1
    2
    3
    4
    5
    6T

    and - watch out - the second list (= nil) returns:

    vl-every: T
    vl-some: nil

    (this result is docuemented for vl-every help)

    So - the help description for vl-every is either misleading or wrong - vl-every stops as soon as it finds a nil value (unless the list itself is nil)

    Therefore, it would seem that in your case that the vl-every function is the most appropriate.

    Peter
     
    petersciganek, Jul 22, 2004
    #3
  4. David Kozina

    John Uhden Guest

    Command: (defun stringp (item)(= (type item) 'STR))
    STRINGP

    Command: (vl-every 'stringp '("a" "b" "c" "d"))
    T

    Command: (vl-every 'stringp '("a" "b" "c" "d" 1))
    nil

    Command: (vl-remove-if 'stringp '("a" 1 "b" 2 "c" 3))
    (1 2 3)

    Command: (vl-remove-if-not 'stringp '("a" 1 "b" 2 "c" 3))
    ("a" "b" "c")
     
    John Uhden, Jul 22, 2004
    #4
  5. David Kozina

    David Kozina Guest

    John,

    Thanks for demonstrating how to simplify things.
    I seem to have a lot of difficulties with that.

    Best regards,
    David Kozina
     
    David Kozina, Jul 23, 2004
    #5
  6. David Kozina

    David Kozina Guest

    Peter,

    Thanks very much for the goods on vl-every.
    Looks like it'll work fine for what I'm trying to do.

    Vl-every is kind of like a beefed up AND statement, and
    vl-some like a beefed up OR statement, then, right?

    Best regards,
    David Kozina


    vl-every stops as soon as it finds a nil value (unless the list itself is
    nil)
     
    David Kozina, Jul 23, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.