Jump to content

Recommended Posts

Posted

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?

Posted
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"))

Posted

Nice one RenderMan - much appreciated:).

Posted

(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

Posted

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.

Posted
Nice one RenderMan - much appreciated:).

 

Your welcome. :)

Posted

Thanks Lee,

you are very good teacher.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...