4. CyML Language Specification

This document specifies the CyML language, an extended Cython subset supported.

4.1. Cython file types

  • The implementation files, carrying a .pyx suffix.

4.2. Basic Types

The following basic types are supported

  • bool
  • int
  • float
  • double
  • string

4.3. Complex Types

The following complex types are supported

  • array
  • list
  • datetime

4.4. Conditional Statements

  • IF
  • IF/Else
  • IF/ElseIf/Else

The ELIF and ELSE clauses are optional. An IF statement can appear anywhere that a normal statement or declaration can appear

4.5. Integer For Loops

CyML recognises the usual Python for-in-range integer loop pattern:

for i in range(n):
    ...

Like other Python looping statements, break and continue may be used in the body, without the loop that have an else clause.

4.6. While Loop

  • Like Python While loop

4.7. Function

  • Parameters with declaration
  • Default value is possible

4.8. Return Statement

  • A function needs to return the same data type.

The following code is valid:

def fibonacci(int n):
    if n <= 2:
        return 1
    else:
        return fibonacci(n-1)+fibonacci(n-2)

4.9. Call functions

  • Call to CyML functions are supported if the function
  • is accessible on the module
  • is accessible from import statement

4.10. Operators

Assignment

Assign b = a

Unary operators

UAdd +a
USub -a

Binary operators

Add a + b
Sub a - b
Mult a * b
Div a / b
Pow a ** b
Mod a % b
BitOr a | b
BitAnd a & b

Augmented assign statements

AugAdd a += b
AugSub a -= b
AugMult a *= b
AugDiv a /= b

Comparison Operators

Eq a == b
NotEq a != b
Lt a < b
LtE a <= b
Gt a > b
GtE a >= b

Bool Operators

&& a and b
|| a or b

4.11. Array routines

`` `` Return a new array of given shape and type, without initializing entries.
`` `` Return a new array of given shape and type, filled with ones.
`` `` Return a new array of given shape and type, filled with zeros.

4.12. Mathematical functions

Trigonometric functions

sin(x) Trigonometric sine, element-wise.
cos(x) Cosine elementwise.
tan(x) Compute tangent element-wise.
arcsin(x) Inverse sine, element-wise.
arccos(x) Trigonometric inverse cosine, element-wise.
arctan(x) Trigonometric inverse tangent, element-wise.

Hyperbolic functions

sinh(x) Hyperbolic sine, element-wise.
cosh(x) Hyperbolic cosine, element-wise.
tanh(x) Compute hyperbolic tangent element-wise.