Live data from Hacker News

Go channels, goroutines and GC available in Nim

forum.nim-lang.org

1–10 of 87 posts

Re: Go channels, goroutines and GC available in Nim

#2
I always wanted to see a Go/Nim interop project in a little different vein. Since Nim is a superset of Go (and Go is fairly simple), why not a Go implementation in Nim via cross-compilation? Then you can even build a Nim macro that does a "Go get" and Nim developers can use Golang libraries right in their code as imports. Not to mention we get a full, alternative Go impl.

It should be easy to bootstrap by first using Go's parser to dump some AST that Nim code can then translate, and then once that version is done, just reference the Go parser using this new impl. The only real struggle with the project from what I can see is deciding which standard library items to use the Go transpiled implementation (probably most of them) vs which need to have Nim backends (e.g. runtime package). Meh, just rambling thoughts in my head I was considering playing with given the time...

Re: Go channels, goroutines and GC available in Nim

#3
I'm very curious to hear the pros and cons of this from somebody who has intimate knowledge of Nim internals. I really really like Go's CSP model and would love to see it properly supported in another lightweight non-jvm language (yes I know about Erlang, it doesn't fit the bill for me).

Re: Go channels, goroutines and GC available in Nim

#4
This is awesome! Go's channels and green threads were one of the features I really liked about Go. One more reason for me to go past basic prime number programs in Nim :)

I'm hoping to see Rust get green threads/tasks/goroutines too. I'm working on a GC myself, and hopefully someone is trying out a green thread scheduler.

Re: Go channels, goroutines and GC available in Nim

#5

I'm very curious to hear the pros and cons of this from somebody who has intimate knowledge of Nim internals. I really really like Go's CSP model and would love to see it properly supported in another lightweight non-jvm language (yes I know about Erlang, it doesn't fit the bill for me).

Well you can already use Nim threads (http://nim-lang.org/docs/threads.html) and channels (http://nim-lang.org/docs/channels.html) - the model is similar although the implementation uses system threads rather than coroutines.

Nim also has lightweight coroutines using `async` and `await` (http://nim-lang.org/docs/asyncdispatch.html) - you can run a bunch of these within one thread.

Also, have a look at gevent for Python.

Re: Go channels, goroutines and GC available in Nim

#6
post #5

I'm very curious to hear the pros and cons of this from somebody who has intimate knowledge of Nim internals. I really really like Go's CSP model and would love to see it properly supported in another lightweight non-jvm language (yes I know about Erlang, it doesn't fit the bill for me).

Well you can already use Nim threads ( http://nim-lang.org/docs/threads.html ) and channels ( http://nim-lang.org/docs/channels.html ) - the model is similar although the implementation uses system threads rather than coroutines. Nim also has lightweight coroutines using `async` and `await` ( http://nim-lang.org/docs/asyncdispatch.html ) - you can run a bunch of these within one thread. Also, have a look at gevent fo…

In addition to the heavyweight threads (http://nim-lang.org/docs/threads.html) there is also `spawn` (http://nim-lang.org/docs/manual.html#parallel-spawn-spawn-st..., http://nim-lang.org/docs/threadpool.html)

Re: Go channels, goroutines and GC available in Nim

#7
post #2

I always wanted to see a Go/Nim interop project in a little different vein. Since Nim is a superset of Go (and Go is fairly simple), why not a Go implementation in Nim via cross-compilation? Then you can even build a Nim macro that does a "Go get" and Nim developers can use Golang libraries right in their code as imports. Not to mention we get a full, alternative Go impl. It should be easy to bootstrap by first using…

> why not a Go implementation in Nim via cross-compilation?

Nim's macros have one limitation that prevents an accurate implementation of another syntax: they can't fully modify the existing syntax.

See how I had to use "scase" inside "select" blocks because the existing "case" keyword insists on having "of" after it. So Nim's semantics put some limits on the amount of hijacking one can inflict on it through macros.

Re: Go channels, goroutines and GC available in Nim

#8
This document describes how the GC works and how to tune it for (soft) realtime systems.

The basic algorithm is Deferred Reference Counting with cycle detection.

I'm sitting here feeling very impressed. Deferred reference counting has very good semantics for games. Even better, you can control the cycle detection part separately and run that part at an advantageous time. (Though it's probably better to just let GC do its thing, unless you really know what you're doing.)

I am currently writing a multiplayer game server in golang, by making sure almost everything is allocated on the stack, and heap sizes are small. This gives me an efficient, nearly pauseless server. However, something like Nim could give me even more flexibility.

Re: Go channels, goroutines and GC available in Nim

#9
post #2

I always wanted to see a Go/Nim interop project in a little different vein. Since Nim is a superset of Go (and Go is fairly simple), why not a Go implementation in Nim via cross-compilation? Then you can even build a Nim macro that does a "Go get" and Nim developers can use Golang libraries right in their code as imports. Not to mention we get a full, alternative Go impl. It should be easy to bootstrap by first using…

> why not a Go implementation in Nim via cross-compilation? Nim's macros have one limitation that prevents an accurate implementation of another syntax: they can't fully modify the existing syntax. See how I had to use "scase" inside "select" blocks because the existing "case" keyword insists on having "of" after it. So Nim's semantics put some limits on the amount of hijacking one can inflict on it through macros.

If you front compilation with Go's parser, you could generate bog-standard Nim code from the AST.

Re: Go channels, goroutines and GC available in Nim

#10
post #2

I always wanted to see a Go/Nim interop project in a little different vein. Since Nim is a superset of Go (and Go is fairly simple), why not a Go implementation in Nim via cross-compilation? Then you can even build a Nim macro that does a "Go get" and Nim developers can use Golang libraries right in their code as imports. Not to mention we get a full, alternative Go impl. It should be easy to bootstrap by first using…

> why not a Go implementation in Nim via cross-compilation? Nim's macros have one limitation that prevents an accurate implementation of another syntax: they can't fully modify the existing syntax. See how I had to use "scase" inside "select" blocks because the existing "case" keyword insists on having "of" after it. So Nim's semantics put some limits on the amount of hijacking one can inflict on it through macros.

I don't believe they should accept the full Golang syntax, just help with the import. E.g.

    macro goImport(path: string): stmt
      // TODO
      discard
    
    goImport("golang.org/x/crypto/nacl/box")
Post reply on HN