Another:Code - Auto/Visual Lisp: [Select]
(if (member "" lst) T)
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
Another, just for variation:Code - Auto/Visual Lisp: [Select]
Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1" "a") returns T
Thanks.Another:Code - Auto/Visual Lisp: [Select]
Very good roy.
I have say a list ("" "" "" "" "").My variant
(apply '= (cons "" lst))
Lee ,can make it like this ?
'("" "" "") returns nil
'("1" "" "") returns nil
'("1" "10" "") returns nil
……
……
Only '("1" "s1" "a") returns TCode - Auto/Visual Lisp: [Select]
Thanks.Another:Code - Auto/Visual Lisp: [Select]
Very good roy.
@ 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...
(setq l '("" "" "" ""))
(eq (strlen (vl-princ-to-string l)) (1+ (length l)))
or
(and (eq "" (car l)) (equal l (acad_strlsort l)))
My variantNice! Very succinct and using 'Classic' Lisp only.Code: [Select](apply '= (cons "" lst))
Nice! Very succinct and using 'Classic' Lisp only.Yes, thank you
_$ (= "" "" "" "")
T
_$ (= "" 2 ABC T)
nil
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)
_$ (= "a" "a" "a" "a")
T
Incidentally,Code: [Select]_$ (= "a" "a" "a" "a")
T
_$ (cons "" '("a" "a" "a" "a"))
("" "a" "a" "a" "a")
_$ (= "" "a" "a" "a" "a")
nil
Hello,QuoteI have say a list ("" "" "" "" "").My variantCode: [Select](apply '= (cons "" lst))
Regards,
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>
(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:
That's nice.Thank you
Oh, I made it smaller!? This one only checks to see if all entries are the same though.Code - Auto/Visual Lisp: [Select]
(defun f5 (l) (if (= "" (car l)) (= "" (last (vl-sort l '=)))))
(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>
(defun f6 (l) (if (= "" (car l)) (not (while (vl-position "" (setq l (cdr l)))))))
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. (setq alist '("" "" "" ""))
(setq alist2 alist)
(setq alist2 (repeat 200 (setq alist2 (append alist2 alist))))
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>
Don't think we've had this one yet:Code - Auto/Visual Lisp: [Select]
_$ (setq A "")
""
_$ (= "" 'A 'A 'A)
nil
_$ (apply '= '("" A A A))
nil
_$ (eval '(= "" A A A))
T
(defun f6 (l) ;F4 like
(if (= "" (car l))
(while (= "" (car (setq l (cdr l)))))
)
(not l)
)
(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>
(and lst (vl-every '= (cons "" lst) lst))
(and lst (apply '= (cons "" lst)))
(defun f (l)
(if l
(not (vl-member-if-not '(lambda (x) (eq "" x)) l))
)
)
(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>
(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
Another:Comando: (f4 '("1" "" "" "" ""))Code - Auto/Visual Lisp: [Select]
Another:Comando: (f4 '("1" "" "" "" ""))Code - Auto/Visual Lisp: [Select]
T
:wink:
@ Marc'Antonio Alessi, thanks these comparisons are interesting, but I find it hard to do ..ok... other tests:
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?
(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>
length: 131073
Comando: (f7 alist0)
; errore: valore dell'argomento errato: does not fit in byte: 131073
$ (eval (cons '= '(A B C D)))
T
http://www.theswamp.org/index.php?topic=49884.msg550800#msg550800_$ (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_$ ((eval 'and) T T)
; erreur: Impossible d'appliquer la feuille spéciale: AND
http://www.theswamp.org/index.php?topic=49859.msg550438#msg550438