Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

example 1


we can use Information , but can not use ?

Sin // Information

Sin // ?

example 2


we can use StringJoin but cannot use <>

"aa" <> 1 <> 2 <> "Ab" <> 123 <> "aend" /. <>-> ~~

"aa" <> 1 <> 2 <> "Ab" <> 123 <> "aend" /. StringJoin -> StringExpression

(*
    aa~~1~~2~~Ab~~123~~aend
*)
share|improve this question
    
~~ is not a symbol, but a binary infix operator that needs 2 arguments, so foo // ~~ doesn't make sense, because it is incomplete. a ~~ b is parsed to StringExpression[a, b], but ~~ (without any arguments) does not parse to StringExpression. –  rm -rf Jun 28 '13 at 6:28
    
@rm-rf Yes, my post was not so exactly. Sometimes, my first response to do those // /. things is ? <> because I've got used to do ?Sin,a<>b, rather that Information[]. Actually I found this also couldn't been done ?/@{Sin} –  HyperGroups Jun 28 '13 at 7:44
3  
That's because ? is not an operator for Information. It so happens that just ?foo by itself is parsed as Information[foo], but otherwise, it does not behave like any other operator. To see that ?foo is not actually a short form for Information[foo], try f[x_Symbol] := ?x and then evaluate, say, f[Sin]. You'd expect it to be the same as ?Sin, right? Check for yourself what happens. Besides, ? is the operator for PatternTest. –  rm -rf Jun 28 '13 at 8:04
3  
Just to make it clear: if ? had been an operator for Information it would have to be entered in prefix form as ?@Sin or ?[Sin] instead of ?Sin. Only if the operator is called as op@arg can you postfix it as arg//op. –  István Zachar Jun 28 '13 at 11:37
    
@rm-rf well Actually in my first post, there is no such word Operator...Anyway, good to learn that. –  HyperGroups Jun 28 '13 at 15:09
show 1 more comment

1 Answer

Input Expressions

There exists a definite grammar which specifies how your input should be converted to an internal form.

There are several operators which basically are overloads for internal functions:

^  -> Power
+  -> Plus
~~ -> StringExpression
etc.

What these operators all have in common is that they are binary operators, meaning their equivalent is a function taking two parameters.

The only two forms that do support binary operators are:

f[x, y]     -> standard form
x ~~ f ~~ y -> infix form

The other two forms support unary operators and they are special cases because of their precedence. When you write:

f @ x + y  ==> f[x] + y
x + y // f ==> f[x + y]

But you could write f[x, y] in prefix form, due to its higher precedence: f@(x+y).

The last example x + y // f shows perfectly the problem here. It is translated to f[x + y] but if f would be the equivalent to ~~ it would be incomplete and therefore a syntax error.

I highly doubt that ? is the operator equivalent for Information

I hope this answers your question.

share|improve this answer
    
I'm not sure the equivalence of ? and Information, Sometimes I use Definition, when I cannot use ? in such case ?/@{Sin,Cos}. One reason about why I ask this question is that some newbie like me know only ? in the beginning, and then after a long time, I know Information and Definition, what a bad thing. –  HyperGroups Jun 28 '13 at 7:48
    
Information prints the same information as ??. Information is a function taking a symbol as a parameter, whereas ?? is not. ? and ?? are just input escapes. –  Stefan Jun 28 '13 at 12:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.