Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedencePrefix operator with low precedence


It occurs to me that if you have if the operators that you wish to string after // match a certain pattern this might be accomplished with something like this:

SetAttributes[Colon, HoldAll] Colon[lhs_, h_[f : _Symbol | _Function, rest__]] := f[lhs] ~h~ rest 

Now:

a + b + c \[Colon] f1 /. c -> 2 a + b + c \[Colon] f1 + q + r + s 

which displays as:

Mathematica graphics

yields:

f1[2 + a + b] q + r + s + f1[a + b + c] 

This however fails and would require a more complicated definition:

a + b + c \[Colon] f1 + q + r + s /. c -> 2 

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence


It occurs to me that if you have if the operators that you wish to string after // match a certain pattern this might be accomplished with something like this:

SetAttributes[Colon, HoldAll] Colon[lhs_, h_[f : _Symbol | _Function, rest__]] := f[lhs] ~h~ rest 

Now:

a + b + c \[Colon] f1 /. c -> 2 a + b + c \[Colon] f1 + q + r + s 

which displays as:

Mathematica graphics

yields:

f1[2 + a + b] q + r + s + f1[a + b + c] 

This however fails and would require a more complicated definition:

a + b + c \[Colon] f1 + q + r + s /. c -> 2 

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence


It occurs to me that if you have if the operators that you wish to string after // match a certain pattern this might be accomplished with something like this:

SetAttributes[Colon, HoldAll] Colon[lhs_, h_[f : _Symbol | _Function, rest__]] := f[lhs] ~h~ rest 

Now:

a + b + c \[Colon] f1 /. c -> 2 a + b + c \[Colon] f1 + q + r + s 

which displays as:

Mathematica graphics

yields:

f1[2 + a + b] q + r + s + f1[a + b + c] 

This however fails and would require a more complicated definition:

a + b + c \[Colon] f1 + q + r + s /. c -> 2 
added 527 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence


It occurs to me that if you have if the operators that you wish to string after // match a certain pattern this might be accomplished with something like this:

SetAttributes[Colon, HoldAll] Colon[lhs_, h_[f : _Symbol | _Function, rest__]] := f[lhs] ~h~ rest 

Now:

a + b + c \[Colon] f1 /. c -> 2 a + b + c \[Colon] f1 + q + r + s 

which displays as:

Mathematica graphics

yields:

f1[2 + a + b] q + r + s + f1[a + b + c] 

This however fails and would require a more complicated definition:

a + b + c \[Colon] f1 + q + r + s /. c -> 2 

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence


It occurs to me that if you have if the operators that you wish to string after // match a certain pattern this might be accomplished with something like this:

SetAttributes[Colon, HoldAll] Colon[lhs_, h_[f : _Symbol | _Function, rest__]] := f[lhs] ~h~ rest 

Now:

a + b + c \[Colon] f1 /. c -> 2 a + b + c \[Colon] f1 + q + r + s 

which displays as:

Mathematica graphics

yields:

f1[2 + a + b] q + r + s + f1[a + b + c] 

This however fails and would require a more complicated definition:

a + b + c \[Colon] f1 + q + r + s /. c -> 2 
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

As a rule I would avoid following // function with anything but another // function2 due to the precedence of //. The very property that makes // convenient to follow code with (grouping the left-hand side) makes it difficult to follow it with anything else, because binding looks like this:

Mathematica graphics

If your style demands it I suggest you configure your code such that your string of operations is done inside functions, e.g.:

a + b + c // f1 // (# /. c -> 2 &) 

Or form a compound function:

a + b + c // (f1[##] /. c -> 2 &) 

This adds semantic complexity, and it would be cleaner of course to just write:

f1[a + b + c] /. c -> 2 

It might also suit your style to use different operators, though at the moment I cannot see how that would directly solve your style issue. As an example see:

Prefix operator with low precedence