← Înapoi la Urmăritori

Cel mai recent articol

Ultima verificare

Urmăritori 0 urmăritori
Articole: 200
  1. Making slices, maps and channels The built-in function make takes a type T, optionally followed by a type-specific list of expressions.

  2. 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.

  3. Capacity of slices

    Length and capacity … The capacity of a slice is the number of elements for which there is space allocated in the underlying array.

  4. Length and capacity

    Length and capacity The built-in functions len and cap take arguments of various types and return a result of type int.

  5. Deletion of map elements The built-in function delete removes the element with key k from a map m.

  6. Today we’re looking at what are almost certainly the least used built-in functions in Go.

  7. Close

    Today we’re looking at the close built-in function.

  8. Clear

    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)]].

  9. Copying slices

    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.

  10. On Friday we looked at what happens when appending to a slice exceeds the capacity of the backing array.

  11. Yesterday we were introduced to the append function, which on the surface seems quite straight forward.

  12. Appending to slices

    Appending to and copying slices The built-in functions append and copy assist in common slice operations.

  13. Built-in functions

    We’ve just finished up the rather long section on different types of statements.

  14. Oops!

  15. Defer execution order

    Let’s talk about some of the nuance surrounding defer that’s often lost, or simply forgotten.

  16. Defer statements

    We’re at the last item in the “Statements” section of the spec, before we move on to built-in functions.

  17. Fallthrough statements A “fallthrough” statement transfers control to the first statement of the next case clause in an expression “switch” statement.

  18. Goto statements

    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.

  19. We’ve been looking at Go 1.23’s new range-over-func feature.

  20. yield

    For statements with range clause … For a function f, the iteration proceeds by calling f with a new, synthesized yield function as its argument.

  21. As mentioned yesterday, today we’re taking a bit of a step back to an earlier portion of the spec, which was just updated.

  22. I missed the last couple of days.

  23. Continue statements

    Let’s continue… haha See what I did there?

  24. 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.

  25. Break statements

    Break statements A “break” statement terminates execution of the innermost “for”, “switch”, or “select” statement within the same function.

  26. 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.

  27. Naked returns

    Now we’re going to look at the third and finaly way to return values from a function in Go.

  28. 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?

  29. 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?

  30. 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…

  31. Return statements

    Return statements A “return” statement in a function F terminates the execution of F, and optionally provides one or more result values.

  32. 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.

  33. I'll be live streaming again today!

  34. I’m looking for a new client or two.

  35. 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.

  36. 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…

  37. Default select case

    Select statements … There can be at most one default case and it may appear anywhere in the list of cases.

  38. Select statements

    Join me again today as I’ll be coding and answering questions on my livestream.

  39. Today we finish the description of go statements: Go statements … When the function terminates, its goroutine also terminates.

  40. 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.

  41. Go statements

    At long last, we’re ready to learn about Go’s namesake feature!

  42. I’ll be live streaming again today!

  43. Range conclusion

    Today we finish up with some final notes, and a big example, from the spec section on for statements.

  44. For statements with range clause … The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=).

  45. I’m back from my holiday!

  46. Two quick related notes: I missed a day or two last week, due to travel.

  47. Iteration over maps

    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.

  48. 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.

  49. 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.

  50. 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…