Removing lists from list based on length

9 views
Skip to first unread message

Stan

unread,
Jul 14, 2012, 6:58:15 PM7/14/12
to symbolic...@googlegroups.com
The following does almost what I want. How do I get it to generate the same output without the nils? Thanks,
Stan

(setq modes '((a b c) (d e f) (g h) (i j) (k) (l m n)))
(defun xnotemodes (x) (if (= (length x) 3) x ))
(mapcar #'xnotemodes modes)

--> ((a b c) (d e f) nil nil nil (l m n))



Here are two things I tried which did not work:

(setq modes '((a b c) (d e f) (g h) (i j) (k) (l m n)))
(defun xnotemodes (x) (remove-if (= (length x) 3) x ))  
(mapcar #'xnotemodes modes)
--> ERROR: Undefined function t called with arguments (a).


(setq modes '((a b c) (d e f) (g h) (i j) (k) (l m n)))
(defun xnotemodes (x) (remove-if 
                                      (not (equal (length x) 3)) 
                              x))
(mapcar #'xnotemodes modes)
-->ERROR: Undefined function nil called with arguments (a).








ole

unread,
Jul 14, 2012, 7:05:42 PM7/14/12
to symbolic...@googlegroups.com
maybe is misunderstand what you want:

(setq modes '((a b c) (d e f) (g h) (i j) (k) (l m n)))
(defun xnotemodes (x) (if (= (length x) 3) x ))
(remove 'nil (mapcar #'xnotemodes modes))
--> ((a b c) (d e f) (l m n))


hth

ole
> --
> You received this message because you are subscribed to the Google Groups "Symbolic Composer" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/symboliccomposer/-/-Ig9zwDk1S0J.
> To post to this group, send email to symbolic...@googlegroups.com.
> To unsubscribe from this group, send email to symboliccompos...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/symboliccomposer?hl=en.
>

pstone imap

unread,
Jul 14, 2012, 7:07:05 PM7/14/12
to symbolic...@googlegroups.com
Mapcan skips nils but you need to list x, otherwise it makes flat result.

(setq modes '((a b c) (d e f) (g h) (i j) (k) (l m n)))
(defun xnotemodes (x) (if (= (length x) 3) (list x)))

(mapcan #'xnotemodes modes)
--> ((a b c) (d e f) (l m n))

Stan

unread,
Jul 14, 2012, 7:14:00 PM7/14/12
to symbolic...@googlegroups.com
Ole and Peter--thank you--both helpful solutions.
Stan
To post to this group, send email to symboliccomposer@googlegroups.com.
To unsubscribe from this group, send email to symboliccomposer+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages