Git Product home page Git Product logo

programming-univbasics-expression-and-evaluation-defined-nyc-web-071519's Introduction

Defining Expression and Evaluation

Learning Goals

  • Define "Expression"
  • Identify the Parts of an Expression
  • Identify Core Operators in Ruby
  • Define "Evaluation"

Introduction

We've seen that we can have a conversation with Ruby by using the IRB program. Conversations, we've seen, are the things that result when two individuals — be they human or machine — communicate expressions to one another.

We've been imprecise in defining "expression" while we were getting the hang of it. Let's propose formal definitions for expression and evaluation.

Define Expression

An expression in a programming language is like a sentence in a spoken language.

Some sentences are simple: "He wept." Some sentences are complex: "I sing of weapons and a man, an outcast of Troy who was driven to the shores of Italy..."

Some expressions are simple: 2. Some expressions are complex 1 + 2. Some expressions are really complex: 10 + (3 * ( -1 ** 3) + 2) / 18.

Definition: Expression: A combination of information called data and symbols indicating how to combine data called operators.

Define "Evaluation"

Evaluation is the process of interpreting an expression, according to rules, to produce a return value.

Expression and Evaluation with Ruby

Expression being evaluated by Ruby

These definitions should align with your experience of having a conversation with IRB from the previous lesson. Think about 255 / 5. Which parts of the expression are data? Which parts are operators?

PRO-TIP: Think it through yourself. Which is a given thing (data) and which parts tell you how to combine things (operators)? When reading technical documents you can't simply read the answers, you have to think along not merely read. You're not reading a gossip site or a sports story, co-participation is needed to help your brain learn that this stuff is important!

Identify the Parts of an "Expression"

The data are: 255 and 5 The operator: is /

In this example, there is only one operator. It's certainly possible for expressions to have multiple operators like 100 + 10 - 3. In this example, the operators are + and -.

Identify Core Operators in Ruby

Here's a table of other operators and their operations. Fortunately, all these operators are either the same or nearly the same as their mathematical partner, so you probably know all the operators you're going to need to get started.

Operator Operation Note
+ Addition
- Subtraction
* Multiplication We use * instead of × because it looks like x-the-letter
/ Division We use / instead of ÷ because that's not on a keyboard
** Exponentiation We use ** instead of ^ because ^ means something else in programming languages
() Association Expressions inside of () get evaluated earlier

Conclusion

In the next few lessons, we're going to introduce the Essential Three Expressions:

Three Essential Expression

  1. The constant expression
  2. The assignment expression (variable assignment)
  3. The variable lookup expression

All expressions, which are the core of every programming language are built on these Essential Three Expressions.

Let's visit the mysterious, yet oddly dull first of the essential expressions: The Constant Expression.

programming-univbasics-expression-and-evaluation-defined-nyc-web-071519's People

Contributors

lizbur10 avatar maxwellbenton avatar sgharms avatar ddeleon267 avatar

Watchers

 avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Matt avatar Antoin avatar  avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.