Hello, I'm new here! :D After searching and trying some other languages, I think I found the one I wanted. My "journey" is a bit weird, I'm a wildly ambitious person. So, this started when I wanted to create my on Lisp without having no quality knowledge on parsers and all of that stuff on C#, the language that I'm currently officially learning - I was able to make a working calculator which was awesome. Then I found out that C# didn't actually compiled to machine code and I was sad.
That lead me to C++, which was awesome, already with another working Lisp calculator done, however, even though my code is fairly organized, concise and coherent, I guess it can also have gazilions of memory leaks.
After trying C++, I tried Go, which was, yuhhhh, a lacking and a not so good experience to say the least. I thought about Python and Ruby, but they're both interpreted and slow. I also gave a look on Rust but it seemed a bit too weird for me. And here we are, I haven't try that much of Nim yet, but after reading the documentation and trying the hello world example, I'm really enjoying it. I have high hopes for both Nim and Crystal!
So, my doubts are the following: it is possible to create a main function where I can pass arguments before the program starts, like these: [program name] [file].[custom file extension]? So, if I had a program called "prog" it would be: prog test.p
Another doubt I also have is: can I format strings without using the C library?
For example, turn "(1) > " to (001) > ", in C, Go and Ruby this is achieved with the printf function, but what is the Nim idiomatic way?
Also, when I get user input, can I chomp the last character: the newline char? And official Regular Expressions support? Like matches, replaces and searches? And, last one: is there a ternary operator or something similar?
That's it! Like I said, I have good hopes for both Nim and Crystal! :D
Welcome to Nim. :)
it is possible to create a main function where I can pass arguments before the program starts
You can use paramCount, paramStr or commandLineParams of the os module: http://nim-lang.org/docs/os.html#paramCount,
import os
echo "Parameter: ", paramStr(1)
$ ./prog test.p
Parameter: test.p
Another doubt I also have is: can I format strings without using the C library?
There is strutils.format: http://nim-lang.org/docs/strutils.html#format,string,varargs[string,]
For more advanced cases the strfmt library can be used: http://lyro.bitbucket.org/strfmt/ (unfortunately doesn't work with current devel branch of Nim)
import strfmt
var x = 1
echo "({:03}) > ".fmt(x) # Prints: (001) >
Also, when I get user input, can I chomp the last character: the newline char?
That's done automatically for you:
stdout.write "Enter your name: "
let name = stdin.readLine
echo "Your name is ", name
And official Regular Expressions support? Like matches, replaces and searches?
http://nim-lang.org/docs/re.html
is there a ternary operator or something similar?
You can just use if expressions inline:
var z = 10
echo "Your number is ", if z < 100: "good" else: "too high"
Actually strfmt works very well with latest Nim devel if you use this fix in nimble/strfmt/strfmt.nim
https://github.com/rgv151/strfmt/commit/7a9c6aadeb039a660d01f620967c713ede5106e3