Re: Nesting functional commands
- To: mathgroup at smc.vnet.net
- Subject: [mg102905] Re: Nesting functional commands
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Wed, 2 Sep 2009 04:00:40 -0400 (EDT)
- References: <h7ijpu$i7f$1@smc.vnet.net>
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? your example is not that good, because it actually works because Mathematica can distinguish between the # very well, at least for this case. There are other cases where it can't and there the usual approach is to not use shortcuts for the pure functions but something like: Function[{x}, x*# & /@ {1,2,3} ] /@ {1,2,3} hth, albert