Difference between revisions of "W1206 Expression Evaluation vs Printing"

From Coder Merlin
Line 11: Line 11:
== Expression Evaluation ==
== Expression Evaluation ==
As we learned earlier, there are many different types of expressions, including integer, floating point, and Boolean.  Expressions, when evaluated, yield a specific value.  But, ''the evaluation of an expression'' is very different from printing.  This can sometimes be confusing, because when using an environment such as a REPL, the results of expressions are ''automatically'' printed to the console.  In a ''real'' program, however, this does not occur.  Let's examine a few examples.  
As we learned earlier, there are many different types of expressions, including integer, floating point, and Boolean.  Expressions, when evaluated, yield a specific value.  But, ''the evaluation of an expression'' is very different from printing.  This can sometimes be confusing, because when using an environment such as a REPL, the results of expressions are ''automatically'' printed to the console.  In a ''real'' program, however, this does not occur.  Let's examine a few examples.  
== Printing vs Expression Evaluation ==
Let's first have a look at what happens inside the REPL.
{{ConsoleLines|
Welcome to Swift.<br/>
Type :help for assistance.<br/>
  1> func multiplyByTwo(number:Int) -> Int { <br/>
  2.    return number * 2 <br/>
  3. } <br/>
  4> multiplyByTwo(number:3)<br/>
<span style{{Equal}}"color:cyan;">$R0: Int {{Equal}} 6</span><br/>
  5>  <br/>
}}
== Key Concepts ==
== Key Concepts ==
== Exercises ==
== Exercises ==
== References ==
== References ==

Revision as of 20:53, 16 November 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Epson MX-80
Nixdorf PC 8810-25

Prerequisites[edit]

Introduction[edit]

Printing refers to sending a stream of data, most often text but sometimes binary data as well, to an output device. Frequently this device is simply the console. The console refers to the input and output devices used to interact with a computer. It's usually comprised of a screen and keyboard, and sometimes a type of pointing device.

Printing is important not only for interacting with humans, but with other computing systems. For example, you've already had a lot of experience in interacting with the  Merlin Mission Manager  through print statements.

Expression Evaluation[edit]

As we learned earlier, there are many different types of expressions, including integer, floating point, and Boolean. Expressions, when evaluated, yield a specific value. But, the evaluation of an expression is very different from printing. This can sometimes be confusing, because when using an environment such as a REPL, the results of expressions are automatically printed to the console. In a real program, however, this does not occur. Let's examine a few examples.

Printing vs Expression Evaluation[edit]

Let's first have a look at what happens inside the REPL.

Welcome to Swift.

Type :help for assistance.

  1> func multiplyByTwo(number:Int) -> Int {

  2. return number * 2

  3. }

  4> multiplyByTwo(number:3)

$R0: Int = 6

  5>

Key Concepts[edit]

Exercises[edit]

References[edit]