package skeb.operation

/** A trait that can be mixed into an Evaluator function to provide it with
  * simple algebraic operators. */
trait Algebraic requires Evaluator {
  
  import expression.Number
  
  operations.update("+",
    { case List(Number(x), Number(y)) => Number(x + y) })
  
  operations.update("-",
    { case List(Number(x), Number(y)) => Number(x - y)
      case List(Number(x)) => Number(-x) })
  
  operations.update("*",
    { case List(Number(x), Number(y)) => Number(x * y) })
  
  operations.update("/",
    { case List(Number(x), Number(y)) => Number(x / y) })
  
  operations.update("%",
    { case List(Number(x), Number(y)) => Number(x % y) })
  
}