Skip to main content
deleted 19 characters in body
Source Link
carlosayam
  • 2.1k
  • 16
  • 22

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potentialHope it helps.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

Hope it helps.

deleted 22 characters in body
Source Link
carlosayam
  • 2.1k
  • 16
  • 22

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following (and simple approach) can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following (and simple approach) can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

added 318 characters in body
Source Link
carlosayam
  • 2.1k
  • 16
  • 22

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following (and simple approach) can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following (and simple approach) can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct.

To clarify one of the answers. Note there is no way to distinguish both # inside # == Nearest[#, 551.748][[1]] in

Select[#, # == Nearest[#, 551.748][[1]] &] & 

as you already noted. So, you need to give the outermost # a name and Function[...] is just for that. This one works:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] 

Personally, I don't like the With trick above: if you need to give it a name, use the language construct for that. Then you do:

Function[{l}, Select[l, # == First[Nearest[l, 551.748]] &]] /@ {ln125,ln126,ln127} 

Note that a Function[...] is already a (...&), so you don't need the usual ...& /@..., just Function[...] /@.

P.S If you do this often, this is, fix a value (i.e. First[Nearest[l, 551.748]]) inside another function of two or more parameters (i.e. Equal in your case) to have a function of the free parameters, then the following (and simple approach) can be useful

FixCurry[f_, v_] := f[v, ##] &; 

So, FixCurry[Equal, 3] is Equal[3,#] &. And this can be used in your case like

Select[#, FixCurry[Equal, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

which avoids the inner (..&) via the FixCurry construct. If you wonder how this could be used in other contexts, notice that the first argument to FixCurry can be a pure function with the (...&) syntax. In your example, more verbose but equivalent,

Select[#, FixCurry[#1 == #2 &, First[Nearest[#, 5.]]]] & /@ {ln125,ln126,ln127} 

and I hope you see the potential.

Added FixCurry
Source Link
carlosayam
  • 2.1k
  • 16
  • 22
Loading
added 269 characters in body
Source Link
carlosayam
  • 2.1k
  • 16
  • 22
Loading
Source Link
carlosayam
  • 2.1k
  • 16
  • 22
Loading