The modern and fun way to program.

View the Project on GitHub

The Smudge Programming Language - Types

Smudge and types

As we’ve alredy seen, we can store many different kinds of objects inside a variable, from integers to class instances.

I’ve alredy previously talked about how objects are treated in Smudge here, but now we’ll linger on them more deeply.


Smudge’s integers are effectively stored at least in 64-bit signed integers. Typically the range of valid values goes from -9223372036854775808 to +9223372036854775807.

To check these values on your machine, try executing the following code:

import, std.math;

 * We're using the integer constants MIN_INT and MAX_INT
 * in box std.math.
func main
    io << "minimum value: " << math.MIN_INT << io.ln
       << "maximum value: " << math.MAX_INT << io.ln;

Note that you cannot insert the minimum value in the code: that’s because the Smudge parser evaluates the absolute value of the integer before applying its sign.

Integers can be written in different bases following the rule:

So, these strings are all valid integer literals:

    -0xFF    0b1010    - -0777    -+-125


Floating-point values are stored in double-precision floating point generally with 64-bits of size.

There are different formats for representing a float in Smudge:

At the moment there’s no way to type an hexadecimal/octal/binary floating-point in Smudge.


In Smudge strings are represented with the UTF-8 enconding, so it’s a simple sequence of bytes. I’ve talked a lot about strings here, so take a look before continuing to read.

Class Instances

Now we’ll see different types of class instances. These are objects derived from a class. The SSL provides several classes for many different uses.

Because the box std.lang is imported by default, classes like String, List or Tuple (with the respective StringIterator, ListIterator and so on) alredy exist in memory and are ready to be used. This is why you don’t need to import anything to use a string, list or tuple.


There are not arrays in Smudge: we use lists instead. A list is a structure which can contain a variable amount of objects; it can grow and shrink dynamically during the execution of a program and is automatically freed by the garbage collector.

A list is initialized with the following syntax:

[obj0, obj1, ..., objN] // list with N elements
[] // empty list
lg.List() // empty list, where 'lg' is box 'std.lang'

You can see all the methods and operators supported by lists here.


Tuples are like lists but immutables. Tuples’ syntax is similar to Lists’:

(obj0, obj1, ..., objN) // tuples with N elements
lg.Tuple() // empty tuple, where 'lg' is box 'std.lang'

NOTE: Syntax #1 doesn’t apply to tuples with one element: because expression (obj) could be ambigous, it’s evaluated as obj.

To create a tuple with an element, you can use any of the following tricks:



Hashtable are associative containers of objects in which you can store values accessed with keys. Values and keys are both objects, but, while values don’t have special requirements, keys need to define:

Integers, Floats, Tuples and Strings can be used as keys, because their hashing and comparing functions are alredy defined.

 . . .
var my_table = lg.Table();
/* storing values */
my_table[120] = (100, 20);
my_table["Hello"] = "World";
my_table[(1, 2)] = (3, 4);
/* printing them */
for(key : my_table.keys())
    io.println(key, ": ", my_table[key]);
 . . .

Other Classes

The SSL consists of many boxes, most of which define classes ready ‘out of the box’. However, very often we need to create and use our customized classes. In the next page we’ll find out how to define and implement them.

Previous Home Next