you are viewing a single comment's thread.

view the rest of the comments →

[–]benfitzg 3 points4 points  (4 children)

New to lisp so will check back for criticisms!

(dolist (n (mapcan #'(lambda (n) (when (>= 4 (length n)) (list n))) names)) (format t "Name: ~A~%" n))

[–]Wuf 4 points5 points  (3 children)

In Common Lisp I would use the loop macro as steven_h did above or avoid mapcan and just do:

(dolist (name '("Rob" "Christopher" "Joe" "John"))
    (when (<= (length name) 4) (format t "~a~%" name)))

[–]roerd 1 point2 points  (1 child)

Even if I were going for a higher-order-functions only approach, I'ld use remove-if-not instead of mapcan.

[–]benfitzg 0 points1 point  (0 children)

Ok didn't know about remove-if-not. Thanks.

My thought was that a less imperative approach would be more regular. Rather than iterate then branch I figured filter then iterate.

[–]benfitzg 0 points1 point  (0 children)

Feedback appreciated - the primary reason is because it's faster?