Ahankhah Posted May 5, 2011 Posted May 5, 2011 Hi, as most of you know, the syntax of mapcad function is as following: (mapcar [i]function [/i][i]list1[/i]... [i]listn[/i]) My question can be explained after showing these two examples: (mapcar 'strcase '("a" "B" "c" "D")) returns: ("A" "B" "C" "D") (mapcar 'strcase '("a" "B" "c" "D") '(T T T T)) returns: ("a" "b" "c" "d") Is any method to pass repeated objects (here T as the socond argument) to mapcar just one time? Quote
BlackBox Posted May 5, 2011 Posted May 5, 2011 Is any method to pass repeated objects (here T as the socond argument) to mapcar just one time? *IF* you know you'll be using T (True) as the Which argument of the Strcase function for each item of the supplied list of valid strings, then the use of Lambda should do the trick. Example: (mapcar [color=blue](function[/color] [color=blue] (lambda (str / string)[/color] [color=blue] (setq string (strcase str [color=red]T[/color]))))[/color] '("a" "B" "c" "D")) Quote
Ahankhah Posted May 5, 2011 Author Posted May 5, 2011 (mapcar [color=blue](function[/color] [color=blue](lambda (str / string)[/color] [color=blue](setq string (strcase str [color=red]T[/color]))))[/color] '("a" "B" "c" "D")) the code can be even shorter: (mapcar (function (lambda (str) (strcase str T))) '("a" "B" "c" "D")) Thanks again RenderMan Quote
Lee Mac Posted May 5, 2011 Posted May 5, 2011 Mapcar is ideal when processing lists of unknown length; should you need to supply other constant arguments for each item, a lambda function (or user-defined subfunction) may be used, as demonstrated. Perhaps have a read of this tutorial, the link at the bottom of that page is also a good read. Quote
BlackBox Posted May 5, 2011 Posted May 5, 2011 Nice one RenderMan - much appreciated:). Your welcome. Quote
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.