Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Deleting expressions containing a certain head, and a plea for Esc-fn-Esc

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126058] Re: Deleting expressions containing a certain head, and a plea for Esc-fn-Esc
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Sat, 14 Apr 2012 03:09:05 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

I might be tempted to use Esc-fn-Esc notation, 
if any of the versions I have recognized it ;)

----- Barrie Stokes <Barrie.Stokes at newcastle.edu.au> wrote:
> In support of my tireless campaign for the Esc-fn-Esc notation for pure functions, I submit
> 
> Cases[{2^(Complex[ 2, 3 ]) + 3 , 2 ,   3 x }, _?(s \[Function] FreeQ[ s, Complex ]) ].
> 
> I have never been comfortable with the fact that
> 
> (#^3 &)[x]
> 
> and
> 
> (#^3) &[x]
> 
> give the same result.
> 
> Admittedly, in the above case, your
> 
> Cases[{2^(Complex [2, 3] ) + 3 , 2 , 3 x }, _?(FreeQ[ #, Complex ] &)]
> 
> works whereas
> 
> Cases [{2^(Complex [ 2, 3 ]) + 3 , 2 , 3 x }, _?(FreeQ [#, Complex ]) & ]
> 
> doesn't, which I think adds weight to my point. Sometimes (&) and ()& are equivalent, sometimes not. Avoiding the question as to where the "&" goes, inside the "()" or outside, is in the spirit of no ambiguity in Mathematica code, IMHO.
> 
> I just noted that the online help entry "tutorial/PureFunctions" mostly does not use parentheses, except for an example involving Fold, thus avoiding my dilemma. Hmm. It also says:
> 
> "When you use the ampersand notation for pure functions, you must be careful about the grouping of pieces in your input. As shown in "Operator Input Forms" the ampersand notation has fairly low precedence, which means that you can type expressions like #1+#2& without parentheses. On the other hand, if you want, for example, to set an option to be a pure function, you need to use parentheses, as in option->(fun&). "
> 
> I like to avoid @, #, and * because - especially in groups - they still remind me of swearing in a comic.
> 
> Cheers
> 
> Barrie
> 
> >>> On 12/04/2012 at 4:36 pm, in message <201204120636.CAA05485 at smc.vnet.net>, Ray
> Koopman <koopman at sfu.ca> wrote:
>> On Apr 11, 3:26 pm, Brentt <brenttnew... at gmail.com> wrote:
>>> Hello, I have a list of expressions, and I am trying to use DeleteCases to
>>> delete expressions in the list which contain a certain head *anywhere* in
>>> the expression. Setting the levelspec for DeleteCases to Infinity almost
>>> works, except I want to delete the entire expression containing the head
>>> from the list as opposed to just the head itself while leaving the rest of
>>> the expression in the list.
>>>
>>> e.g.
>>> I want this
>>> DeleteCases[{2^(Complex[2,3])+3 , 2 ,3x }, Complex[_,_], Infinity ]
>>>
>>> to output this
>>> {2,3x}
>>> Getting rid of any expression that has a complex number in it.
>>>
>>>  How does one go about this?
>> 
>> Cases[{2^(Complex[2,3])+3 , 2 , 3x }, _?(FreeQ[#,Complex]&)]
>> 
>> {2, 3 x}



  • Prev by Date: Re: Replace each f in f^n to different variables
  • Next by Date: Re: What characters are allowed in mathematica variable names? i.e. how
  • Previous by thread: Re: Deleting expressions containing a certain head, and a plea for Esc-fn-Esc
  • Next by thread: Why the loop gain no result?