Skip to content
CShift0.45

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.

  1. Basics — program structure, namespaces, variables, control flow, operators
  2. Structs — fields, visibility, initializers, methods, inheritance
  3. Tuples — (int, string), return (a, b);, names, var (x, y) = t;, swapping, ==, tuples as keys
  4. Interfaces and generics — interfaces (constraints, parameters), sum types, generic structs/functions
  5. Enums — enums with an explicit base type
  6. Memory model — value vs. reference semantics, ARC, ref/const ref, unsafe
  7. Error handling — Error<T>, Optional<T>, try, is/switch patterns
  8. Threads — thread, Thread/Thread<T>, SharedPtr<T>, Mutex<T>
  9. Resources and using — IDisposable, deterministic cleanup
  10. Functions and function pointers — overloading, parameters, Action/Func, lambdas
  11. Arrays, strings and collections — arrays, strings and interpolation, slices, List, Dictionary, indexers
  12. Constants and global variables — const, globals, the compile-time evaluator
  13. C interop (FFI) — extern "C", importing C headers
  14. Projects — cshift.json, building programs with more than one file
  15. Tests — test "name" { ... }, Assert, cshiftc test
  16. Doc comments — /// and //!, tags, links, cshiftc doc
  17. Language status — the complete list of what’s implemented
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.