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
See the navigation at the top of this page for more in-depth information about specific features of Cyen. I will update this page and add more pages there as I work out ideas.
Features
Conditional statements
If-else
if expression:
~~ Things happen here
else if anotherExpression:
~~ Other things happen here
else:
~~ Remaining things happen here
::
Switch
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
::
Loops
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
forever:
~~ never stopping, unless you break me
::
Control in loops
loc i: int = 0
while i < 10:
~~ do stuff
~~ Instantly go to the next iteration
continue
~~ Instantly leave the loop
break
finally:
~~ 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
then:
~~ Invoked when the loop exited without break
~~ You can still 'break' here to jump to the 'else' block
else:
~~ 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
Functions
@ () -> 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 typenum
is any numeric typeint
is an integerfloat
is a floating point number
str
is a stringregex
is a regular expression (it’s assignable tostr
)
bool
is a booleanrange
is a range of numbers
int?
is an integer pointer that may be null[int]
is an array of integers[!int]
is an array of integers whose elements may not be set(int, str)
is a tuple of an integer and a string
Hi! I'm Samū, a furry, artist and game developer from the Netherlands. This is my blog, where I write about my projects and ideas.