Welcome back.
In the last lecture, you have learned how to declare initialise and print as you also learned how to
retrieve and assign to struct fields.
Now it's time to talk about how struct comparison and assignment work.
Let's say you have a strike value like this one, it has two fields by I do not initialize them yet,
so its fields are zero.
Here is another one with the same time.
This time I initialised with the strike.
Values are bare values.
For example, unlike a slice, they don't contain a hidden pointer feel to a back.
Correct.
So I strike value is as it is.
It is just like an of value.
Let's see what happens if you assign the strike value at the right to the one at the left.
So this is what happens.
Go capias all the fields of the strike value.
Add the right to the strike value at the left.
So there are two distinct strike values.
That one, if you want to compare the value, do that go compares each field of the strike values one
by one.
Here, all the fields are equal, so the strike values are also equal.
Of course, as almost everything in go to compare or assign a strike value to another one, there types
should be identical or there will be a type mismatch error.
Now, let's take a look at an example in the coding, Ed.
Let's say you want to create a playlist, so here are two songs from the rock band or Oasis Wonderwall.
And supersonic, let me also print them like some.
Of course, there is no song struck top yet this time I'm going to declare it at the package level as
an example like song, you usually want to declare the strike types at the package level so you can
use them throughout the package.
There are two Springfields title and artists like song.
OK, ready?
Now let's take a look at how to compare them.
I'm going to compare their titles first.
And I'm going to compare their artist feels like so.
If they are equal, I'm going to say that they are equal.
Otherwise, I'm going to say that they are not equal.
Of course, they are not equal, even though they are artists, fields are equal, but their title fields
are not.
So they are not equal.
By the way, here I compare all the fields manually.
However, God can do that for you.
So I'm going to replace the comparisons simply with destruct values like so I can do so because values
are better values, by the way, I can easily make them equal like so.
Now they are equal because all their fields are the same.
Now here, Gore sets the field values of the song Guam to the field values of the song to one by one
like song.
OK, now it's time to create the playlist to do that.
I'm going to go to the top of the file here.
I'm going to declare a new playlist type Lexar.
Let's say I want to store playlists according to their music genre, so I'm going to add a genre field
here.
Each song has two fields title and artist.
So here I'm going to start the song titles and artist in String Slicers likes to think about us rock
with a lot of fields.
Should you create a different slice for each field of that struct?
As you can see, this might become cumbersome quite easily.
So instead I'm going to use a song slice like so as you can see, as track can contain another track.
Remember, track fields are variables.
So I struck field can be of any type.
Now I've got a playlist.
Let's go down and create a playlist there.
I'm going to create a playlist for indie rock LACHSA.
Here are the Fields, genre and songs.
First, I'm going to set its genre to indie rock like so.
Remember, the songs field is a slice of songs, so I'm going to use a literal like so I can easily
add the songs like so because I already have them.
By the way, as you learned in the slideshow section before, you don't have to repeat the element types,
so I'm going to remove the.
Don't let this syntax confuse you, by the way, for example, I can move the slice to a variable and
I can include the songs slice here instead, lachsa it is the same.
OK, now let's say I want to clone the playlist.
I can easily do that by assigning it to a new variable like saw here.
The type of the clone is also playlist struck.
Now I'm going to compare them like so.
But it doesn't work, is because the plane is struck, contains a slice and slice, values are not comparable.
Think about it go needs to compare every field of the track to the other one.
But it cannot do so here because there is an incomparable value in the play lists.
For example, I cannot compare the songs even to itself is the same thing here.
All right, so if you need to compare them, you need to do so manually.
I already explained how to do so in the slices section before.
Now let's print the playlist first.
Let's print the header LACHSA.
Now I'm going to print the songs.
I'm going to retrieve them from the rocks struck value lachsa here, I'm going to print the title and
artist of the next song.
Could you get a pretty good looking outfit now, lastly, let's talk about the copying behavior of strikes.
Let's say I want to change the title of the first song to do that.
I'm going to get it from the playlist LACHSA.
OK, now I'm going to change the title like so.
Check out the first song, its title is the same.
How come why doesn't it change the assignment here?
Doesn't change the original title because the song Variable is a column of the original.
There are two different values here.
Let me print them.
As you can see, they are different truck values here, when I signed the original one to the new variable,
the original one gets copied.
That's why it cannot change the original one.
So how can you change the original one?
Well, you should directly do it like so.
This time, the original one changes the loop, also prints the original one with the new title.
Let me show you one more thing.
Let me duplicate the full range loop here inside the first full range loop abo.
I'm going to override the titles of every song LACHSA.
As you can see, only the first loop sees the change, not the other one blob inside here, it initializes
the variable from the original one Laakso.
So the variable here is a clone of the original.
So in summary, abstract values are bare values.
They get copied when you assign them past them to a function or return them from a function.
All right.
That's all for now.
Thank you for watching.