TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnK on October 22, 2003, 09:54:35 AM
-
I was thinking this morning and i have been trying to come up with a slick way to test a list and return the nil member of a list. I cant think of anything. (Am i missing anything?) What is the opposite of "cond"? Is there one?
The only thing i could come up with is: "(mapcar 'cond '(a b c d))" to evaluate each member of the list but all i get is something like "(T T T nil)" as a return. I was wondering if anyone knew of a way to return the item that is nil in a list?
Am i nuts?! ...I must be nuts.
-
do what..............
I think you've been taking to much cold medicine. :D
-
funnily enough I was trying to do exactly the same thing two days ago.
I gave up :roll:
-
:? Smartass! Funny, cause I need to go get more. (I'm out)
Ok, lets say I have a list of stuff.
(setq a 1 b 2 c 3 d nil)
and I want to run thru the list to see what member dose not have a value.
I can use a "(mapcar 'cond "mylist")" to evaluate each member of my list but that dosent tell me which one in the list is nil.
-
Well it can be done. Here is "a way" but it aint smoooth (like me)
Run each of these lines in your vlide and watch the return values.
(setq a 1 b 2 c 3 d nil)
(setq x (list a b c d))
(setq y '(a b c d))
(setq n (- (length x) 1))
(setq nu
(1+ (while
;; test each
(equal (nth n x) nil)
;; drop the n variable down one increment
(setq n (1- n))
))
)
;; return the nil variable.
(nth nu y)
-
If you are sure that you only will have one nil, you could use vl-position
Command: (setq aa (list "A" "b" nil "c"))
("A" "b" nil "c")
Command: (vl-position nil aa)
2
-
If you are sure that you only will have one nil, you could use vl-position
Command: (setq aa (list "A" "b" nil "c"))
("A" "b" nil "c")
Command: (vl-position nil aa)
2
Oh crap! im sorry, i forgot to mention that i wanted a way without VL. But nice.
Edit: Im actualy just playing around with the lisp language; looking for cool stuff that i overlooked. Sorry, i prolly should have mentioned that huh?!
-
Ok, lets say I have a list of stuff.
(setq a 1 b 2 c 3 d nil)
and I want to run thru the list to see what member dose not have a value.
OK..........now you're startin to make sense. :D
Check out he eval function.
(if (not (eval x))(prompt "is nil.."))
-
Se7en,
Putting the nil in the middle of the list resulted in error.
I had to move the 1+ for the index var and don't see why eval is needed.
Still just a variation on your routine..
(setq a 1 b 2 c nil d 3)
(setq x (list a b c d))
(setq y '(a b c d))
(setq n (- (length x) 1))
(setq nu (while
(nth n x)
(setq n (1- n))
)
)
;; return the nil variable.
(nth (1+ nu) y)
-
This appears to work as well.
(setq a 1 b nil c 3 d 4)
(setq x (list a b c d))
(setq y '(a b c d))
(setq nu (-(length x)(length (member nil x))))
(nth nu y);; return the nil variable. If no nil returns nil
-
(setq a 1 b 2 c nil d 3)
(setq syms '(a b c d))
(foreach item syms
(if (not (eval item))
(princ item)
)
)
-
am I missing something ??
(setq xxxx (list 1 2 3 nil 5 6))
==>> (1 2 3 nil 5 6)
(member nil xxxx)
==>> (nil 5 6)
(length xxxx) ==>> 6
(length nil) ==>> 0
(length (member nil xxxx)) ==>> 3
-
am I missing something ??
(setq xxxx (list 1 2 3 nil 5 6))
==>> (1 2 3 nil 5 6)
(member nil xxxx)
==>> (nil 5 6)
member function
Searches a list for an occurrence of an expression and returns the remainder of the list, starting with the first occurrence of the expression
-
yep
.. if the return from (member nil xxxx) is not nil
(- (length xxxx) (length (member nil xxxx))) will be the position of the nil.
it's early here, so I may be incorrect :) need coffee
-
Mark, That is what i was attmepting to do. Damn! I cant find my "foreach" test. (I must have destroyed it.) But it was craaaazy.
Look at this one:
"(mapcar 'if (not (cond (eval x))) (setq x (princ "this one")) '(a b c d))"
Dahell is that?!!!
Kids, do you see what cold med's do to your mind. They make you go nuts!
-
looks correct to me, but se7en while have to make the final say-so since he started this mess........:D
-
if you are after the index, this may suit :
(defun test (theList / tmp)
(if (setq tmp (member nil theList))
(1+ (- (length theList) (length tmp)))
nil
)
)
-
Oh i dont care. I was origionaly looking for the opposite of "cond" like it was the fountian of youth or something but anyof those will do. Thanx alot guys.
-
If i had to pick one i would have to say marks because its cleaner. But their all cool.
-
< snip > and I want to run thru the list to see what member dose not have a value.
I can use a "(mapcar 'cond "mylist")" to evaluate each member of my list but that dosent tell me which one in the list is nil.
ahh ok ..