News for hackers. Stuff that matters.
Re:Interactive Go REPL by jitl on Thursday July 13, 2017 @12:25PM (#14762627)
I love this! I really think the title could use the project name in it; I almost didn't click because there are tons of other go REPLs out there for explanatory programming; but nothing that gives you this drop-to-repl in a program.
Re:Interactive Go REPL by gjem97 on Friday July 14, 2017 @08:46AM (#14769330)
Wow this is a HACK. In the old-school getting-things-done-I-dont-care-if-its-ugly-but-it-has-a-certain-elegance-to-it sort of way. Well done.
Re:Interactive Go REPL by akavel on Thursday July 13, 2017 @01:22PM (#14763168)
Does anybody know if this is finally a real full-blown REPL? Does it allow starting new goroutines and communicating with them over channels? Does it support FFI, i.e. package syscall + unsafe? on Windows and Linux?

Or is it again a "recompile and rerun everything after each new line is added and pretend to be a REPL"? Or is it maybe something inbetween?

Re:Interactive Go REPL by d4l3k on Thursday July 13, 2017 @01:27PM (#14763229)
Author here.

It's something inbetween. Pretty much the way it works is it dynamically inserts references to all objects/packages/functions in scope at compile time. It then has an in Go interpreter that uses reflection to be able to interact with those references in a transparent way.

The compiled part is just go so that part interacts the same way. The Go interpreter is only partially complete so there may be a few things that don't work as expected, but should be easy enough to add.

I'm also thinking about adding go1.8 plugin support so you can import new packages during the run instead of specifying them on the command line.

Re:Interactive Go REPL by cosmos72 on Friday July 14, 2017 @03:51AM (#14768261)
Hello d4l3k,

I did not try go-pry yet, but I am very curious to compare it with my own attempt at an interactive Go REPL https://github.com/cosmos72/gomacro

They look similar in several aspects, and different in some key ones. For example, mine does not try to instrument compiled code and, among other things, uses exactly go1.8 plugin to import compiled packages at runtime.

Re:Interactive Go REPL by wybiral on Friday July 14, 2017 @01:15AM (#14767664)
Oh wow. You're interpreting right from go/ast? Very cool!
Re:Interactive Go REPL by d4l3k on Friday July 14, 2017 @01:59AM (#14767845)
Yup!
Re:Interactive Go REPL by sushisource on Thursday July 13, 2017 @02:00PM (#14763580)
How'd they miss the name "gobar"? :D
Re:Interactive Go REPL by sigjuice on Thursday July 13, 2017 @02:34PM (#14763898)
It is good that they missed it. Google "gobar" and you will see why.
Re:Interactive Go REPL by gknoy on Thursday July 13, 2017 @04:38PM (#14764966)
I'm a little afraid to do that - is it safe for work?
Re:Interactive Go REPL by chaosfox on Thursday July 13, 2017 @04:40PM (#14764987)
Re:Interactive Go REPL by sushisource on Thursday July 13, 2017 @04:56PM (#14765153)
Wow. Guess I learned something new today.
Re:Interactive Go REPL by paulddraper on Thursday July 13, 2017 @10:18PM (#14766937)
Dried cow dung
Re:Interactive Go REPL by rajathagasthya on Thursday July 13, 2017 @01:13PM (#14763071)
As someone who just started learning Go, what are the other popular Go REPLs in addition to this one?
Re:Interactive Go REPL by spyspy on Thursday July 13, 2017 @05:42PM (#14765530)
https://play.golang.org/ isn't a "real" REPL but it serves the same purpose for me in most cases. You can write a few quick lines just to test a theory e.g. "What happens if I pass this function this weird input?" or "Will this regexp function do what I think it does?"

https://chrome.google.com/webstore/detail/better-go-playgrou...

^ this plugin also adds some bells and whistles like syntax highlighting to make it feel like a real IDE.

Re:Interactive Go REPL by samuell on Thursday July 13, 2017 @01:33PM (#14763294)
The one that has seemed reasonable last I checked, was gore [1]. Then, you might want to check out the Golang Jupyter kernel as well (gophernotes [2]), which mentions gore as an inspiration.

[1] https://github.com/motemen/gore

[2] https://github.com/gopherdata/gophernotes

Re:Interactive Go REPL by alecthomas on Thursday July 13, 2017 @05:50PM (#14765593)
Unfortunately, gore seems to be abandonware (last commit was a year ago).
Re:Interactive Go REPL by sdsk8 on Thursday July 13, 2017 @01:34PM (#14763305)
Wow, in my tests everything seems to run fine, fast and bug free, congratulations for that!
Re:Interactive Go REPL by kwamenum86 on Thursday July 13, 2017 @01:35PM (#14763321)
repl.it's Go REPL is quite good: https://repl.it/languages/go
Re:Interactive Go REPL by jitl on Thursday July 13, 2017 @01:42PM (#14763397)
I find repl.it's go REPL to be totally unsatisfactory. I don't want to have to type `package main` at the top of my REPL before being able to evaluate any expression [0]. Avoiding that sort of boilerplate is a REPL's raison d'être.

In contrast, [gore](https://github.com/motemen/gore) lets you start evaluating expressions right away [1], and provides nice REPL short-hand for importing packages [2].

[0]: https://monosnap.com/file/OIO9dwR3n85xSNIdJIapGrBhbqWS4J.png

[1]: https://monosnap.com/file/AzuB6JsqRSN5f07H1ydB5t74Qh9pSA.png

[2]: https://monosnap.com/file/J3llCwPTwAcchYJWZpVG7wdB8fFXZ1.png

Re:Interactive Go REPL by sp0ck on Friday July 14, 2017 @04:41AM (#14768433)
Another VIM ? How to exit that damn thing ? :)
Re:Interactive Go REPL by icholy on Thursday July 13, 2017 @01:08PM (#14763028)
This is the first real Go REPL!
Re:Interactive Go REPL by gamesbrainiac on Friday July 14, 2017 @04:41AM (#14768432)
How does this compare to gore?
Re:Interactive Go REPL by sedeki on Friday July 14, 2017 @09:35AM (#14769642)
Thank you for this
Re:Interactive Go REPL by ice109 on Thursday July 13, 2017 @12:34PM (#14762709)
it's funny coming from python i missed the repl for the first few weeks but go's insane compilation speed almost completely obviates the need for one.
Re:Interactive Go REPL by frou_dh on Thursday July 13, 2017 @01:18PM (#14763133)
Fast compilation and restarts doesn't at all address the style of programming where you evolve an in-memory program in an exploratory way.
Re:Interactive Go REPL by Johnny_Brahms on Thursday July 13, 2017 @01:55PM (#14763524)
It doesn't,but op mentioned coming from python and I don't think many programming languages outside the lisp family have anything near a good REPL experience.

The few times I have tried to do serious work in python hasn't really impressed me much in that regard.

Re:Interactive Go REPL by jerf on Thursday July 13, 2017 @04:10PM (#14764736)
If that is your desire, you already know not to use Go.

Personally, the idea of developing code that way for use in a server brings back many memories, mostly not good, so this is not a big problem for me.

Re:Interactive Go REPL by ice109 on Friday July 14, 2017 @12:44PM (#14771181)
yes it does? unless you're unable to write a single line without interactivity. i do literally the same thing in go as i did in python (when i needed to): write a little and hit compile to watch what happens (except i add a fmt.Println(fmt.Sprintf("%#v",x)) or something like that). often the entire thing happens faster than it would take python to just interpret a similar line and execute.
Re:Interactive Go REPL by frou_dh on Friday July 14, 2017 @01:18PM (#14771433)
Find a screencast along the lines of someone livecoding something from scratch in a single editor-connected REPL session. Maybe using Clojure (or similar), and you'll appreciate the fundamental difference vs booting up fresh processes that start from line 1 of 'main' again and again.
Re:Interactive Go REPL by ice109 on Friday July 14, 2017 @03:03PM (#14772330)
https://www.youtube.com/watch?v=a9xAKttWgP4

that's a trick though - no one uses interpreters like that. for most people they're for experimentation, which is exactly what i was saying i'm able to do with go.

Re:Interactive Go REPL by frou_dh on Friday July 14, 2017 @03:36PM (#14772559)
The style I'm talking about, code isn't typed directly into the REPL/interpreter!!

You work in your real text editor and it has a connection to a persistent session of the language runtime, over which you can send fragments, lines or whole files into. And receive data back if you wish. You can refine or replace as little or as much of the program as you want, while it is running.

Say there's a power cut and your computer turns off. No big deal because you were working in your real text editor and saving source files to disk (but not necessarily sending all of their content into the session).

It's not trivial or a novelty. I get that a traditional line-at-a-time interpreter inside a terminal à la /usr/bin/python isn't super compelling. That's not what I'm talking about.

(I am also a happy user of Go FWIW. It's the C style of programming in a super-refined form (not surprising considering who 2 of its creators are!))

Re:Interactive Go REPL by ice109 on Saturday July 15, 2017 @02:58PM (#14778297)
>You work in your real text editor and it has a connection to a persistent session of the language runtime, over which you can send fragments, lines or whole files into. And receive data back if you wish. You can refine or replace as little or as much of the program as you want, while it is running.

...that's even closer to the style that fast compilation lends itself to

Re:Interactive Go REPL by frou_dh on Saturday July 15, 2017 @03:11PM (#14778361)
Alright, I get it. You're not interested in the subject I brought up.
Re:Interactive Go REPL by mikeflynn on Thursday July 13, 2017 @01:20PM (#14763147)
Agreed. Where I do miss a true REPL (and fingers crossed, this project is it) is when I don't have a specific Go project I'm working on but want to quickly explore an idea.
Re:Interactive Go REPL by whatnotests on Thursday July 13, 2017 @12:17PM (#14762563)
This makes Go much more accessible to coders who prefer this style of development.

Can't wait to give it a shot!