(setq x ("" "" "" "" "" "" "" "" "" "" "" "" ""))
(setq x ("" "" "" "" "" "" "" "" "" "" "" "" "" 1))
Outside of libraries it's uncommon to have an unbounded "problem space". One of the key parts to planning software, either top-level or in the weeds, is to create that limited and well defined "problem space" so you don't go cross-eyed trying to handle every possible eventuality.Agreed .. if you know what data you're passing ( and you should ) why add overhead to check the data.
... I've never heard advice about when it is okay to NOT be type-safe.
(setq l '("" "" "" "" "" """" "" "" "" "" """" "" "" "" "" """" "" "" "" "" """" "" "" "" "" """" "" "" "" "" ""))
(defun test-str (l) (= "" (apply 'strcat l)))
(defun test-str-2 (l) (apply '= (cons "" l)))
(defun _allemptystrings (l) (defun _chk (x) (and (= 'str (type x)) (= x ""))) (vl-every '_chk l))
(benchmark '((test-str l) (test-str-2 l) (_allemptystrings l)))
;;; (TEST-STR-2 L)...........1922 / 2.25 <fastest>
;;; (TEST-STR L).............2062 / 2.10
;;; (_ALLEMPTYSTRINGS L).....4328 / 1.00 <slowest>
(defun test-str-3 (l) (not (vl-remove "" l)))
Agree with Lee, Owen etc. Link (http://www.theswamp.org/index.php?topic=9709.msg124496#msg124496).Same mindset here.
You win! :)Code: [Select](defun test-str-3 (l) (not (vl-remove "" l)))
(TEST-STR-3 L)...........1375 / 2.77 <fastest>
(TEST-STR-2 L)...........1688 / 2.26
(TEST-STR L).............1781 / 2.14
(_ALLEMPTYSTRINGS L).....3813 / 1.00 <slowest>
...
You win! :)
...
Command: (setq x '("" "" "" "" "" "" 1))
("" "" "" "" "" "" 1)
Command: (defun test-str-3 (l) (not (vl-remove "" l)))
TEST-STR-3
Command: (test-str-3 x)
nil
Looks good to me? You gave it a 1 and it said NO not all empty strings?...
You win! :)
...
Nope. Doesn't meet the criteria to fail.Code: [Select]Command: (setq x '("" "" "" "" "" "" 1))
("" "" "" "" "" "" 1)
Command: (defun test-str-3 (l) (not (vl-remove "" l)))
TEST-STR-3
Command: (test-str-3 x)
nil
Looks good to me? You gave it a 1 and it said NO not all empty strings?
Recursive one -And the numbers are in :)Code - Auto/Visual Lisp: [Select]
:)
(TEST-STR-3 L)...........1344 / 2.86 <fastest>
(TEST-STR-2 L)...........1703 / 2.26
(TEST-STR L).............1735 / 2.22
(TEST-STR-4 L)...........3172 / 1.21
(_ALLEMPTYSTRINGS L).....3844 / 1.00 <slowest>
And the numbers are in :)Quote(TEST-STR-3 L)...........1344 / 2.86 <fastest>
(TEST-STR-2 L)...........1703 / 2.26
(TEST-STR L).............1735 / 2.22
(TEST-STR-4 L)...........3172 / 1.21
(_ALLEMPTYSTRINGS L).....3844 / 1.00 <slowest>
OK .. maybe I'm missing something. My argument is that data that is passed should be checked before using this function as to not be 'superfluous' as Lee stated. My benchmark shows that there is definitely a performance hit if you don't check the data prior.Looks good to me? You gave it a 1 and it said NO not all empty strings?
According to you guys, it is supposed to fail.
Pretty similar:
And the numbers are in :)Quote(TEST-STR-3 L)...........1344 / 2.86 <fastest>
(TEST-STR-2 L)...........1703 / 2.26
(TEST-STR L).............1735 / 2.22
(TEST-STR-4 L)...........3172 / 1.21
(_ALLEMPTYSTRINGS L).....3844 / 1.00 <slowest>
Doh, recursion is slow no matter what :geek:
BTW I think if you externally define '_chk' (outside of _allemptystrings) it should perform drastically faster, since it wont redefine the subfoo each time.
_$
("" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "")
TEST-STR
TEST-STR-2
TEST-STR-3
TEST-STR-4
_CHK
_ALLEMPTYSTRINGS Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
(TEST-STR-3 L)...........1360 / 2.81 <fastest>
(TEST-STR-2 L)...........1719 / 2.23
(TEST-STR L).............1750 / 2.19
(TEST-STR-4 L)...........3203 / 1.20
(_ALLEMPTYSTRINGS L).....3828 / 1.00 <slowest>
OK .. maybe I'm missing something. My argument is that data that is passed should be checked before using this function as to not be 'superfluous' as Lee stated. My benchmark shows that there is definitely a performance hit if you don't check the data prior.
(= "" "" "")
Sure .. but the data is in a list .. and I'm outta here too :P.OK .. maybe I'm missing something. My argument is that data that is passed should be checked before using this function as to not be 'superfluous' as Lee stated. My benchmark shows that there is definitely a performance hit if you don't check the data prior.
The scope keeps changing; you guys talk among'st yourselves and come to a consensus. ...I can't really keep up but as far as I can keep straight, = should work just fine for you guys.Code: [Select](= "" "" "")
I'm out of here.
It is the same as:Code - C++: [Select]Are [you] honestly telling me this is not "correct". -i.e. in this code the program exits (falls out of the IF statement) if the number isnt postive; are [you] telling me the programmer should have just "preformed math" or "entered a loop" or "launched N rockets" on/with a negative number?
if (n <= 0) { printf("The number should be positive.\n"); } else { for (int i = 1; i <= n; ++i) {
You are mearly[sic] accepting data (from a source you may not have control of--user or text file for example)
Because trees.
(defun test-str-9 (l) (eq (1+ (strlen (vl-string-trim "()" (vl-princ-to-string l)))) (length l)))
Another (slower):Code: [Select](defun test-str-9 (l) (eq (1+ (strlen (vl-string-trim "()" (vl-princ-to-string l)))) (length l)))
Ok the horse is dead.Code - Auto/Visual Lisp: [Select]
;; Make John happy ( but maybe not ) ...
If you're comparing a key to a list ( function above ) why should it 'fail'? It's either T or nil and can accept multiple datatypes to test. Perhaps happiness is not in the cards for you. ;) Have a nice weekend.How should I know why it `has to fail'?! I asked several different times/ways.
There is a very small possibility :) ... no really, have a nice weekend.If you're comparing a key to a list ( function above ) why should it 'fail'? It's either T or nil and can accept multiple datatypes to test. Perhaps happiness is not in the cards for you. ;) Have a nice weekend.
Wait a minute. If happiness isn't in the cards for me do you really think my weekend will be nice? :)
Another (slower):Code: [Select](defun test-str-9 (l) (eq (1+ (strlen (vl-string-trim "()" (vl-princ-to-string l)))) (length l)))
Nice and it's probably pretty quick but it doesn't meet the specifications--to error upon non-string entries (int, nil, list, etc).
; (test-str-3 + test-str)
(defun AllEmptyStrings (l / o)
(cond
( (not (setq o (vl-remove "" l))) )
( (not (apply 'strcat o)) )
)
)
(AllEmptyStrings '("" "" "" )) ==> T
(AllEmptyStrings '("" "" "1")) ==> nil
(AllEmptyStrings '("" "" 1 )) ==> error
(AllEmptyStrings '("" "" nil)) ==> error
(AllEmptyStrings '("" "" '())) ==> error
<…>Command: (test-str-7 '("" "1" "" ""))
Here is a very quick tally of the posted functions that pass specifications (double check please. I don't think I got them all and I didn't see test-str-8.).Code - Auto/Visual Lisp: [Select]
(test-str l) ;; (test-str-2 l) ;; does not error ;; (_allemptystrings l) ;; does not error ;; (test-str-3 l) ;; does not error ;; (test-str-4 l) ;; does not error ;; (test-str-5 l) ;; does not error (test-str-6 l) (test-str-7 l) ;; (test-str-9 l) ;; does not error