/* Copyright (C) 2011-2023 Patrick H. E. Foubet - E2L Ivry Ecole du Logiciel Libre : https://e2li.org/ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see *******************************************************************/ package main import "fmt" func init() { fmt.Println("Salut depuis main 1") } func init() { fmt.Println("Salut depuis main 2") } func init() { fmt.Println("Salut depuis main 3") } func main() { fmt.Println("Salut tout le Monde") q, r := NamedDivide(15, 6) fmt.Printf("Division 15 / 6, Quotient: %d Reste: %d\n", q, r) fmt.Printf("Facture: %.2f\n", Facture(8.75, 10.2, 3.7)) Bonjour() Bonjour := func() string { return "On cache la fonction externe Bonjour" } TakeFunc(GiveFunc()) TakeFunc(Bonjour) } func Bonjour() { fmt.Println("Bonjour") } // ceci provoque une erreur de redefinition // func Bonjour(m string) { // fmt.Println(m) // } func Add(a, b int) int { return a + b } func Divide(a, b int) (int, int) { return a / b, a % b } func NamedDivide(a, b int) (quotient int, remainder int) { quotient, remainder = a/b, a%b return } func TakeFunc(take func() string) { data := take() fmt.Println(data) } func GiveFunc() func() string { f := func() string { return "Fonction retour" } return f } func Facture(mht float64, items ...float64) (total float64) { for _, item := range items { total += item } total *= (1 + mht*.01) return }