TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: csgoh on August 03, 2015, 06:20:57 AM

Title: null string in list
Post by: csgoh on August 03, 2015, 06:20:57 AM
I have say a list ("" "" "" "" "").
How to check if all the items in a list is null string.
thank you.

Title: Re: null string in list
Post by: roy_043 on August 03, 2015, 06:42:01 AM
Here is one way:
Code - Auto/Visual Lisp: [Select]
  1. (setq lst '("" "" "" ""))
  2. (not (vl-remove "" lst)) => T
Title: Re: null string in list
Post by: AIberto on August 03, 2015, 07:23:52 AM
csgoh

if list ("" "" "" "" "") you want returns T ,
list  ("" "1" "" "" "") you want returns T or nil ?
Title: Re: null string in list
Post by: ronjonp on August 03, 2015, 09:21:13 AM
Here's some more for fun.  :)
Code - Auto/Visual Lisp: [Select]
  1. (setq l '("" "" "" ""))
  2.  
  3.  
  4. (vl-every '(lambda (x) (and (= (type x) 'str) (= x ""))) l)
  5.  
  6.  
  7.  
  8.  
  9. (= "" (apply 'strcat l))
  10.  
  11.  
  12. (zerop (apply '+ (mapcar 'strlen l)))
Title: Re: null string in list
Post by: ribarm on August 03, 2015, 09:30:42 AM
Based on Roy's example - for more general purposes :

Code - Auto/Visual Lisp: [Select]
  1. ;; (eqellst '(10.0 10.0 10.0) 10.0 1e-6) => T
  2. ;; (eqellst '(10.0 10.0 10.0) 1.0 1e-6) => nil
  3. ;; (eqellst '(10.0 10.0 1.0) 10.0 1e-6) => nil
  4.  
  5. (defun eqellst ( l el f )
  6.   (while
  7.     (vl-some
  8.       (function
  9.         (lambda ( x )
  10.           (if (equal el x f)
  11.             (setq l
  12.               (vl-remove-if
  13.                 (function
  14.                   (lambda ( x )
  15.                     (equal el x f)
  16.                   )
  17.                 )
  18.                 l
  19.               )
  20.             )
  21.           )
  22.         )
  23.       )
  24.       l
  25.     )
  26.   )
  27.   (zerop (length l))
  28. )
  29.  
Title: Re: null string in list
Post by: roy_043 on August 03, 2015, 10:12:40 AM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every '= (cons "" lst) lst)
Title: Re: null string in list
Post by: Tharwat on August 03, 2015, 12:32:34 PM
Contrary way  :-D

Code - Auto/Visual Lisp: [Select]
  1. (setq l '("" "" "" ""))
  2. (not (vl-some '(lambda (u) (/= u "")) l))
  3.  
Title: Re: null string in list
Post by: Lee Mac on August 03, 2015, 12:50:25 PM
Another, just for variation:
Code - Auto/Visual Lisp: [Select]
  1. (defun f ( l ) (or (not l) (and (= "" (car l)) (f (cdr l)))))
  2. _$ (f '("" ""))
  3. T
Title: Re: null string in list
Post by: Lee Mac on August 03, 2015, 12:56:13 PM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every '= (cons "" lst) lst)

Very good roy.
Title: Re: null string in list
Post by: Keith™ on August 03, 2015, 01:08:14 PM
Wouldn't this work, just to determine if it is in the list?

Code: [Select]
(if (member "" lst) T)

NOTE: I am not where I can test it
Title: Re: null string in list
Post by: Tharwat on August 03, 2015, 01:13:28 PM
Wouldn't this work, just to determine if it is in the list?

Code: [Select]
(if (member "" lst) T)

NOTE: I am not where I can test it

That checks for one item and the OP wants to check all the items in a list  :wink:
Title: Re: null string in list
Post by: 77077 on August 03, 2015, 01:21:46 PM
Another, just for variation:
Code - Auto/Visual Lisp: [Select]
  1. (defun f ( l ) (or (not l) (and (= "" (car l)) (f (cdr l)))))
  2. _$ (f '("" ""))
  3. T

Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1"  "a") returns T
Title: Re: null string in list
Post by: Lee Mac on August 03, 2015, 01:55:48 PM
Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1"  "a") returns T

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun f ( x ) (equal x '("1" "s1" "a")))
  2. _$ (f '("1" "s1" "a"))
  3. T
Title: Re: null string in list
Post by: roy_043 on August 03, 2015, 04:56:54 PM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every '= (cons "" lst) lst)

Very good roy.
Thanks.

@ ANJALI: If you want to check for the absence of empty strings you should try Keith's contribution. His code checks for the opposite, but that can easily be fixed...
Title: Re: null string in list
Post by: bruno_vdh on August 03, 2015, 05:22:18 PM
Hello,
Quote
I have say a list ("" "" "" "" "").
My variant
Code: [Select]
(apply '= (cons "" lst))

Regards,
Title: Re: null string in list
Post by: csgoh on August 03, 2015, 11:08:25 PM
Thank you all for the contribution.
cheers
Title: Re: null string in list
Post by: 77077 on August 04, 2015, 12:01:21 AM
Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1"  "a") returns T

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun f ( x ) (equal x '("1" "s1" "a")))
  2. _$ (f '("1" "s1" "a"))
  3. T

Thanks Lee,
Title: Re: null string in list
Post by: 77077 on August 04, 2015, 12:03:53 AM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every '= (cons "" lst) lst)

Very good roy.
Thanks.

@ ANJALI: If you want to check for the absence of empty strings you should try Keith's contribution. His code checks for the opposite, but that can easily be fixed...

Roy, Thank you. useful
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 04, 2015, 12:33:51 AM
another:
Code: [Select]
(setq l '("" "" "" ""))
(eq (strlen (vl-princ-to-string l)) (1+ (length l)))
or
(and (eq "" (car l)) (equal l (acad_strlsort l)))
Title: Re: null string in list
Post by: roy_043 on August 04, 2015, 05:21:33 AM
My variant
Code: [Select]
(apply '= (cons "" lst))
Nice! Very succinct and using 'Classic' Lisp only.
Title: Re: null string in list
Post by: bruno_vdh on August 04, 2015, 05:41:27 AM
Nice! Very succinct and using 'Classic' Lisp only.
Yes, thank you
I'm surprised it is not written on TheSwamp

 = function alone is sufficient,
Code: [Select]
_$ (= "" "" "" "")
T
_$ (= "" 2 ABC T)
nil

Regards,
(Ps: roy_043, congratulation your solution with vl-every is very efficient)
Title: Re: null string in list
Post by: Keith™ on August 04, 2015, 08:35:39 AM
Nice! Very succinct and using 'Classic' Lisp only.
Yes, thank you
I'm surprised it is not written on TheSwamp

 = function alone is sufficient,
Code: [Select]
_$ (= "" "" "" "")
T
_$ (= "" 2 ABC T)
nil

Regards,
(Ps: roy_043, congratulation your solution with vl-every is very efficient)


But it is written on TheSwamp :-) You just added it ...

Incidentally,

Code: [Select]
_$ (= "a" "a" "a" "a")
T
Title: Re: null string in list
Post by: bruno_vdh on August 04, 2015, 09:36:09 AM
Incidentally,

Code: [Select]
_$ (= "a" "a" "a" "a")
T

Sorry Keith, translator problem
I thought I explained why (apply '= (cons "" lst)), work in all cases
Code: [Select]
_$ (cons "" '("a" "a" "a" "a"))
("" "a" "a" "a" "a")
_$ (= "" "a" "a" "a" "a")
nil

Regards,
Title: Re: null string in list
Post by: JohnK on August 04, 2015, 09:55:06 AM
My first lisp in many years. Kinda fun (the code is kludgy but it was fun).

Code - Auto/Visual Lisp: [Select]
  1. (apply 'and (mapcar '(lambda (x) (eq (ascii x) 0)) '("" "" "")))
Title: Re: null string in list
Post by: JohnK on August 04, 2015, 10:17:31 AM
Oh, I made it smaller!? This one only checks to see if all entries are the same though.

Code - Auto/Visual Lisp: [Select]
  1. (apply '= (mapcar 'ascii '("" "" "")))
Title: Re: null string in list
Post by: JohnK on August 04, 2015, 10:27:39 AM
Hello,
Quote
I have say a list ("" "" "" "" "").
My variant
Code: [Select]
(apply '= (cons "" lst))

Regards,

That's nice.
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 04, 2015, 10:41:29 AM
for maniacs...

Code: [Select]
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....2000 / 3.6 <fastest>
    (VL-REMOVE1 ALIST).....2000 / 3.6
    (VL-EVERY12 ALIST).....2282 / 3.16
    (VL-EVERY12 ALIST).....2297 / 3.14
    (F ALIST)..............2375 / 3.03
    (F ALIST)..............2391 / 3.01
    (APPLY1 ALIST).........2547 / 2.83
    (APPLY1 ALIST).........2563 / 2.81
    (APPLY3 ALIST).........2672 / 2.7
    (APPLY3 ALIST).........2672 / 2.7
    (APPLY2 ALIST).........2719 / 2.65
    (APPLY2 ALIST).........2734 / 2.63
    (F2 ALIST).............2922 / 2.47
    (F2 ALIST).............2938 / 2.45
    (APPLY6 ALIST).........3156 / 2.28
    (APPLY6 ALIST).........3172 / 2.27
    (APPLY4 ALIST).........3375 / 2.13
    (APPLY4 ALIST).........3375 / 2.13
    (VL-SOME1 ALIST).......5516 / 1.31
    (VL-SOME1 ALIST).......5546 / 1.3
    (APPLY5 ALIST).........5656 / 1.27
    (APPLY5 ALIST).........5672 / 1.27
    (F3 ALIST).............6407 / 1.12
    (F3 ALIST).............6421 / 1.12
    (VL-EVERY1 ALIST)......7187 / 1
    (VL-EVERY1 ALIST)......7203 / 1 <slowest>

Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....1860 / 3.72 <fastest>
    (VL-REMOVE1 ALIST).....1875 / 3.69
    (VL-EVERY12 ALIST).....2140 / 3.23
    (VL-EVERY12 ALIST).....2141 / 3.23
    (F ALIST)..............2250 / 3.08
    (F ALIST)..............2250 / 3.08
    (APPLY1 ALIST).........2297 / 3.01
    (APPLY1 ALIST).........2313 / 2.99
    (APPLY3 ALIST).........2406 / 2.88
    (APPLY3 ALIST).........2422 / 2.86
    (APPLY2 ALIST).........2438 / 2.84
    (APPLY2 ALIST).........2469 / 2.8
    (F2 ALIST).............2750 / 2.52
    (F2 ALIST).............2765 / 2.5
    (APPLY6 ALIST).........2797 / 2.47
    (APPLY6 ALIST).........2797 / 2.47
    (APPLY4 ALIST).........3000 / 2.31
    (APPLY4 ALIST).........3016 / 2.3
    (APPLY5 ALIST).........5218 / 1.33
    (APPLY5 ALIST).........5250 / 1.32
    (VL-SOME1 ALIST).......5265 / 1.31
    (VL-SOME1 ALIST).......5266 / 1.31
    (F3 ALIST).............6016 / 1.15
    (F3 ALIST).............6032 / 1.15
    (VL-EVERY1 ALIST)......6875 / 1.01
    (VL-EVERY1 ALIST)......6922 / 1 <slowest>
Code: [Select]
(defun apply1 (lst) (apply '= (cons "" lst)))
(defun vl-remove1 (lst) (not (vl-remove "" lst)))
(defun vl-every1 (l) (vl-every '(lambda (x) (and (= (type x) 'str) (= x ""))) l))
(defun apply2 (l) (zerop (strlen (apply 'strcat l))))
(defun apply3 (l) (= "" (apply 'strcat l)))
(defun apply4 (l) (zerop (apply '+ (mapcar 'strlen l))))
(defun vl-every12 (lst) (vl-every '= (cons "" lst) lst))
(defun vl-some1 (l) (not (vl-some '(lambda (u) (/= u "")) l)))
(defun f ( l ) (or (not l) (and (= "" (car l)) (f (cdr l)))))
(defun f2 (l) (eq (strlen (vl-princ-to-string l)) (1+ (length l))))
(defun f3 (l) (and (eq "" (car l)) (equal l (acad_strlsort l))))
(defun apply5 (l) (apply 'and (mapcar '(lambda (x) (eq (ascii x) 0)) l)))
(defun apply6 (l) (apply '= (mapcar 'ascii l)))
  :crazy2:
Title: Re: null string in list
Post by: bruno_vdh on August 04, 2015, 11:20:21 AM
That's nice.
Thank you
Title: Re: null string in list
Post by: ElpanovEvgeniy on August 04, 2015, 11:39:57 AM
additional variant:
Code - Auto/Visual Lisp: [Select]
  1. (defun eea (l) (vl-every (function =) (cons "" l) l))
Title: Re: null string in list
Post by: ElpanovEvgeniy on August 04, 2015, 11:46:50 AM
sorry this option is already there.  :-)

Code - Auto/Visual Lisp: [Select]
  1. (defun vl-every12 (lst) (vl-every '= (cons "" lst) lst))
Title: Re: null string in list
Post by: Lee Mac on August 04, 2015, 12:24:38 PM
Oh, I made it smaller!? This one only checks to see if all entries are the same though.

Code - Auto/Visual Lisp: [Select]
  1. (apply '= (mapcar 'ascii '("" "" "")))

A slight tweak would suit the task  :wink:
Code - Auto/Visual Lisp: [Select]
  1. (vl-every 'zerop (mapcar 'ascii '("" "" "")))
Title: Re: null string in list
Post by: Lee Mac on August 04, 2015, 01:30:52 PM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun f4 ( l )
  2.     (not (while (= "" (car l)) (setq l (cdr l))))
  3. )
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 04, 2015, 04:32:35 PM
slover:
Code: [Select]
(defun f5 (l) (if (= "" (car l)) (= "" (last (vl-sort l '=)))))
Code: [Select]
(setq alist '("" "" "" ""))
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....1719 / 1.29 <fastest>
    (VL-REMOVE1 ALIST).....1734 / 1.28
    (F4 ALIST).............1938 / 1.14
    (F4 ALIST).............1969 / 1.13
    (VL-EVERY12 ALIST).....2015 / 1.1
    (VL-EVERY12 ALIST).....2016 / 1.1
    (APPLY1 ALIST).........2047 / 1.08
    (APPLY1 ALIST).........2047 / 1.08
    (F ALIST)..............2093 / 1.06
    (F ALIST)..............2125 / 1.04
    (F5 ALIST).............2125 / 1.04
    (APPLY3 ALIST).........2125 / 1.04
    (F5 ALIST).............2125 / 1.04
    (APPLY3 ALIST).........2141 / 1.04
    (APPLY2 ALIST).........2203 / 1.01
    (APPLY2 ALIST).........2219 / 1 <slowest>
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST).....1765 / 1.31 <fastest>
    (VL-REMOVE1 ALIST).....1766 / 1.31
    (F4 ALIST).............1969 / 1.17
    (VL-EVERY12 ALIST).....2031 / 1.14
    (F4 ALIST).............2046 / 1.13
    (VL-EVERY12 ALIST).....2047 / 1.13
    (APPLY1 ALIST).........2109 / 1.1
    (APPLY1 ALIST).........2110 / 1.1
    (F ALIST)..............2140 / 1.08
    (F5 ALIST).............2171 / 1.07
    (F ALIST)..............2188 / 1.06
    (F5 ALIST).............2188 / 1.06
    (APPLY3 ALIST).........2188 / 1.06
    (APPLY3 ALIST).........2203 / 1.05
    (APPLY2 ALIST).........2265 / 1.02
    (APPLY2 ALIST).........2313 / 1 <slowest>
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 04, 2015, 05:21:33 PM
Code: [Select]
(defun f6 (l) (if (= "" (car l)) (not (while (vl-position "" (setq l (cdr l)))))))
Code: [Select]
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST2).....1703 / 1.29 <fastest>
    (F6 ALIST2).............1875 / 1.17
    (F4 ALIST2).............1953 / 1.13
    (VL-EVERY12 ALIST2).....1969 / 1.12
    (APPLY1 ALIST2).........2078 / 1.06
    (APPLY3 ALIST2).........2140 / 1.03
    (APPLY2 ALIST2).........2203 / 1 <slowest>

Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST2)......1688 / 8.65 <fastest>
    (F6 ALIST2)..............1875 / 7.79
    (F4 ALIST2)..............1938 / 7.54
    (APPLY1 ALIST2)..........2031 / 7.19
    (APPLY2 ALIST2)..........2187 / 6.68
    (APPLY3 ALIST2).........12219 / 1.2
    (VL-EVERY12 ALIST2).....14609 / 1 <slowest>
Strange result on  VL-EVERY12 and APPLY3 on second test.
   
Title: Re: null string in list
Post by: Lee Mac on August 04, 2015, 05:27:29 PM
Code - Auto/Visual Lisp: [Select]
  1. _$ (f6 '("" "" "a"))
  2. T

;)
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 04, 2015, 05:29:15 PM
@Lee ok I take a look...

long list:
Code: [Select]
(setq alist '("" "" "" ""))
(setq alist2  alist)
(setq alist2 (repeat 200 (setq alist2 (append alist2 alist))))
Code: [Select]
Elapsed milliseconds / relative speed for 65536 iteration(s):
    (VL-REMOVE1 ALIST2)......1172 / 10.95 <fastest>
    (APPLY1 ALIST2)..........2328 / 5.51
    (VL-EVERY12 ALIST2)......4875 / 2.63
    (APPLY3 ALIST2)..........6094 / 2.11
    (APPLY2 ALIST2)..........6125 / 2.09
    (F6 ALIST2)..............8469 / 1.51
    (F4 ALIST2).............12828 / 1 <slowest>

Elapsed milliseconds / relative speed for 65536 iteration(s):
    (VL-REMOVE1 ALIST2)......1031 / 11.77 <fastest>
    (APPLY1 ALIST2)..........2094 / 5.8
    (VL-EVERY12 ALIST2)......4907 / 2.47
    (APPLY2 ALIST2)..........6094 / 1.99
    (APPLY3 ALIST2)..........6203 / 1.96
    (F6 ALIST2)..............8188 / 1.48
    (F4 ALIST2).............12140 / 1 <slowest>
Title: Re: null string in list
Post by: Lee Mac on August 04, 2015, 05:45:36 PM
Don't think we've had this one yet:
Code - Auto/Visual Lisp: [Select]
  1. (defun f7 ( x ) (eval (vl-list* '= "" x)))
Title: Re: null string in list
Post by: bruno_vdh on August 04, 2015, 06:21:19 PM
Don't think we've had this one yet:
Code - Auto/Visual Lisp: [Select]
  1. (defun f7 ( x ) (eval (vl-list* '= "" x)))

I have preferred him apply because eval evaluates arguments
Code: [Select]
_$ (setq A "")
""
_$ (= "" 'A 'A 'A)
nil
_$ (apply '= '("" A A A))
nil
_$ (eval  '(= "" A A A))
T

Regards,
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 05, 2015, 03:27:29 AM
Code: [Select]
(defun f6 (l) ;F4 like
  (if (= "" (car l))
    (while (= "" (car (setq l (cdr l)))))
  )
  (not l)
)
Code: [Select]
(setq alist '("" "" "" ""))
(setq alist2  alist)
(setq alist2 (repeat 20 (setq alist2 (append alist2 alist))))
Elapsed milliseconds / relative speed for 131072 iteration(s):
    (VL-REMOVE1 ALIST2).....1000 / 5.44 <fastest>
    (APPLY1 ALIST2).........1390 / 3.91
    (VL-EVERY12 ALIST2).....1875 / 2.9
    (APPLY3 ALIST2).........2093 / 2.6
    (APPLY2 ALIST2).........2157 / 2.52
    (F6 ALIST2).............3281 / 1.66
    (F4 ALIST2).............3406 / 1.6
    (F7 ALIST2).............5438 / 1 <slowest>
   
 
Elapsed milliseconds / relative speed for 131072 iteration(s):
    (VL-REMOVE1 ALIST2).....1047 / 5.3 <fastest>
    (APPLY1 ALIST2).........1468 / 3.78
    (VL-EVERY12 ALIST2).....1907 / 2.91
    (APPLY3 ALIST2).........2250 / 2.47
    (APPLY2 ALIST2).........2281 / 2.43
    (F6 ALIST2).............3422 / 1.62
    (F4 ALIST2).............3438 / 1.61
    (F7 ALIST2).............5547 / 1 <slowest>
Title: Re: null string in list
Post by: roy_043 on August 05, 2015, 04:28:12 AM
@ Marc'Antonio:
Your speed test is interesting but you only test with a list in which all elements are equal. If there is an alternate element halfway in the list the results will be quit different. For example, as bruno_vdh already hinted, solutions using (vl-every) will then perform relatively better.
Title: Re: null string in list
Post by: bruno_vdh on August 05, 2015, 06:17:26 AM
Good explanation of roy_043, if one is maniac in comparisons, we can add a condition to apply and every for a nil argument  :wink:
Code: [Select]
(and lst (vl-every '= (cons "" lst) lst))
(and lst (apply '= (cons "" lst)))

For the game, one last less powerful variant with vl-member-if-not
Code: [Select]
(defun f (l)
   (if l
     (not (vl-member-if-not '(lambda (x) (eq "" x)) l))
   )
 )

Regards,
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 05, 2015, 08:37:30 AM
Ok... new test:
Code: [Select]
(setq alist0 '(""  "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""))
(setq alistS '("1" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""))
(setq alistE '("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "1"))

Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-REMOVE1 ALIST0).....1828 / 3.8 <fastest>
    (APPLY1 ALIST0).........2312 / 3.01
    (VL-EVERY12 ALIST0).....2625 / 2.65
    (APPLY3 ALIST0).........2782 / 2.5
    (APPLY2 ALIST0).........2875 / 2.42
    (F6 ALIST0).............3985 / 1.74
    (F4 ALIST0).............4078 / 1.71
    (F_VDH ALIST0)..........6719 / 1.03
    (F7 ALIST0).............6953 / 1 <slowest>

Elapsed milliseconds / relative speed for 262144 iteration(s):
    (F4 ALISTS).............1657 / 4.04 <fastest>
    (F6 ALISTS).............1750 / 3.82
    (VL-REMOVE1 ALISTS).....1906 / 3.51
    (VL-EVERY12 ALISTS).....2000 / 3.34
    (APPLY1 ALISTS).........2047 / 3.27
    (APPLY2 ALISTS).........2953 / 2.26
    (APPLY3 ALISTS).........3125 / 2.14
    (F_VDH ALISTS)..........4672 / 1.43
    (F7 ALISTS).............6687 / 1 <slowest>

Elapsed milliseconds / relative speed for 131072 iteration(s):
    (VL-REMOVE1 ALISTE).....1110 / 3.27 <fastest>
    (APPLY1 ALISTE).........1125 / 3.22
    (VL-EVERY12 ALISTE).....1313 / 2.76
    (APPLY2 ALISTE).........1750 / 2.07
    (APPLY3 ALISTE).........1765 / 2.05
    (F6 ALISTE).............1797 / 2.02
    (F4 ALISTE).............1969 / 1.84
    (F7 ALISTE).............3484 / 1.04
    (F_VDH ALISTE)..........3625 / 1 <slowest>
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 05, 2015, 08:47:59 AM
Totals:
Code: [Select]
    (VL-REMOVE1 ALIST0).....1828 / 3.8 <fastest>
    (VL-REMOVE1 ALISTS).....1906 / 3.51
    (VL-REMOVE1 ALISTE).....1110 / 3.27 <fastest>
                     Total: 4844
    (APPLY1 ALIST0).........2312 / 3.01
    (APPLY1 ALISTS).........2047 / 3.27
    (APPLY1 ALISTE).........1125 / 3.22
                     Total: 5484
    (VL-EVERY12 ALIST0).....2625 / 2.65
    (VL-EVERY12 ALISTE).....1313 / 2.76
    (VL-EVERY12 ALISTS).....2000 / 3.34
                     Total: 5938
    (F6 ALIST0).............3985 / 1.74
    (F6 ALISTS).............1750 / 3.82
    (F6 ALISTE).............1797 / 2.02
                     Total: 7532
    (APPLY2 ALIST0).........2875 / 2.42
    (APPLY2 ALISTS).........2953 / 2.26
    (APPLY2 ALISTE).........1750 / 2.07
                     Total: 7578
    (APPLY3 ALIST0).........2782 / 2.5
    (APPLY3 ALISTS).........3125 / 2.14
    (APPLY3 ALISTE).........1765 / 2.05
                     Total: 7672
    (F4 ALIST0).............4078 / 1.71
    (F4 ALISTS).............1657 / 4.04 <fastest>
    (F4 ALISTE).............1969 / 1.84
                     Total: 7704
    (F_VDH ALIST0)..........6719 / 1.03
    (F_VDH ALISTE)..........3625 / 1 <slowest>
    (F_VDH ALISTS)..........4672 / 1.43
                     Total:15016
    (F7 ALIST0).............6953 / 1 <slowest>
    (F7 ALISTS).............6687 / 1 <slowest>
    (F7 ALISTE).............3484 / 1.04
                     Total:17124
Title: Re: null string in list
Post by: bruno_vdh on August 05, 2015, 09:49:52 AM
@ Marc'Antonio Alessi, thanks these comparisons are interesting, but I find it hard to do ..

alist0 = alistE – 1  Performance comparison
And if alistS very long and it is more difficult for the vl-remove function

Regards,
PS: A list is infinite, how can we say that the list is long?
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 05, 2015, 01:17:28 PM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun f4 ( l )
  2.     (not (while (= "" (car l)) (setq l (cdr l))))
  3. )
Comando: (f4 '("1" "" "" "" ""))
T
 :wink:
Title: Re: null string in list
Post by: Lee Mac on August 05, 2015, 04:07:10 PM
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun f4 ( l )
  2.     (not (while (= "" (car l)) (setq l (cdr l))))
  3. )
Comando: (f4 '("1" "" "" "" ""))
T
 :wink:

 :-(
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 05, 2015, 09:18:42 PM
@ Marc'Antonio Alessi, thanks these comparisons are interesting, but I find it hard to do ..

alist0 = alistE – 1  Performance comparison
And if alistS very long and it is more difficult for the vl-remove function

Regards,
PS: A list is infinite, how can we say that the list is long?
ok... other  tests:
Code: [Select]
(setq alist0 '(""  "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""))
(setq alist0 (repeat nn (setq alist0 (append alist0 alist0)))) ;nn max = 12
(setq alistS (append '("1") alist0 alist0))
(setq alistE (append alist0 alist0 '("1")))
(setq alistM (append alist0 '("1") alist0))
(setq alist0 (append '("")  alist0 alist0))

length: 8192
Elapsed milliseconds / relative speed for 16384 iteration(s):
    (VL-REMOVE1 ALIST0)......1969 / 16.92 <fastest>
    (APPLY1 ALIST0)..........4547 / 7.33
    (F2 ALIST0)..............6500 / 5.13
    (VL-EVERY12 ALIST0).....13000 / 2.56
    (APPLY3 ALIST0).........14281 / 2.33
    (APPLY2 ALIST0).........14391 / 2.31
    (F_VDH ALIST0)..........25625 / 1.3
    (F6 ALIST0).............33313 / 1 <slowest>

length: 32768
Elapsed milliseconds / relative speed for 4096 iteration(s):
    (VL-REMOVE1 ALIST0)......1610 / 7.15 <fastest>
    (APPLY1 ALIST0)..........4015 / 2.87
    (F2 ALIST0)..............6157 / 1.87
    (VL-EVERY12 ALIST0).....10875 / 1.06
    (APPLY2 ALIST0).........11500 / 1
    (APPLY3 ALIST0).........11516 / 1 <slowest>

length: 131073
Comando: (f7 alist0)
; errore: valore dell'argomento errato: does not fit in byte: 131073

Elapsed milliseconds / relative speed for 1024 iteration(s):
    (VL-REMOVE1 ALIST0)......1656 / 7.6 <fastest>
    (APPLY1 ALIST0)..........4234 / 2.97
    (VL-EVERY12 ALIST0).....11343 / 1.11
    (APPLY2 ALIST0).........11406 / 1.1
    (APPLY3 ALIST0).........11422 / 1.1
    (F2 ALIST0).............12578 / 1 <slowest>

length: 2049
Elapsed milliseconds / relative speed for 131072 iteration(s):
    (VL-EVERY12 ALISTS)......1109 / 28.32 <fastest>
    (APPLY1 ALISTS)..........2297 / 13.67
    (VL-REMOVE1 ALISTS)......4250 / 7.39
    (F2 ALISTS).............14937 / 2.1
    (APPLY2 ALISTS).........29297 / 1.07
    (APPLY3 ALISTS).........31406 / 1 <slowest>

length: 2049
    (VL-REMOVE1 ALISTE).....1234 / 7.64 <fastest>
    (APPLY1 ALISTE).........2657 / 3.55
    (F2 ALISTE).............4187 / 2.25
    (VL-EVERY12 ALISTE).....6594 / 1.43
    (APPLY2 ALISTE).........9375 / 1.01
    (APPLY3 ALISTE).........9422 / 1 <slowest>

length: 8193
Elapsed milliseconds / relative speed for 262144 iteration(s):
    (VL-EVERY12 ALISTS)......1985 / 48.43 <fastest>
    (APPLY1 ALISTS).........11875 / 8.1
    (VL-REMOVE1 ALISTS).....27015 / 3.56
    (F2 ALISTS).............96141 / 1 <slowest>

length: 8193
Elapsed milliseconds / relative speed for 16384 iteration(s):
    (VL-REMOVE1 ALISTE)......1688 / 6.56 <fastest>
    (APPLY1 ALISTE)..........4187 / 2.65
    (F2 ALISTE)..............6079 / 1.82
    (VL-EVERY12 ALISTE).....11078 / 1 <slowest>

length: 262145
Elapsed milliseconds / relative speed for 512 iteration(s):
    (VL-REMOVE1 ALIST0).....1609 / 2.55 <fastest>
    (APPLY1 ALIST0).........4109 / 1 <slowest>

Elapsed milliseconds / relative speed for 1024 iteration(s):
    (APPLY1 ALISTS).........1391 / 2.39 <fastest>
    (VL-REMOVE1 ALISTS).....3329 / 1 <slowest>

Elapsed milliseconds / relative speed for 512 iteration(s):
    (VL-REMOVE1 ALISTE).....1625 / 2.5 <fastest>
    (APPLY1 ALISTE).........4063 / 1 <slowest>

Elapsed milliseconds / relative speed for 512 iteration(s):
    (VL-REMOVE1 ALISTM).....1609 / 1.5 <fastest>
    (APPLY1 ALISTM).........2406 / 1 <slowest>
Title: Re: null string in list
Post by: bruno_vdh on August 06, 2015, 03:11:39 AM
Comprehensive testing, thank you for your sharing.
Regards,
Title: Re: null string in list
Post by: Marc'Antonio Alessi on August 06, 2015, 03:38:13 AM
 :-)
Title: Re: null string in list
Post by: bruno_vdh on August 06, 2015, 04:17:25 AM
length: 131073
Comando: (f7 alist0)
; errore: valore dell'argomento errato: does not fit in byte: 131073

Yes it is known and that's why I'm always very wary with the use of the eval function to replace apply.
3 reasons to be wary:


The symbolic arguments are evaluated 
Code: [Select]
$ (eval  (cons '=  '(A B C D)))
T
http://www.theswamp.org/index.php?topic=49884.msg550800#msg550800


The number of arguments is limited
Code: [Select]
_$ (length (repeat 255 (setq L255 (cons 1 L255))))
255
_$ (eval (cons '+ (cons 1 L255)))
; erreur: limite interne: nombre d'arguments trop important dans l'appel de la fonction: +
http://cadxp.com/topic/39608-fonctions-et-%e2%80%93-limite-a-255-arguments/page__view__findpost__p__220345


With this writing, the special form are not supported
Code: [Select]
_$ ((eval 'and) T T)
; erreur: Impossible d'appliquer la feuille spéciale: AND
http://www.theswamp.org/index.php?topic=49859.msg550438#msg550438

Regards,
(Ps: I speak with an automatic translator, I hope that the translation is good, sorry)
Title: Re: null string in list
Post by: Tharwat on August 06, 2015, 07:22:44 AM
Another slightly different.

Code - Auto/Visual Lisp: [Select]
  1. (apply 'and (mapcar '(lambda (x) (eq x "")) '("" "" "" "" "")))
  2.