Learn With Me | Intro To Elixir Lesson Six - Pattern Matching Homework

Elixir Web Development
Transcript

English (Auto-generated)

Hello. Welcome back to the learn with me Alexa series. I just finished less than six on pattern matching. And I'm going to tackle the homework. Um So I have this up here, I'm gonna go ahead and do what I did last time and make a new file called the X. And then we can get started. So this is the first one. I'm gonna go ahead and copy this over as comment. Okay so expect the second element of this pupil elixir is awesome. It's a variable A. Alright well let's just copy this so that I can be lazy and we're going to do pupils equal to this and we're gonna do underscore a underscore and we're going to I'm just gonna sign this because it will be easier. Uh Actually we'll just do io dot puts hey criminal so you guys are gonna hear typing today? Um I normally wear my headphones so that it doesn't come through but I noticed the headphone quality is really poor so I'm getting a new pair. Um But for now I figured typing was less terrible than all the weird static sounds coming from my headphones. Um Question six and then we'll do a lecture. Mhm. Yes. Perfect. The second element and it's said to this so that's exactly what we wanted. Alright, easy enough for the first one there, let's go over here. Mhm. Mhm. Alright so we're gonna do all this in a single pattern matching line. We're gonna take this list 12, 3 and four. So given the list, do the following set variable 8 to 1. So variable B. 22 and set variable C. To the list, remainder three and four. So I'm gonna make a list here, do pattern matching. And we're gonna do a B. Mm hmm. See after that. And then let's do io dot puts. Hey, Yeah, let's be Yeah. Right, mm hmm. So if you'll see to the list, remainder three and 4. Alright, I've done something wrong. Let's check out my notes. I feel like I did that right. But I guess not. What's the list? A new list. Yeah. The rest of the list. X. C. C. Mhm. What did I do wrong? 1, 2 3, 4. Mm hmm. So A and rest list is equal to new list, restless is 123. Yeah. So. Mhm. Oh, it puts the list. Yeah. There we go. Okay. So I was right. I just needed to not used parts. Okay, now. Um Okay. So, mm hmm, mm hmm. Let's do the module mystery box that behaves as follows. Let's just set up by defining our mystery box. Mhm. Okay. And then we're gonna go, this is gonna be the first one. We're gonna want it to run these, make sure to use pattern matching for all. So. Okay. Oops. Okay. So we're gonna do death run. Okay. I take a tuple with two parameters. You perfect. And then we're gonna do Steph run which is going to take two strings. So we'll see A B. And then this is at the top ephron, actually, I think that people need to be above it. Let's try it up here. I think it might actually break if we put it up top, it might have to be below. So it's a good method of trying that. Okay, so the first one, Let's put it below first, so that they're in order so that I don't lose my mind trying to do this and then we'll move it and see if it still works. Okay, returns 20 multiplied two numbers. So we're just going to say a okay, let's be I'm assuming you're gonna pick up the same, probably just check that uh for hello and world, we're gonna return hello world. Um No, there is a space here and there isn't a space here, so we're gonna need to cabinet that. Okay, so we're gonna do a space and then I didn't want five, I want to be. And then for this one we're gonna do hello? Hey, So now, if we were to do three box dot run, we'll give it 45. Let's just copy these down so that it saves us time here, ST box, right copy. Mhm. Hey, and yeah, also with the same name, should be grouped together deaf. Run one was previously defined. Okay. Yeah, Okay, so let's try this now clause for run one cannot match because the previous closet line 24 always matches. Okay, so this one needs to go below this is what I was saying before that. I didn't think it could be about this. Okay so that one works because it runs them all. But let's see here if we can do right We have 20 hello world and hello John Perfect. So they all work exactly how we want them to. Um So yeah things with the same amount have to be together. That makes sense. You want them to run in order? So we have one argument, one argument one parameter. We want the ones that will run with certain amount of restrictions before the ones that will run via anything. So we wanted to go in order of like most restrictive to least restrictive so that it checks them in the appropriate order. So basically it's just cascading. Okay so let's go back here, attempt the following mystery box. Start. Run 1234 returns 10 some of list of elements. Mhm. Mhm. Okay. I don't want to overdo incursion. Um Never want to see that ever. But let's try. So what we're gonna do because we're gonna say run yeah. What? 1234. Refresh your memory on record version returns 10 Plus two Plus 3. Why would I need to use your question? I'm so confused. Um Sorry I don't want to be good because I want to do A. B. C. Can be so this is going to need to move. Yeah. Okay so inside of here we're gonna want to do can we just do a plus B Plus let's see plus. See what happens if we do. Yes. 10. Okay. Okay. I'm confused to why I needed Riker version. Mhm Or maybe no, that was for this one Tent Run 1, 2, 3 and four. Some of list of elements. Yeah. And then if I just did like seven plus six plus 11 plus four, which is going to be 10, 28? Mm hmm. Yeah. Okay. I don't know why we need incursion. Okay, well I'm leaving it like that And then the last one attempt the following look up guard clauses in elixir. Alright, um constructive. So this one's gonna take two parameters. What? Oh, it's doing length of the strengths. Yeah. Okay. So we're gonna take two here. Yeah. Uh huh. Mhm mhm returns Hello world Returns 10 some of list of elements. Um I don't think I can literally do this with this is exactly the same function. Maybe the stretch, you're not supposed to have the same one. Hello world returns, list, guard clauses and elixir. Mhm cards are a way to argument pattern matching with more complex checks. They are allowed in a predefined set of constructs where pattern matching is allowed. Not all expressions are a lot of hard classes. They built a list in guards, personal operators. Okay. So we can define whether it's string or whether it's integer. Okay, that makes more sense. So I wonder if I if I put it below or above this one to find your breath. Run A B. When is integer? Mhm, mm hmm. Do let's just say hello. Let's just see if we can get it to run the Okay. Oh wait. Okay. To be defined with deaf guard. A custom guard is always defined based on existing guards. Other constructors are for with they're both strings. Okay. Um I think maybe we're supposed to just run these two separate of this one here. I'm gonna remove this mystery box here. Um I'm gonna remove this one because I think what we want to do is we wanted to find another one later That says one is string. Maybe our 1st 1 that's binary and run A B when his integer. Hey, we'll say goodbye for now. Before we do that now I'm gonna do. Okay. No, finer invoke local is binary. Inside guard only macros can be invoked in the guard and they must be defined before their invocation called as is binary. A mm hmm. So there's a guy real quick this. Mm hmm. Cannot find or invoke local is binary. two. Inside Guard only Macros can be invoked in a guard and they must be defined before their invocation real terms that exists and is being expanded to term. Please use parentheses to remove it. But you would change the variable name. Mhm. Mm hmm, mhm. Value, value. Mhm. Mhm. The term does not equal to left. Right. I got you. Let's check up here. Mhm mm hmm. Data types guards. No um correct. Okay. Mm hmm. I want to see what macros are. Mhm Pilot time researchers that evoked between functions and macros. Value value. Pass an expression receives a representation of code. Okay. So it seems to not be able to take multiple terms. Is that what it's saying? But Okay. I don't know. Yes. Only the clothes from 11 cannot match because the previous clause, deadline 37 always matches def macro def macro type. Mhm mm hmm. Looks your cards. Okay. Mm hmm. Yeah, multiple expressions and guard clauses can be combined with bullying operators. Oh. Mhm. Is it an end comparison operators? End That's just a fact. Mhm. Okay. Yeah. Mhm. No function closet mystery box run to the following arguments were given to mystery box run to Hello World Marwan. Hello. # two Worlds. Okay. Okay. When is adam? Okay. So I need to do when is binary? A. And is binary? Oh yeah, it only takes one argument and the police says that let's just copy copy that still for a second. The last one is going to fail. Hey rand. Look at that. Okay. So is integer A. And is picture be right. Hello. Goodbye. Okay. Perfect. So what we're gonna do now is we're going to do? Ah let's go to for strength. Strange functions. It's just length. Alright. So we want to do gay dot blinks crust me dot thanks this should return Pet attempted to apply function dot length. If you're using kernel, apply make sure the modules and adam if you're using the data centers such as magnetic field play. Hello to links. Oh uh that's not string dot length. Okay. String dot length E. Okay. 10. Yeah. Okay, awesome. And five and two returns the sum of two elements. So we're just going to do a plus three. Look at that. Okay. So I'm pretty sure we're fine there. Um We did have to Take out this one to get it to run but um because they're both strings, I'm not sure how we would be different but that's okay. I will accept that as a solution and then we'll see what he comes up with. Okay, this is much longer cast than I was expecting. Um But there is the homework including the stretches
32 Views 0 Likes 0 Comments

We go over the exercises from lesson six including my best attempt at doing the stretch exercises.

Comment
Leave a comment (supports markdown format)