/* 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 <http://www.gnu.org/licenses/>
*******************************************************************/

package main

import "fmt"

type person struct {
	name string
}

var p = person{name: "R Stallman"}

func main() {
	p1 := person{name: "Jane Doe"} // ici person definit en global

	type person struct {
		name string
		age  int
	}

	p2 := person{ // ici person en local
		name: "John Doe",
		age:  27,
	}

	fmt.Printf("Type de p: %+v\tp1: %v\tp2: %v\n", p, p1, p2)
	blocks()
	scopes()
	shadowing()
}

func blocks() {
	i := 10
	{
		i := 5
		fmt.Println(i) // i vaut 5
	}
	fmt.Println(i) // i vaut 10
}

var y = 100

func scopes() {
	x := 10
	var z int
	{
		fmt.Println(x)
		y := 15
		fmt.Println(y)
		z = 20
	}
	fmt.Println(z)
	fmt.Println(y)

}

func shadowing() {
	x := 10
	{
		x := 15
		{
			x := 20
			fmt.Println(x)
		}
		fmt.Println(x)
	}
	fmt.Println(x)

}

