narimiran / nim-basics Goto Github PK
View Code? Open in Web Editor NEWSource files for Nim basics tutorial
Home Page: https://narimiran.github.io/nim-basics/
License: MIT License
Source files for Nim basics tutorial
Home Page: https://narimiran.github.io/nim-basics/
License: MIT License
I'm very experienced, and this tutorial really brought up to light quickly the syntax differences of nim. I don't think this is "not for advanced folks". Perhaps there is a better way to say this:
"Looking for something beyond the basics?" perhaps
I think structs could very simply be described to some degree in the basics section
In the modules section:
echo sin(cRadians).round(2) # Warning: use strformat module instead; round is deprecated
In this section:
"Types might seem like a restriction at first, but they allow the Nim compiler to both make your code faster, and make sure you’re not doing something wrong by accident."
Large code bases in particular really are much easier to manage with strong types. Perhaps this is worth mentioning.
I thought this sentence above sounded a little too humble. Strong types are awesome.
If we also need to have an iteration counter (starting from zero), we can achieve that by using for , in : syntax. This is very practical if you want to iterate through one iterable, and simultaneously access another iterable at the same offset.
However, as far as I know, this works only with strings, it does not work for iterators in general (for example countTo fails). However, it does work on containers. At least in my Nim 1.4.0.
So I suggest changing the text to:
If we also need to have an iteration counter (starting from zero), we can achieve that by using for , in : syntax. This is very practical if you want to iterate through one container, and simultaneously access another container at the same offset. Containers are explained just a little bit later.
As the epub and pdf are generated files, it makes sense to put them in releases rather than in git - git isn't really made for that, and releases can be associated with tags. For GITenberg, we've actually used travis-ci to build epub and pdf (including from asciidoc source!) whenever a repo is tagged.
Hi Miran, this line in basic data types - Integers - 3rd paragraph:
"The expected mathematical operators — addition (+), subtraction (-), multiplication (*), and division (/) — work as one would expect. The first three operations always produce integers..."
echo 3.5 * 2 #=> 7.0
echo 3.5 + 2 #=> 5.5
echo 3.5 - 2 #=> 1.5
Possible edit:
"The first three operations always produce integers when both operands are integers, and produce a float (floating point number ie decimal) if one or more of the operands is a float, ..."
This is no longer true:
"VS Code users cannot run this the usual way (using Ctrl+Alt+N) because output window doesn’t allow user inputs. This needs to be run in the terminal."
I just ran the example from vscode and typed my name in the output window and it worked fine.
Hint: c:\Projects\Nim\interaction.exe [Exec]
What is your name?
Robert
Hello Robert, nice to see you.
because if the argument passed is a sequence of all negative numbers, the result is 0 (which is not an element of the list).
It should be pointed out that proc is like so just for telling about the implicit variable 'result' behavior.
This was a question that went through my mind as modules can be quite complex in various languages.
What character do I use for path separator to get a file in a sub directory?
what happens if I import a directory? what file does it choose first?
At result.nim
you write: "Beware! The default value of strings and sequences is nil, and when we use them as returning types, the result variable needs to be initialized as an empty string ("") or as an empty sequence (@[])."
It changed in Nim 0.19. The default value of strings and sequences is ""
and @[]
. See https://nim-lang.org/blog/2018/09/26/version-0190-released.html .
BTW, I love this tutorial. Do you plan a continuation?
The section on tuples only shows how they are initialized, not how they can be declared with tuple[<field>: <type>, ...]
. This notation wasn't shown until Procedures exercise 3.
From narimiran/narimiran.github.io#1 by @nixfreak:
Anyway you can add "Tables" especially with procs?
Thank you for great book on nim.
From discord:
[3:50 PM] yumi: how about a little section on how to parse command line parameters?
[3:50 PM] yumi: i was using commandLineParams().contains because the first result for flag parsing was a stackoverflow question
[3:51 PM] yumi: but then it turned out parseOpt existed
Your font has something weird going on with "fi" sequences. My guess is its because the font you are using has ligatures, usually there's a version of the font without it.
If this is really the best tool support we have currently, we should recommend it.
A suggested addition to
Basic Data Types -> floats
(or maybe its own sub-section)
An extended example with two operators of the same precedence, e.g.
5.0 * 3.0 mod 10.0
is evaluated as
(5.0 * 3.0) mod 10.0
because multiplication and modulus have the same precedence level
It might help to include a reference to Precedence Levels
at https://nim-lang.org/docs/manual.html#syntax-precedence
How to translate to another language?
I forked original to my GitHub and opened selected russian
branch.
Should I send pull requests?
Are any limitations exist related to copyright/left, for example, can I extend translation more than original with extra themes, or change format (LaTeX markup or something like this)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.