spool-lang / Spool-Legacy-Repo

Legacy repo for the Spool programming language.
3 stars 0 forks source link

Operators and Operator Overloading #7

Open RedstoneParadox opened 5 years ago

RedstoneParadox commented 5 years ago

The Silicon language has various operators for arthimetic, mathematical, and boolean operations. They are listed here alongside their typical uses.

Arthimetic:

The following symbols function as arthimetic operators.

+ addition - subtraction and unary subtraction/negation when the left side of the equation is not present. * multiplication. / division. % returns the remainder after division. ++ increments. -- decrements.

Concatation Operators

To reduce ambigiuty, seperate operators are provided for Concatation operations as opposed to certain arthemetic operators doubling as concatation operators.

|+ concatanates. |- Removes the last instance of the right side of the equation from the left side of the equation. |-- Pops off the last element of the right side of the equation.

Overloading

Operators can be overloaded by declaring an operator function with the operator keyword and the symbol of the operator as the identifier. Operator functions can either have 1 parameter for most operations.



class Foo{

    operator /(foo : Food) -> Int {
        return 2
    }

}