Code Monkey home page Code Monkey logo

expression's Introduction

Expression

Inspiration:

This is inspired by André Bergner talk https://www.youtube.com/watch?v=QYNRoeWJuAw . The goal is to capture expressions and automatically propagate changes through different variables.

Example

The example can be compiled with g++ -std=c++17 example.cpp

#include "expression.h"

#include <iostream>

using expression::operator ""_v;

int main()
{
    auto x = 5._v;
    auto x2 = 5._v;
    auto y = x2 * x;       // x2 * x
    auto z = x * y;        // x * x2 * x
    auto w = 2. * z / 3. ; // 2* x * x2 * x / 3.

    std::cout << "x:  " << x.getValue()  << "\n"; // print 5
    std::cout << "x2: " << x2.getValue() << "\n"; // print 5
    std::cout << "y:  " << y.getValue()  << "\n"; // print 25
    std::cout << "z:  " << z.getValue()  << "\n"; // print 125
    std::cout << "w:  " << w.getValue()  << "\n"; // print 83.3333

    x = 6;
    std::cout << "x:  " << x.getValue()  << "\n"; // print 6
    std::cout << "x2: " << x2.getValue() << "\n"; // print 5
    std::cout << "y:  " << y.getValue()  << "\n"; // print 30
    std::cout << "z:  " << z.getValue()  << "\n"; // print 180
    std::cout << "w:  " << w.getValue()  << "\n"; // print 120

    x2 = 7;
    std::cout << "x:  " << x.getValue()  << "\n"; // print 6
    std::cout << "x2: " << x2.getValue() << "\n"; // print 7
    std::cout << "y:  " << y.getValue()  << "\n"; // print 42
    std::cout << "z:  " << z.getValue()  << "\n"; // print 252
    std::cout << "w:  " << w.getValue()  << "\n"; // print 168

    return 0;
}

expression's People

Contributors

sgssgene avatar

Stargazers

 avatar

Watchers

 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.