From: Stas B. <sta...@gm...> - 2009-10-15 00:55:54
|
On Thu, Oct 15, 2009 at 4:38 AM, Carlos Konstanski <cko...@pi...> wrote: > I don't think I understand REDUCE fully. Take the following two > examples. The first one REDUCEs a list of two items. It works as > expected. the second one REDUCEs a list of one item. It does not give > the result I was hoping for. > > I guess I should ask for clarification: what is REDUCE supposed to do > when given a list of one element? > > > SVBRONZE> (let ((roles '(roles_dealer roles_architect))) > (reduce #'(lambda (&optional x y) > (cond ((and x y) (format nil "~a = true OR ~a = true" x y)) > ((and x (not y)) (format nil "~a = true" x)) > (t ""))) > (mapcar #'(lambda (role) > (string-downcase (symbol-name role))) > roles))) > "roles_dealer = true OR roles_architect = true" > > SVBRONZE> (let ((roles '(roles_dealer))) > (reduce #'(lambda (&optional x y) > (cond ((and x y) (format nil "~a = true OR ~a = true" x y)) > ((and x (not y)) (format nil "~a = true" x)) > (t ""))) > (mapcar #'(lambda (role) > (string-downcase (symbol-name role))) > roles))) > "roles_dealer" "If the subsequence contains exactly one element and no initial-value is given, then that element is returned and function is not called." from http://www.lispworks.com/reference/HyperSpec/Body/f_reduce.htm -- With best regards, Stas. |