Learn to Code via Tutorials on Repl.it!

← Back to all posts
##### Official 🌑 Night v3.0 🌕 Tutorial

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 :)

hotnewtop
HahaYes (1861)

I'm not sure who made Night, but its really good

fuzzyastrocat (1859)

@HahaYes The evil Earth with its pesky rotation makes night

firefish (947)

@fuzzyastrocat Earth makes night, but squids make Night

DynamicSquid (4893)

@firefish lol yeah! also what should I name my compiled language? I'm thinking of starting it once I get v3 done. What about syntax?

firefish (947)

@DynamicSquid I have this sort of good idea me and lethdev were doing, called SliceLang, wanna help? It's in lex and yacc though, would you like to do that?

DynamicSquid (4893)

@firefish ew yuck make your own parser and lexer

DynamicSquid (4893)

@firefish what lang are you doing it in?

firefish (947)

@DynamicSquid It's already been made, it's only 20 lines of lex code in and 1124 lines of C code out

DynamicSquid (4893)

@firefish bruh, who cares? a self made lexer is always the best, and you don't have to install anything. and if other people want to use your language, don't they have to install yacc and bison as well?

firefish (947)

@DynamicSquid No, the user doesn't need lex and yacc, lex and yacc output C code which you put into your compiler

DynamicSquid (4893)

@firefish oh, but still make it yourself, everyone on stack overflow agrees with me too: https://stackoverflow.com/questions/3593149/yacc-lex-or-hand-coding

firefish (947)

@DynamicSquid The parser you can write yourself. The lexer you can let lex do

DynamicSquid (4893)

@firefish ok fine, I guess I can help, but I don't think I'll be able to do much since I'll be really busy if that's fine with you guys

DynamicSquid (4893)

@firefish it'd also be nice to do some C stuff, really need to polish up my skills with that language

firefish (947)

@DynamicSquid Well we can both contribute to Both night and slice simultaniously, or maybe Night could compile to slice or vice-versa

firefish (947)

@DynamicSquid
C program == valid C++ program,
C++ program != valid C program

DynamicSquid (4893)

@firefish eh, I kinda want to keep Night separate from this

firefish (947)

@DynamicSquid They could both compile to the same bytecode, and we could write a virtual machine for it

DynamicSquid (4893)

@firefish hmm... haven't done much research one those... quick question, we can make up our own bytecode syntax right? and a vm is basically a program that either interprets or compiles bytecode right?

firefish (947)

@DynamicSquid Yep, things like
`0df97c96796d7c6fd96c96767c6` could mean to print Hello World (That was just me mashing hex on my keyboard but you get the idea)

DynamicSquid (4893)

@firefish oh, well i kinda want to keep night interpreted, but maybe for my compiled lang i'll do something similar

firefish (947)

@DynamicSquid Well we can have a night script evaluator, and maybe a night compiler as well, kind of like OCaml

firefish (947)

@DynamicSquid alright, but I kind of want to link them in some way, because having two completely different but similar minded projects is a bit pointless

DynamicSquid (4893)

@firefish hmm... not really feeling it. I just want Night to be it's own thing

fuzzyastrocat (1859)

@firefish So... the Earth is a squid!

###### (That's how logic works, right?)
firefish (947)

@DynamicSquid But that's weird having two completely different langs that are not connected in some way, It just feels weird. It'd be good to hav e it like .NET, with c#, VB, like that.

firefish (947)

@fuzzyastrocat No, Earth makes night (concrete noun), and squids make Night (proper noun)

Get it?

fuzzyastrocat (1859)

@firefish Yes, I get it, I was just trying to expand on it with my own joke :D

firefish (947)
###### @fuzzyastrocat You still haven't admitted you ripped off dusk
fuzzyastrocat (1859)

@firefish reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee not this again

HahaYes (1861)

@fuzzyastrocat bruh I come back to like 33 messages smh

fuzzyastrocat (1859)

@HahaYes Oops sorry, in my defense most of the conversation here I wasn't involved in :P

firefish (947)

@DynamicSquid I've done some bytecode prototyping, here is so far:

