Learning Nim: Write an Interpreter [Episode 01]

preview_player
Показать описание
I'm learning Nim at the same time as I learn how to write an interpreter. To do this, I'm working through the book, "Crafting Interpreters" and translating over the Java to Nim. #nim #nimlang
Рекомендации по теме
Комментарии
Автор

Nice video! I enjoy stream of consciousness videos because when you've learned something, it's easy to forget the pain points that other people might hit learning it later.

Here are a few things I noted while watching it:

1. You don't necessarily need to do forward declarations of procs if they're written in the correct order (this is C-like), i.e. the proc is already in the file before it's mentioned in a call. In practice, this means you have files where the 'isMainModule' is at the end and you read upwards, so forward declarations may still be helpful if you're not used to that (it's a matter of taste).


3. There's a REPL called 'INim' on GitHub (I've not used it myself) that you might want to try as an alternative to 'nim secret'

4. 'discard' is just a keyword to indicate 'no code goes here', like an empty pair of curly braces in Java, a noop, or similar. This can be used as a placeholder to do nothing at all when you need an implementation until you have something worth writing in its place (or you decide to remove the function because it does nothing :)

5. When you use standard library packages (like strutils), you want to include 'std' as a prefix (std/strutils for example). This was a change introduced midway through Nim's life so older modules might work without the prefix but newer modules require it. You can use std/[a, b, c] to import many std lib modules at once.

pointystick
Автор

Best of luck on the project and learning Nim dude. Once I learned Nim my fingers wouldn't let me touch the keyboard using another language lol. I think around 60% of Nim developers have decades of professional programming experience, a testament to the power, efficiency, and productivity of Nim. And they're all happy to help if you run into snags writing this interpreter ;)

leonlysak
Автор

If Andreas Rumpf manages to make the breakthrough I know he is capable of in terms of finalizing very fast incremental compilation functionality in Nim(and I see him achieving that since he managed to create probably the most well thought C++, D or Rust alternative) I could see myself using it instead of Julia even for exploratory data science where you need fast feedback.

encapsulatio
Автор

Nim is my favorite lang, thanks for video.

trmund
Автор

Cool video, looking forward to watch the rest of them. Just a couple small things, `$` is already defined for int and many other basic types. It's why `echo "My favourite number is: ", 100` works, because all the arguments can be converted to a string by calling `$`. Also you ended up using a space after the `$` in your proc declaration, that's a bug in the documentation, the convention is to have no space there.

peterme
Автор

Nice. I hope you'll continue this project for us to follow along. Please raise the volume of the audio, I have to use headphones to hear it.

ViaConDias
visit shbcf.ru