bobokent Posted July 13, 2012 Share Posted July 13, 2012 Learnt all numbers in a list, all alphabets in a list. but how if both in the same? such as (count-alpha '(8 0 b 7 h u 6 d ) ) -> 4 (count-no '(8 0 b 7 h u 6 d ) ) -> 4 Quote Link to comment Share on other sites More sharing options...
ReMark Posted July 13, 2012 Share Posted July 13, 2012 Your request looks vaguely familiar. I swear that someone posted this same question recently. Try a search on the word "alphabet". Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 13, 2012 Share Posted July 13, 2012 Things like this ... (mapcar (function (lambda (x) (if (numberp x) (setq n (cons x n)) (setq a (cons x a)) ) ) ) '(8 0 b 7 h u 6 d) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 13, 2012 Share Posted July 13, 2012 Anther with the use of foreach function .... (foreach item '(8 0 b 7 h u 6 d) (if (numberp item) (setq numbers (cons item numbers)) (setq alpha (cons item alpha)) ) ) Would return the same result as the first codes . numbers = ( 6 7 0 8 ) alpha = ( D U H B ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2012 Share Posted July 13, 2012 (defun count-alpha ( l ) (length (vl-remove-if 'numberp l)) ) (defun count-no ( l ) (length (vl-remove-if-not 'numberp l)) ) Quote Link to comment Share on other sites More sharing options...
bobokent Posted July 18, 2012 Author Share Posted July 18, 2012 (mapcar (function (lambda (x) (if (numberp x) (setq n (cons x n)) (setq a (cons x a)) ) ) ) '(8 0 b 7 h u 6 d) ) Error: Attempt to take the value of the unbound variable `N'. [condition type: UNBOUND-VARIABLE] (foreach item '(8 0 b 7 h u 6 d) (if (numberp item) (setq numbers (cons item numbers)) (setq alpha (cons item alpha)) ) ) Error: attempt to call `FOREACH' which is an undefined function. [condition type: UNDEFINED-FUNCTION] (defun count-alpha ( l ) (length (vl-remove-if 'numberp l)) ) (defun count-no ( l ) (length (vl-remove-if-not 'numberp l)) ) Error: attempt to call `VL-REMOVE-IF' which is an undefined function. [condition type: UNDEFINED-FUNCTION] Quote Link to comment Share on other sites More sharing options...
MSasu Posted July 18, 2012 Share Posted July 18, 2012 What CAD application are your using in fact?!? Those don't appear as AutoLISP error messages... Quote Link to comment Share on other sites More sharing options...
MSasu Posted July 18, 2012 Share Posted July 18, 2012 Or are you talking in fact of LISP language? Then please pay attention that this Forum is dedicated to AutoLISP, a dialect of LISP used under AutoCAD editor; so I'm afraid that will have to find other resource for help on your issue. Quote Link to comment Share on other sites More sharing options...
Lee Roy Posted July 19, 2012 Share Posted July 19, 2012 It appears to be an error message formatting from the Common Lisp language. Quote Link to comment Share on other sites More sharing options...
irneb Posted July 20, 2012 Share Posted July 20, 2012 In which case: Using ECL's Lisp Shell: (length (remove-if-not (lambda (a) (stringp a)) '(1 3 6 "34" 5 "name"))) 2 Quote Link to comment Share on other sites More sharing options...
irneb Posted July 20, 2012 Share Posted July 20, 2012 Or using a similar approach as Tharwat's in post #4: ECL-0.9i % (setq count 0) 0 ECL-0.9i % (loop for item in '(1 3 6 "34" 5 "name") do (if (stringp item) (setq count (1+ count)))) NIL ECL-0.9i % count 2 Quote Link to comment Share on other sites More sharing options...
irneb Posted July 20, 2012 Share Posted July 20, 2012 Sorry:oops: ... the OP didn't use strings, only symbols. ECL-0.9i % (length (remove-if (lambda (a) (numberp a)) '(8 0 b 7 h u 6 d ))) 4 ECL-0.9i % (setq count 0) 0 ECL-0.9i % (loop for item in '(8 0 b 7 h u 6 d ) do (if (not (numberp item)) (setq count (1+ count)))) NIL ECL-0.9i % count 4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.