# datatypes

Datatypes in SliceNight DatatypesBytecode
i8 i16 i32 i64int0xD1 - D4
u8 u16 u32 u640xD5 - D8
f32 f64dec0xD9 & DA
chrsyb0xDC
bool nilbit null0xDB & D0
fun()0xDF

# strings

LengthDataNull
15`Squids are cool`
0F5371756964732061726520636f6f6c00

# samples

BytecodeNight codeSlice code
DFD0`null ()``fun () -> nil`
DC04706C6F7000`syb plop``let plop of chr`
fuzzyastrocat (1859)

@DynamicSquid @firefish Just now seeing your above conversation. My double pieces of circular flattened copper on the matter:

#### On Lex/yacc:

I feel that lex/yacc is not a good route to take. It is really beneficial to have complete control over the insides of your lexer/parser. While yacc is nice if you just want to get something done, it completely abstracts the actual workings of your parser from you — meaning there can be no optimizations specific to your language, no special behaviors, and the parser will always work one way (which might not be beneficial depending on the way your language works). If you do it yourself, you can choose which algorithms you use and you can decide the structure of your parser.

I'm not saying lex/yacc is bad, it's a very useful tool, but if you're trying to make a mature language I feel that doing it by hand is best.

#### On bytecode VMs:

Here's a common misconception: creating a bytecode VM makes your language compiled. While your language has a compiled element, it is not a compiled language — it's interpreted. I think the biggest factor in this misconception is Java. We think of Java as a compiled language — but it's really not. It compiles to JVM bytecode, yes; but that bytecode is then interpreted by the JVM runtime. So Java, in a technical sense, is interpreted.

So, when you (squid) say

well i kinda want to keep night interpreted

Writing a bytecode VM would still be keeping Night (overall) interpreted. Yes, there is a compilation part of it, but it's really more interpreted than compiled.

A side note: If either of you would like help on creating a bytecode VM, I could write a tutorial for that.

P.S: SliceLang sounds cool!

DynamicSquid (4893)

@fuzzyastrocat oh thanks for the explanation! and are there any benefits of compiling to bytecode and using a VM rather than compiling straight to assembly?

fuzzyastrocat (1859)

@DynamicSquid Okay, this a double-edged-sword situation. Here's one edge of the blade:

• A bytecode VM will be way easier to translate to than assembly. Believe me, translating to assembly by hand is arduous and complex. Especially if you're making a higher-level language. On the other hand, translating to bytecode will be really easy, since you define how the bytecode works. The best way to think of it is like this: is it easier to learn a complicated foreign tongue, or create a simple (spoken) language yourself?

And now the other:

