Official 🌑 Night v3.0 🌕 Tutorial
DynamicSquid (4602)

A week ago, a language called Night released its third version. Now, I may be a little biased, but I heard it was actually a really good language. You should definitely check it out.

Anyways,

Night is a simple statically typed language. It's syntax is very similar to the C family, but it also combines the simplicity of Python, making learning it a breeze.

So here's a short little tutorial of what it can do so far. Enjoy :)


Hello World!

Night has a built in print function in the form of print().

print("Hello World!\n");

Comments are also supported by using //.

// this is a comment
print("woah, that is a comment");

Variables

Night has 5 basic types, booleans, characters, integers, floats, and strings.

bit boolean = true;
syb character = 's'; // 's' for squid
int integer = 10; // '10' for 10 legs on a squid
dec float = 100.00; // '100.00' for 100.00% smartness for a squid
str string = "squid"; // 'squid' for squid

All of them support common expressions relative to their type.

bit boolean = "squid" == "smart";
int number = 3 * (2 + 4);
str string = "squid has " + 10 + " legs";

If Statements

The syntax for if statements in Night closely follows the C family.

if ("squid" == "smart")
{
	print("squid is smart");
}
else if ("squid" != "smart")
{
	print("lol squid dumb");
}
else
{
	print("squid is squid");
}

Functions

Functions support the 5 basics types, as well as a null type.

bit isSmart(str name)
{
	return name == "squid" || name == "octopus";
}

if (isSmart("squid"))
{
	print("Squid is smart");
}

null displayFriends()
{
	print("lol we're coders we don't have friends");
}

displayFriends();

Loops

Night has two types of loops, while and for loops. While loops take in a boolean condition, and for loops take in an integer.

loop while ("squid" == "smart")
{
	print("squid so smart\n");
}

int a = 5;
loop for (9)
{
	print(a + " ");
	a += 1;
}

Arrays

Arrays are very fexible in Night, meaning they can be assigned to other arrays regardless of their size.

// array of 3 elements, 2 of which have been assigned
int[3] nums1 = [ 5, 7 ];
int[] nums2 = nums1;

str[] words = [ "squid", "is", "smart" ];
words[2] = "not " + words[2];

Example

Here's an example of what you can do with Night:

// classic fibonacci sequence using recursion
int fib(int num)
{
    if (num <= 1)
    {
        return num;
    }

    return fib(num - 1) + fib(num - 2);
}

// array of 3 values, 2 of which have been initialized
int[3] fib_nums = [ fib(5), fib(6) ];
fib_nums[2] = fib(7);

// printing out the values of the array
int a = 0;
loop for (3)
{
    print(fib_nums[a] + " ");
    a += 1;
}

And that's it! You can check out the GitHub page for more info on future updates.

Thanks for reading :)

You are viewing a single comment. View All
JordanDixon1 (451)

You could also make custom file extensions that can be run on python and c. (If run on python and/or c you must import a module.)

JordanDixon1 (451)

@DynamicSquid For example: the language can run .py files and .c files. It also runs .n (night) files. If you code in python and import night code then you have to import a module to do so (same for c).

fuzzyastrocat (1504)

@JordanDixon1 What do you mean by

the language can run .py files and .c files

As I understand it, Night only runs night files (you use python3 to run .py files and gcc to run c files)

DynamicSquid (4602)

@fuzzyastrocat, @JordanDixon1, yeah that's what I'm confused about too...

JordanDixon1 (451)

@DynamicSquid @fuzzyastrocat It would be cool to have the ability to maybe add a block of night code straight into python or c with a module.

fuzzyastrocat (1504)

@JordanDixon1 Ok, that makes more sense. @DynamicSquid, if you're looking to do that, I'd research a Foreign Function Interface (FFI). It's a way for functions from different languages to interact. That way, rather than having to write a whole new Night interpreter in C and Python and any other language that you want to have it interface with, you just write one FFI which handles most languages. (You might have to write multiple FFI's, I'm not sure, but regardless it's much easier to write an FFI than a new interpreter.) I'm not an expert on this or else I'd describe it better here, but I'm sure there's some tutorials out there on how to make one.

DynamicSquid (4602)

@fuzzyastrocat oh that sounds interesting! thanks for the idea @JordanDixon1

fuzzyastrocat (1504)

@DynamicSquid Great! One note of caution — I'd only recommend implementing an FFI once your language is fairly mature. If it's in a state where you think you'll be making significant changes to it, don't write the FFI yet, as you might have to end up going back and rewriting parts of your FFI because of what you changed in the language implementation.