Skip to content

The Basics

Jacopo De Luca edited this page Feb 16, 2021 · 9 revisions

Like most other language, Argon uses variables to store and refer to values by an identifying name. In Argon are also present variables whose values can't be changed, these are known as constants. Constants are used to make code safer and clearer when you work with values that don't need to change.

Declaring Constants and Variables

Constants and variables must be declared before use, you can declare constant with let keyword and variable with var keyword. Here's an simple example of how constant and variables can be used:

let CONSTANT = 10
var my_var = 0

If a stored value in your code won’t change, always declare it as a constant with the let keyword.

By default the declared constants and variables are not visible outside the module/structure in which they were defined. Variables and constants can be made visible by using the pub keyword before their declaration.

pub let CONSTANT = 10
pub var my_var = 0

Naming rules

Constant and variable names can contain almost any character, but can’t contain whitespace nor unicode characters, also, they can't begin with a number, although numbers may be included elsewhere within the name.

Clearly once you’ve declared a constant or variable, you can’t declare it again with the same name, or change a constant into a variable or a variable into a constant.

Semicolon

Unlike many other languages, Argon doesn’t require you to write a semicolon (;) after each statement, although you can do so if you wish. However, semicolons are required if you want to write multiple separate statements on a single line:

let HELLO = "hello"; println(HELLO)

Comments

Use comments to include a note or reminder to yourself. Comments are ignored by the Argon compiler when your code is processed.

In Argon there are two way to create a comment:

  • in-line comment with: #
# This is an in-line comment.

This in-line comment style, enable you to insert at the start of the script file, the famous Shabang (#!) characters to tell to system which interpreter use to start to execute this file.

  • multi-line comment with C-like syntax: /* */
/*
 * This is a multi-line
 * comment.
*/

Datatypes

Argon wraps many fundamental C types, like Integer for integers, Decimal for floating-point values, Bool for Boolean values. Argon also provides powerful versions of the three primary collection types, Array, Set, and Dictionary, and a personalized version of String type for textual data.

Booleans

Argon has a basic Boolean type, called bool and provides two bool constant values, true and false:

let ARGON_IS_A_NOBLE_GAS = true
let ARGON_HAS_NO_KNOWN_COMPOUNDS = false

bool values are particularly useful when you work with conditional statements such as the if statement:

if !ARGON_HAS_NO_KNOWN_COMPOUNDS {
    println("HArF")
}

Furthermore Argon allows non-bool values to be replaced with boolean values:

var my_list = []

if !my_list {
    println("my_list is empty.")
}

Integer

Integers are whole numbers with no fractional component, such as 1 and -24. Integers are either signed (positive, zero, or negative) or unsigned (positive or zero). Argon provides only a signed integers, the size in bits depends on the underlying system.

Integer literals

Integer literals can be written as:

  • Decimal number, with no prefix
  • Binary number, with a 0b prefix
  • Octal number, with a 0o prefix
  • Hexadecimal number, with a 0x prefix

All of these integer literals have a decimal value of 18:

let decimal = 18
let binary = 0b10010
let octal = 0o22
let hexadecimal = 0x12

Decimal

Decimal (floating-point) numbers are numbers with a fractional component, such as 39.948, and -189.3. Decimal types can represent a much wider range of values than integer types, and can store numbers that are much larger or smaller than can be stored in an integer. Argon wraps C double floating-point number.

Tuples

Tuples group multiple values into a single compound value. The values within a tuple can be of any type and don’t have to be of the same type as each other.

An example of tuple can be the HTTP status code 200("OK") can be expressed in Argon language as:

let HTTP_OK = (200, "ok")

Once you have a tuple, you can decompose its value if you prefer, using the following syntax:

var code
var msg

code, msg = HTTP_OK

Or you can access a single element using an index with the [] operator:

var msg = HTTP_OK[1]

Nil

You can set a variable to a valueless state by assigning it the special value nil:

var valueless = nil

If you define a variable without providing a default value, the variable is automatically set to nil for you:

var valueless /* valueless = nil */

REMEMBER: In Argon nil is the absence of a value, not a pointer to a nonexistent object.
Just to know, internally, nil is an object! 😉

Clone this wiki locally