A programming language

Cyen is a general-purpose programming language designed for readability and flexibility. It combines syntax rules from Python, Java, TypeScript, C, Rust, Haskell, and Lua, and introduces various new concepts in programming.

I wanted to make Cyen a bit different from usual programming languages, while not immediately deviating from the path of usual programming languages.

Cyen Program to find the factors of a number

@ int -> void
func printFactors(x):
    println "The factors of #x are:"

    for loc i in 1..x+1 where x % i == 0:
        println i

loc fixed NUM: int = 320
printFactors NUM

I will update this page and add more information about Cyen as I work on the language.


Conditional statements


if expression:
    ~~ Things happen here
else if anotherExpression:
    ~~ Other things happen here
    ~~ Remaining things happen here


Switch statements are a bit different from how they are provided in most languages. It takes advantage of Cyen’s design of code blocks. Main differences are that there is no default label (unlike C, this is instead the code before any case label) and that each case block separates its own action, so there’s no need to use a break keyword. More on switch statements and their design coming later.

switch expression:
    ~~ Default action
case value1:
    ~~ Action 1
case value2, value3:
    ~~ Action 2


Conditional loops

An until loop is the exact same as a while loop with the inverted condition. Cyen provides syntactic sugar for easy inverting of the entire condition without having to change the condition directly.

while condition:
    ~~ waiting...

until condition:
    ~~ impatient waiting...

Range loops

for i in a..b:
    ~~ i goes from a (inclusive) to b (exclusive)

for i in a..b where condition:
    ~~ i goes over any number from a to b for which condition holds

Iterator loops

for i in iterable:
    ~~ i goes over all elements in the iterable

for i in iterable where condition:
    ~~ i goes over all elements in the iterable for which condition holds

Infinite loops

    ~~ never stopping, unless you break me

Control in loops

loc i: int = 0
while i < 10:
    ~~ do stuff

    ~~ Instantly go to the next iteration

    ~~ Instantly leave the loop

    ~~ Invoked at the end of each iteration,
    ~~ whether 'continue'/'break' is used or not
    ~~ Useful to modify the loop counter in complicated loops
    incr i
    ~~ Invoked when the loop exited without break
    ~~ You can still 'break' here to jump to the 'else' block
    ~~ Invoked when the loop exited via 'break'
    ~~ This only invoked when the loop itself is broken,
    ~~ if an outer loop/block is exited via 'break', this block
    ~~ is ignored

More on loops to be specified soon


@ () -> bool
func paradox:
    return not paradox!

With parameters

@ (int, int, ...[int]) -> void
func noReturnValue(but, three, params):
    ~~ 'params' is an '[int]' but the '...' indicates
    ~~ that it must collect any extra argument after the first
    ~~ two arguments into a list

With type parameters

@ T -> T where T: num
func square(n):
    return n * n

Type signatures

  • any is any type
    • num is any numeric type
      • int is an integer
      • float is a floating point number
    • str is a string
      • regex is a regular expression (it’s assignable to str)
    • bool is a boolean
    • range is a range of numbers
  • int? is an integer pointer that may be null
  • int! is an integer pointer that may not be null
  • [int] is an list of integers
  • (int, str) is a tuple of an integer and a string
  • {int} is a set of integers
  • {str: int} is a map with string keys and integer values
  • ((int, str) -> bool) is a dynamic function taking an integer and a string, returning a boolean

Hi! I'm Shadew, a game developer from the Netherlands. This is my blog, where I write about my projects and ideas.

Copyright © 2021 Shadew

All rights reserved

Powered by Jekyll