CShift language guide
A tour of CShift’s language features, each explained briefly with common code examples. It is the friendlier companion to the design document (the rationale) and the language status (the precise list of what’s implemented, and the decisions the design leaves open). The exact rules are in the language reference. The library is described in ../stdlib.md.
Contents
Section titled “Contents”- Basics — program structure, namespaces, variables, control flow, operators
- Structs — fields, visibility, initializers, methods, inheritance
- Interfaces and generics — interfaces (constraints, parameters), sum types, generic structs/functions
- Enums — enums with an explicit base type
- Memory model — value vs. reference semantics, ARC,
ref/const ref,unsafe - Error handling —
Error<T>,Optional<T>,try,is/switchpatterns - Threads —
thread,Thread/Thread<T>,SharedPtr<T>,Mutex<T> - Resources and
using—IDisposable, deterministic cleanup - Functions and function pointers — overloading, parameters,
Action/Func, lambdas - Arrays, strings and collections — arrays, strings and interpolation, slices,
List,Dictionary, indexers - Constants and global variables —
const, globals, the compile-time evaluator - C interop (FFI) —
extern "C", importing C headers - Projects —
cshift.json, building programs with more than one file - Doc comments —
///and//!, tags, links,cshiftc doc - Language status — the complete list of what’s implemented
A first program
Section titled “A first program”using System;
struct Vec2{ float X; float Y;
float Length() { return sqrt(X * X + Y * Y); }}
int Main(){ var v = Vec2 { X = 3, Y = 4 }; Console.WriteLine(v.Length()); // 5 return 0;}Save this as hello.cshift and build it with cshiftc hello.cshift -o hello --run, or start a project with
cshiftc new hello && cshiftc run hello. See the main README for how to get or build cshiftc itself.