Re: Re: Nesting functional commands
- To: mathgroup at smc.vnet.net
- Subject: [mg102968] Re: [mg102898] Re: [mg102875] Nesting functional commands
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Thu, 3 Sep 2009 05:40:50 -0400 (EDT)
- References: <200909010751.DAA18675@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Better yet,
a = {1, 2, 3, 4};
Select[3 a, (# < 7 &)]
{3, 6}
As for how to "nest functional commands", my answer is simple: don't. It's
never necessary, and it makes for less readable code.
Bobby
On Wed, 02 Sep 2009 02:59:25 -0500, Patrick Scheibe
<pscheibe at trm.uni-leipzig.de> wrote:
> Hi,
>
> in this case it is easy. Just "say" how you want it with braces
>
> A = {1, 2, 3, 4};
> Select[(3*# & /@ A), (# < 7 &)]
>
> in other examples this would not work. Then you have the chance to use
> Function[{x,y,..},...] and it gets clear to Mathematica.
>
> Cheers
> Patrick
>
>
> On Tue, 2009-09-01 at 03:51 -0400, Erin Noel wrote:
>> Hi,
>>
>> So how would you go about nesting a functional command inside of another
>> functional command? For example, say A={1,2,3,4}, then 3*#&/@A =
>> {3,6,9,12}.
>> No problem. But then what if, within that vector {3,6,9,12}, I wanted
>> to use
>> the Select command to choose elements less than, say 7. The command
>> Select[3*#&/@A,#<7&] doesn't work because, as far as I can tell,
>> Mathematica
>> doesn't know which "#" belongs to Select and which "#" belongs to the
>> &/@
>> mapping over A. I know that I could define 3*#&/@A as a new variable and
>> then use that new variable in the Select command, but is there any way
>> to
>> nest multiple commands in this way?
>>
>> Thanks a lot in advance,
>> Erin
>>
>>
>
>
--
DrMajorBob at yahoo.com
- References:
- Nesting functional commands
- From: Erin Noel <enoel2@gmail.com>
- Nesting functional commands