1

Learning the wolfram Language, in section 32

"The Wolfram Language" // Characters[#]& /. Alternatives @@Characters["aeiou"] -> Nothing

Returns {T,h,e, ,W,o,l,f,r,a,m, ,L,a,n,g,u,a,g,e}

I expected it to return {T,h, ,W,l,f,r,m, ,L,n,g,g}

Changing it to

Characters["The Wolfram Language"] /. Alternatives @@Characters["aeiou"] -> Nothing

Returns the expected result, why?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 3
    Be careful with afterthought (//) notation. In this case, everything after // is grouped together. You can see this by repeatedly clicking Characters and see how the selection expands. You'd need to write ("The Wolfram Language" // Characters[#]&) /. ... to make this work. – Sjoerd Smit Aug 25 '20 at 20:23
  • 1

1 Answers1

2

Characters[#] & /. Alternatives @@ Characters["aeiou"] -> Nothing is processed together. You can see this by quadruple-clicking on Characters[#] -- the extended highlighting shows the operator associations and order of processing.

Processing the operations together is equivalent to constructing f, as here:

f = Characters[#] & /. Alternatives @@ Characters["aeiou"] -> Nothing;

"The Wolfram Language" // f

{T,h,e, ,W,o,l,f,r,a,m, ,L,a,n,g,u,a,g,e}

As well as the method you show, the operator binding can be fixed like this:

ReplaceAll["The Wolfram Language" // Characters[#] &, 
 Alternatives @@ Characters["aeiou"] -> Nothing]

{T,h, ,W,l,f,r,m, ,L,n,g,g}

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108