Creează un cont pentru a te abona la acest blog și a-i urmări articolele pe pagina Lectură.
-
Making slices, maps and channels The built-in function make takes a type T, optionally followed by a type-specific list of expressions.
-
A few of the built-in functions are very special, in that they can evaluate to constant expressions. len and cap are two such functions.
-
Length and capacity … The capacity of a slice is the number of elements for which there is space allocated in the underlying array.
-
Length and capacity The built-in functions len and cap take arguments of various types and return a result of type int.
-
Deletion of map elements The built-in function delete removes the element with key k from a map m.
-
Today we’re looking at what are almost certainly the least used built-in functions in Go.
-
Today we’re looking at the close built-in function.
-
Clear The built-in function clear takes an argument of map, slice, or type parameter type, and deletes or zeroes out all elements [[Go 1.21(https://go.dev/ref/spec#Go_1.21)]].
-
Appending to and copying slices … The function copy copies slice elements from a source src to a destination dst and returns the number of elements copied.
-
On Friday we looked at what happens when appending to a slice exceeds the capacity of the backing array.
-
Yesterday we were introduced to the append function, which on the surface seems quite straight forward.
-
Appending to and copying slices The built-in functions append and copy assist in common slice operations.
-
We’ve just finished up the rather long section on different types of statements.
-
Oops!
-
Let’s talk about some of the nuance surrounding defer that’s often lost, or simply forgotten.
-
We’re at the last item in the “Statements” section of the spec, before we move on to built-in functions.
-
Fallthrough statements A “fallthrough” statement transfers control to the first statement of the next case clause in an expression “switch” statement.
-
We’ve finished the discussion of the new range-over-func feature, so let’s continue where we left off before the Go 1.23 release, with a feature you’ll rarely, if ever, use.
-
We’ve been looking at Go 1.23’s new range-over-func feature.
-
For statements with range clause … For a function f, the iteration proceeds by calling f with a new, synthesized yield function as its argument.
-
As mentioned yesterday, today we’re taking a bit of a step back to an earlier portion of the spec, which was just updated.
-
I missed the last couple of days.
-
Let’s continue… haha See what I did there?
-
Break statements … If there is a label, it must be that of an enclosing “for”, “switch”, or “select” statement, and that is the one whose execution terminates.
-
Break statements A “break” statement terminates execution of the innermost “for”, “switch”, or “select” statement within the same function.
-
Just a couple small notes before we move on from return statements… Return statements … Regardless of how they are declared, all the result values are initialized to the zero values for their type upon entry to the function.
-
Now we’re going to look at the third and finaly way to return values from a function in Go.
-
We already saw the “normal” way to return values from functions… But did you know there’s a shortcut if you ever want to directly return the values returned from another function?
-
Return statements … There are three ways to return values from a function with a result type: Do you know all three off the top of your head?
-
Let’s continue our discussion of return statements by looking at functions that don’t actually return anything… Return statements … In a function without a result type, a “return” statement must not specify any result values. func noResult() { return } Si…
-
Return statements A “return” statement in a function F terminates the execution of F, and optionally provides one or more result values.
-
Select statements … If the selected case is a RecvStmt with a short variable declaration or an assignment, the left-hand side expressions are evaluated and the received value (or values) are assigned.
-
I'll be live streaming again today!
-
I’m looking for a new client or two.
-
Exactly a year ago (yesterday), Russ Cox submitted a proposal to add two new range capabilities to Go: range-over-int, and range-over-func.
-
I’m taking a detour from the Go spec today, to share my experience with the new range-over-func feature coming in Go 1.23: Exactly a year ago (yesterday), Russ Cox submitted a proposal to add two new range capabilities to Go: range-over-int, and range-ove…
-
Select statements … There can be at most one default case and it may appear anywhere in the list of cases.
-
Join me again today as I’ll be coding and answering questions on my livestream.
-
Today we finish the description of go statements: Go statements … When the function terminates, its goroutine also terminates.
-
Now that we’ve talked about what goroutines are and aren’t, lets look at the details of a Go statement: Go statements … The expression must be a function or method call; it cannot be parenthesized.
-
At long last, we’re ready to learn about Go’s namesake feature!
-
I’ll be live streaming again today!
-
Today we finish up with some final notes, and a big example, from the spec section on for statements.
-
For statements with range clause … The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=).
-
I’m back from my holiday!
-
Two quick related notes: I missed a day or two last week, due to travel.
-
For statements with range clause … The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next.
-
For statements with range clause … For a string value, the “range” clause iterates over the Unicode code points in the string starting at byte index 0.
-
For statements with range clause … For an array, pointer to array, or slice value a, the index iteration values are produced in increasing order, starting at element index 0.
-
For statements with range clause … For each iteration, iteration values are produced as follows if the respective iteration variables are present: Range expression 1st value 2nd value array or slice a [n]E, *[n]E, or []E index i int a[i] E string s string…