// Single Line
/*
Multi-Line
Comment
*/
@package Main
@if @true {
// ...code...
}
// Let is for constants
// Strings are immutable unless you use
@let name @str : "John"
@let name : "John"
$name : "John"
@let age @num : 28
@let age : 18
$age : 18
$$MAX : 10
@ - Keywords
@@ - Annotations
$ - Let Declaration
$$ - Var Declaration
^ - Nominal Type prefix
~ - Structural Type prefix
! - Mutable variable or method suffix Like convention in Ruby except this is enforced by the compiler.
// Mutable string
@str!
// Method mutates passed data. Compiler enforces that at least one parameter is passed by reference and modified for functions and that at least a field or property is modified for methods.
#Reverse! arr
# - Method Call prefix
#Add 1,3
_ - Placeholder
[0:_]
@for ;_ < 10; {
}
a, _ : #GetTwoValues
? - Optional suffix (Like Nullable)
@num?
@let Div? $a $b : $b = 0 ? @nil : $a / $b
Silicon / Sigil is a strongly statically typed language with a very strong but flexible type system. You'll rarely see types explicitly declared as the compiler does type inference (but not auto conversion).
Silicon uses type hierarchies / unions to simplify the type system (making it run as an interpreted language quiet well too).
@num - signed integer Union of int(8|16|32|64|128) and float(32|64|128). Unlike C unions only the memory size of the used type. Generic Union or Dynamic Union. Like how we can declare an array of arbitrary size.
@nat - natural number uint(8|16|32|64|128)
@str - immutable string supports Unicode
@str! - mutable string supports Unicode
@bool - boolean @true | @false. Alias for @Bits(1).
@char - UTF-8 /16 and Unicode support. Alias for uint8 / uint16 but with different Nominal type which then has different methods / operators associated with it as well.
@bits - An arbitrarily sized continuous block of bits (Like Cell in Scheme)
All keywords are prepended with the @ sigil.
when inside loops there are some keywords that are just syntatical sugar for commonly used statements.
for $i range arr {
##Print arr[i+1]
// ^ could be written as the following
##Print $$next
}
@next -> arr[i+1] @previous -> arr[i-1] @first -> arr[0] @last -> arr[len(arr)-1]
It is a language that I'm designing and building a compiler and VM for. The working name is Silicon or Si (like the symbol in the periodic table of elements). It is inspired by Golang, OCaml and several other languages.