HOME

Atom 🌖

Variable Binding

Atom allows values to be bind to particular name, referred as 'variable binding'.

In atom, variables are immutable, and assignments are not supported.

let name = "Bharat"

However, you can redeclare the variable with same name using concept called shadowing. Old value will not be accessible further.

let name = "Hany"

Data Types

Atom is dynamic language where types are associated with values, not with variables.

It supports integer (32 or 64 bits - architecture dependent), float (64 bits), string, boolean.

let name = "Bharat"
let age = 14
let heightInMeter = 1.7
let isAdult = true

Operators

Atom is strongly typed meaning all the operands in an expression must be of the same type.

1. Arithmetic

+, -, *, /, %

let name = (12 + 13) * 15

2. Relational

<, <=, >, >=, !=, ==

let eligibleToVote = age >= 18

3. Logical

and, or, ! (not)

let eligibleToBePolitician = talkNonsensical and hyprocite

If else expression

Atom has if else expression that works with single expression in its body.

let isEven = if num % 2 == 0 do true else false

Else part is optional.

let isEven = if num < 10 do "smaller"

Function Declaration And Expression

Functions in atom are first class citizens. You can bind them to names and pass them as arguments to another functions like normal values.

Atom supports functions in 2 formats: as normal function and as expression

let incr = fn |a| -> a + 1 end fn sum |a, b| ->
    a + b
end
incr(10) sum(10, 20)

Functions by default returns the last statement from the body, unless we explicitly return using 'return' keyword. In case, the last statement is not an expression, they return unit value '()'.

Function are pure functions. They only work with the provided arguments. In short, they are not closures.

fn id |a| ->
  return a
end

Iteration

There are no looping constructs in atom, however it supports recursion for the purpose.

fn fact |n| ->
  if n == 1 do return 1
  n * fact(n-1)
end