Un cours pour se lancer dans la programmation avec le langage Go (golang).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 regels
441 B

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. adder := func(a int, b int) int {
  7. return a + b
  8. }
  9. fmt.Println(adder(5, 6))
  10. counter1 := counter()
  11. counter2 := counter()
  12. fmt.Println(counter1())
  13. fmt.Println(counter2())
  14. deferredPrint()
  15. }
  16. func counter() func() int {
  17. i := 0
  18. return func() int {
  19. i++
  20. return i
  21. }
  22. }
  23. func deferredPrint() {
  24. defer fmt.Println("defer 1")
  25. fmt.Println("regular thing")
  26. defer fmt.Println("defer 2")
  27. }