I am trying to understand the exact behavior of the "enter" character in Mathematica. (I am not even sure what to call it: perhaps it is really the carriage return or newline character, which is input using the enter or return key. What I mean is whatever character gets input when I hit the key above "shift" on my mac.)
I haven't been able to find any Wolfram documentation about what how exactly the "enter" key works. I have noticed that it behaves very differently in at least four situations, described with examples below. What is the general behavior of "enter," and how does this general behavior explain the different specific behaviors I've encountered in the four cases below?
Case 1: Repeated evaluation
When I use the "enter" key to separate two lines of code in the same cell, both lines get evaluated and the results display in separate output cells:
Input:
1+1
2+2
Output (separate cells):
2
4
Case 2: Same as semicolon
If each line in the input code above is wrapped within InputForm
, then for some reason only the output of the final line is evaluated. This behavior would also result from placing a semicolon after the first line.
Input:
InputForm[1 + 1]
InputForm[2 + 2]
Output:
4
Case 3: Same as space
Within Module
, the enter character/key behaves the same as a space, which is often the same as multiplication:
Input:
Module[{},
1 + 1
2 + 2]
Output:
5
Case 4: Same as \n
When the "enter" key is used within a string in quotation marks, the result seems to be the same as entering the formatting character "\n":
Input:
Print["Line 1\nLine 2
Line 3"]
Output:
Line 1
Line 2
Line 3