
2 min read
The type of a function call expression
Calls … The type of the expression is the result type of F. A method invocation is similar but the method itself is specified as a selector upon a value of the receiver type for the method. math.Atan2(x, y) // function call var pt *Point pt.Scale(3.5) // method call with receiver pt We recently talked about method calls already, so we don’t need to expand much more on those.

2 min read
Calls
Calling all gophers! It’s time to talk about… Calls! Calls Given an expression f with a core type F of function type, f(a1, a2, … an) calls f with arguments a1, a2, … an. This basic syntax is common to many languages, so should not feel at all strange if you have any programming experience at all. So let’s dive right into the nitty-gritty details… … Except for one special case, arguments must be single-valued expressions assignable to the parameter types of F and are evaluated before the function is called.

3 min read
Type assertion values
By now you’ve guessed there was no live stream today. Illess has been hitting my family hard. I’ll try to pick it up again after the new year. Type assertions … If the type assertion holds, the value of the expression is the value stored in x and its type is T. If the type assertion is false, a run-time panic occurs. In other words, even though the dynamic type of x is known only at run time, the type of x.

1 min read
Type assertions of interface types
Type assertions … If T is an interface type, x.(T) asserts that the dynamic type of x implements the interface T. This simple sentence has some pretty profound implications. Let’s start with a simple example: type Fooer interface { Foo() } type thing int func (thing) Foo() {} var x interface{} = thing(3) x.(Fooer) // Valid, the result is an interface of type Fooer This can be very useful to convert from the empty interface (aka interface{} or any) to a more specific interface, as in the above example.

2 min read
Type assertions of non-interface types
Yesterday we started on type assertions. Today we’ll look at some of the specific details, as they relate to type assertions to non-interface types. Tomorrow we’ll look at interface types. Type assertions … More precisely, if T is not an interface type, x.(T) asserts that the dynamic type of x is identical to the type T. Recall that variables of interface types contain a dynamic type, which represents the type that satisfies the interface:

1 min read
Type assertions
Type assertions For an expression x of interface type, but not a type parameter, and a type T, the primary expression x.(T) asserts that x is not nil and that the value stored in x is of type T. The notation x.(T) is called a type assertion. For now, let’s look at some examples of type assertions that hold, and that don’t. In the next day or two, we’ll look at more details from the spec.

1 min read
Half way there
No live stream today. I’m still feeling a bit under the weather. Hopefully next week we’ll be back on schedule. In January, I started this series on the Go spec, not having any idea if I'd have even 2 readers, or how long it would take to get through the whole spec. This week we passed the half-way mark on that journey through the spec, and there are over 400 of you subscribed to this daily list.
Subscribe to Boldly Go: Daily
Every day I'll send you advice to improve your understanding of Go. Don't miss out! I will respect your inbox, and honor my privacy policy.
Unsure? Browse the archive.

2 min read
Full slice expressions
Full slice expressions The primary expression a[low : high : max] constructs a slice of the same type, and with the same length and elements as the simple slice expression a[low : high]. Additionally, it controls the resulting slice’s capacity by setting it to max - low. So I’ll be honest here and say I’ve never used this slice expression format. I’ve been vaguely aware that it exists, but I’ve never felt the need for it.

2 min read
Slice expression result types
No live stream today. Next week I expect to be back at it! Forgive me for not sending an email Friday. I spent the day in bed. 🛏️ But I’m back on my feet now! So up to now we’ve learned how to use slice expressions… but what is the type that results? Well, you can probably guess. It’s pretty intuitive: Simple slice expressions … Except for untyped strings, if the sliced operand is a string or slice, the result of the slice operation is a non-constant value of the same type as the operand.

2 min read
Range of slice expressions
Simple slice expressions … For arrays or strings, the indices are in range if 0 <= low <= high <= len(a), otherwise they are out of range. This is probably intuitive. a := [5]int{1, 2, 3, 4, 5} s := "Abracadabra" a[-1] // Out of range s[5:1] // Out of range a[12] // Out of range s[999] // Out of range For slices, the upper index bound is the slice capacity cap(a) rather than the length.

1 min read
Quiz
Today’s quiz day. Tomorrow I’ll provide the answer as we continue with the section of the spec that explains today’s code. Consider the following program. What is its output? package main import "fmt" func main() { a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} s := a[2:5] s2 := s[5:7] fmt.Println(s2) } [6 7] [8 9] A runtime panic A compilation error