From 48a76da07e0a63f6a0e3bfd4a22e3e4e83369c87 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 22 Jun 2022 19:12:41 +0200 Subject: [PATCH] Added a lot of stuff to README.md --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/README.md b/README.md index e69de29..1a75db8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,73 @@ +# Sapphire +A modern, fast and reliable programming language. (WIP) + +**WARNING**: Most features in this README (especially the About section) are planned for the future and not yet implemented. + +## About +Sapphire is a relatively high-level programming language, yet low-level when it needs to be. The language supports low-level memory manipulation using pointers, but pointer arithmetic is only allowed in unsafe contexts, for greater memory safety. Dynamic memory allocation is also a thing, though it is recommended not to use it directly, but instead make great use of [smart pointers](https://en.wikipedia.org/wiki/Smart_pointer). + +Sapphire is a [compiled](https://en.wikipedia.org/wiki/Compiled_language) programming language, with static typing, although [type inference](https://en.wikipedia.org/wiki/Type_inference) is also supported. It also has a high-level standard library, which supports console/file I/O, operating system functions, advanced math operations, string manipulation, and many more. + +## Basic usage +"Hello world" in Sapphire: + +``` +const io from @'core/io'; + +let @main in { + io.outln('Hello, World!'); +} +``` + +or alternatively: + +``` +const { outln } from @'core/io'; + +let @main in { + outln('Hello, World!'); +} +``` + +## Examples +FizzBuzz: +``` +const io from @'core/io'; +const { toString } from @'core/type_utils'; + +let @fizzBuzz(i32 i) in { + String result = ''; + if(i % 3 == 0) + { + if(i % 5 == 0) + { + result = 'FizzBuzz'; + } else { + result = 'Fizz'; + } + } else { + if(i % 5 == 0) + { + result = 'Buzz'; + } else { + result = toString(i); + } + } + io.outln(result); +} + +let @main in { + for(i32 i = 1; i <= 100; i++) + { + fizzBuzz(i); + } +} +``` +Quine: +``` +const io from @'core/io'; +String fmt = 'const io from @%ccore/io%c;%cString fmt = %c%s%c;%clet @main in {%c%cio.outf(fmt,39,39,10,39,fmt,39,10,10,9,10,10);%c}%c'; +let @main in { + io.outf(fmt,39,39,10,39,fmt,39,10,10,9,10,10); +} +``` \ No newline at end of file