• Because assembly is so low-level, it will naturally be faster than a VM. The VM has a builtin overhead because of the little bit of abstraction you give it to make it easier to translate to. (And no, even if you make it just like assembly it will still be slower since you're running it in a host language, not a "bare" CPU.)
fuzzyastrocat (1859)

@HahaYes @firefish VM is not slow compared to traditional interpreted languages. Obviously it won't be as fast as compiling, but you can make it pretty fast.

fuzzyastrocat (1859)

Noo this just dropped off the main repl talk page (all), now I have to click on "view more"

ChezTacoz (340)

Squid for squid. Woah nice comparison dude!!!lol

code913 (17)

who else paid no attention to the tutorial but was just laughing uncontrollably because this is too funi

JordanDixon1 (178)

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 (178)

@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 (1859)

@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 (4893)

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

JordanDixon1 (178)

@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 (1859)

@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 (4893)

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

fuzzyastrocat (1859)

@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.

Henslo (26)

Didn't you make night?

Code1Tech (109)

You should try getting your language on repl so everyone can use it freely! :D

DynamicSquid (4893)

@Code1Tech good idea! might release a template soon... in the meantime you could always build this from source, or just clone the github repo onto a repl

DakotaHarris (0)

@DynamicSquid how do I clone the repo onto repl?

DynamicSquid (4893)

@DakotaHarris when you create a new repl, click "imprt from github", and copy this link in: https://github.com/DynamicSquid/Night

DynamicSquid (4893)

@DakotaHarris then once you have the repl set, in the `.replit` file, type `run="make; ./night source.night"`. then create a new file called `source.night` and that's where you'll write your code

fuzzyastrocat (1859)

Ah, nice! But one thing that really irks me...

Night is strong statically typed language

``"squid has " + 10 + " legs"``

That's pretty weak...

DynamicSquid (4893)

@fuzzyastrocat lol yeah.. I was thinking about that too, but I guess that and floats<-->ints are the only ones. Other languages have implicit conversions on booleans to ints, and ints to chars, and stuff like that

fuzzyastrocat (1859)

@DynamicSquid Still, I wouldn't call it "strong". I wouldn't call it "weak" either though, I'd just not put any specifier on it.

DynamicSquid (4893)

@fuzzyastrocat yeah, true I guess. i'll fix it

fuzzyastrocat (1859)

@DynamicSquid Oh also, what happens when you do `nums1[2]` for the arrays example? Is it null or does it throw an exception, or does something else happen?

DynamicSquid (4893)

@fuzzyastrocat oh, I forgot to mention, all variables and arrays, if not assigned, will be given a default value. for `int` it's `0`

potatojs (846)

### haha VERY COOL!

btw this is mind blowing!

"squid has " + 10 + " legs";

codermaster8 (7)

DynamicSquid is a mean moderator to my posts

fuzzyastrocat (1859)

Hey, I see night v3.2 is out. Cool! Could you walk me through how the new changes work? (as in, how to use them)

DynamicSquid (4893)

@fuzzyastrocat There's a package manager! Also you can now get Night from the website!

I tried to download the binaries from the website and it worked fine on my computer, but it didn't work for other devices... I think I need to statically link some libraries in the `exe` file so I'm working on fixing that.

fuzzyastrocat (1859)

@DynamicSquid Cool! (Also none of the reference links on the website work, is that supposed to happen?)

I noticed you say that Night v5 plans to be self-hosted... is Night going to stay interpreted? If so, then that's not really possible; since interpreted languages don't generate an executable, you can't generate an executable to run Night through itself and therefore you'll always be relying on the original C++ executable. (Even if you implement Night in itself, you'll still have to use the C++ executable to run that implementation, which defeats the point. Additionally, this will be very slow performance-wise.)

DynamicSquid (4893)

@fuzzyastrocat I haven't really thought about it yet, but yeah, you're right. Maybe not 100% written in Night though. CPython is written in 63% CPython, so that's where I got my idea

fuzzyastrocat (1859)

@DynamicSquid Hmm ok, I'm unfamiliar with how CPython partially hosts itself but I'm guessing it has to do with Python's easy interop with C.

fuzzyastrocat (1859)

@DynamicSquid Oh, and the fact that CPython is a bytecode VM-based approach (so it is compiled to bytecode).

DynamicSquid (4893)

@fuzzyastrocat Wait, so Python can Java have similar backends?

fuzzyastrocat (1859)

The fact that Java has a VM is often construed as this mystical thing, when in reality almost all interpreted languages have a VM.

DynamicSquid (4893)

@fuzzyastrocat Ah okay. Oh! And Night works now! So you can just download it from the website

fuzzyastrocat (1859)

@DynamicSquid I set up a quick little repl and it seems to be all working, however I can't figure out how to import sqdlib. Am I doing something wrong?

DynamicSquid (4893)

@fuzzyastrocat `import "sqdlib"`

DynamicSquid (4893)

@fuzzyastrocat yeah so import for dusj pkgs, but include for local files

fuzzyastrocat (1859)

@DynamicSquid Ahh, ok I had seen something on the github about `use` so I tried it after `include` (which of course didn't work since it's a dusk package).

elipie (371)

@DynamicSquid How may I use this in repl.it? I would love to start coding in night :D

DynamicSquid (4893)

@elipie Create a new repl, but click "import from GitHub". Then paste in this URL: https://github.com/DynamicSquid/night

Then create a new file called `source.night` to write your actual code.

Then in the `.replit` file, write this:

``run="make; ./night source.night"``

And that's it!

Epicmuffinepic (56)

i sense c++ flowing through this tutorial...

fuzzyastrocat (1859)

@Epicmuffinepic As of now, Night is basically a different C++. That will probably change, but it's hard to make a language very different when it's fairly new.

DynamicSquid (4893)

@Epicmuffinepic true. Although I'm panning to have Night dynamically typed in the future

fuzzyastrocat (1859)

@DynamicSquid If you're planning on making Night dynamically typed then I'd suggest making that change as quickly as possible. A dynamically typed language will have a different infrastructure than a statically typed one, so if you wait too long it might become difficult/cumbersome to change it.

DynamicSquid (4893)

@fuzzyastrocat yeah, I'm already working on v4 (each new version I completely restart from scratch) which will be dynamically typed

fuzzyastrocat (1859)

@DynamicSquid Noice. (hopefully you won't have to keep restarting once Night gets fairly stable)

fuzzyastrocat (1859)

Any guess as to when the next Night version will be released?

fuzzyastrocat (1859)

@DynamicSquid Whoa, like literally right now? I just checked the github and didn't see it, but now I do...

DynamicSquid (4893)

@fuzzyastrocat yeah, and that means sqdlib is now fully compatible!

DynamicSquid (4893)

@fuzzyastrocat there's probably a billion trillion hidden bugs but it worked fine for me so it should work fine for everyone, that's how things work right?

fuzzyastrocat (1859)

@DynamicSquid Of course! :D (I'm running into the same problems with eros lol, occasionally I make one addition and suddenly half of the rest of the things don't work)

DynamicSquid (4893)

@fuzzyastrocat lol yeah. I'm currently working on putting tests into my CI so that I can instantly tell if one of my commits is bad.

fuzzyastrocat (1859)

@DynamicSquid That's a good idea! I would've done that with eros, but the problem is that because of how it's designed (the language itself, not the implementation) I can't really test many things because there's a lot of cyclic dependencies (I need to implement x, but x will only be fully working if I implement y, but y will only be fully working if I implement z, but z will only be fully working if I implement x). So, I just have to kinda blindly implement things, test what I can of them, and make the big leap to do it all and hope it all works.

DynamicSquid (4893)

@fuzzyastrocat Oh, that must be tough to do! Well, I'm definitely going to take a break from Night. Might start working on a package manager actually.

Oh quick question, I'm looking on the web and everyone's using JS to build a package manger. Your package manager tutorial also used JS. But firefish used Go to build his package manager... and Go doesn't seem like a bad language to work with... so which one do you recommed?

fuzzyastrocat (1859)

@DynamicSquid It's good to take a break sometimes, I'm considering it with Eros.

My tutorial uses JS and Go. I use Go for the command line tool (the "front end") and JS for the CLI (the "back end"). So basically, use both — use Go to make requests to the JS and do the actual package installation, and use JS to deliver the package content to Go.

DynamicSquid (4893)

@fuzzyastrocat Oh.. that's interesting. Might have to take a second look then. Well, all a package manager is, is (two "is" right next to each other sounds weird) something that downloads files right? So any language that can download files from a CDN would work?

fuzzyastrocat (1859)

@DynamicSquid (Yeah, two "is"s do sound weird.) Well, yes and no. Yes, because that's the Go half of the package manager (it's the executable you download, so it's what you generally think of as "the manager"). But the JS half of the package manager is what hosts those files. Basically, each part is useless without the other (why host files if you never download them and why make a downloader if there are no files to download).

DynamicSquid (4893)

@fuzzyastrocat Okay, I get it now. Let's see, tomorrow's thanksgiving so no school, so yeah I can stay up until 12am coding a package manger

fuzzyastrocat (1859)

@DynamicSquid Ah, a Canadian. Have fun coding!

DynamicSquid (4893)

@fuzzyastrocat I didn't have much time to do it, but I got an error. Here's are the two repls:

When I try to install a package, I keep getting a `package does not exists error`

fuzzyastrocat (1859)

@DynamicSquid Hmm, I don't get that error when I run your repl.

DynamicSquid (4893)

@fuzzyastrocat Okay I tried again an I put `./packager install example`, and it gave me an index out of range error

fuzzyastrocat (1859)

@DynamicSquid Yeah that's what I get. It's because you've used different parts of the tutorial which are incompatible. I'd suggest going through step-by-step or just jumping to the final code, but don't do a mix of both.

fuzzyastrocat (1859)

@DynamicSquid Great! (Also, here is the pre-release, albeit a bit late to distract you from your work: https://repl.it/talk/share/GAME-MULTIPLAYER-3D-Survival-Game-SNEAK-PEEK/58053)

fuzzyastrocat (1859)

Does Night have a garbage collector? More importantly, does Night collect anything? I'm looking at the upcoming sqdlib and noticed this:

``````int[] add_back(int[] arr, int len, int val)
{
int[len + 1] temp;

int a = 0;
loop for (len)
{
temp[a] = arr[a];
a += 1;
}

temp[len] = val;

return temp;
}``````

In C, that would create a local variable (`temp`) which would then be freed when the function returns. But for that function to work at all, this would have to not be the case... so how does Night deal with freeing memory?

DynamicSquid (4893)

@fuzzyastrocat nope! night's interpreted, so it doesn't collect anything. i fell like it would make more sense for a language to have to deal with memory if it were compiled instead

fuzzyastrocat (1859)

@DynamicSquid Actually, just because a language is interpreted doesn't mean it shouldn't collect anything! I mean, the memory is still used (in fact, even more so). You'll want a Garbage Collector if you don't want the user to deal with managing memory then.

In theory, you could continue collecting nothing as you are now. But there's an issue with that — when you call `add_back`, you create the temporary vector, but you never delete the old one! So you end up with two copies of the vector each time you push to it, which is gonna eat up memory like crazy.

DynamicSquid (4893)

@fuzzyastrocat well I know what a garbage collector is, but the way I code my language there isn't a need for such thing. idk, I always thought of compiled langs to be more about memory.

fuzzyastrocat (1859)

@DynamicSquid It's actually opposite! See, all languages have to manage memory. It's just a thing about computers. The way they do that is different though. The reason you probably thing compiled langs are more about memory is because most compiled langs make the programmer themselves manage memory (with things like `free`, `malloc`, etc). Most interpreted langs do the memory management "behind the scenes" so the programmer doesn't worry about that — but because that means you have to make an automated system to do it, there's way more going on!

fuzzyastrocat (1859)

@DynamicSquid Actually, I just thought of a really interesting idea for memory management. You could make it so that no objects are ever freed until the programmer tells them to (with some kind of `free obj;` statement maybe). So that way, you could still do what you're doing now with the temporary vector inside the function outliving the function call, and you'd just add a `free arr;` at the end of the function to make sure the original array is cleaned up once the new one is created.

This would also be dead simple to implement — literally do what you're doing now (no freeing) and just call [C++] `free` on the object when the `free obj` statement gets executed.

DynamicSquid (4893)

@fuzzyastrocat Oh that does sound cool! But I might leave that to my compiled lang later on. I kinda like the approach Python took to memory management, and that's like to not have the user to worry about anything. I feel like what makes interpreted languages (or I guess high-level) good is that you can just write code in them, without worrying about anything.

fuzzyastrocat (1859)

@DynamicSquid In that case, you'll definitely want to write a garbage collector. (It's what Python and basically every other lang that allows you to forget about memory does)

DynamicSquid (4893)

@fuzzyastrocat well, I'm a bit confused since the way I code my language is like this:

``````void Parser()
{
vector<Variable> variables;
}``````

Like I store Variables in a local array, so as soon as the function finished parsing the code, the local variables just disappear...

fuzzyastrocat (1859)

@DynamicSquid Does anything get executed during the parsing stage?

DynamicSquid (4893)

@fuzzyastrocat well, right now the parser does everything (ik it's really bad but i've already started work on refactoring everything)

fuzzyastrocat (1859)

@DynamicSquid Ok, that's what I thought.

Now, that probably seems great. Once you're done executing, all the variables go away so that should be fine right?

Well, that's fine for simple programs, but consider a program with an infinite loop that is constantly constructing new arrays (in each iteration). That's gonna spam tons of memory that should be reclaimed by a garbage collector if all the arrays are local (since you can't reference an array if it doesn't "exist in the scope", so the language should make it magically disappear). And if it can be that bad with a simple program, just imagine a huge user-made program with tons of complex (and more importantly, large) data structures getting thrown around and then becoming unused (the user expects this to mean "gone", but with your implementation it's still technically there). There's a good chance you might unexpectedly run out of memory on a simple program where that wouldn't be expected.

DynamicSquid (4893)

@fuzzyastrocat uh... I just remove local variables from the array once they're done with... is that good enough?

fuzzyastrocat (1859)

@DynamicSquid Well, depends. If that local variable is a simple thing (say, an int), sure. But suppose it's an array. That array contains lots of other (potentially) local variables. So you have to determine whether to free them too by checking if they themselves are in the scope, if they are referenced by something else in the scope, if they are referenced by something that is referenced by something in the scope, etc etc. The process of doing this is called Mark-Sweep — there's a good tutorial on it here, even though it's for writing a custom bytecode VM I think it should still be applicable here.

(Also, when you remove the variables, make sure to free them properly ; ie, if they have some kind of inner structure like a `Value` or something make sure to free that when you pop them.)

fuzzyastrocat (1859)

@DynamicSquid This is why garbage collectors get complicated — a program is like a web of references, and the challenge of the garbage collector is to find out which nodes of the web aren't pointed to by any others. It's also why earlier "high-level" languages (FORTRAN, C, etc) didn't have garbage collectors (computers were not powerful enough to do all this and run the program) and so they force you (the programmer) to do the memory management.

DynamicSquid (4893)

@fuzzyastrocat Yeah I might make the user free the collection themselves, and tbh, I don't really see a problem with that. Don't sure why calling `delete` is too much of a hassle (it also forces you to actually understand what your program in doing), and for more complicated programs, you can just use smart pointers

fuzzyastrocat (1859)

@DynamicSquid Yeah, memory management for this kind of language is not a bad thing. (Also, smart pointers are a form of automatic memory management, which is kinda like a garbage collector — implementing them won't be as difficult as a full garbage collector, but it might be challenging.)

DynamicSquid (4893)

@fuzzyastrocat For smart pointers, I was thinking more of C++'s approach where it's not a build in feature, but rather made using a class with a destructor in it, but for that my lang would need classes and destructors... so maybe I'll go with a build in feature

fuzzyastrocat (1859)

@DynamicSquid EDIT: Yeah, I suppose they aren't built-in... but they require a lot of intricate things like move semantics, destructors, etc... if you're planning on adding those things then don't make it builtin, otherwise yes it would be advantageous just to make them a builtin feature

DynamicSquid (4893)

@fuzzyastrocat Nope, you can easily create since C++ supports destructors, and templates.

So a really basic one would look like this:

``````template <class T>
class smart_ptr
{
public:
~smart_ptr();

private:
T* ptr;
};``````
DynamicSquid (4893)

@fuzzyastrocat Since a smart pointer is really just a wrapper class for a raw pointer

fuzzyastrocat (1859)

@DynamicSquid I'd edited my comment, but pinging you because you might not have seen it (and your bio says to :D)

DynamicSquid (4893)

@fuzzyastrocat lol! but yeah, my goal is to create a language similar to C++ (but that'd take me like 5 years to code by myself :(, wish I had some friends who coded irl)

fuzzyastrocat (1859)

@DynamicSquid Eh, you could get the core functionality going a lot quicker than that. (I know... it's sad how few people actually enjoy coding)

I'm not sure if this is a motivation for you, but when I make things I always like them to be different. This is a mostly irrational impulse, but sometimes it does have benefits. One area where I think this is something to consider is when you're making a new language. Often, people slap together tons of syntactic sugar and funky syntax and call it a "new language", when in reality they've just cloned Python and made it look different. Make sure to include some real, useful semantic differences in Night (for instance, allowing variables to outlive their function calls). I think a great example of this is Rust: they took the core idea of low-level languages like C and added a whole unique memory paradigm that makes Rust a valid new language.

So, tl;dr: It's fine to make languages similar to others, but make sure you don't end up making a clone with a few syntactic sugar differences. Make sure to include cool semantic differences as well, that way there's a reason to use your language over, say, C++.

DynamicSquid (4893)

@fuzzyastrocat Yeah, good point. That's also one reason why I gave up learning Haskell, so I could see what interesting ideas are there. But mostly I'm just making a language based off what I want... which... I mean... if no one uses it at least I will xD

fuzzyastrocat (1859)

@DynamicSquid Well, if you wait a little while (hopefully not too long) you'll get to see the alpha version of Eros, a functional lang I'm working on that's related to Haskell but probably easier to understand :D

And yes, if you use Night than at least you have a userbase of 1 not 0!

DynamicSquid (4893)

@fuzzyastrocat Can you ping me when you release Eros (it's in JS right?). Also even if my language has 0 users, you have to say it with an exclamation mark like this:

My language has a userbase of 0!

Cause 0! is equal to 1

fuzzyastrocat (1859)

@DynamicSquid Sure, I'll ping you! And no, it's in Rust! :D It's gonna be fast (hopefully). Rust is basically almost on-par with C for performance if I recall correctly.

Ha, didn't think of that! (wait, what's the factorial of "that"? :D)

Oh also, one thing I thought about — this is a finer point, but something good to consider. By making pushing to an array be:

1. Create a new array with a length of one greater than the old length
2. Copy the elements into the new array from the old one, add the new element
3. Delete the old array (if you implement `delete x;`)

It will naturally be slower than if you were to implement some way to directly modify the size of an array, ie `realloc`. However, this could be avoided with an extremely smart interpreter which would translate Night source code into Static Single Assignment Form and then run that. Now, it would have to be pretty smart, so this definitely isn't the easiest way to do it or something I would focus on right now, but it might be something to consider.

DynamicSquid (4893)

@fuzzyastrocat I think I heard of SSAF before, and I think it's a major part of C++, but there's a problem because while the interpreter sees nothing is modifying the variable, and outside function could, that's why there the `volatile` keyword in C++

fuzzyastrocat (1859)

@DynamicSquid That's for when a variable gets changed by something outside the whole program, ie the compiler won't detect it. I doubt you'd run into that problem any time soon, but if you did you could implement some kind of `volatile` system (either manually by a specifier or automatic by some kind of language-designed protocol to detect when you're interfacing with something that might invoke this kind of behavior) to fix it as well.

DynamicSquid (4893)

@fuzzyastrocat yeah, that's what I meant, but yeah you're right, not happening any time soon!

firefish (947)

@DynamicSquid nice work on the sqdlib (squidlib? standardlib? squandardlib? lol)! I have opened a pr on it just fixing a minor fewture

JordanDixon1 (178)

Question, would you like to work on a language called grammarLang?
Basically the syntax is simple english-like syntax for example:

``print "hello world". h is 3. print h. -- This is a comment -- print "how many squids are in the world?".``
JordanDixon1 (178)

@JordanDixon1 Basically each statement is ended with a period. Comments begin with "--" and end with "--" Just like English. As for special keywords, they follow python.

firefish (947)

@DynamicSquid So is v3.1 the target for dusk bring added, or is it v3.3? or v4? It's a bit unclear

DynamicSquid (4893)

@firefish v3.3 cause that's when the sqdlib will be released

firefish (947)

@DynamicSquid Also why is Codelong making a preprocessor? I though I made that

DynamicSquid (4893)

@firefish yeah I like yours more, codelongs is in python too which is kinda weird

DynamicSquid (4893)

firefish (947)

@DynamicSquid Or on HahaYes's hahachat, I can make a room (if I have access to it still)

firefish (947)

@DynamicSquid Done the pull for you, changed apache to gpl because gpl has the extra "Same license" feature

LChan24 (9)

I may or may not have been browsing your profile and I noticed that you go night running on repl.it, are you going to tell us how to do this?

DynamicSquid (4893)

@LChan24 oh it's nothing special. repl.it runs on a linux environment, and Night works for linux. it's not like my language is actually an option to chose from when you create a new repl. it just works on this website, that's all

CodeLongAndPros (1622)

Hey btw I made a preprocesser at https://github.com/CodeLongAndProsper90/nighti

Commands are:

• .include filename
• .define new old
DynamicSquid (4893)

@CodeLongAndPros oh cool! can that be used with the package manager or is it something separate? also I built Night on linux and it works great! thanks for the fix!!

CodeLongAndPros (1622)

@DynamicSquid It just provides a bit of modularity and defines

DynamicSquid (4893)

@CodeLongAndPros oh okay. could you also check the github? you asked for a new release for the `PKGBUILD`

firefish (947)

@CodeLongAndPros there is Already under THAT PULL 28 already `use lalalapkgnamehehethisactuallymightwork`

firefish (947)

@CodeLongAndPros A preprocessor already exists. Look at pull 28. HOW MANY TIMES.

CodeLongAndPros (1622)

The only thing I’d add is an auto keyword, so we can do stuff like this:

``````int test(auto func, auto expected) {
if (func() != expected)
Print error
Return 1

Return 0
}``````
DynamicSquid (4893)

@SwaroopBappanad lol yeah the website has night v2.2!! don't worry though, I'm working on putting v3.0.1 on the website soon

fuzzyastrocat (1859)

@DynamicSquid I'd recommend changing the error from "language grammar is invalid" to "invalid syntax". `language grammar is invalid` sounds like there's something wrong with the language itself, which in reality it's just the user's improper program.

Bookie0 (6257)

Clean, beautiful, precise tutorial! It's great!

Question tho: indents needed?

fuzzyastrocat (1859)

@Bookie0 I would guess not because of the braces... if it is, that's pointless, the braces do the same thing

Bookie0 (6257)

yea, I see, but braces are nice, I find that they make the code look "nicer" @fuzzyastrocat

fuzzyastrocat (1859)

@Bookie0 Um... I'm not saying braces are pointless, I'm saying that forced indent is pointless if you have braces.

programmeruser (604)

This seems very similar to Dlang.

fuzzyastrocat (1859)

@DynamicSquid I do see a lot of similarities though...

CodeLongAndPros (1622)

@fuzzyastrocat Not really. The docs are better…

CodeLongAndPros (1622)

@fuzzyastrocat Night, Dlangs docs are garbage.

fuzzyastrocat (1859)

@CodeLongAndPros True. But I just meant the language itself, not necessarily the information surrounding it.

fuzzyastrocat (1859)

@DynamicSquid Those scoundrels! Quick, make ready the siege engines, we shall lay ruin to their stronghold!

just let me make programming sound fun by describing it as medieval times, ok?

ysofka (1)

i still don't get functions.
can you explain that to me?
also, is this available on repl.it?

DynamicSquid (4893)

@ysofka try learning functions in your language first. also yes but no. Check the website which is on the github page and go to the Online IDE to see Night 2.2. haven't found a way to make Night 3.0 work on repl.it yet

fuzzyastrocat (1859)

@DynamicSquid Why is night v3 not working on repl?

DynamicSquid (4893)

@fuzzyastrocat it should now, but it's because repl is linux and I use windows

k9chelsea2 (735)

noice time to create a language called Day to rival Night 👀

DynamicSquid (4893)

# 👀👀👀

fuzzyastrocat (1859)

@DynamicSquid You know, Lua is named Lua because it wanted to rival Sol...

Codemonkey51 (1057)

Hey are custom types / classes / structs a thing, or ever will be?

DynamicSquid (4893)

@Codemonkey51 might have a simple class that can only store variables and methods. I'm not really a big fan of OOP but I do like classes

fuzzyastrocat (1859)

@DynamicSquid If you're not a fan of OOP, I wouldn't go for classes. Instead I'd go for a Haskell-like approach, which provides basic functionality for OOP but doesn't emphasize it.