Skip to content

Instantly share code, notes, and snippets.

@kittech0
Last active June 18, 2023 08:54
Show Gist options
  • Select an option

  • Save kittech0/4e615e4e5df1cf355cb55a8c10297957 to your computer and use it in GitHub Desktop.

Select an option

Save kittech0/4e615e4e5df1cf355cb55a8c10297957 to your computer and use it in GitHub Desktop.
The Prismatica Programming Language idea

Example hello world!

import std
main: f() = std#out.println("Hello world!")

Comments

main: f() = doingSomething(;; something can be here ;;) ; doing something!
;;
	or can be nowhere!
;;

Variables, constants, lambdas and mutable!

fool: i8 = 2
	; or
let fool: i8 = 2
const anotherFool: bool = true
l: f(x: i128): i128 = x^2
mut nonFool: i32 = 1234567890
	; or
let mut nonFool: i32 = 1234567890

More of lambda

main: f() = {
	fstop ; will stop lambda and return here
}
example: f(): i32 = {
	fstop 1 ; return value is required when fstop
}

Scalar types

  1. i8 to i128 and isize integers
  2. u8 to u128 and usize unsigned integers
  3. f8 to f128 float
  4. bool boolean
  5. char character

Tuple type

Tuple groups multiple types into one type. Example use:

example: f(x: i8): (i8,i8) = (x-2,x+2)

Arrays

Way of grouping multiple values into one collection. Example use:

example: f(x: char, y: char): [char:2] = [x,y]

References

Due to our language being null safe there are no pointers that you can see in C/C++ which are nullable. Example use:

main: f() = {
	mut x: i32 = 1
	example($mut x)
	std#out.println("It is now: $x!") ; It is now 2!
}
example: f(x: $mut i32) = x := 2

Loops

  1. each loops through stuff
  2. while loops as long as it is true
  3. loop infinite loop

Example use for each

main: f() = {
	elements: [char:5] = ['a','b','c','d','f']
	each element : elements std#out.println(element)
		; now range operator
	each int : 1..100 std#out.println(int)
}

Example use for while

main: f() = {
	elements: [char:5] = ['a','b','c','d','f']
	mut found: bool = false
	mut i: i8 = 0
	while !found {
		if elements[i] == 'd' = found = true
		i++
	}
	std#out.println("Found 'd' on $i place")
}

Example use for loop

main: f() = {
	mut i: i32 = 0
	loop {
		std#out.println("Now number is $i")
		if i == 100 = stop ; stops loops and blocks of code and returns
		i++
	} 
}

Structure

Ability to construct own data. Example use:

stuct Example {
	pub x: i32 =2 ; supports default too!
	y: $mut char
}
Example.getY: f(): $char = &.y
mut Example.mutateY: f(y: char) = &.y := y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment