[–]▶ No.994023>>994024 >>994027 >>994032 >>994034 >>994050 >>994091 >>994378 [Watch Thread][Show All Posts]
https://nim-lang.org/
Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
- POSSIBILITIES WITH NIM -
Nim can be compiled to C, C++, AND Javascript out of the box.
$ nim c hallo.nim
$ nim cpp hallo.nim
$ nim objc hallo.nim
$ nim js hallo.nim
- LEARN NIM -
https://nim-lang.org/documentation.html
https://learnxinyminutes.com/docs/nim/
https://rosettacode.org/wiki/Category:Nim
- GET HELP -
#nim @ irc.freenode.net
https://discord.gg/rnTh2N
https://gitter.im/nim-lang/Nim
▶ No.994028>>994031
>CoC status
devs rejected it as pointlessly controversial, rather than saying "yeah it's but it's only controversial to garbage people"
>koch status
it's a tool used to build nim itself: https://nim-lang.org/docs/koch.html
▶ No.994031>>994114
>>994028
The main developers are pretty intelligent (I'm most familiar with Araq and dom96).
▶ No.994034
▶ No.994037>>994038
>OpenBSD status
$ sh build.sh
$ doas sh install.sh /usr/local/bin
builds and installs in a minute, and works great. A+++ software.
>cancer status
not cured: nim's only approach to memory management is to have a GC
>sysadmin status
NimScript is available: https://nim-lang.org/docs/nims.html
but it's too limited: you can use Nim as an alternative to C, but you can't use it as an alternative to Perl
OTOH, https://nim-lang.org/docs/manual.html#taint-mode
>2018 status
defer statement for your resource management
easy compile-time work, including file I/O: https://nim-lang.org/docs/manual.html#statements-and-expressions-static-statementslashexpression
nim tells you if your switches aren't exhaustive
has easy-mode "I want the code like this" macros, and also more serious AST-construction macros
▶ No.994038>>994043
>>994037
the gc memory safety stuff was a little weird at first, but I got used to it and the performance of the language overall is phenomenal
▶ No.994043>>994045
>>994038
aye, thanks anon. I'd gotten distracted by Zig (which is too much in flux and too poorly documented to really use) and Ada (which is secretly extremely cool but it has Common Lisp levels of RSI threat)
Nim might be exactly what I should be doing right now.
▶ No.994045
>>994043
Zig is a really cool language, and the guy who works on it is incredible, but yeah, it's in no state to use without a ton of extra work on your part
▶ No.994050>>994052 >>994057
>>994023 (OP)
Why would you cross compile nim to c++ instead of writing c++?
Are you dumb?
▶ No.994052>>994053
>>994050
for a superior C++ FFI, when working with C++ libraries
▶ No.994053
>>994052
it goes without saying that you would not yourself want to write C++
▶ No.994054
is it memory safe?
does it allow fearless concurrency?
▶ No.994057>>994060 >>994091
>>994050
C++ libraries idiot, C++ is shit
▶ No.994060>>994061
▶ No.994061>>994062 >>994091
>>994060
https://www.youtube.com/watch?v=7KjCOe0oBIw
The Nightmare of Move Semantics for Trivial C++ Classes
the whole language is like this. It's just a mess.
▶ No.994062
▶ No.994067>>994069
What does it compile to when no external language is specifiec? What is its default output?
▶ No.994069>>994070
>>994067
its default output is usage information. 'c', 'cpp', et al. are the commands you use to compile Nim. The only alternative is the interpreted subset of the language.
▶ No.994070>>994071 >>994075
>>994069
So instead of using C++ you use this shit and then get C++ anyways?
What's the quick win here then?
▶ No.994071>>994087
>>994070
man it's real fucking boring having to explain compilation to people on /tech/ a hundred times a year.
▶ No.994072>>994091
▶ No.994074>>994076 >>994087 >>994150
Crystal is better.
Prove me wrong.
▶ No.994075
>>994070
the quick win is "you get to use a language other than C++". That C++ is actually involved (when compiling with cpp) is only important for
1. FFI, which as a result is easy-peasy and easy to understand. You can go as far as injecting raw code into the output.
2. the C++ compiler you use, which takes that code and works on it.
if this were a thin wrapper and you'd possibly have to debug the C++ yourself, that's suck pretty hard. That's not the case with Nim, which handles everything for you.
The only downside is that you can't just have a 'nim compiler' on a build system; you also need a compiler for your target language.
That C or C++ is involved doesn't mean that your code has any extra overhead. It doesn't even mean that your code can only be as optimized as C code. C compilers can have an easier time with generated C code vs. nearly identical hand-edited C code. I've only seen cases of that with ATS though.
▶ No.994076>>994091
>>994074
the guy who came up with Crystal realized that it would never not be shit, told the community, got told off by the community, and then abandoned the project.
▶ No.994078>>994081
What are some projects written in NIM?
▶ No.994081>>994082 >>994088
>>994078
https://github.com/def-/nimes - NES emulator.
https://github.com/nim-lang/Aporia - an IDE for Nim
I haven't run into anything I'm that interested in that's written in Nim.
▶ No.994082>>994088
▶ No.994087
>>994071
people are idiots
>>994074
crystal is good but isn't really comparable in a lot of ways
▶ No.994088
>>994081
what exactly are you interested in?
>>994082
nobody uses that ide for nim, there are vim/emacs/vscode plugins
▶ No.994091>>994105 >>994111
>>994023 (OP)
Nim seems rather interesting. If you posted a couple of more posts, I think I might actually try it.
>>994061
>>994057
C++ is mess because it has too many features but the fact that C++ has so many features is also its greatest strength and weakness. C++ is good enough, however, C++ is seriously flawed, too.
>>994072
Not always. If you are application developer, you want to have good GC.
>>994076
Sauce pls. I am interested.
▶ No.994103>>994106 >>994108
How is this any less pointless than any other transpiled meme lang? They all really seem like trying to turn a screwdriver with a novelty claw grabber toy.
▶ No.994105>>994110 >>994112
>>994091
The GC is as out-of-the-way as it can possibly be. The pause time is practically nonexistent.
There is a (largely) irrational disregard for languages when retard /g/ programmers hear "garbage collected". It has 0 performance impact unless you use it improperly (you can even configure it to your tastes), not to mention, you can disable it entirely.
▶ No.994106>>994107
>>994103
reeeeee dont insult the flavor of the month meme lang reeeeeeee
▶ No.994107
>>994106
epic xD. I love reddit too haha
▶ No.994108>>994125
>>994103
'transpiled' isn't a category of language, you're just a brainlet. If Nim development stopped for a month so that it could get its own native code compiler, all that would happen is
>hooray you can "nim asm" to compile direct to asm!
>this doesn't work on most platforms
>we only have a fraction of the optimizations the c and cpp targets enjoy
>so it's pretty much a useless feature but some stupid people are less triggered now
▶ No.994109>>994115
Nim needs to get mainstream, then getting as many libraries as possible (like Python)
▶ No.994110
>>994105
>you can disable it entirely
theoretically.
if you write your own stdlib.
if you don't mind not having any way to manage memory anymore.
when D people say this, they at least have betterC as a concrete example of a way to use the language, sans-GC.
▶ No.994111
▶ No.994112>>994113
>>994105
Faggots like you really are the stupidest. Speed isn't the main problem of GCs, it's the greatly increased runtime complexity making a the total running code for a hello world ridiculous, greatly increased memory use and glorification of lack of rigour in programming. In this last regard, it is truly something fit for these degenerate times.
inb4 meme GC benchmarks not measuring both throughput and latency
▶ No.994113
>>994112
>really are the stupidest
>doesn't know that only one subset of performance is speed
>OP even mentions pause time
heh, /g/
▶ No.994114>>994115
>>994031
>dom96
He seems like a real faggot (wants the CoC real bad)
▶ No.994115>>994117
>>994109
what library do you need that nim doesn't have?
>>994114
I didn't know that
▶ No.994116
This is what the founder of Nim said about CoCs.
Because it's a waste of time. The recent troll attacks wouldn't have been prevented by a CoC. CoCs are naive and actually can start all sort of fights over the precise wording etc. I can already envision this very thread to become a page long discussion with people arguing about the pros and cons about CoCs. I would lock this thread if I could (maybe I'll patch nimforum) to save everybody's time ("safety first"). Please! Before answering here: Consider working on Nim instead. ;-)
He's great.
▶ No.994117>>994119
>>994115
Everything from Keras to Django/Flask to Selenium/bs4 to NLP to the SciPy suite of libraries
▶ No.994118>>994119
HA. You have genuinely not searched AT ALL. I can name replacements off the fucking top of my head you idiot.
▶ No.994119>>994126
▶ No.994125>>994129
>>994108
wellll... downside: OpenBSD's gcc is so old, nim's C breaks with it.
there are open issues about it, and getting nim to emit egcc commands instead of gcc commands isn't trivial (gotta edit a compilerExe field and then bootstrap rebuild Nim)
▶ No.994126
▶ No.994129>>994130
>>994125
>wellll... downside: OpenBSD's gcc is so old, nim's C breaks with it.
clang is now distributed with the base OpenBSD system.
▶ No.994130>>994135
>>994129
ok, then just change cc to clang to config/nim.cfg before running build.sh
... I still can't get past 'koch tools' though.
▶ No.994135>>994136
>>994130
what does it say? I've seen people use it on openbsd b4
▶ No.994136
>>994135
it's specifically 'koch nimble' that fails.
nimblepkg/options.nim(128, 14) Warning: Couldn't determine GIT hash: fatal: not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). [User]
nimblepkg/options.nim(215, 6) Hint: 'options.renameBabelToNimble(options: Options)[declared in nimblepkg/options.nim(215, 5)]' is declared but not used [XDeclaredButNotUsed]
Hint: download [Processing]
Hint: packageparser [Processing]
nimblepkg/packageparser.nim(3, 67) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
Hint: nimscriptsupport [Processing]
nimblepkg/nimscriptsupport.nim(8, 11) Error: cannot open file: compiler/ast
FAILURE
▶ No.994148>>994186 >>994753
>cross-compilation
Seems like a good idea, but I can't see myself using it in production. Look at all the superfluous instructions it generates for a simple blurb of JavaScript.
▶ No.994150>>994152
▶ No.994152
▶ No.994159>>994169
>compiled
The dumbasses can't even tell the difference between a compiled language and a transpiled language.
▶ No.994162
I've been using nim quite a bit lately and it's been damn nice. It offers multiple GC implementations alongside an off option for tailoring to your needs. On top of that the FFI is one of the simplest implementations I've ever had the pleasure of using, so using existing C code is painless, and also lets you bypass the GC altogether. You can even use pragmas to include the necessary sources into the build from your nim modules. The language feels like what python should have been.
▶ No.994169>>994176
▶ No.994175
▶ No.994176>>994177 >>994188
>>994169
Can you compile it to a lower level language, like asm?
▶ No.994177>>994180
>>994176
yeah. it happens automatically, and it involves a bunch of intermediate languages. Which is exactly what happens when you compile a C program with a C compiler.
▶ No.994180>>994181 >>994182
>>994177
>it involves a bunch of intermediate languages.
Then is a transpiled language.
▶ No.994181>>994183
>>994180
lol asm is intermediate language
▶ No.994182>>994183 >>994185
>>994180
>gcc has to compile c to gimple firsts
>its a transpiler! not really compiled! into the trash!
this is you
▶ No.994183>>994203
>>994181
asm is a lower level language.
>>994182
So is gimple.
▶ No.994185>>994203
>>994182
gimple isn't a programming language, though.
▶ No.994186
>>994148
I've really got to liking it, the extra stuff doesn't really do anything bad except look weird
▶ No.994188>>994189
>>994176
There is a different version you can use for that but it makes no sense to
▶ No.994189>>994190
>>994188
What is "this different version"?
▶ No.994190>>994191
>>994189
That idiot is referring the the bootstrap, which is written in C.
▶ No.994191>>994192
>>994190
So you can't get it directly into a lower level language and instead must go through another high-level language?
▶ No.994192>>994194
>>994191
speaking of levels, I'm lowering myself to your level by pointing out that
C is a lower-level language
▶ No.994194>>994195
▶ No.994195>>994196
>>994194
just go down side bar at https://nim-lang.org/docs/manual.html and look at all the shit that you can only cobble together from spit and dirt if you use C.
▶ No.994196>>994197
▶ No.994197>>994198 >>994203
>>994196
THAT
MEANS
THAT
NIM
IS
HIGHER
LEVEL
▶ No.994198>>994199 >>994200 >>994202
>>994197
It doesn't. Both are highest level languages when you write them.
▶ No.994199>>994201
>>994198
This is incredibly bad bait
▶ No.994200>>994203 >>994204 >>994220
>>994198
_____________________________________
/ this is a nonsenical assertion. Are \
| there lower-level languages in your |
\ world? /
-------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
▶ No.994201>>994202 >>994205 >>994206
>>994199
Is not my fault you are too much of a brainlet to understand C and think it might as well be machine code.
▶ No.994202>>994204
>>994198
>>994201
nope. for example python is higher level language than C/C++ then there is ASM and finally machine code is the lowest level before electronics.
▶ No.994203>>994204 >>994209
>>994183
>>994185
>nim uses intermediate languages, so it isn't compiled
>reeeee gimple doesn't count
just to be clear: insofar as transpiled is a meaningful word, it isn't exclusive of compiled.
>>994197
>look at this c compiler I wrote in python guise
<c is lower level than python
>>994200
>what is asm
▶ No.994204>>994220
>>994200
ASM and the bytecode that java and the likes use. Also compiler intermediary languages.
>>994202
Python is as high level as C.
>>994203
My original question was: can it be compiled to a LOWER level language?
▶ No.994205
>>994201
haha, im only pretending to be stupid guys
▶ No.994206>>994207 >>994220
>>994201
_________________________________________
/ I don't have any trouble understanding \
| C. It's much harder to understand |
| languages like Nim and Ada, simply |
| because they have more features. People |
| screw up C, but screwing up with a |
| hammer doesn't make a hammer a power |
\ tool. /
-----------------------------------------
\
\
/\_)o<
| \
| O . O|
\_____/
▶ No.994207>>994210
>>994206
Then you should know it is as high level as any other high-level language.
▶ No.994209>>994220
>>994203
_________________________________________
/ you can write any turing-complete \
| language in any other turing-complete |
| language. You can write a C compiler in |
| Python. As that's the case, it |
| obviously has no bearing on how high- |
\ or low-level a language is. /
-----------------------------------------
\
\ \
\ /\
( )
.( o ).
▶ No.994210>>994211
>>994207
>what are abstractions?
▶ No.994211>>994212
>>994210
By your logic, a library is a higher level language because it abstracted already high-level features of the language.
▶ No.994212>>994213
>>994211
_____________________________
< yes, that is also the case. >
-----------------------------
\
\
\ >()_
(__)__ _
▶ No.994213>>994216 >>994218 >>996551
>>994212
No, is not. Everything is high-level. When you start having code that is not meant to be edited by humans, then you went down a level. When it deals directly with hardware instructions, that's another level.
▶ No.994216>>994219 >>994220
>>994213
________________________________________
/ every time you say 'everything is high \
| level', you're just attempting to do |
| away with the distinction. You can't |
| deny a classification system while |
| arguing about how languages fit into |
\ it. /
----------------------------------------
\ /\ ___ /\
\ // \/ \/ \\
(( O O ))
\\ / \ //
\/ | | \/
| | | |
| | | |
| o |
| | | |
|m| |m|
▶ No.994218
>>994213
If this is not bait, I genuinely feel sorry for your fucking family.
▶ No.994219
>>994216
>refresh page
>all of these cowsay images are syntax-highlighted
trippy
▶ No.994220>>994221 >>994229
>>994204
>Python is as high level as C.
now lets slow down. python is interpreted by an interpreter written in c. It would be idiotic to compile python directly; it has to run on top of a lower level vm. nim could be compiled directly, they just haven't got around to it yet.
>My original question was: can it be compiled to a LOWER level language?
It's hilarious how quickly the original question gets lost. Anyways, you can compile it to c, and then compile the c to asm; therefore it can be compiled to asm. The internal details of the compiler are irrelevant.
>>994209
basically this. The real question for low levelness is how much access to the hardware you have, not what compiles what.
>>994216
>>994209
>>994206
>>994200
_____________
< this is fun >
-------------
\ / \ //\
\ |\___/| / \// \\
/0 0 \__ / // | \ \
/ / \/_/ // | \ \
@_^_@'/ \/_ // | \ \
//_^_/ \/_ // | \ \
( //) | \/// | \ \
( / /) _|_ / ) // | \ _\
( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\ / ~-. _ .-~ .-~^-. \
(( /// )) `. { } / \ \
(( / )) .----~-.\ \-' .~ \ `. \^-.
///.----..> \ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
▶ No.994221
>>994220
the worst part of cowfagging is the term itself
▶ No.994229>>994230 >>994350
>>994220
>The internal details of the compiler are irrelevant.
No they are not because you are bound to what C can do. nim becomes useless if you can't do anything C can't.
▶ No.994230>>994240
>>994229
it's a good thing C is turing complete, then.
▶ No.994237
meanwhile
>learning Ada
>cancer-curing language with manual memory management
>"OK now I will show you Access types--what Ada has instead of pointers."
>code is basically this:
with Ada.Unchecked_Deallocation;
procedure WTF is
type Int_Access is access all Integer;
type Container is record
Some_Int : Int_Access;
Another_Int : Int_Access;
end record;
type Cont_Access is access Container;
Box : Cont_Access;
Test_Int : aliased Integer := 42;
procedure Free is new Ada.Unchecked_Deallocation(Integer, Int_Access);
procedure Free is new Ada.Unchecked_Deallocation(Container, Cont_Access);
begin
Box := new Container;
Box.Some_Int := Test_Int'Access;
Box.Another_Int := new Integer'(40);
-- do nothing
Free(Box.Some_Int);
Free(Box.Another_Int);
Free(Box);
end WTF;
Note: Test_Int is statically allocated memory. A pointer to it is stored in Box.Some_Int. Box.Some_Int is then free'd at the end. This results in a runtime abort with "bogus pointer (double free?)"
>keep waiting for author to say "as you might have noticed, this crashes!"
>where it the lesson
there's no lesson. it's the author's error.
▶ No.994240>>994243 >>994259 >>997555
>>994230
>what are system functions
>what are opmitizations
Even then, might as well skip the middle man and use C.
▶ No.994243>>994248
>>994240
>system functions
what about them? You're concerned about system functions that C doesn't have?
>what are optimizations
what about them? Nim's performance is very good. Some simple programs in Nim are marginally slower than comparable programs in GC-less languages, which is the overhead from the runtime.
If /tech/ had a "write a tiny program to do this thing" captcha, would you be able to post?
▶ No.994248>>994259
>>994243
>"write a tiny program to do this thing" captcha
That would be pretty funny. Something like 'write a program that outputs n fibonacci numbers in x chars or less'.
▶ No.994259>>994261
>>994248
I wonder if this could be a real captcha? you'd need it to be able to come up with program specs automatically. Maybe you could generate a random string, and ask them generate the string in x chars or less. x could be half the gz compressed size. One problem with using problems like fib is that a computer could google stack overflow to find the answer.
>>994240
>skip the middle man and use C
your c program compiles to assembly. Why not skip the middle man? hint: the compiler takes care of details so you can ignore them.
▶ No.994261>>994265 >>994356
>>994259
Because ASM is on a lower level, is not portable. Are you nim faggots literally retarded?
▶ No.994265
>>994261
>c is so portable
does it compile to javascript? anyways, why not write in llvmir of gimple? portable and c compiles to it.
>those aren't programming languages
you can write programs in them ∴ they're programming languages.
▶ No.994315
>another meme lang being shilled by brainlets
*yawn*
▶ No.994350
>>994229
you are not the brightest
▶ No.994356
>>994261
>C is portable
It is until you want to write something useful in it.
▶ No.994378
>>994023 (OP)
Nim is godtier
▶ No.994386>>994391
▶ No.994391
▶ No.994753
>>994148
Use release mode to remove linetracing and debug features, the little boilerplate code it adds doesn't get in the way, and it can't be any worse that those languages that transpile to JS and are widely used.
▶ No.996235>>996236 >>996262 >>996263 >>996266
>>996216
How do I install sdl for nim? I can only get sdl2 but that doesn't seem to work:
Hint: used config file '/etc/nim.cfg' [Conf]
Hint: system [Processing]
Hint: raytracer [Processing]
Hint: math [Processing]
Hint: sequtils [Processing]
Hint: macros [Processing]
Hint: sdl2 [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: algorithm [Processing]
raytracer.nim(18, 14) Error: undeclared identifier: 'Float'
▶ No.996236>>996249
>>996235
I can install sdl with
nimble install sdl1
but I still get the same error.
▶ No.996249>>996263
>>996236
no idea. that raytracer image probably didn't involve SDL. "Ray Tracing in One Weekend" is a good book that has you write raw .ppm files.
▶ No.996262
>>996235
That raytracer is from 6 years ago, sorry. `Sdl2` installs and works completely fine for me, it wouldn't be hard to change some of it to suit the newer version.
▶ No.996263
>>996249
It does use sdl.
>>996235
Success: sdl2 installed successfully.
▶ No.996266>>996293
>>996235
That error was what I got when attempting to compile his raytracer.nim with:
nim c raytracer.nim
But yeah that code is way to old to be compatible with the current version (0.19)
▶ No.996293>>996344 >>996416
>>996266
>that code's 6 years old, of course it won't compile
>after all, the current version is [something starting with 0.]
jesus christ
▶ No.996344
>>996293
bleeding-edge linguistics.
that code's 6 years old. after all, the current version is C++lastyear
there's always Ada and Common Lisp if you want something that'll last.
▶ No.996416
>>996293
do you realize how long nim has existed or are you just pretending to be retarded
▶ No.996478
You can create a website (full back-end and front-end, server-side and JavaScript on client-side if you so wish) all in pure nim.
include karax / prelude
# alternatively: import karax / [kbase, vdom, kdom, vstyles, karax, karaxdsl, jdict, jstrutils, jjson]
var lines: seq[kstring] = @[]
proc createDom(): VNode =
result = buildHtml(tdiv):
button:
text "Say hello!"
proc onclick(ev: Event; n: VNode) =
lines.add "Hello simulated universe"
for x in lines:
tdiv:
text x
setRenderer createDom
▶ No.996509
▶ No.996517>>996519
>>996508
Using Nim to replace CPython sounds perfect
▶ No.996519
>>996517
Yeah, it accomplishes what cpython wants to much more elegantly IMO.
▶ No.996551
>>994213
<I just learned asm and basically I am god
Stop embarrassing yourself
▶ No.996884>>997055
Here's the Nim documentation (downloaded with Wget and stripped of Google Analytics and Google Fonts):
https://my.mixtape.moe/rtjzbj.tar.gz (2.4 MiB)
>>996520
Try Zig if you want to manually manage your memory.
I'm planning to use Nim myself to replace my slow Python scripts, I think that's well-suited for it.
▶ No.997055
>>996884
Thanks, good stuff. I'm trying to learn Nim but I feel like the documentation is a bit lacking.
▶ No.997059>>997110
Do you still need to add a tabs-to-spaces substitution filter to every Nim source file or is that fixed?
▶ No.997110
>>997059
I don't think you need to do that but the standard is spaces
▶ No.997189>>997536
>>996508
Now rewrite all the libraries here in Nim. I dare you. (you can't, which is why Numpy is always better)
https://docs.anaconda.com/anaconda/packages/py3.7_linux-64/
▶ No.997536
▶ No.997555>>997651
>>994240
>Even then, might as well skip the middle man and use C.
A computer only calculates stuff, skip the middle man and calculate stuff on your own.
▶ No.997651
>>997555
skip the middle man and just don't do anything