WEBVTT 00:02.050 --> 00:02.870 Welcome back. 00:03.310 --> 00:10.420 In the last lecture, you have learned how to declare initialise and print as you also learned how to 00:10.420 --> 00:12.970 retrieve and assign to struct fields. 00:13.510 --> 00:18.610 Now it's time to talk about how struct comparison and assignment work. 00:19.770 --> 00:26.280 Let's say you have a strike value like this one, it has two fields by I do not initialize them yet, 00:26.730 --> 00:28.410 so its fields are zero. 00:29.100 --> 00:31.170 Here is another one with the same time. 00:31.560 --> 00:34.110 This time I initialised with the strike. 00:34.110 --> 00:36.120 Values are bare values. 00:36.270 --> 00:41.100 For example, unlike a slice, they don't contain a hidden pointer feel to a back. 00:41.190 --> 00:41.640 Correct. 00:42.090 --> 00:44.760 So I strike value is as it is. 00:45.180 --> 00:46.940 It is just like an of value. 00:47.490 --> 00:53.160 Let's see what happens if you assign the strike value at the right to the one at the left. 00:53.910 --> 00:55.760 So this is what happens. 00:55.920 --> 00:58.740 Go capias all the fields of the strike value. 00:58.740 --> 01:01.690 Add the right to the strike value at the left. 01:02.100 --> 01:04.550 So there are two distinct strike values. 01:04.560 --> 01:12.570 That one, if you want to compare the value, do that go compares each field of the strike values one 01:12.570 --> 01:13.160 by one. 01:13.620 --> 01:18.690 Here, all the fields are equal, so the strike values are also equal. 01:19.960 --> 01:27.970 Of course, as almost everything in go to compare or assign a strike value to another one, there types 01:27.970 --> 01:31.450 should be identical or there will be a type mismatch error. 01:31.990 --> 01:34.660 Now, let's take a look at an example in the coding, Ed. 01:36.750 --> 01:44.220 Let's say you want to create a playlist, so here are two songs from the rock band or Oasis Wonderwall. 01:46.620 --> 01:50.580 And supersonic, let me also print them like some. 01:56.670 --> 02:03.420 Of course, there is no song struck top yet this time I'm going to declare it at the package level as 02:03.420 --> 02:09.900 an example like song, you usually want to declare the strike types at the package level so you can 02:09.900 --> 02:11.480 use them throughout the package. 02:11.910 --> 02:15.510 There are two Springfields title and artists like song. 02:16.420 --> 02:17.320 OK, ready? 02:17.380 --> 02:19.640 Now let's take a look at how to compare them. 02:20.230 --> 02:22.480 I'm going to compare their titles first. 02:25.020 --> 02:28.020 And I'm going to compare their artist feels like so. 02:30.990 --> 02:34.210 If they are equal, I'm going to say that they are equal. 02:34.710 --> 02:37.140 Otherwise, I'm going to say that they are not equal. 02:42.120 --> 02:48.660 Of course, they are not equal, even though they are artists, fields are equal, but their title fields 02:48.660 --> 02:49.210 are not. 02:49.410 --> 02:50.990 So they are not equal. 02:51.450 --> 02:54.600 By the way, here I compare all the fields manually. 02:54.990 --> 02:56.960 However, God can do that for you. 02:57.540 --> 03:04.710 So I'm going to replace the comparisons simply with destruct values like so I can do so because values 03:04.710 --> 03:09.360 are better values, by the way, I can easily make them equal like so. 03:12.140 --> 03:15.300 Now they are equal because all their fields are the same. 03:15.320 --> 03:22.820 Now here, Gore sets the field values of the song Guam to the field values of the song to one by one 03:22.910 --> 03:23.440 like song. 03:24.450 --> 03:27.740 OK, now it's time to create the playlist to do that. 03:27.770 --> 03:30.890 I'm going to go to the top of the file here. 03:30.890 --> 03:33.790 I'm going to declare a new playlist type Lexar. 03:34.310 --> 03:42.590 Let's say I want to store playlists according to their music genre, so I'm going to add a genre field 03:42.590 --> 03:42.960 here. 03:43.760 --> 03:47.330 Each song has two fields title and artist. 03:48.080 --> 03:55.490 So here I'm going to start the song titles and artist in String Slicers likes to think about us rock 03:55.880 --> 03:57.170 with a lot of fields. 03:57.740 --> 04:01.220 Should you create a different slice for each field of that struct? 04:01.910 --> 04:05.060 As you can see, this might become cumbersome quite easily. 04:05.420 --> 04:11.840 So instead I'm going to use a song slice like so as you can see, as track can contain another track. 04:12.270 --> 04:14.570 Remember, track fields are variables. 04:14.630 --> 04:16.960 So I struck field can be of any type. 04:17.240 --> 04:18.770 Now I've got a playlist. 04:19.550 --> 04:21.980 Let's go down and create a playlist there. 04:22.760 --> 04:26.050 I'm going to create a playlist for indie rock LACHSA. 04:26.210 --> 04:29.030 Here are the Fields, genre and songs. 04:29.210 --> 04:33.170 First, I'm going to set its genre to indie rock like so. 04:34.120 --> 04:41.620 Remember, the songs field is a slice of songs, so I'm going to use a literal like so I can easily 04:41.620 --> 04:44.680 add the songs like so because I already have them. 04:47.180 --> 04:52.340 By the way, as you learned in the slideshow section before, you don't have to repeat the element types, 04:52.790 --> 04:53.780 so I'm going to remove the. 04:54.680 --> 05:01.010 Don't let this syntax confuse you, by the way, for example, I can move the slice to a variable and 05:01.010 --> 05:06.080 I can include the songs slice here instead, lachsa it is the same. 05:06.740 --> 05:09.770 OK, now let's say I want to clone the playlist. 05:10.250 --> 05:15.830 I can easily do that by assigning it to a new variable like saw here. 05:15.830 --> 05:19.510 The type of the clone is also playlist struck. 05:20.150 --> 05:22.030 Now I'm going to compare them like so. 05:24.070 --> 05:31.780 But it doesn't work, is because the plane is struck, contains a slice and slice, values are not comparable. 05:32.530 --> 05:37.650 Think about it go needs to compare every field of the track to the other one. 05:38.140 --> 05:43.990 But it cannot do so here because there is an incomparable value in the play lists. 05:44.560 --> 05:50.320 For example, I cannot compare the songs even to itself is the same thing here. 05:50.840 --> 05:55.450 All right, so if you need to compare them, you need to do so manually. 05:55.690 --> 05:59.310 I already explained how to do so in the slices section before. 05:59.890 --> 06:02.500 Now let's print the playlist first. 06:02.500 --> 06:04.390 Let's print the header LACHSA. 06:05.940 --> 06:07.380 Now I'm going to print the songs. 06:08.420 --> 06:14.120 I'm going to retrieve them from the rocks struck value lachsa here, I'm going to print the title and 06:14.120 --> 06:15.470 artist of the next song. 06:20.260 --> 06:27.280 Could you get a pretty good looking outfit now, lastly, let's talk about the copying behavior of strikes. 06:28.150 --> 06:32.080 Let's say I want to change the title of the first song to do that. 06:32.090 --> 06:34.780 I'm going to get it from the playlist LACHSA. 06:35.780 --> 06:38.330 OK, now I'm going to change the title like so. 06:41.370 --> 06:44.590 Check out the first song, its title is the same. 06:44.910 --> 06:49.620 How come why doesn't it change the assignment here? 06:49.650 --> 06:54.940 Doesn't change the original title because the song Variable is a column of the original. 06:55.350 --> 06:57.680 There are two different values here. 06:58.050 --> 06:58.860 Let me print them. 07:02.460 --> 07:09.090 As you can see, they are different truck values here, when I signed the original one to the new variable, 07:09.090 --> 07:11.220 the original one gets copied. 07:11.400 --> 07:13.630 That's why it cannot change the original one. 07:14.130 --> 07:16.620 So how can you change the original one? 07:17.160 --> 07:19.770 Well, you should directly do it like so. 07:24.600 --> 07:30.550 This time, the original one changes the loop, also prints the original one with the new title. 07:31.140 --> 07:32.740 Let me show you one more thing. 07:33.090 --> 07:38.280 Let me duplicate the full range loop here inside the first full range loop abo. 07:38.280 --> 07:41.910 I'm going to override the titles of every song LACHSA. 07:43.360 --> 07:50.710 As you can see, only the first loop sees the change, not the other one blob inside here, it initializes 07:50.710 --> 07:53.050 the variable from the original one Laakso. 07:53.330 --> 07:56.620 So the variable here is a clone of the original. 07:57.070 --> 08:00.730 So in summary, abstract values are bare values. 08:01.000 --> 08:06.970 They get copied when you assign them past them to a function or return them from a function. 08:07.540 --> 08:08.020 All right. 08:08.290 --> 08:09.110 That's all for now. 08:09.400 --> 08:10.540 Thank you for watching.