News for hackers. Stuff that matters.
Re:Neugram – Scripting in Go by kornish on Friday November 03, 2017 @08:48PM (#15623224)
"Go is syntactically a big language. Neugram’s front end has to match it, and that’s a lot of work, much of which is still to do."

I appreciate the sentiment – that there's a lot of work left to do – but isn't the assertion about syntax size false? I thought Go's syntax was quite small compared to other popular languages? It only has 25 reserved words (Java has 50+) and was designed in part to be uniform and easy to read.

Re:Neugram – Scripting in Go by crawshaw on Friday November 03, 2017 @08:54PM (#15623244)
I made this point poorly, because I agree with you that Go is quite easy to read and very predictable.

With more words: I have written a parser and type checker for an ML-style language, with parametric types and several other neat tricks in it, and I've now written a parser and type checker for a good subset of Go. The latter has been far more work. I am not entirely sure how to explain the work. Go has lots of syntactic and type conveniences that are easy to use and read, but quite difficult to implement.

As there are few implementers and many users, I think the original designers of Go picked well when they put the work on us implementers.

Re:Neugram – Scripting in Go by ainar-g on Saturday November 04, 2017 @03:22AM (#15624130)
Can you elaborate on what syntactic conveniences are difficult to implement and why? Language design is on of my hobbies, so I really would like to know that.
Re:Neugram – Scripting in Go by crawshaw on Saturday November 04, 2017 @07:44AM (#15624609)
One good example is untyped constants. They form a large extension to the type system only present at compile time. It is a good example because there is an excellent blog post describing them in detail: https://blog.golang.org/constants

In particular note the difference between

    const hello = "Hello, 世界"
and

    const typedHello string = "Hello, 世界"
one of these can be assigned to named string types, the other cannot.

As a user of Go I find untyped constants to be extremely useful. They almost always do what I want without surprise. Implementing them however, is not trivial.

A tricker example is embedding. It adds a lot of complexity to the type system. As a user, it can be a bit surprising, but I admit it is very useful.

Re:Neugram – Scripting in Go by mjburgess on Saturday November 04, 2017 @07:13AM (#15624553)
At a guess, I would describe it as a trade off between syntax and semantics.

Languages that have simpler syntax tend to have far more complex semantics (to infer what's missing, etc.).

Eg. python's semantics is horribly complex: "hello".upper() is something like str.__dict__['upper']("hello")) -- which is all run-time. Whereas say a C++ version amounts to quite a simple run-time function call on some bytes.

Re:Neugram – Scripting in Go by ansible on Friday November 03, 2017 @09:32PM (#15623365)
What stopped you from using the parsing in the standard library?
Re:Neugram – Scripting in Go by crawshaw on Friday November 03, 2017 @09:42PM (#15623398)
Because Neugram is a different language. It is so only in small ways, but they add up when you are in the parser, and especially in the type checker.

First is the fact that the top level is statements, not declarations. That would mean heavy modification to the go/parser package to make the inner-function statement parser the top level.

Second is the fact I need to parse incrementally, to implement a REPL. That would not require serious modification to go/parser, but it would to go/types.

Third is I wanted to experiment with new syntax. It was quicker to get to that experimentation by working from scratch rather than adopting go/parser and go/types.

Fourth is there are some fundamental things I would like to do differently, particularly around how comments are handled. I haven't got there yet.

In retrospect, if the new Go parser inside cmd/compile existed when I started this, I probably would have started from there. (It does many of the things I wanted to do to go/parser.) I suspect I still would have ended up with my own type checker though, if for no other reason than incremental type checking.

Re:Neugram – Scripting in Go by ansible on Saturday November 04, 2017 @05:07AM (#15624310)
I've toyed with making some kind of interpreter for Go. Something that integrates well with it, giving access to all the libraries, channels, goroutines and such. Discussing this with an acquaintance, we decided the best scripting language for Go was... Go. It is interesting to see that you've headed in the same general direction, though you've thought things through much further than we did.

I'll have to try it out.

Re:Neugram – Scripting in Go by TheDong on Saturday November 04, 2017 @12:53AM (#15623866)
Go's small number of keywords is deceptive.

Let's look at some of Java's keywords which have no analogue in the Go specification's list of keywords

1. boolean: go has the `bool` type, but it's a builtin, not a keyword, so it doesn't count against it.

2. byte: same thing

3. null: Go's `nil` is again not counted as a keyword in their list of 25

....

And hey, that accounts for almost the entire difference if you count all the primitive types.

Go, on the other hand, does not consider those "keywords", which leads to absolutely silly behaviour.

A programmer can accidentally redefine `len` to be a variable, and then `len(x)` will be an error later.

Because go has a ton of important builtins which aren't reserved keywords, you can write incredibly confusing code:

https://play.golang.org/p/-xChCblMEh

For a nice list, check out https://play.golang.org/p/yjkxqVY4eo

... yeah, Go's small number of keywords is often touted by Gophers, but really it's because the go team made this incredibly stupid decision.

If you counted the same sorts of things as keywords that java did, Go would have almost exactly the same number... and more problems would be caught at compile-time (like `len := 1`) .

Re:Neugram – Scripting in Go by Vendan on Saturday November 04, 2017 @01:54AM (#15623983)
I think the true argument is that you can read the Go specification in a slightly extended sitting, whereas (for example), the current working draft for C++ is 1416 pages.
Re:Neugram – Scripting in Go by kibwen on Saturday November 04, 2017 @11:06AM (#15625334)
The Go specification is not the same sort of document as the C++ or Java specifications. Go is doubtlessly less extensive than C++ or Java, but it would be dishonest to attempt to leverage their respective specification documents as yardsticks for complexity. If Go were submitted to a standards body such as ISO, the drafting committee would produce a more detailed and more verbose document than currently exists.
Re:Neugram – Scripting in Go by camus2 on Saturday November 04, 2017 @02:05AM (#15624008)
Is the Go "specification" considered a normative spec, like ECMASCRIPT spec? And AFAIK the C++ draft also covers the std lib.
Re:Neugram – Scripting in Go by Vendan on Saturday November 04, 2017 @02:10AM (#15624017)
Unless the C++ draft is 90+% stdlib, it's still quite a difference in size (printed, which would not be a good way to use it, the Go spec is 90 pages). And I'd consider it normative, though not to the point of "spec wins if the spec and the toolchain disagree".
Re:Neugram – Scripting in Go by didibus on Saturday November 04, 2017 @02:40AM (#15624070)
I'm not sure Go has a spec. The page says spec, but the content says its the reference manual. So I'm guessing it's more focused on learning how to use the language then on writing an alternative implementation of it.
Re:Neugram – Scripting in Go by crawshaw on Saturday November 04, 2017 @07:48AM (#15624617)
https://golang.org/ref/spec certainly is a specification of the Go language.

Whenever a difference is found between the two Go compilers, gccgo and gc, the spec is consulted to see which is right. If the spec is not clear on which compiler is right, then the spec is changed so it is.

When the third frontend was written (go/parser and go/types in the standard library), the spec played a similar role. Though far fewer changes were made to the spec, suggesting it is getting pretty good.

Re:Neugram – Scripting in Go by didibus on Saturday November 04, 2017 @05:40PM (#15627043)
Oh, that's good to know. I'm happy to hear it is trying to be a language with a formal spec.
Re:Neugram – Scripting in Go by neild on Saturday November 04, 2017 @02:40AM (#15624068)
If the spec and an implementation disagree, there is a bug in one or the other. (There are multiple implementations of the language.) The Go spec is not entirely normative in that a disagreement between it and the implementation may be resolved in favor of the later. It is normative in that you should be able to implement the entire language from the spec alone.
Re:Neugram – Scripting in Go by vorg on Saturday November 04, 2017 @02:38PM (#15626302)
> If you counted the same sorts of things as keywords that java did, Go would have almost exactly the same number

Java has 53 keywords, whereas Go has 25 keywords and 39 special identifiers, totalling 64, a little more than Java's but less than C#'s 78.

Re:Neugram – Scripting in Go by diggan on Saturday November 04, 2017 @01:11AM (#15623903)
Guess it's relative. Different lisps are probably syntactically the smallest group of languages, but compared to Java (which most people would say is a bloated language) it's a tiny one.