Socordia
  • Intro
    • The Compiler
  • The Basics
    • Variables
      • Arrays
    • Conditional Flow
    • Loops
    • Functions
    • Data
      • Casting
      • Enumerations
      • Ranges/Aliases
      • Structs
      • Tuples
      • Unit of Measure Types
  • Mixins
  • Accessibility
  • Primitive Datatypes
  • Extended
    • Conditional
    • Inline IL
    • Operator Overloading
    • Unions
    • OOP
      • Classes
      • Interfaces
Powered by GitBook
On this page
  • Definition
  • Assignments
  1. The Basics

Variables

PreviousThe BasicsNextArrays

Last updated 5 months ago

Definition

A variable can hold a value. Variables are by default immutable to prevent from changing the value. If you want to change the value later you can declare the variable as mutable with mut.

The syntatic structure of a variable definition:

<name> ::= [a-zA-Z_][a-zA-Z0-9_]+
<expression> ::= <literal> | ...
<variable_declaration> ::= "let" "mut"? <name> (":" <typename>)? = <expression> ";"

Sample of a variable definition:

let age = 42;

Back can automaticly deduce the type of the variable but if you want to specify the type, here is how:

let name: string = "Bob";

You can also specify the type by a literal type specifier:

let pi = 3.1451d;

A list of all basic primitive datatypes can be found .

Assignments

You can only assign mutable variables. If you try to change an immutable variable the compiler throws an error.

The syntactic structure of assignments:

<assignment> ::= <name> "=" <expression> ";"

A simple example:

let mut day = "Monday";
day = "Tuesday";
here