7 ms·
A JavaScript parser and interpreter written in Go
- jchrisa 13y agoWe use this for the sync function interpreter in Sync Gateway. Robert has been very helpful and responsive with pull requests etc. thanks! Edit to add link to example code using Otto https://github.com/couchbase/sync_gateway/blob/master/src/github.com/couchbaselabs/sync_gateway/channels/sync_runner.go https://github.com/couchbase/sync_gateway/blob/master/src/gi...
- jzelinskie 13y agoThank you for being one of the few gophers that put newlines between standard, third party, and local imports. I wish gofmt forced that standard on people.
- gyepi 13y agoIt is a useful convention in C and C++ to group includes, but I don't see the benefit in Go. Since gofmt sorts imports, the grouping is soon undone. In any case, it is quite easy to distinguish the three kinds of imports if local imports share a common prefix or set of prefixes. Am I missing something here?
- agentS 13y agoNote that gofmt sorts within groups. So if you leave spaces between groups of imports, it'll sort them all separately. Presumably, this sort of grouping is the reason it does it this way.
- codebeaker 13y agoIt's possible that if you have packages that understand flags (config package, with flags in init(), for example) that if you include it after the testing package, or before. One of them won't accept flags. (because flag.Parse() has already been called)
- 1631- 13y agoYou can't rely on the order of imports initialization anyway. See http://golang.org/ref/spec#Program_execution http://golang.org/ref/spec#Program_execution .. I believe that's also the reason, you shouldn't call `flag.Parse()` in `init()`
- deleted 13y ago[deleted]
- ebilgenius 13y agoThis is the most Hacker News sounding title I've ever heard.
- ihsw 13y agoNo, there's not enough Redis here. It needs more Redis.
- nl 13y agoHaskel!
- carterschonwald 13y agoIts actually really easy to get involved in hacking on GHC, the main Haskell compiler. Seriously, its as easy as taking some time to just try to build current head and report any build problems! https://ghc.haskell.org/trac/ghc/wiki/Building https://ghc.haskell.org/trac/ghc/wiki/Building I'm actually really excited by all the people starting to jump in and try to learn/help. We've even got 2 really smart high schoolers doing some amazing contributions to GHC recently. seriously: its easy to get involved in hacking on interesting open source projects. Just choose one you care about and stay excited by, and dig in!
- jkchang 13y agoI think the title has been changed. Can you say what the original was?
- wldlyinaccurate 13y agoI could be wrong, but I think they're just poking fun at all the "An X interpreter written in Y" where X and Y are the current trendy languages. Usually one of X or Y are JavaScript or Go, so seeing both in the same headline is like some sort of Hacker News headline jackpot.
- hbbio 13y ago
- runn1ng 13y agoIsn't there also a Go parser and interpreter written in JavaScript?
- jheriko 13y agoParadox!!!! Infinite loop!!! Oh, wait causality doesn't work that way. Never mind. :P
- scosman 13y agothe perfect hacker news title
- ChronosKey 13y agoShow HN: How a JavaScript parser and interpreter written in Go allowed my startup to succeed and Why your company should switch to Go
- jheriko 13y agoyou forgot to mention someframework.js, and Edward Snowden... :)
- deviltry 13y agoBut does it web scale?
- mushroomhead 13y agoShow HN: A JavaScript parser and interpreter written in 30 lines of Go
- alexkus 13y ago...we accept Bitcoin too!
- ceronman 13y agoAnd that's how we learned not to use MongoDB.
- ek 13y agoA couple years ago for a programming languages course, we wrote a bytecode compiler and interpreter for a JavaScript-like language we were using in the class (objects, prototype-based inheritance, higher-order functions, etc), and we initially started building it in Go, but the biggest thing that made us switch to C++ at that time was the fact that Go didn't have a straightforward union type. It looks like this interpreter is using tagged unions for values, and using the empty interface to emulate a union type. I seem to remember that we may have read something at the time that recommended using the empty interface instead of unions, though I don't remember for sure. Nice to see some interpretation efforts finally being realized in Go!
- robzyb 13y agoExcuse the silly question, but why was a union type so important?
- toong 13y agoI was wondering myself why you needed a union type. Is it because JS has dynamic types ? var x = 5; x = "John Doe";
- jessedhillon 13y agoThe alternative is a data structure which has N-1 empty, yet allocated, slots (N is the number of possible types.) instead you can have one field indicating the type of the variable and then your code can switch which field it accedes based off that indication. Total size is one int plus size of largest type represented.
- 1631- 13y agoYou could potentially also have an interface that defined methods for all the basic types `interface { AsString() (string, error), etc. }` and then each basic type implements this interface and returns an error if it can't/shouldn't be represented as the requested type. A type-switch could give you the same info you get from the tag and you don't pay for type-assertions
- omeid2 13y agoSomeone please bind the Go Net and IO and there you have a Node.js-esque-Go-Hybrid. Not serious. haha.
- borplk 13y agoFeed from node to go channels ... and then fly it on top of gevent async overload!
- riobard 13y agoIt would be nice to have some rough performance numbers to compare with existing JS engines.
- recuter 13y agoAlright, 90 points, most comments being meta about the title so I'll be the brave one and ask: What is this actually good for? I can't think of any reasonable use case. Grab little NPM ditties and incorporate them into your Go binary - Javascript to Go becomes as Lua is to C? Somebody enlighten me. Edit: Not that this needs a use case per say, just that the intent behind it is underspecified enough for me to wonder about it.
- columbo 13y agoIf it was fully functional it could be useful for automated testing. Write your tests in javascript, execute them at the point of integration in Go.
- gouggoug 13y agoNot everything needs a use case. But if you really want one, here's one: I'm a student and I want to write my own interpreter. Well, here's a good example of how to write your interpreter.
- mushroomhead 13y agoWe have distributed crawler written in go configurable with xpath and javascript for advanced crawling using javascriptcore-go[1] and also our knowledge engine serves various form of formatted information card scripted in javascript. Duckduckgo goodies[2] also a good example of what we've been doing. 1) https://bitbucket.org/rj/javascriptcore-go https://bitbucket.org/rj/javascriptcore-go 2) https://duckduckgo.com/goodies https://duckduckgo.com/goodies
- Goranek 13y agoCan someone explain to me whats wrong with using V8 in Go? I mean what's the point in building js interpreter in Go, when you already have a better one made.
- raverbashing 13y agoWell, maybe they will come with a better Google Closure in Go Because Google Closure Compiler is unbelievably slow
- BMorearty 13y agoWhat's the point of starting anything new, when something like it already exists? Why become a doctor when there are already good doctors? Why write a book when there are already good books? Why sing a song when somebody else already sings it better?
- Goranek 13y agoBy putting in the context the amount of money and number of one of the best programmers in the world building a V8, building a Go V8 alternative is probable not a best business choice unless you're a huge company with clear goals
- BitMastro 13y agoI suppose this could be useful when generating a statistically compiled binary
- alecthomas 13y agoAt least two concrete reasons: 1. No cgo required. 2. Portable to any platform Go runs on that V8 doesn't.
- oelmekki 13y agoDoes this aim to compete with v8 implementations for high level products usable by non go developer (I think qtwebkit, here), or is it just a mean to have js integration in go for small low level scripting ?
- mseepgood 13y agoObviously the latter. Otherwise it would have to be a JIT compiling VM, not a simple interpreter.
- yOutely 13y agoThis is not a good thing nor will it lead to good things.
- fabriceleal 13y agoI have no idea how to really ask this, but does it uses continuation-passing style [0] to execute expressions? I tried to search for "cps" or "continuation" in the repo, but no luck. I also don't really have the time right now to go dig through the source. [0]: http://en.wikipedia.org/wiki/Continuation-passing_style http://en.wikipedia.org/wiki/Continuation-passing_style
- barrkel 13y agoMost languages don't have reliable enough tail call elimination to implement CPS without trampoline techniques to get rid of the excess stack frames, which in turn has a fairly hefty performance impact unless you're using it for something high-level like async callbacks.
- deleted 13y ago[deleted]
- Aardwolf 13y agoNow someone must make a Go interpreter written in JavaScript, so you can JavaScript while you Go while you JavaScript while you ...