
Yaegi – Yet Another Go Interpreter - emilevauge
https://blog.containo.us/announcing-yaegi-263a1e2d070a
======
dilap
Very cool idea. Doesn't seem ready for prime time yet -- tried running it on a
small Go program to score boggle boards, and got errors in the interpreter.

Playing around, it seems to have problems assigning int literals to int8
variables, and it seems to sometimes have problems re-assigning pointer
values.

------
mwkaufma
Bench-marking a fat native call, rather than a purely-interpreted function, is
a bit bait-and-switch.

~~~
chrisseaton
They do explain it very clearly though, and give a reason why that is what
they are interested in for business purposes. Benchmark and optimise for what
you're running, right? Better than a Mandelbrot?

~~~
the_duke
They explain it, but it's still deceptive.

I would have expected a honest benchmark result. Which will be much worse than
6%.

Which is totally fine! an interpreter will of course be much slower. But this
seems like the wrong kind of marketing by omission to me.

------
kbd
Programming in a language lacking a repl is always uncomfortable. I always
wind up making a 'scratch.{ext}' file and running it to test things (scratch.*
is in my global gitignore). Happy an interpreter+repl now exists for Go.

~~~
weberc2
I think this is a matter of personal preference. At work my primary language
is Python and I rarely use the REPL, and when I do, it's a regrettable
experience--can't use up arrow to get previous command, can't use arrow keys
to move cursor, entering tabs after the `. . .` makes it hard to figure out
how many tabs to enter, etc. And of course you can't visualize the whole
"program" at a glance like you can in a text editor. Not sure if Python's REPL
is just subpar among repls or if I just don't understand how to leverage REPLs
for my benefit, but `$EDITOR /tmp/foo.py` just works so much better for me.

~~~
kbd
> when I do, it's a regrettable experience--can't use up arrow to get previous
> command, can't use arrow keys to move cursor

Dunno what's wrong with your readline but what you describe is default Python
behavior. Try installing ipython, you'll get all that and more (such as syntax
highlighting, multi-line editing, and much more).

~~~
weberc2
Yeah, I'm not sure why, but this happens in VS Code's integrated terminal,
which also has other readline-related issues (alt+backspace deletes to the
previous space instead of deleting the previous word, for example). In any
case, I still don't use the REPL except when I need to dynamically inspect
some value (which isn't necessary in Go, since it's statically typed).

~~~
mixmastamyk
Windows is crippled somewhat on that front, but there are workarounds. Often
easier and way more functional to just install a wrapper like ptpython,
bpython, ipython, etc.

~~~
weberc2
I'm using a Mac.

~~~
mixmastamyk
Sounds like a broken terminal configuration. Try running python at the
standard terminal and see what it does.

~~~
weberc2
Yeah, like I said, it works at a standard terminal, not in the VS Code
integrated terminal.

------
penagwin
Around a ~6MB interpreter for those curious, not bad.

~~~
weberc2
Generally the Go runtime (garbage collector, scheduler, allocator, etc) alone
is 2-5MB, for additional context.

~~~
f2f
a bit less:

    
    
        $ cat > t.go
        package main
        func main() {}
        $ go build t.go
        $ ls -l t
        -rwxr-xr-x  1 f2f  staff  1101432 24 Jul 23:19 t

~~~
zimpenfish
And you can drop that down to ~775k by using `strip`.

    
    
        [rjp@hostname tmp]$ ls -l gosize 
        -rwxr-xr-x 1 rjp rjp 1126905 Jul 25 07:00 gosize 
        [rjp@hostname tmp]$ strip gosize
        [rjp@hostname tmp]$ ls -l gosize 
        -rwxr-xr-x 1 rjp rjp 793704 Jul 25 07:00 gosize
        [rjp@hostname tmp]$ go version
        go version go1.12.7 linux/amd64

------
frou_dh
From the "another" archives, I remember this one, that looks abandoned:

[https://news.ycombinator.com/item?id=15622894](https://news.ycombinator.com/item?id=15622894)

[https://neugram.io/](https://neugram.io/)

[https://github.com/neugram/ng](https://github.com/neugram/ng)

------
haolez
It seems to be from the creators of Traefik, which is another great tool.

[https://traefik.io/](https://traefik.io/)

------
ysleepy
I'd be interested in an opinion of the dev on what was the hardest part to
build. I could imagine reflection features or the incremental type checking
would be hard to do. But I always see these projects (like cling/ROOT from
cern) and think that some subproblems are really hard to do if done
incrementally with only local knowledge.

------
forgot_old_user
Why would I need a Go Interpreter? What advantage does it provide over using a
precompiled binary?

~~~
mcpherrinm
There are some circumstances where an interpreter is useful: For example, it
should be possible to make better golang repls with an interpreter than with a
binary.

In a "scripting" scenario, you can load some golang code at runtime without
needing to bring the full golang compiler toolchain along, which keeps the
nice "single binary" deploys of golang. It may be possible to sandbox scripts
as well (though I haven't looked into how that could work with this
implementation), which could reduce the risk of running scripts (less likely
to shoot yourself in the foot. Probably not a security boundary -just look at
how much work goes into safe JS in browsers to have that).

~~~
mhh__
Sandboxing is possible but only if it brings it's own standard library (I
think... I'm not familiar with how go implements io at it's roots)

~~~
stcredzero
I'm working on an approach for Golang sandboxing which works through
whitelisting imports, and munging all references, casting operations, and
function calls, which lets one whitelist those as well. I would disallow all
io and network access.

~~~
the_duke
Seems like a wasm interpreter with WASI might be a better approach.

~~~
stcredzero
I've also given that some thought as well. Actually, all of the above could be
combined.

------
drinane
Does it have any pretty printing capabilities? Repo doesn't seem to...

------
ldez
Now, you can play with it in the Go Playground [https://play.golang.org/p/P--
lUj4Vbax](https://play.golang.org/p/P--lUj4Vbax)

------
childintime
Wasn't clear to me: will it run say a serial port without additional steps?

------
drinane
That's pretty cool. Definitely going to use this on my projects.

------
leshow
Like runhaskell for Go?

------
webscalist
YAGNI?

~~~
quickthrower2
Yaegimeister?

------
InvOfSmallC
Please add generics at least on Yaegi! :P

~~~
stcredzero
He doesn't have to:
[https://github.com/cosmos72/gomacro](https://github.com/cosmos72/gomacro)

~~~
ausjke
is gomacro better for repl on golang comparing to yaegi? both look well

~~~
ausjke
gophernotes is sort of like a repl under jupyter

------
tomphoolery
Yaeji is going to be very happy that an interpreter was named after her!
[https://soundcloud.com/kraejiyaeji](https://soundcloud.com/kraejiyaeji)

~~~
hammeiam
I was thinking the same thing :)

