#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2017 lafrite # # Distributed under terms of the MIT license. """ Computing with MO """ from .exceptions import ComputeError from .add import add from .minus import minus from .multiply import multiply OPERATIONS = { "+": add, "-": minus, "*": multiply, } def compute(node, left_v, right_v): """ Computing a node :example: >>> from ..MO.mo import MOnumber >>> compute("+", MOnumber(1), MOnumber(2)) >>> compute("-", None, MOnumber(2)) >>> compute("*", MOnumber(1), MOnumber(2)) >>> compute("~", MOnumber(1), MOnumber(2)) Traceback (most recent call last): ... mapytex.calculus.core.compute.exceptions.ComputeError: Unknown operation (~) """ try: operation = OPERATIONS[node] except KeyError: raise ComputeError(f"Unknown operation ({node})") return operation(left_v, right_v) # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: # cursor: 16 del