Skip to content
CShift0.32

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. Interfaces and generics — interfaces (constraints, parameters), sum types, generic structs/functions
  4. Enums — enums with an explicit base type
  5. Memory model — value vs. reference semantics, ARC, ref/const ref, unsafe
  6. Error handling — Error<T>, Optional<T>, try, is/switch patterns
  7. Threads — thread, Thread/Thread<T>, SharedPtr<T>, Mutex<T>
  8. Resources and using — IDisposable, deterministic cleanup
  9. Functions and function pointers — overloading, parameters, Action/Func, lambdas
  10. Arrays, strings and collections — arrays, strings and interpolation, slices, List, Dictionary, indexers
  11. Constants and global variables — const, globals, the compile-time evaluator
  12. C interop (FFI) — extern "C", importing C headers
  13. Projects — cshift.json, building programs with more than one file
  14. Doc comments — /// and //!, tags, links, cshiftc doc
  15. 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.