Master Lua Programming with Lua 5.3 | Abhishek Kumar | Skillshare

Master Lua Programming with Lua 5.3

Abhishek Kumar, Computer Scientist at Adobe

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
59 Lessons (8h 29m)
    • 1. Welcome to the Course

      2:32
    • 2. What is Lua?

      2:13
    • 3. Why choose Lua?

      3:35
    • 4. Setup and Installation

      2:41
    • 5. Hello World Program using IDE

      2:47
    • 6. Chunks

      8:21
    • 7. Lexical Conventions

      5:12
    • 8. Comments

      5:51
    • 9. Global Variables

      2:42
    • 10. Types and Values

      4:46
    • 11. Nil

      3:25
    • 12. Booleans

      9:31
    • 13. Numbers

      6:32
    • 14. Operators - Arithmetic and Relational

      12:20
    • 15. Math Library

      19:39
    • 16. Strings

      7:28
    • 17. Long Strings

      5:39
    • 18. Coercions

      8:07
    • 19. String Library functions

      14:23
    • 20. Tables: Introduction

      8:56
    • 21. Table Indices

      9:27
    • 22. Table Constructors

      10:03
    • 23. Arrays, Lists and Sequences

      8:36
    • 24. Table Traversal

      6:21
    • 25. Table Library

      14:14
    • 26. Functions

      10:38
    • 27. Multiple results

      8:10
    • 28. Variadic Functions

      11:05
    • 29. table.unpack function

      8:09
    • 30. Input/Output

      4:10
    • 31. Simple I/O model

      10:12
    • 32. Complete I/O model

      8:49
    • 33. Control Structures in Lua

      2:53
    • 34. If Then Else

      5:49
    • 35. While loop

      3:23
    • 36. Repeat-until loop

      3:16
    • 37. Numerical For

      4:59
    • 38. Generic For

      3:13
    • 39. Break and Return statements

      9:43
    • 40. Functions as First Class Values

      15:11
    • 41. Closures and Lexical Scoping in Lua

      8:39
    • 42. Pattern matching functions

      10:56
    • 43. Patterns

      22:23
    • 44. Date and Time Functions

      3:51
    • 45. os.time function

      5:19
    • 46. os.date() and os.difftime()

      13:58
    • 47. Modules in Lua

      3:46
    • 48. Modules as Tables

      4:18
    • 49. require - load module

      12:21
    • 50. Writing Modules in Lua

      14:59
    • 51. Data Structures in Lua - Introduction

      2:12
    • 52. Arrays

      11:10
    • 53. Matrices and Multi-dimensional Arrays

      15:23
    • 54. Linked Lists

      15:57
    • 55. Queue and Deque concepts

      3:09
    • 56. Deque implementation in Lua

      19:09
    • 57. Implementing a Stack data structure

      19:13
    • 58. N-Queens Assignment Solution

      17:14
    • 59. Iterators and Closures

      10:14

About This Class

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode with a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

Topics covered are:

  • Introduction to Lua
  • IDE and installation
  • Basic Language Constructs
  • Numbers
  • Strings
  • Tables
  • Functions
  • Input/Output
  • Blocks and Loops
  • Closures
  • Pattern Matching
  • Date and Time
  • Bitwise Operations
  • Data Structures in Lua - Arrays, Matrices, Linked Lists, Queues
  • Modules and Packages
  • Iterators and generic for
  • Metatables and Metamethods
  • Object Oriented Programming
  • The Environment
  • Garbage
  • Coroutines
  • C API

So, let's learn some cool stuff and dive into the course.

Transcripts

1. Welcome to the Course: welcome to the scores own lower programming language. First of all, who are you sure Lou is a powerful, efficient later it in veritable scripting language. It supports procedural programming, object oriented programming, functional programming, deter driven programming and deter description. It combines simple procedural Syntex with powerful data the scripts and constructs based on associative Berries and extends well, semantics. Louise dynamically typed runs by interpreting bite cold with register based were still machine and has automatic memory management with incremental garbage collection, making it ideal for configuration scripting and rapid prototyping. Hi, my name is over, say, Kumar and I work at a computer scientist at Adobe. And in this course I will teach you the nuts and bolts off lower programming language. This course is supposed to be the one stop solution for all of your lower knowledge. So let's briefly look at the course contents. So our discourse will start with a basic introduction to lure. Then we will do idea and an installation. Whatever idea we will use, will you Jiro Grain studio for this. Then we look at some of the basic language constructs. Then we will look at numbers string stables, functions in port or port blocks and loops in lower closures, pattern matching dirt and time, and we will also look at between your presence. Then we will look at Ah Abu or implement various data structures in lower using Ables. And in particular, we will look at a raise mattresses link list to use double 100 cues. Then we'll see how Boro create your own more guilt in lower and packages and how to use the existing models. Then we will also look at traitors and Gen req form a meta metered centimeter tables. They will look at Coteau du object oriented programming. Lure well, look at the environment, garbage collection, scorpions and CHP. There we will see how toe are right if functionality in C and expose that to Louis side and call it from lower, So let's dive into the course. 2. What is Lua?: Let's start program in lower, and in this course we will be starting Lua version 53 which is the latest, was an awful what that is available at the moment. So first, let's see who had the name lower. So it comes from a Portuguese word and it means whom. And if you see that, I kind of lure, you can see that this ICANN is inspired from the sleep off him. It looks like a moon, and it's revolving and are now let's see what is Lou and why do we study? Were wise. It's so popular. Eloisa powerful assistant lightweight, incredible scripting language. And it supports procedural programming. Object oriented programming. Functional programming data driven program ended her description. It combines simple procedural Syntex with powerful data description, constructs business with city Berries and extensible semantics. Lloyd is a dynamically typed language, and a transfer interpreting bite good with the Register based was to losing, so you don't need to satisfy the IBO variables here. These are interpreted. Automatic memory management is provided in lower with the help of incremental garbage collection. Now let's see, or what are the learning resources or this course in itself will be sufficient to get you started with Lou and have some good knowledge of lower. But if you want toe big, different to it on, want to learn the language in we really tell you can refer this book. This is the most popular book for Lower, and currently 4 37 is the littlest one 4 37 or it is lower 53 or their third. It isn't also which Fox is on Lower five to. There may not be too much difference, but if you have a choice, we'll go with the latest one. And then you can always move back to the Reference Manual of flu, which has Indust documentation so you can refer this also. 3. Why choose Lua?: in this Listen, we will see ways lower program so popular and why one so choose Lou has a programming language. The first reason is that it is a proven language and robust language because there have been many industrial applications on. Mainly, I had always light room, which has been written Indian lower within impasses on embedded systems and games, and our games like World of Wild Craft and angry words have been returning Lure. Liu is currently also the leading scripting language in games. Lou has a solid difference and extensive documentation and several versions of Liu has been released and used industrial applications since its creation in 1993. And Lou featured in its appeal Tree the 30 CMC Clan History of Program Languages Conference in 2007 and Lou Wonder Front Line Award 2011 from Game Developers magazine. So we tested Midi Ah long history and it has been proven in various applications. Then the next region is that always first, it has deserved reputation for its performance, so performance is another region where you can sort truth to sure. Then the next region is that it is portable. Louise distributor in a small package on bills are off the box in all platforms that have a standard C compilers. So it turns on all flavours of UNIX and Windows on more widely races on embedded microprocessors on IBM means Prince etcetera. Then the next region is that ploys. Invaluable Blue is fast language Indian with a small footprint that you can invert easily into your application. The no always powerful and still it's simple, if ornamental conception, the vaginal fluids to pride mater mechanisms for implementing features and stood up providing who stuff we just directly in the language for young. For although it's smart, it's not a pure object or into language in just provide meter mechanisms for implementing classes and inheritance. And the next reason in that it's a small adding lower to application does not blow the application. The none of the reason is that Eloise three so it had three weapons or software. It's tutored, and in my d license, it may be used for any purpose, including commercial at absolutely no cost for those if you are interested in machine learning you, or that a very popular machine learning framework called Torch was returning to have been lure, and it was so popular there, too, by 10 version off. This was also written called Pytorch, so you can see that lure has a proven to be a very robust language. It's a small forest portable, and it's very powerful yet simple. That's why user tools Lou as a programming language. 4. Setup and Installation: Let's get started with Luke programming. So, in orderto get started with lure, you should visit This website will order card. So this is the website here. You can find the various details about how to get started with you and you will also see what is the letters towards enough. Florida was at least on duh. Before downloading anything you can our try the in built demo site off floor. This is called Lord Out or iPhone. It's last nimule dot html on this place will come. So before even making any installation, you can try some small court on this website. For example, if we want to run a hello world All right, print. Hello world. So this is the prince in Texas law. We will see all of this letter and then you can return it and then you can see the output. So this is a very quickly off getting structure. Another thing is to our lord and I D. So this is the most late on next is I d this general brains to do? It's a lightweight I d for lower. So you say you want to download that you can go toe studios orginal brain dot com and download it on. This idea makes your life very easy because it will. I like this in Texeira m various things so you can go to download piece and you can or donate to it if you want or no, I will skip this, so don't order the package that is suitable for your computer. So I didn't go ahead and don't put Mac another. Longwood has completely so let's go ahead and install it. If you are on Mac, please move it toe applications so that you're able to find it. So once you're done with tends to listen. Let's start your brains to do so. First time it will ask for your permission whether you are sure of hoping it. Then you should click open and it has opened. I really for you. So in the next video we'll start Hello World Program using the digital brain I D and I will follow this. I detour on the course 5. Hello World Program using IDE: in this. Listen, we will start using our I D, which is Deliverance Studio I D. For lower and in particular, we will look at a hello early jumping. That is the case with most other programming languages. We start with hello World Program, so it's a very simple thing in lower who has in built in function print on Bring Takes a string so you can see Hello world return within strings within courts And you don't need to specify a semicolon and end off this statement. If you write it, then also it's not a problem. So let's start our I d. So we need to create in new file so it has greater in new lower file for us on Title Lord Lower nuts. Save it it a new name lower and seaweed. No, uh, you can write the bring distinct mint so you can add a common to for deserter than they took comment in law. We will let you see what are there different ways of coming disease, a single line comment, and then we will write the print statement and no, we can not only so visit the done button. This is continually working So the robot had started. And when we done it again, you see the R. Patel. Hello, word. Or you can this directly from here. And it will not be able Another CVRD seen in Colonia. Is there a difference? So he's either they didn't know difference on, uh, in this way. You can write multiple statements here If you are semi colon on a little word on you for you. Don't you see that these two statements are together? So that was a basic hello world program in lower and further lessons will start learning on the various concepts of the language. 6. Chunks: in this. Listen, we will study or chunks junks every piece of court that you executes, leader. A file or a single line in interactive mode is called junk. So are there multiple range of running the court? One is you can entering to interactive old and you enter some expressing and you type enter on. That plane is executed immediately on the 2nd 1 is to write your code in a file and then execute that which we saw in the last week. You were recreated a hell overlord blue friend and we just printer Hello, All inside that trailer. And then we learned while so can we thought of her as a sequence of commands or statements . So it can be a simple, uh, as simple a single statements such as the hello world example that there we just printed a lower or it can be composed off mix of statements and functions organisms. So some function meth one. They're definitional funks, um, on some statements and where we're calling yes and assigning very really so the zone are different types of chunks, so the first way let's see the first way off executing the chunk of it is intractable. So here, instead of writing your program toe, well, you just in turn to the intractable by typing lure. And then now you are in the intractable and we're talking work Lou off. I've got three. So there is a small difference with older persons. So here you type this expressing and it immediately prince this value, then this is assignments. It will not print anything. And here you're taking square off, and it was encrypting through it immediately. Prints. So same thing if you wanted to do in order, wasn you could you would have to proceed it with a equal to symbol. So instead, off a race to the power of to yield up correct you called to this editor would happen to the same thing to 20 feet. But starting five tree that equal to is not required. But even in $5.3 to maintain backward come fertility fury right equal do It's fine. It's not another. So you're usually interpret each line that we type in in 30 more as a complex complete sunk on. That's way to lexical dark. But if the line is not complete, it will wait for more input mental, it finds a complete junk, and this way you can are define, um, are dealing function definitions in interactive mode also, and we will shortly see that in our deal brain i. D. Onda. But I find it convenient toe, foot long deficits in file and then run lower from the file. Let's quickly see some example in our I D for dizzy local console. So let's type 10 plus 15 and enter any immediate legions it and Prince 25. Let's try the or lower bay 10 plus 15. So only difference is that we're adding equal to same and still entrance on this I deep right, Another bills writing multilane Cool, it says Yousef percenter instead of normal and to So let's try to mark the lines, of course. Hello Then I will press if plus into and print world. And now if I press center, you see that it executed these two lines. So hello, hello Bre were So we can also defined functions here so we can write function so and let's a dysfunction prince just cool and in lower you up to end the function body with hand and we will see all of this letter when we study song since and then we dress, enter and this executes it and this is defined the folks and food Now we can call through so it will print full Who is was the body off dysfunction? So this is the interactive A off running cored? No, Let's see another way. Another ways there do fire mattered We're, uh, unifying all the functions inside some file. Let's say this is this this file not lived or clue. So you refine some function definitions inside one side. And then in the interactive, more users do file followed by this file name. So it will load all of these functions into the intractable Italy equivalent toe writing these multi line thanks end of innocents in the oh interactive moored itself, which we just saw here. So you really find a function here itself, but it's not. It doesn't look so elegant away or for defining functions. So we define it all the funds and emissions inside one file and then reloaded using to foil so it will immediately execute the file. And no, these norm and twice functions are present here, and we are a lot to call these functions here, So let's try it in other I D. So let's create in new file Onda. Let's say it has Ah, Matt Lib. And here we will live in the same two functions and then good and the function similarly defined. Another council Lorne, which takes two inputs Knicks and way and returns toe normal. These and no, here we can call Lukoil Onda Fighting name is Matt and that you will. So we test lorded both these functions here. No, we can assign it to some very able like a call to normal, then 20. And if you print a it's it's nil. It's not a little too conclude the norm that's tried other function so twice it's able to do. But Norm, it's notable to do Okay, so we're not returning the value. This is the mistake and lower let's load this again. So now it's able to do that. So you see this is another way off or executive you Oh, Lord chunks 7. Lexical Conventions: let us see some of the lexical convince insecurity in your program. So first is a very real naming convention. So while naming your variable the variable name or guard, 24 hours can be any string and this a string can consist off letters, digits and underscores. But one exception is that it can begin with letters and under school, but it cannot begin. Vitor Digit, for example, Leader, some of the varied wherever names here it's just ended it just a little similarly here and in these three cases do you're just letters here We have a letter followed by and visit hurts underscore, followed by letters here. So it's a long name on. You can see a combination off letters in lower case and upper case. So these are not valued. Even this oh name is valid, but you should avoid using this kind of name. So I mean, under school, pull away capital letters. Although this is valid, you should not to use this kind off very well aims to frequently because they're reserved for a special uses in what they're certain variables like this under school, followed by wars in in capital letters. So the year internalization for Lou. And then there are some reserved words in lower, which you cannot use this identifiers. So be are those your words? We are and break do else Joseph and falls. So you can see all of the you can recollect even these from If you have some experience in other programming languages this end and usedto combine multiple conditions than break to break out of him. Oh, condition or low, and then do also is for loop than else. If one condition is true else other or else it for multiple, said conditions. Andi is used frequently in lieu of we will see this throughout the course every block and city and the keyword. Similarly, this true and false her brilliance, then this mill not did your under your words and you are not allowed to use these very real names. I know one important thing toe on my work would worry that noise que sends it to. So if you have a very well received, it could took 10. And if you print a variable a capital B C. And you will think that ABC I ever signed 10. So if I print this, it should print 10 but it will not. It's not your deplane and so it's equivalent to nil. So these two are different and in the list of Richard Words, these er in small cases or gambler and is all a small case. So you can have ah, available which is like this capitally Andy in all caps or any other communism like a and captured early for bigger Lord, although this and is not alone. Then there are statements in lower on. There are different ways people write his statements and you can use semi colon and there no statement or you cannot both are correct. You may or may not use. So are these are barrels statements and these four all are equivalent, so they're equal to one on be called to a multiplier directo notice being used to. So here we have separated the two statements into different lines, and we have not added any semi colon. At the end of statements here we are just introduced seven columns, but still the meaning women seem here. We are rich in Buddhist treatments in a single line. On we have 100 semicolon, a coda 1st 1 So this are looking at this. You can think that. Yes. Here the first statement earns and here the second statement means. But even this semicolon is not required. For example, here, a call to one and then we leave some space on be called to a multiplied rightto So this is also valid. Although this looks ugly and it may be sometimes can confusing if you have are too many such kind off. According So you should not use this kind of thing. You can use this, but why save some just to save one line y combined murderous treatment to singling. So I would prefer this one. What? Even this one to keep our code called clean where we're writing every statement in separate lines. So this will just be a basic convincing using Lua program. See you in the next with you 8. Comments: comments are a useful, well, threading some extra information for the leaders of the court. Or there may be cases that you have returned some logic but that logic You want to improve , and but you don't want to delete that logic. So you commit out that part of too cool so that you can repeat it later. For whatever be the region are what provides us single line as the last marker line comments. So for single line comments, it starts with two consecutive ripens and build until the end of the line. So if we ignore this part than it should have been tricked in. But since we have added to high prints before this, so whatever follows this to happen, still learned of the line will be commented out and will be ignored so it would not drink them. Now we come to the next line, so there is no commentary, so it will print De And here there's a comment single line coming because again there are two weapons, so this part will be signaled. So there are a lot of these two lines will be just 1 20 Then we have multiple line comments for here. There's a different that instead, off this type ones, it will read. I couldn't happen than these two open and square dresses. And what would is in between these two will become in total. So it starts with two weapons, followed by two or square brackets, open square records and then until it finds a closing square record. All the comment in between according between will be ignored or any texting between believe naled No, this is the standard way. But there is a common trick that people do instead off using this, you can read. So before disclosing square bracket, we added two extra consecutive happens from the story current. But the decision trick which can be used for quick given, for example, are you come into this? No, you want Oh, uncommitted. So you will need to delete this as well as this. This were two step process. So since you have used this, you can add one extra hyper before this. Now, this is not the beginning off him multilane coming because we have three consecutive icons . So this will be this trust to high possible take presidents and anything after that will be ignored. So it will act as a single line coming. And since there is no beginning off Martel and comment, there is no meaning off this. So this will alter actors single line coming for just where you adding one extra happen, you are basically removed. These two and this lane will again work. But if you had written on the standard well multilane coming, then you could not have done this. You'd have added here, then again here, so that would be a long process. This can be very useful trick, so let's eat in our cold to understand the comments in lower. Let's add a few printed statements for when we are on it, we see that it prints 123456 knowledge, huge single line common to come in tow with you, I have commented, or three and three. If I don't, you see that tree and flavor not printed those anything off cold Arctic signaled. No, let's add the singling coming here. Then this will be printed because after printing the seek it, in contrast, the single and common so it will print tree. So in this case, just fire will signal. So you say here it prints. 12346 No, let's try the multilane coming. So let's coming from 3 to 5. So we have had read a multilane comment here, so it's not print 34 and five. It should escape all of these. You should just bring 12 and six. Return it. So you see you, prince want forensics? No. If I want to. One comment it Here is the trick part. We will use this one so still. It's common, terrible. And there will be no Tinian. Our is it Still it's 1 to 6. So this or this boat are able to come and talk. But they're wanted with this, is there? No, let's say want to renewable this. So what I need to do is just at this here and now. Everything will be printed. So it is a very neat trick. Oh, Then using multilane commits 9. Global Variables: Let's see what our global revels in lieu. So these variables do not mean declaration. We simply use them. I know it is not an area to access known initialized variable. We just to get us a mill. So even before initializing and variable or declaring a very well, we can use it on Lee. Thing is dark, expertly well written. And here we tried toe print be we'll get meal because it has not mean initialized. And here we initialize a value of 10 to it. And now if I print, I will get a value of them. And if we assign a value of nil to a global variable, it will be seem as as good as not declaring it at all. So here, for example, then before our declaring we try to print will be bigger nil, we assign it value. No, we told the value of Tim. Now we're saying it back mill And now if we try to couldn't be it becomes nil. So at this point, and at this point, the state of being is similar. So assigning a value mill makes it similar to or it has not been declared at all and Lord is no different security and non initialized variable like this case from the one that was assigned and in this case for both of these cases are equivalent and after the assignment of Millwork and eventually reclaimed the memory use radio. Really? So this is a briefer introduction toe Lola. Very well for the sake. Off completeness. Let's try toe Use your values for me. So we frayed on it. They get me. I don't know if we assign a value can put and again print one game No way will get a value 10 as expected and no way can certainly to new on. If they bring Tareen, it will really again. So the state of becomes him as what it was earlier. Even we heard declaration. 10. Types and Values: Let's see, what are the different variable types? Oh, in your Louisiana dynamically typed language and there is no type definition in the language. For example, you don't need to write a variable with type like in Take a look in. So are these type definitions are not there and are each value that the very well is holding our defiance? It's one type, so the same. Variable. If I a saint in its type, in your number. If I use any string to it. The Newts tape Kenya's sort of value carriage. It's one type and in lower. There are two basic types. Nearly a 1,000,000,000 number string, usually Duta. Thanks, um, thrill and cable. So if you have worked in some other language than this Ah, user data, it makes him new to you similarly Table orchard. So we will study what all of those types in the later listens and then in orderto find out the type name off. Given variable, we can use the function type and it will return the type name based on the value for paper mill is name. So remember this is one of the types so well takes a value which do no steps, sense of value or the absence of variable. For we can be trained where loser literally can assign milk so it will be as good as this very, very well never existed. So it's tape is me than the type of true is bullion. Similarly, for false it will civilian. In this case, it's number here. It's history and this is a user deter. Are your Lord Mysterion? Then we will certainly see what is you, the editor andan the type of print, 20 inbuilt function in law. So it's type is a function similarly type we have already seen. It's a function which we're calling here. So it's funks him and in love with the plane our tables so we can have multiple a key and value inside the table for its type of stabilisation empty table. And then this type of fix the returns one of these eight Wellies and we're finding the type of that. So it's history because it returns a type name, which is string. So no matter what the variable X is here, this will always return the string. Now let's shortly see what is your editor The user data type clothes. Arbitrary seed eater, too, is told in lower levels, and we will see more of this when we study work. CPS It has no prettify. No prisons in law except assignment and equality, usually later are used to represent new types created by an application program or level militancy. For example, this tender are you Larry? Use them to represent woken fights. So there's eBay off representing. Oh, see data in the form of floor variables. Know the variables do not have three different types, as we have already talked about. Any variable can contain values off any type. And here in the big name, Easy, very well does not exist. So we tried to find this. It will return nearly is not initialized. No, I initialize it to 10 and again find the type, then it's a number. I use a new value to this same variable, which is stream, so it's type changes to stream. No way can even assign influx into it. So this may seem strange trust, but this is a very thing in Lula and you can assign a concentrate. And I remember we were using the same variable A to assign different value and had reassigned a different really words type changes after its inventor print it stay becomes thanks him now with assigning new, which time again becomes real Samos recording, we certainly use. So we will see our study word, some more types in detail ins for the lessons. 11. Nil: in this. Listen, we will study about especially type in lower Cornell. Why did you do special? Because it's a type as the less it's a value. So when we try to access value, which has not yet been in, it's a light. Its values equal toe with eso. The main property is to be different from any other value. It uses lower user nil as a kind off non value to represent absence off a useful value. Global variables haven't value by default, as we have already singing. Even some of other examples behold its first assignment. It's Neil, and we can assign need to a global very well toe delete. Delete it once we're done. So let's see when the jumbled and it will be slightly more here. So let's say that other program starts from here. There is nothing before it. Onda. We try to print a than what believed print, since it's only initialized equipment. And whenever I write something some called in the presentation, you should try toe, write it in your I D or even the lower the mobile site, which I had said earlier. So it will print. Really? No. If I bring that type off it. It will again print will. But this type returns a string. So this militia string in this case No, If we do A and 10 remember that is holding a values mill and then then it will print will. And this is an interesting, uh, case and you may not get it. In the first instance, it's slightly different Syntex in lower. So a and 10 or 20. So this works sometimes like the ordinary operator in some other languages. So if is valued, then it will pick the 1st 1 or if is nil or falls, then it will pick the value after or so In this case, Asian ill suited will print then Sorry, 20 because it is Neil. So it will pick the 2nd 1 You said trade and see their clearance of matches with this. Now this war before everybody miss late. So when he was, you know, we assign 22 a. Now again, we repeat the same thing. So clear, able print couldn t and type of hair will print number and he and then will print. I didn't and this again we'll print them because is really there. So it will ignore the everything off floor rules. You can see the answer changes here. So you should try practicing more examples and whatever comes to your mind, which can be useful. Try practicing it in your idea and you will get more clear. Idea. What? Isn't it? 12. Booleans: Let's look at another typing lower call begin from bullion. Has two values. Samos, other languages, which it calls. And and these are not the only condition values that is the new. Compare some condition if some condition then do something, so they are not the only value. Should these variables or the Expressen need not evil Loot are true or false. Explicitly. These can be anywhere you like. If I say you fix is 20 and they say, If X then do something, then also it's true, going existent, you will see that it's not a 1,000,000,000 type. It's number, but still we can use it and conditions from that year. It means that these are not the only condition. Values and even you can represent a condition and conditional tastes. Consider boot false and Neil has false so only toe values us evaluate to false the condition. Either it's a bullion with value falls or it's in. You either explicitly returned little or no one off insulated value, so the yard only to lose material er to false all the other values, will be true. Even Jiro in C plus plus, if you're right, if Geo then this believe Elder to falls between lure. That is not the case. Even Jiro is considered true. So you have to keep in mind there. This is very important and this can be a source of bug in your court. You should always keep in mind that false and well apart from these any other values are true. So even geo you it's true. It will be evaluated in C plus. Plus you do not re Willard even an empty string very early on its in history. Then also it's true. It will pass the condition noticed. Now let's look at some logical operators and or not the other three lord kilometers and like control structures or logical operators consider boat false and Neil s fault. And anything else has true result off and operative digits was talking. And if they're not grimness Paul's Otherwise, the result It's second Ockrent. We will certainly see an example of this and it will be more clear if you have ah, some condition and some value. Even then, If this is false, then this one will be a sign. So this one will return. If it's true, then the second value will be returned and for the world, the result of for its first open efforts not false otherwise resulted. Second up. So let's see the example and it will clear. So we have four and five in this case, the first parties. True, because his duties neither knew or falls, so the second will be returned. So the result is right. It will print fight here if we try toe print mill and 30 than it will me. Because the first parties false. So it will cost part with recruiter. No false and working again fools gentle What's lead So dear? 05 year. The passport is true. So here, Uh Ginobili visitor, we'll do is true and no falls or I hear first condition is false. So here the return value will be quite here. The first condition is false because Mylan fourth boater falls so the second part will return in this case falls and false or feel the need to little will. So you see the difference here. These tours, the mill or false heat returns false, false or military chance mill, depending on which one is the first part on the second part. So I hope you work some increase in ALS ho and and or works in lower. Now let's look at logical operators, hold their evaluated the boat A and or use this sort secretary even listen So you might have guessed it from these examples that is the value of their second opened on living necessary. Why is it so? Because you see that if the first parties true, then only it will see the second part in the case of hand. If the first part is false, then it will not look at the other option. It will simply return Neil similarly here for four stop trend itself is false. So it will return here. It would not bother. What is the second open? And this ensures there to express in like these are valid, so it's quite often to compare. Uh, combined multiple are expressed since we're like a D rated maybe. But before this you must until that b is not nil. So you will see in there bees not me or not a cool two mil. And so if bees nil, then it will not go ahead. It will return here itself because this expression cannot be diluted. It will read or to the right with you, So these are quickly valid. If I is not a Jew and a dreaded by I E is greater than be. If you write this before this condition, then it will through another, because it will try to develop this so you test to visiting before the second explosion, so this will avoid runtime errors. And there is one useful medium where you don't know whether some variable is holding a valid value or not. For example, if you write X equal to explore every so in this case, if X is metal, then it will assign it value. Be free if it's normal, or if it's not false, then it will keep the value of sex, whatever it it was. So it's equivalent to with neurotics, then, as I never lose me. So it's used when you want to assign a default value to a variable. Now let's look at the turn. Rio Piter. It's equivalent off this turn every operator in sleeplessness, they generate A and B or C, so if it is true, that is not mill Or of course, then it will return. The first value be is not real, so I will Right here. Not real or false. Then you to will return b other ways it will return. See? So this is same as this here also it means in C plus less. It means if this condition is true, then take the value. Be otherwise see So for example, if we want to find the max of two numbers Nixon way, then we can write it in one line, executed in way and x or way for if X is greater than way then this condition is true. So to litter X If this is false, notice X is less than way or less than 1/4 way. Then this is false. Which will turn, boy? No, let's look at the last of fraternities. Not not This is Ah lots collaborator. So it returns a 1,000,000,000 value. For example, If we write not mill, then it will return to the site Not false again it to return. True, if they did not needle, it would return false. Because mill and false are the only two values which are relatively as false, so negative that will be true. Otherwise it will be false. So their delivery also true from not of Jiro is false. No, not on Germany's souls and not off. This thing is false. So not off sauce is true. Similarly not off, Not off the police force because not off mill is true. So not a full not of true will recourse. So these were some of the bullion and logical operators in lower. 13. Numbers: in the next few lessons. I really were discussing a work numbers in your so earlier before I've got to tell you, if I got to, there was a single double precision floating point presentation off numbers. But to starting with blue off Igor Tree, it has two separate representations One foreign teaches, which is 64 bit contagious on 14 flukes, which is same elderly years, double precision floating point numbers and the introduction off in teachers is the hallmark off Luke five your tree that it is one of the most important changes that was done in lower $5 tree. And it also led to some incompatibilities whose which we will see later. So for no, you can you know those incompatibilities. So the right Nuri Constance with in different forms when it's simple into here Then way we can absolutely are a decimal point and we can also hard decimal exponent. So here you see, nor are the cement No exponent Here you see decimal here you see dismal as well, exponent. So what does this mean? This for it Very clear for same you're going for if it's ah e and then minus three then it means 10. Raised to the power my industry through a portal gun trace heaven. My team played away didn't dynasty. We just seem it new. A tingly 1000. So during my 10 decimals, sift one place. Similarly, little more places. Two zeros before for 57 Here it's 42 so it's less Tolliver, so you can see there will be 11 euros. So 321 it will come here, then followed by 11 needles on the same as this capitalise. Emit Smalley on your wrist with the small point, or exponents are considered floats. So these all are floats Onda. Otherwise, they're in teachers. In this case, this is the only into you for every tell you. Our day is so if you're right type than it will always print in teacher. But we have other method off finding the exact type. Also, after that, you can try yourself for each of these values. What is the type return, whether it's intentional or fruit. So good interior and float values have type number. So I said earlier, if you just tried type, whether it's indicator float, it will always return number not into your throat. They have some type because more often than not, they're interchangeable. And here you can see I am not using type, but I'm using matador tape. So in some cases you may want to distinguish whether you are working with throat or interiors. Although in most of the cases you will not require that In that case, you can trade matador type and try with their different values different example their taps on. And you will find that in this case this will only return into you. Others will return fruit similarly here, Treason teacher than this in this article and Aaron teachers and flirts with the same value will compare as equal in low. So if you compare is one equal to 1.0, then yes, it's true. But if you compare Madar tape of this and matter tape of this, they're not saying similarly Ministries Samer minus tree door. Do you similarly here? Oh no. If you print these values, it will not be printed like this. So this hair there, noting noting And here if you drink this, you try it right now bring to one ET then it will print 1000 going you. So since these are folks. It will open. Nordo and Louis nearly also supports hex, artisanal constants and exodus. Metal constants are perfect. Smith Digital X for this deer except for us. So the next day this will be our values from 01 toe till nine, then after nine a b c B e. And it's so this is equivalent to 16 10 11 12 13 14 15 15 so you can calculate this FF for it first if who have multiplied Way 16 raise to power one plus after articulated very 16. Race to the bottom and you So this is anything goes to the party everyone. So it's 15 plus for your physical. We're into 15 so 13 times sixties, 16 years to hookey 2 40 plus emptiness toe cryptically. Similarly, this is 14. This is 13 total level and kill. And these values your family so you can similarly calculate this Ana. Here it will be one time. 16 square plus here. Tynes 16 hour, one plus three times 16 Power Dedeaux. So extreme is organ 1 60 then 2 56 So six plus three line and going to fight for 16 forgiven. So this was a brief introduction off the numbers. We will continue our discussion on our numbers into, and we will see in the next few dribbles. He heard the various mathematical prison back. We can perform with these numbers. 14. Operators - Arithmetic and Relational: in this listen, we will study or their different types of operators in lower in particular, we will look into automatic and relational operators. So, our dear, the 20 go critters, which is a reason subtraction, multiplication the reason. And yes, this looks similar to the subtraction. But I mean here when you use him because forgetting number or some value, you write a minus and in front of it and this means subtracts him. And then this is in teacher division. This is normal division. So if you do a three way to, then it will return 1.5. But if you do three more this into your division toe the nettle return one. So this is their difference. This is Modelo and this is exponents season. We will certainly see thes operators in detail. And for personal operators, the less technical less than greater than less technical toe greater than he called to equal toe and nautical toe. So let's start with the automatic operators. So as for the reference, man will love flu, which is that one of the main guidelines for the introduction of in teachers in Lower $5 tree Waas, The programmer may choose to mostly ignore the difference between teachers and folks or to a June complete control over their representation off beat number. So therefore, any automatic operators should give the same result of and working on in teachers. And when working on real most for ah reason subtraction, multiplication and negation infiltrating In our division, there's a ruler. If options are in teachers, that is a low concerning teachers. So in this case, thes these values Alaa Prince and these this These are the operators. So here multiplication addition gets and these are the operators and the other options. So you four prints are in teachers, then the result is all 20 year other way use floor. So what? We'll do the other case either or Lokeren's our floor or there are mixed cases, some in tears and some pork. So in all those cases, the really, really float on leaving. All options are in teachers the real quickly in teacher. So in case up mixed opulence lower converse the in teachers to afloat before the person in this case boat our interior Sorry. Lt's interior airboat are floats with the aeltus float Here it's and mixed through this 25 will be converted to $25 0 Andrea literally calculated, which is 38 20 year. Similarly, in this case, it's 18.0, and then the ism there, so minus 18.0, what do you use? Them does not follow that rule because has the sword earlier? If we write, redirected, wait to hear both three and tour in teachers. But the result is not interior. It's one point fight, so delusional twenties is there's not me to run into you. It may be in here, for example, in this case, but not always so in two years. In mathematical terms, we say that in teachers are not closed under during this. This thing to avoid are different regions between our division off vintages and Derian. Aflac's division already operates on Fox and give floor traders. So here it's one country. And even if you're right, treat or deal away to your dear Oh, it's still the same thing. Let's look at the floor division or interior division. We say I've been calling, so it's for doing so. It was newly introduced in you off the three and always songs The cosign tours negative infinity and uring an integral result for all our prince. So if you see a number line decided, the Party of Infantry decided the negative infinity. This is let's 012 So if the values, anything would win this this range, it will sifted to the nearest interior towards this direction. Negative infinity Derrickson, That is, if the values hear, hear, hear, anything we want into it will be one similarly on negative side if any values between years here or anywhere between this, it would read. Teach addressed this towards the negative infinity side. So this no prison can follow the same rules off the automatic operators. Lettis. If both your parents are in teaches, result is an interior. Other ways. A float returned integral value, so it will be through. But the value will be interior. For example, it very three throw division two. It's one. If we write three daughter old divided, very fruity reason to. Then again, since it's a mixed toe, will you can order took Toto and the result will be one not fail between late here, so it will recieve tried here. So the values one but represented us for, because it's a mixed type Similarly, in this case, water in two years or three. But in this case, three Toto. So you see, follow the same rulers other operators, similarly, in this case, so minus lane floor. So you will see that the majority's so if you see the number line minus for a beer minus played would be here and negative and gives this side or two infinities decide. So the majority's minus four dogfight. If you do normal division, so the values here so it will be take the nearest interior. What? Visit the newsprint in your minus four or minus way so it will see the left side towards the negative infinity and you will find minus five, so the result is minus failure. Similarly, in this case, the result is three. But since what our weapons are floats with real history daughter, that is. Let's look at the more the low critters. So it's defined using this formula more. The lullabies a minus. Oh, a floor Division B then multiplied baby on. Everything subtracted from so you can very for you on different examples and you will see that it works. Uh, so in fact, you can derive particular so you floor B is what it's Ah ah, Whatever the value off divided might be, there will be some in T zero value plus, um, Flaxman value. So this tingling chop off this vaccine value, it will leave the into your only, and when we multi plate, it will multiply baby to this. And when we subtract from me, you will get the this model looting. So So there are two cases for this, although the same formula would apply towboat but foreign teacher case It's very simple. If we're taking X Morley, look a, then the value will always be in the rain. You go to K minus one even when X is negative. Korean belief, it's minus nine divided way model to then. Also, the valley will be one only because it can take any value from Joe Cook Pu minus one. But in the case of real appearance, because some unexpected uses example, if you write X minus makes more below 0.1 then it will choke off the older decimal digits, leaving two decimal digits. Similarly, if you write X minus six more below do point driven, then it will choke out all the remaining digits after three decimal places. So, for example, if you're eight match not by then it will take some long value 3.14159 and phone. So if it takes minus X mortal Europe on your own, it will take the two digits of Kurdistan. So do little 3.14 The world in this case three tips 3.141 So we will see why the same formula balls here. So, first of all, we want this X minus X more deluded upon your oven. So we will replace this more deliberate this definition, which is X minus excellent teacher division through the region Ah, 0.1 Marty played way needle point either one, and closed this record and this record. No, it's 3.14159 So if we do flow to be in my your 0.1 it will read 314 and everything will be talked. So it will return 314. If the market play this with toe do 0.1 we will get 3.14 So if we open the bracket and becomes X minus X plus 3.14 This cancer cells can. We're left with 3.14 So you see Ah, the same formula box here. And if you write this, then it was pick the 1st 2 digits after decimal. Similarly, you can prove that this works for charities. No, let's moving forward. Let's look at our relational operators. So these are the relational produce list, then greater than less than equal to or greater than equal toe equal to end nautical toe. And all the operators produce a green value and on this are biblical to test for equality on this test four nautical negative or see quality. And if the values er off different types demonstratively, you will consider them nautical. Otherwise, we will compare them as for their types and by type here mean normal tape and not matador tape, which it soon him bring this video because matador tape will return you in teacher or float . But this normal table return you number even for interior or throat. Good. So here we're refering to this type. Let's see an example than you look here or you believe the right one week or 21 point Jew, then a tape off voter seem boastful. Looks it tape one, then it's number. And if we write type or North Leigh one. No deal and still it's number. So we're roughing toe this type. So now let's compare when you call to Wonder Deal, since the same type, that is number and their value, yours the same to return. True. But if they're type is different, that's the one. It's a string here, so this will return False because this is a different type. So this more the briefing Kerekes into the different operators in lower. 15. Math Library: Let's look at some other important functions in the math level. Really, Luke. So we can categorize the functions into Mainly are these categories, and there will be some other functions will which will not thes categories. So when it's to a metric, then we'll study or random numbers in order. Constance men elongated make functions and drowning functions and, ah, constant due to representation limits. So let's begin. So first, his trigger metric functions on. One thing to note here is that well, while we will be passing the arguments, the parameters to these trigonometry functions, we will be dealing with radiance. For example, we all know that sign off 92 degrees one. So sign curve is like this. So does it want to degree? This is not contradictory, and it's really lay between plus one on minus one. So ingredients this one it easy girl in tow by. So if you pass sign Oh, when it then it will not regional. It will think that it's radiance it will convert. You can convert how many degrees are one. So if you passed 3.14159 Sign 3.14159 it will be pretty close to zero because this will lose very close to pine or you can pass sane. I not directly pay what man not play. So this will be close to you. So you should keep in mind that while passing the values you are passing the radiance and not degrees. But if you want to convert a degree toe radiant, then you can use support. You know the degree. What? You don't know the radiant so you can write as matter not there and then one itty so it will convert this 1 82 radiance and then pass it toe to electric transom. Similarly for ah, Radian to degree conversing you could use Be easy. So dear, the constants provided for collusion to know we have sanctions for sign cost 10 you're saying which is our sense? I'm yours similarly for cost 10 and you tend to hear it's different from a 10 that very well past two will use and it will take the issue of these m It will decide which Corden treaties depending on externally, the same place you can occur due Toa positive xnegative worry and similarly negative explosively both refuse will be seem what he's doing these values. It will decide the Cordant and accordingly dangle loosely term. And then the easy and radiant we are already seeing. So let's see some of the examples. So let's see. We want to find the sign off 90. So what, we will write? Well, right, Matt? Dark. I divided right to food by his one victory by way to 90 degree. So this is one similarly, uh, they three times by huge to 70 so that we live minus one on, uh, if you buy, it should be very close to diesel. So x years Tober minus 16 with approximately zero. But if you're right, Maine Deer, you will see that it will not. We will. It will resume the loot going to get name. So whatever is the or degree current of this, it's conflicting the value on that. And no, let's say we want to convert Oh, degree to really in so we can rate 1 80 Wanted to degrees pirate insert really very close to 3.14159 So this is very cool, like sprinkling to control me. So you see that it's these to the leader saying, because it, you know, quantities point Similarly, you know, we can try for course function so it will work just like same. So it's minus one and let's trade one value for 10. 10 40 favors one because same 45 costs particularly voter one over, Ah matter dark. But you do it in very cool. So disagree one. So it's almost one. But whatever Cuban so busy although you can are used to the metric constant. No, let's stay one. You're saying, Oh, it's 1.57 which is by way to Julie Zero, because oh, this is universe. So this is by way to so you can confirm that it's same s in this value because, say not by way to is one. Similarly, you can try for all other functions and then it's next. Let's look at the random number generator. So blue has, uh, random function in math literary, so you can use it to generates. You don't random ums dangers, pseudo random numbers and not real random numbers thes depend under seed that it takes and their function for feed random seed also get you concert. But in this so really we will not be using that. I will take the divorcee so there are three ways off calling. Either you can call it zero argument, one argument or two arguments. So if your argument it will return a value between zero and 13 Joe is included. What one is not included? Suit Willis Strictly less than one. If you pass one argument one intentionally and then it will return a value from one to win , and it can even return in any jolt included and when it also included. And if you passed to values to into your values well and you for lower bound and a permanent, it will return an integer between Andy included. So let's try with different values. So let's clear it. So you see it returns of between zero and one, and it will never eternal. And now let's pass one value. Let's fight so it should return from Want to fight, including five. So let's stray a few times to confirm that. So when you see that it has returned one so one is always included. Similarly, five years included. If you try a few things, it should return for him sometime. so you can see here it also returns. Fight. So this so is that it will return a value from one side boat included. No, let's trade. Do we lose lower and upper bone here also. Five went in both our into big Who does translating six. So you see that even 10 is included? Similarly future? A few times it will even print fight No, next to catalog. It makes sense. Um foreign. This lecture we will just talk about two longer. It makes Johnson's one simple log ritual returned the natural logarithms in mats. We also write like Ellen, So this will be somewhere between, huh? Closed toe gunfire or slightly more. So it means log based Be so easy. Kremlin toe 0.7 or something like that. So it was take the basis. Oh, you can also use Lord him. So it will take the base off. 10. So in this case, it will return one because 10 days to organise tin. But in this case, simply Lord means log base. So next tried here to confirm so it was simply right locked in. It would not everyone we should use Matt Search 2.3 because years to the power to countries whose cooked in Now let's use log 10,000. So in this case, it should be one. Now, let's look at some of the rounding Constance who we had tree turning functions. One floor, see and Emily give so floor been around Works negative. Infinity. Here we have you. You know what? To minus one minus two and the same minute security and plus infinity. Let's see Vieira value here when we used float. So it will take the nearest into year towards negative infinity. So from 0 to 1, it will return. Heroes really want toe to toe little one if it's exactly into your it with little Actelion . So this is the living off through similarly ceiling. So the same really re passed to seal instead of floor. It will move towards this and it will return one. Similarly, for one to do it will return to and moody if, uh, around stored 03 If it's in the boys to side it will sift tours left foot in the negative Say it will save towards right and these old values returned the rounded value. But this mots returns the undervalue and a dismally the Flaxman Park. So let's trade these three functions. So matador must use flu. We'll use 3.4. So it's short term thing. No, we use minus danish a chance minus four because through will receive towards left Negative infinity. So on the number line. Uh, so use minus. She's here. Mine escorted here from your listing Teachers towards lefty minus school. No use CD. So here you to return minus tree. And in case I wanted to make a return school. No, Let's trader last folks in which is a mobile 3.44 studio. So to return three three and you see the appetizer turn the fractional part also. So these were these two will get this one similarly retried for minus 3.4 to return minus tree and minus going training. So you see the difference from currency and if you again and these two will usually get in this one. So these were the trees are in Constance. Next look at the representatives and limits. So most programming languages represent numbers, but six number of books. So therefore there is a limitation on the Mac's been value that you can repair Botin drinking and precision so it hasn't mattered. What Maxim teachers and meaning did You do know Tyndall Max Value. So this is who is to 64 minus one and this values minus to restore hurt 64. So when we compute an interior prison that could result in value smaller than 1,000,000 teachers or larger than Max intention then result wraps around through the values always between meaning teacher and maxim to you. So what is the meaning of this rapper? Um let's say this is the representation off in tears. This is, you know, similarly somewhere it will reach. Let's see here it's relaxing teachers, I've alert Max. And, um, this is, let's see can care 100 k and so on. So these are poised to values and these are the negative values. This is minus 10. Okay, minus 100 key and some other large negative value. And then you've been moving this direction Are gonna Cleveland reach meaning to this look So it's minus tourist about 64 and its tourist over 64 minus one. So these tour immediately next to each other. So in these jerks and also magnitude increases important to Jackson in this direction Also magnitude increased but didn't make it to. So what happens? Is Mr here a maximum minus one? The red one. Could we get Max it? If we had Maxie? One tool accent, we will get meaning. So I mean to say Maxine, this one. So if you add some the Luke was devalue. It will keep moving in the circle so ultimately will reach me accent and no if you were some more value. If you are one could next values meaning so it will become meaning. This is acquitted. We named If you had one to it, it will become meaning minus one. So we really keep earning. It will treat zero when it is minus one. You had 12 to make. It becomes you. You can add one. It will come one keep hurting. It will reach Maxine's. I'd want to it again. It will again become meaning So this is the rapa wrong. So always the value will be between minute and my accent. So let's try to our i d. So this control is some more notable? Do represent the max introduce alerts tried trading on the program. So let's man not Max Interior. Let's see foot several Children from here or not, Yes. So its able to bring the value makes India no. Uh similarly, we will printer. We didn t shirt and no Lech Sprint Maxim teacher plus one. So I want to illustrate the point off. Is that being it on? So you see you know you heard one to maxim to you It becomes Samos meaning to you. So this is the concept off wrapping around for No. Let's look at what other way. So if we have meaning teacher so if we subtract one from any value, it will move in this Jackson anti clockwise if the everyone put it will move in clock so clock ways wants to And antique clock wages, medical So is this Subtract one from this Meaning teachers, it will come here. So let's see if it actually happens. So what I I mean in teacher on minus one. Excellent. So you see, meaning teacher minus one become Samos Max in two years. So this is very important concept that you should keep in mind wrapping around and then let's look at some of the other functions which I do not cover in any specific category. So this Max return the maximum value among its arguing. You can pass my little village to Max similarly for minute will return the minimum value. Then he was will return Infinity. He experience here is to products, but we have already used power is X way. Who? The power you need toe past two will use its next quickly. Look at these. Uh, let me train the console itself. Matador Next one go for it. So it prints to find the maximum. No, right. The mean You find the minimum? No, to restore our for similarly matador XP on here. Oh, let's right to go three between Edward will or calculating our natural logarithms often so it should be close to him. Received very close to 10. So this experience here is to the power. Oh, x, no. Let's try the usual. It's so one directed by do you use Oh, let's print from here. It returns i units. So it's kind off infinity. You can a Jew Mitory infinity The maximum value that it can be that can be represented. So I hope you are. You learn about the various mathematical functions and these are very useful and I would encourage you towards it again so that you are very family of it. These functions 16. Strings: in this. Listen, we will start our discussion on the strings in lower strings are sequence of bites which represent text. And these are immutable values in lower. That is, we cannot change a character inside a string as we can doing See instead, we can create in new stream with earlier modification for young cliff We have a string Oh, a depressions once drink and we want to substitute one bit another. Then we can use the diesel function off the stream. Oh on. And then it will be a saint. Good Newbury will be, but is still remain the same, for example, will be printed. It is still the same old string, and we print b is the new modified this drink and you are. The strings are subject to automatic memory. Management's like all other objects, like tables and other things. So we don't need to worry about the location and the location of memory. These will be automatically taken care way, Lou. Now, in order to find the length of the strings, we are seeing that strings of sequins of bites. So when we try to find the length of the strings it represents, it returns the count off bites and not the characters, for example, or indifferent include ings. May use different number of bytes for representing a character in utf eight. Also, some characters Mary single about it. So maybe Marty, right? So for young jealously bring the length of this diesel. Are simple characters local going one bite so it will return flight De simply return the bites and not characters. And we will see an example of this similarly here. But what will happen here? You see that it's not a simple A it's. And then this Ah, small Jiro like this is there. So let's try it in our I d. So if the right it turns one ABC Space D. So there we have four and one MySpace trance fight. No, let's trace a Multivariate characters like this. So this is still one character. What, you see that it was just too, because it takes two bites to revision this similarly so I have written two characters, but to two returns played. So let's take return return work. This is to throw this mystery. Three birds so dizzy. Another integration symbol, you told. So takes three rights. So I think you are diarrhea, that it will not triple return the number of characters, but instead it will return the number of bytes now can. Contaminating off multiple strings is very useful in all the programming language. You must know some way off adding to strength in some languages. You may have seen most like plus and for making things like percentages and then you specify the actual string to continent thes kind of things in lower. We have this concatenation strength which is to docks with our tennis place. Onder if any opportunities number if we're to string the next train older Kikkan Kogenate them. But if one of the attendees number their first Louisville convert this number to stream and then concrete any William Billy a hello world, these disease really irk similarly, the concatenation number it will creating new sting out of this and you remember that strings are immutable as we have already talked. So the concatenation operator always creates in new string without any modification. Cuda programs for young police. We assign a value of hello to a and we can contaminate a with two world. So let's trade in already clearly 20 you tell No way, right? Unsellable, I concur. Originated world to a but still it's him. So these are in you tool? No, we have literally strings. So these are the limiter device single or double matin courts. So you can either use the courts to represent little. Or you can use a single court water. Fine. Both are equivalent. The only thing is that if you want oh, add some a single or double court within that string also, then, if you're using double cooks, then you can use single could without any backs less, although we can use it backs last single coital fruit will work, but if you use it double court inside the vehicle, it will enter out units need to, you know, backslash similarly for single string. If you you devil cooks, it's fine. But if you want to use single court than you need to you next, lis. So let's straight another cool. So let's say I want to print. ABC gave me No, let's say one word. Single cold. So there is no error here because I am using double court for our strictly true. So it works for foot. But if I use and the other cooks and you see there is error. But if you want to use double courts, then you can proceeded with backs less and now it works are expected. Similarly, you can drive it single court, a single court and double chord within this explain no need greenbacks less. But if we want to use single court, it again is area. So we need to use Max less. She really. If you want to have some other characters like Max, less backs less itself, then you can if you like. Like this, it will leader. So you should proceed. This backs less also with Maximus. So now you'll get one single backs last similarly, for in any other special characters for that credit. Brief introduction off strength. We will continue our discussion on strings in the future Wiggles. 17. Long Strings: in continuation off the previous lecture on strings looks look at some of the cases where the string maybe very long or it may have certain certain former within the literal string itself. So how we can handle that? So we are seeing that little strings can with limiter using single courts or federal courts . Oh, but this can be limited using matching square on record, suitable for many square record, then some long string and then including square bracket. And it can run for several lines and do not interpret escape sequences, and it ignores the first character, the string. When this character is newly so, it is very convenient for writing strings which contain large pieces or cold jumper. Let's see, here we have a complete html deg completist, Eamon, our text beating the same string, literal. So here we have used this working square record, and here is the that you square record, which will close this. So first, let's try to run it to number. There's some former things who turns Nuland characters, so let's try to an hour cold and allude. Bring to this pay paid and now let's run it so you see that This is a complete one string and eats. It has no problem in printing that in the objects informant that we wanted. So this can be very handy in such scenarios. But in this altar there are some scenarios you need to handle for gamble if if you're called that you're trying to include included in this opening, including square records. So you're including your court within that. But that cold made self content some of square record like this case or didn't even contain some court that is coming, turtle. So we had all under the scene while studying how toe had comments in lieu of that for singling comments. Were this for multilane comments we used to looking dresses this this followed way, toe square bracket and then multilane comment on them This So let's see your core contents , um, commented cool. So while including the sale in this string, so you want to include your court within this opening, including record. So some part of your court contains this so we could be likeness. So here this the scanner will get confused that this is the start of the string and this is the close your district for this comes from this. So how to handle such case? So in order to handle searching areas you need toe include change this hoping including off your string wit this and equality Not this but first to square record followed by equal to sane, then another square record. So when it encounters this, it will see that this does not match with this. The matching a square bracket for this will be matching pair off. A square record will be like this. So when you could insane when he called to sane. Similarly, you can have two or more recorded the same and the matching cruising dresses. So here to matters with 23 feet in Contras, any one or two little Jiro one equal to sign in between it will not consider that at the match in case and the same thing was true for common scalable. So we have seen that we can vary multilane comments like this, but you could have returned multilane comments like this three called Hussein's than the comment and then so the same jury holds forth Maculan Commons article No, let's try to modify our are cool. Let's a beard when he called Hussein. No, we don't ever did any clues anything. So this does not print end him. It says that unfinished long string because it did not find any match, including a pair of braces, no wired when he called to sign. No, this exactly much of this. So he took in Princeton. Value no looks hard three or even fooled. And if you don't eat again again, it prints it. So I hope you'll find this trick very usefully while working with longer strings. 18. Coercions: Let's look at what our core sins in lower. Oh, dear. The automatic conversion between numbers and the strings at turn time without you explicitly converting a number to a string Your string to a number. So, for example, while doing any numerical prison, are you a string? It will try to convert the string to a number if possible. Are you a place? Of course. Since Morton leanest omitting operators. But also in places that expect in number. For example, if you pass Oh, a string to Matthew out sign it will first try to convert that to a number of possible other ways it will leader. Uh, no. Well, uh, you will find the number. We're a string. What expected? It will first converted to a string. So we have already seen in the strings we do way have studied What? Concatenation, for example. Concatenation expects history. So first it will convert number two string and then in the value. Let's quickly try it. So 10. 22 welcome coordinating. You should keep in mind that you should leave this place after the first interior. If you don't leave a space after second, it's not a problem like here immediately after two dots. I 20 Still, it converts. But now let's see what happens if we remove this. Is this it true than ever? Because you think they're does first dot is still decimal part of this, so still consider So it all depends on this piece after the first numbers, so it's mandatory to wear the space here. No, there are rays off doing explicit conversion as a bill for that you need to use to number if you want to convert its string to a number or two string. If you want to convert something twisting, not necessarily number for Let's look at two number in some detail as the names aged, converted toe to number and it returns nil. Your district is not denoted to number. For example, if I is right to number on my part one you'll sleep. I entreat it works. What? Let's see. I write e me space footprints nil because it's not a proper number. So in that case it will return in on by default to number June start. You're using this small notice in, but you can use other notations like Brian Riak Alexis dismal. In fact, any base between two and 36. Although, you know you will not be using any other base other than our decimal boundary octo our exodus. Um but you can You are very welcome to try other notations. So if you write to number minus tree you Trojans ministry this in this case it returns. Giorgio. Why is that? Because the type of there it is. So let's clear t A. In fact, we're working with strings itself. So alerts right over cold in this Be easier to for Let's say I want to print matter nor tape and they write 10 e four. And in this case I will earn 10,000. And if I run it, you see that the 1st 1 is fruit on. The 2nd 1 is in dear so accordingly If I write to number tow this, it returns afloat value and not in here. If I had written 10,000 here, you could have return 10,000 fully right? It's a Justin Tajin. But if I write teaching this notice in in this case, it returns What I think in accord it will not return to see attacks, Giorgio. Because it was fruit No. 10 is not village. So if it's not really it will return new. We have already seen this in this case. This will you? Here we have a signed base to it. If we don't assign base, it will take 10. So visit them under notice and you can make sure that ridge 30 zone It's one plus four plus 32 32 blissful 36 plus 1 37 Similarly, visitors this 16 and if the right way see it here. But this is again invalid because in base to beer Gerawan digits only in Basten. We have, you know, to remain in their 16 year, you know, to nine. Followed way. ABC the denoting. So in short, we have, you know, 2 15 similarly in basic it we will have from you know, 27 only no other yet But here you can see that we're main it. So this is not a valid doctor Representations So unit two tons mill No, in orderto convert something two strings represent is, um we can use to stream And these convergence are always worried. For example, you can compare this to strengthen and this will evil you two true however, we have no control over the former. That is, the number of the smell gets in the resulting string. For full control, we will use a string dot format, which we will see later the door to more systematic operators. Order operators don core similar to automatic operators in case of plus, if some stringers there to try to convert it to a number. What Dad does not happen in the case? Off comparision order operators in this case, Visa strings for the You're not converted to numbers and it will return force. So if you write to less than 15 it's true. If you're right being called Stoller than 15 it's false because off alphabetic order, it's not converted to numbers, so it's treated as string only so they will. Compared to anyone, so too is larger. So it's false. Let's try in the corner. Then it will work here, so we write to listening. 15. It's true, but every right to list them routine. It's false because beer strings, But if you write mixed thing, one string everyone number, then locals and will happen instead, it will through an error. So to avoid inconsistent rials Oh, through there in such scenarios, 19. String Library functions: in this. Listen, we will go through the radios. Important functions in the string library in lower. So this is a list off function that we will cover in this. Listen, So these functions are pretty simple and we will not go into the details of news. So string Nordland returns diligent of the stream and it seem as this operative which we thought you return the number off bites and not the actual characters. So the ex quickly look at this. So here, if we rated it, will return one simpler for this operator. But we have seen that if we had written this and it returns toe and similarly for any other character with takes more than one right. So it returns three and it betrayed the limb again. It returned the same very low return rate. This so it also turned the number of bytes. So it's identical to this. No are really piecing some. We pass history on a value in so it repeats the string and times. So you see tribute. See, we see. We see a visit three times. So again ah, straightforward. And next to the reverse. So it will print the string in reverse order. And in all those cases of with right I treat can work. So are returns. It means that it returns a new string because we had already seen that strings are immutable and original string remains the same. It's not that difficult. A string Notre versus the original string Did you always know string remains seem. This points and returns a new string, which is reverse off no original one on the next 20 chopper, which converts to a per case and similarly lower converse to lower case. So let's see example off all of these every see space d So this returns reverse research a few upper case also so it converts everything toe uppercase. So whatever we're living uppercase remains in a per case, but lower case are converted to uppercase. Similarly, Nagel Lord off this everything is converted to lower case on originally lower case remains in lower case. Now let's look at what some more functions string dot sub. So let's look at it in detail so this sub means sub string. So before you call So yes, ideas where I engaged or dinos is, so it extracts a piece of a string a piece of the string is from Ah yet toe gait Characters including boot. So both characters are included. Every city Yes and relate. Let's say we want to extract CD. So sees third. So point. You know, Terry, is that in string? The index's starts from one. So is that index would to see their three right? Three and it will return from 3 to 5 foot CD. No, we called. We can also use negative in This is so if this is the stream. So this is Geez Oh, sorry, Mrs One, This is 2345 and six and negative indexes like that The last one in minus one, then minus two minus tree minus four minus 40 and minus six. So if you want to access the last index began, simply write minus one and second last minus two Who bought in the scissor valued. So if the right s one day, then the first index is one that is from the first character NJ so good to return a prefix from one toe. Whatever is the value of J Similarly for J two minus one. So if let's say the CJ so from here build minus one in the last one. Free to return. It's a fix. This will return it perfect. I would do for so it will return every city. And, uh, next kiss. We will write for two minus one. So four is de suite to return the yes and a two to minus two s O minus two. With this, I can last character And who is this again? Character? So this will return a copy of the original string with death was generalized character removed. So this is very useful than you must understand. The various are things we can do with it Next is a string dot care and string dirt might so in Kerry three Pass Eroglu in teacher It will convert to character So you get the road more interior We can't even pass more intelligence. For example. In this case, Eyes 99 we know that in escape representation is 97 b is 90 years c is 99 so on the so we initially I to 1918 and we passed to string, not care. So I was 99 So it will print to see I place him in his 100. So D and e school, it's trade all right. 97 98 99. It was his return. ABC Similarly, reports to will lose you too little A B and so on So you can pass one or more, uh, escape value or the value of characters And it look inward to character on bitey does the reverse thing. So here we pass ABC and you can call it in multiple ways. Here you just call string, not Vitus. You don't pass any second our perimeter, so it will return the value first character is 97. You can add and index here so it will return. The internal represent is not far yet Character for young will be passed to through it will return value be Mrs 98 And here we passed minus one who lost character we to see through 99 and we can pass even more values It returns all the characters with me I nd so one toe maybe 97 98 We want from 1 to 3 so we can pass 13 So you to return for a B and C suite a little 97 98 99 as expected. Now let's look at another very important function for Mitt, so to use, for for my teen strings and converting numbers two strings, it was returns a copy of its first argument, so called for ministry, which, with each directive in that extremely placed way, formatted version off its course warning argument. And these directives are very similar to the sea printer function. And if you're not family, we directive, then it's, ah formation for much of the strength. So you have some stream than percent sign, and you can have your Li X. If yes, these values, you can have multiple of these within the same stream. And, ah, if we have to for months as specified here, then you need to pass dual use. Forced to lose substituted a second here on a new string will visitor. So let's see the example and it will clear So there these times for decimal integer export exoticism there for floating point, and it's for the strings and there are some other. But we'll only be focusing on these, for example, here we have to form into specifies person Indian personally, so it expects to this morning to you and we bust tend Kim. So the combined the string will be These will be replaced with these values. So 10 will come here and can't even come here. The new string will be X equal to 10. Why call to country? So let's try this. So I have made a tape for years. So you see that these former justice fires a replace waiter actual values, So this is the usual format. Similarly, if we write X after percent, then it will convert it to Exodus amount through the extradition. Television isn't 200 BC it Similarly it's zero x. It will not be converted because it's not proceeded very any for mattresses. For only this part is converted, so it's zero x on then 200 Superintendent C eight were capital. It's so season capital and then here float so it converts it to floor. So this is a very, very, very important function. You must tow, you know how to use it and no next to let's look at find So it's used to find a pattern in a given stream. It also returns the initial and final reasons off the pattern, and if it cannot find it. It will return will. So in hello world, we're trying to find the floor. So it's 1234 White Spaces six and the blues seven. So it finds the allure from 7 to 9. So it returns 79 in this case, the blue here we're trying to find This is not there. Smith returns. I knew just to confirm that it works. Let's see for its case in city or not returns nil. No, let's search fourth in the room. No trains. So its case institute, if you right the exact case than on little match for to turn Bendix And if it does not find eternal So it is not identity No. The next four cities Jesus, Jesus times for global substitution on it replaces all occurrences up Better ministry with another string again Music places does not mean that in the original street. Oh, I'm reiterating this point again and again because this is a place where people can make mistake. If you write a string or diesel, replace all the l it not so the new single really replace with dot, dot and same here. So this is not the original string is not tend and new a string is Oh, return Soto from the point. Let's severe equal toe had alert. No, if I write string Dart Jesu yeah, and the place a little bit north, then it's hello words or less a replaced, right? Not. And it also a dismally returns how many characters it actually substituted. Ah, but if you print a, it's a still L over the same old string. So the door is interesting. It's not changed because the strength her immutable. So I over you are understood the various functions and you should practice These functions are again and again so that you are very family with these and these air. In fact, there are the building blocks of anything you want to do with the strings a little. 20. Tables: Introduction: in this listen, we will start discussing on tables, which are one of the main for no mental blocks off floor programming language. These are the main and in fact, the only data structuring mechanism in lower. And we used tables to represent Henry's Certs Records and many other data structures in simple, uniform and efficient way. Shortly we will see examples of this, and it will be more clear for table in Lewis's in Cillian as a city. Very that means you have a northern off key and value. Do you feel Insert some number in tow table the automatically saying some index. But you can also assign a key and a value to, for example, heels. It may see equal to 20. That means a key named a veces there, and its value is 20. So it's X Laken associate it very it table is an area that accepts not only numbers as in this is but also in strings or any other value off the language, except that Neal is not accepted. Milk cannot be a key. Oh, you meeting Capdevila's dynamically located object programs, manipulate only their friends or co interest to them. You are never does a hidden copy or Christian off new table behind the scenes. So let's see some examples. So first fallout to create a table. So we clear tables by means off constructor expressing which is simply this too curly braces. So here we write equal to this so the table is created empty table and it's reference Is it different to their table? And now we say equal to X A case, um, normal variable. And then we write a K call to Tim and Cage ICS. So inside that table we have no exceeded key and it's for a loose Tim. So now is referring to this table the same table. But it's ah kee and value has taint. It has a new key will appear so is currently different to this. Now we're I th 20 equal to great. So we added another clean. So this was there any suitable and the aged 20 So 20 call to great no retest toe give a loop ears and he's a different to this. So they print a X. It will print 10. No, I guess I never your country tok andan. I print a K that is 20 so it will go and look for key 20. And it'll find great with this line. Will print great. And then we xs x x equal doing express mints or whatever is the value of fix inclement Italy one. So now this becomes X equal to 11 and can tickle toe Great. For now you'll be print IX. It should print 11 full its trade in our i d through reeled this empty. So you bring day, you will see that it's an empty table. No, right. Uh, ex? We are the key x with value tin and continue to values. Great. Who nor any different. You can see that it has one value early records and next again print A So you see, the same table now has to keep early Appears now. We printed a 20. Okay, call to 20 then A Okay, it prints minute. No, the root x It could do X. This one. So what it will do? It will go to the, uh, this a, uh, table. And it will find a key bit of values. X which is this? So using this, it will excess its value and assign a value of one more than earlier value. No, you haven t we will get a new table more quite table. This has become a living so on Laker strings were already knew string with created here It's just referring to the stable and were directly singing the table itself. Now let's look at what the same thing that whenever we're assigning a variable and we're assigning a table to it, it's just too referring to it. Same table who it table is always anonymous. There is no fixed relationship between a variable that holds the table and the table itself again empty table 10 insane to X so X equal to 10 Is it a friend to here? No, be equal to a So when we might be equal to it The ever very will be It is also different Tow this So now wearables are different The same table after this Expressen Now we try to be ex food. It will go to this table and find the key X and print its value So this will print them Now we write be executed 20 so it will go and modify its value to 20 to know the same table as the value 20 and be an air still referring to this same table. So this table No, no longer in just ah, no, we the modified ritual using B. But if you try to access it the same key using a well, uh, get 20. Because of what? I had a friend to the same table. No, I rate equal to nil. So this link is broken and only be referring to this. No, we're right to be called to new. So no, there is no reference to this table. So when the program has no more references to a table, the garbage collector will eventually lead the table and reach its memory. So let's try to do the same thing here. So we write equal to this empty table. No, it right. Ah, the other nicks. No different e We get this no ways and we equal to it. So if you print it, it's in this. You couldn't be. It's this So you see, boat are the same table from this value. No, uh, I tried to print will be. Thanks. Obviously will print him. No, I write B X equal to 50. So now if I print you see that even these modified will be more decorated using B. Believe me, excess, the Knicks, it's 50. So both are different to the same table. It be modified using be a also modify you be modified using it. We will be also modified, Andrea saying equal to nil. So is nil. But be still. Now it's angry culture nil. And now there is no reference to this table. So this was just a brief introduction to table. We're getting started into this. We will continue our discussion and for the lectures. 21. Table Indices: in the previous listen, we have seen that in lower tables. Are Esposito buried? So it stores Valukas burning toe a key or an index. So we will see what are there different ways we can in acceptable. So it's stable store values with different types of indexes, and it grows as needed to accommodate the new entry. Like global variables, Table feels a failure to nil when not initialized. So let's say we have initialized table and we tried to access this, so this was not initialized so to litter similar toe we had seen that is, there is a global wherever. Lex. It's not what does not exist, and we try to print. It will print will. And this is not a coincidence because you're stores are little revels in the form off table itself. So let's look at an example so first create addictive in its allies tables. If you're granted, it's empty. No, I absolutely losing key to it. So for well, you someone to fight i d Sector Valley off 10 times that value. So, uh, is eyes one? It's 10 if I use to its 20 and so until 50 and and and now If I drink, you can see it has sleep of allusion sated and you can access Uh, excessive using this a one Everyone is 10. It too is 20 and so on. No, I always had a three could do minus 100. Now if you printed you see that the this will lose changed. So this is the new table Onda. We can assign some different keys also like we are added some into GIs Nowhere. It's drinky and miss any values. Hello. It's not that it is drinking. Atalay says Still. Really you can have numeric value also. Now you see you test one more devalue and always I try to excessive this. It prints correctly. If I access a key piece is not here and there it will return. Well now let's see how to represent the structure using tables so they'll know We have used this kind of key notice in So for roadways, some string key or some variable or some intelligence but the same thing they can represent us writing a dot name is equal integrating me then the string name and it's not equivalent to his name. This is the example of this people season. So here it means some terrible name and it will get the value of that. It means a string name here, it means in a field name which is told in a formal string. So are the same thing from the previously we have missile ized and a table. Then instead of writing X equals toe Hello. We write your Texaco develops from these tour equivalent. But again, to reiterate my point, this is not equivalent to X. We create our techs or in string X the same. So if I print this, it will print Hello. If I bring this, it will trim. So this is equivalent to nearly and this is equivalent to X. I am repeating these points with our desire, the places where most commonly people make mistakes and a common mistake is toe think that we don't exit Same it X. It's not the case. Theodore Texas. Same as this a. Then the string value X literal air, not the variable Eso, for example. Here were the same X equal took 10. So X is the value. Why? Let's write it here than it really more clear. So right now is this really make it real. So no X created fresh table, so is empty now exceeds available records in the value No, wait, no X equal. 200. So what will be the key here inside the table? If I print a village, we X or military way? So the value the key will be. Why going X adjusting placeholder in this case, Mrs. During a value boy, you re right two senior. But he's way and narcotics because so this is the place of mistake or thinking that you adore Texas This and you know that's nexus you got. Wait, Utah takes So it's nil. So this is not Samos. This was a great exit Greens 100. You could write a Gortex prints meal drinking you don't way it's 100 which just seem that just so this you should always remember. Now we can index a table with different types so we can have all these three. Please were the first to just in teacher second string with a value of 10 and 30 string with values plus Tim. So these all our difference where everything nautical term article toe. We can have all of these three simultaneously. Why? He's holding a values, then. Okay, let's clear. So let's have equal to 10. They could to strengthen Kikwit to strangle less. 10. Uh, no, I write e could do. Didn't e j quarto 20 and a key? It could do 30. So, you see, this is their table. It has 10 strengthen on string plus 10. All three s keys. So you play access E. I get in. If I access energy and 20 k 30 if I accessing a number. Okay. So the number keys or this place? 10 string. If I convert it to number K, then it becomes 10. Same business? No. Let's is this equal to pain? Okay. And it is true. So this is string is converted to number, and it becomes 10. So no, it will access the key having in teacher Integral Keaton. So in this case, it will return them. And in teachers and folks do not have their a problem. Because we have already seen that if we compare these build article, for example, if we compare to equal to God, did you get through? Please be a sane to require too 100 and we excess a toe going toe. Then it will return under and not me. What for a string. It will remain so that floats on into years. There is no confusion because these voters Oh, tape number. So I hope you understood how gay village in next. And are you a boy doing these kind of settle mistakes in your coop? 22. Table Constructors: in any object oriented programming language. Constructors are used to construct objects in its allies and construct objects, and in Louviere Street that tables are kind off object. So in lieu, also, constructors are expressing that create any mysteries tables and there are There are different types of constructor, as in the case of other programming languages like C Plus plus, we have our report constructor, when we don't define our own constructor a default construct trees defined by the compiler . Similarly, there are different ways off defending constructor for tables. So one of the simplest one we have already seen this is Oh, just empty curly braces. So this initialize is it table so we can write a call to this So this create in your kitchen. So first, let's look at another matter. So this is simple metal on, and every constructor has to be, uh, constructor. Using this curly braces, I know there is a diesel engine list kind of constructor where we just put the values. So when we just put the value, they're not keys than to a lot of bad. Cleared Index's 123 So starting from one. But this certainly will be stored at the next one. So it's equivalent to rating days one equal to Sunday, these two equal to Monday and so on. So but here we are dispirited list on these insider or two generated by Lou. So when we print days four, it's 1234 So it will print Wednesday so we can try this. That's a very rate equal to are 10 2030 40 hip deep and rewrite a tree in this casing that it starts from one. So that third index it 30 it will print 30. So now let's look at other mentors. So this was the list like construction. Next look at the court like constructions. There we provide he as well as value. So here we're providing X is the key and 10 is the value. Then why is the key 20 the value? So it's equivalent orating. Yeah, X. You could took them. So they're not simple expert within the wilcox or single Chorzow existing or you're not X equal to 10 for the other different ways. An equivalent ways off. This mattered recorded late construction so you can create an empty or table, then are well used to it using the key or like this for the 1st 6% of every faster. Because you're straight away. Are telling lower that I want to elements the other Tookie's deal The hookers. Morning valued there is in the second Expressen. You're not filling in for that information. So for state constructs a table, the new ad a key. So it increases our changes the table. Then you're gonna Dickie. So the first method is the prefer one on would be faster in general, so we can try it. Another case. So is here. You can access it using this this but not this eso this 50 comes home. Well, because I think we're not cleared the environment from where Clear? So excellent earlier way. So this when we right e x, it takes the value of X which is very and then which is this? No thanks. Could you, um we knew this still really this But now with the right X, it will be well now let's look at the mixed case. We'll be mixed list as religion records in tax. So here you can see these are the record, Syntex because you provide key as a lot of value. And these are the list syntax. But they're just resulting about this You cannot seem police salto. But just to convey the message that you can have on Mr Tables within tables. So this itself in the table. So this table has cookies. Excellent way holding villages. Ou This table also has Tookie's similarly, here and here who we haven't restrictive. A little toe the business Two tables can reuse toe define complex structures they will inside table And since leisure list initial Edison, this will get their next over. 123 and four So deal harder. He's internally used for these values. And here we are explicitly assigning the keys and one had in a strict table, So does it ever table? So this will be accessory this discipline 20 Similarly, 30 we can access using this. What is the key for? Hello? Because we had added using list. So it will be acting next one. So this is a long and this table will react in next to true with me. Try to drink toe. We will get their table. Andi, it may want individual. We lose. We will trait not X, which is 1 50 on Norway will be X rays. Easy. No, let's look at a very general constructor. So these earlier two methods had some limitations we cannot initialize fills with negative . In. This is Norbit stringing Mrs Hope. Like, uh if you're right, a cortical. And you want some two story next minus one, so you will write. If you write like this, it will be better if you had Index, you don't read her. So the Morgan decrease toe includes everything in square resistant key. So you're gonna try to minus one cortical 10 and you can also write like this minus one in the square record and go in this. So if you're 20 you will see that minus one has very often and two as values 30 that these you cannot do using earlier two meters the list meter and the record minted. You cannot do these and similarly let's so you have to define keys l operators than you can write it in this square races and the usual way of writing the value you can even write express Since their eyes 23 plus zero is 20. I place him honest went even so it really evaluate within this square record. And some were Lillis of what? The list style and record stayed artists facilities in the last one the Morgan Rixon text way Because in record, like right like this. So using this generally I think key and value we can write you Tess X equal to hear Michael Digital. Between this, a square record. Similarly, If you're using list like constructor, then still you can write. This will get in next one. This really getting next to on the celebrating next three So you can explicitly, right? 1213 So this method can are do the task of mortal does. 23. Arrays, Lists and Sequences: Let's see how we can represent a really store sequences, using tables in lower. So in order to represent it as a literalist with represented table with in teacher keys, we had already seen that if we initialize table in the list, former like 10 2030 the keys are implicitly want to entry so we can exist in using human. Similarly, you don't believe US 20 and so on. So this is similar to a raise in other languages. But with one difference back here, indexes starts from one, and when we're mentally, uh, doing it with creating an empty list and then herding keys to it, we should add in sequence starting from one. And nor do Olivia a lot to, uh, but any index. But we should start with one, so there is neither a nor and need to declare this side of the list just initialize elements we need. For example, in this case, the initial is it with five elements. So it will know contain who? 2468 and 10 because we're playing with two. So, as I told early, it is convincing to start the next from one. So that's a beauty aimed list. Now you see the list is this re access 83 survivors. Six. Similarly, a four. Do you fly? If the ecstasy of six, it will give Neil because it's strongly wanted to fight. So this seems pretty straightforward on there is a need for a length of list. Most often. So how do we find the length off list? So you see that this we can use this operator, find the length rider. This is simple. Like in this case, there are no holes in it. What I mean by holes. Let's say I write in three equal to me. No. You see, this is are the new state off list a test for elements. And we had already said that in lower setting A very well to nail it, same as the absence of their Very that means statistical well into the case where the very well did not take this tackle. Uh, so if we know for England, it will still return for you five, but now actually test four elements. One is real. But if I said let's 1/5 element me. So there is no difference here. I certain third element to kneel here. I'm starting fifth element, Tony. It has five elements. I'm a lot to do right now. If you print a you see that 15 20 not so displayed a call. So, uh, if no every day it sold for so you can see the difference If I said third element to new its arguments unchanged. If I said the 51 to nil it say it's citing it So although we can use this operator to get the length, But if the list has holes in it that that idiot has some real values in between and then followed racism, uh, other values salmon. I am talking about the case where you have some interior in teacher keys. Sochi one. Some value, even he to Valerie two and so on. Then some mill value followed way. Some indeed a value, Let's say 20. So if you have integral keys afternoon, then it really include that meal also. But if Neil is in the end off the integral keys, it will return the land until that point. So that's where we cannot use this operator very level in the case off list with hold on the lists, which do not have any home we called. Oh, there's sequence. We have a special name for their called sequins and, uh so that for the list of is all this problem using keeping the value in some custom variable. So let's make it mill Clear it. So we had another custom feeling it Let's in In many programmes he was in for this purpose for initial excellent with zero So this is the list Onda we can in certain element fruit e equal to place off my turned we also incremental And so whenever we had an element we can incriminate the length And when we re set to the value two nil in between which will create holes we really clement them so it will be much more level. No, this is the list. So if they want to know the lentil simply restaurant in Norton now, that problem in north raids so initially it'll be Seamus this Okay, But I favour no way Sit three new so you can define a wrapper function toe Remove element in with you You will assign mill to it And also a lot Any could to a door and minus one. No, if you printed or Tim it's for. And if you drink this, it will still be fight. So in this way you can handle the case off land in the case off lists because this operator will not work as you mingle. List has some holes in it. Now let's talk over the sequences. So I had said earlier this year the lists without whole. So this means there take table where the positive numeric keys comprises. Set one toe in for some in that is any. Keep it a value. New is not in the table and in particular table with no numeric keys. Each sequence. Which length? Deal. So let's try out of this. So let's say we have a new table and we will not have any new Ricky's declared some string cheese exit quarto. One. Wait. He could school on 1/3 t injured. It could tree. So here we have notated. And in your key three Vaid, uh, bring the length on me. It's do so. This is still a sequence, but wetland zero as there are no holes in it. So this is the meaning off this sequence. Wetland zero. No name Ricky's and no in the case of sequence dys operator can be used to reliably. For example, if we have a sequence e and we want to print all elements, we can I trade from one toe, leant off new brickies and then just bring this using that, uh, numerically, similarly feel you want to a pen, a value we to the end of the sequence. We can find the length of this and then plus one and that one next we will have the value. 24. Table Traversal: I know that we know about the different ways in which became store data in the table. It's time to look how we can tell us. The table in particular. We will look at three different way of traversing a table so we can traverse all key value pairs in a table with Versailles. Traitor. So let's see an example of this. Let's say we have a table D and you tell value then and reared a function bring digit function that we have already used. Then we had some value in the form of key value. And here we averted a couple of them in the form of a list and then another key and another value Busy over table. You can see their table and let's I treated you, Zynga. He s a traitor who gave me in. Here's how it will return here. So it really is saying Okay. Me. So this prince one, then 10. Because for 10. The keys one then too. This function Onda. Then these were explicitly assigned keys toe. These will retain the keys that were assigned to them. But you see, that daughter is changed. So we had added X equal total before K called Hello. But here you can see K call to help and then x equal total. So this is the problem here. Due to the way Lou Increments tables the order that elements appear in the traverse, it is undefined. The same program can produce different orders each time it trance. Now let's look at another way of traversing it. The 2nd 1 is very similar to the 1st 1 and this time we use by piers a traitor. So let's take an example of this this time levels no, no cleared the table in the form of socialist, then the same values print freedom and hello. So in this case, we're not adding any kids, so the keys will be defined there. 123 and four. No, let's I treat to it. But and instead here with you lose I piers and you see here the it drugging Prince 10 than the consummate Identical, then hello. In this case, the order is maintained. So in this case, you insured order because we had added in the foremost list. So they this is there a sign that 123 and four in this case for the first to the industry were defined. But the rest, uh, the TV acted. The ordering is not there or drinking only for numerous keys. Eso if three try to run are the same method on another table. Let's it earlier one. Let's go, Pete. Next ever table becomes this. No, we want to used I Pierce. Then we see that only the new brickies are printed. So I pairs will only work for Munich case And these are not wintered here the last rays using numeric for and we will traverse it for do this for sequences because for sequence, we know that Oh, this operative is really defined the lento predators and we will use the numeric for So in this case, you see neither the list and it has He's 123 And for so when we printed Let's do that. Let's clear it. And this is the other people for, uh, want to let off this table really bring the key. In this case, I and deal fly. So this is to lure. It's works Fine. This will return four and even is this Tito print? The tree is still And last time I will be for the let off this ritually help. So again, if you had a few key Stoute, this will not work. For example, let's say we aired one key Kevin Equal toe border No, if the print t x four So if we printed using this, it will not bring the last one. Similarly, if they printed using I appears again, it will miss the last one. So these two metres work on leaving. We have numeric keys. 25. Table Library: Dave Delivery or first, several useful functions. Toe right over lists and sequences, the first important from finished table, not insert. And it's very clear. Felman name that it inserts an element. So there are different ways of calling an insert when we give it to prison on it will insert element in a given position off a sequence and moving up the elements. Toto Open space So it be insert anything in with me. Everything will be served. Two tours, right? For example, Let's ever table ISTEA 10 2030 and Record table, not insert T 1 15 apartments in 3rd 15 Actually someone, and we know that this is the police in 112 and three so it will insert 15. Actually send one. Everything else will. A suspicion will in creep Eben. So No. 10 which really right one becomes comes out of prison to similarly 20 from 2 to 3 and 30 from 3 to 4 and 15. The new element comes that reason one that story here and when we call insert adult a prison, it in sort of element in the last question of the sequins sewn of element will removed Onley. It will be upended in there and no decision. Another function to remove, which is equivalent off that insert So it removes and return the element from the given prison. In a sequence moving subsequent elements down to fill the gap for here again, you can call remove it up, reason to remove government so it be removed. This 20 Let's see, then 30 will come here to fill the reason, and when we call it without a reason, it will remove the last element from the sequence. Now, with these two off functions in certain remove, you can influence some of the basic data structures Lakers stacks use and early in vehicles . So each of them has the notional using element and whopping element in the stack. Because at the top, what we can say that we put in the end of the list and we bought also from the end of the list in q B. Uh, who stores learned and what from the beginning. So what a relevant came first similar Linda Belinda Cube. You can push to Putin's and welcome to both dance so toe influence the US methods you can use. They will not insert, but Cooper arguments depending on whether you're implanting stack from where you want to who spoke. Zins is in fact, in the end, for struck and killed. For that thing, you can use table, not remove with appropriate perimeters, so you should try to implement Oh, these three data structures using that to, ah, function that you learn. They will also look at another function table, not move. But before that, let's trailed some examples. Let's say we have a table. A 40 1234 So when we printed this is the table. Let's take an example of concert so we will use terror. Lord insert. Let's call it without reason. Tripti. Now you could print you'd see their UPS company and because we did not disperse for a position. No, let's insert with a reason T and we want to insert 1/3 reason 100. So what sort without one toe, these prisons will be on our turf and we want to insert this a three. So this will calm a tree. So 1 200 everything else most 1 203 4 cup tea. You know, if you bring this, we get the value had expected. No, Let's removed, they told her. Returns the removed element. So you see, we call it with your prisons would remove the last element and it returned 50. No, let's school with tourism to return to. And now the table is too removed here and 50 were removed in the beginning. So it's 103 and four. Now let's look at the last metal table dot Move. It was newly introduced in Lord five tree and it moves element in the table and it also can be called in different ways. The first turn, the simple method is to call table, not move. So this is the table A. This is the starting police, um, starting index inclusive, including this index. And this is the end and extra cost and an index and a move it pretty 70. So let's look at an example, and it will reward clear. So I'm worried that it will not work in console. We need to use our gold because five tree features are not working in my counsel. So let's create a table here. 123 Full sleep. Onda, we want to move all elements towards the right that city. I want to move all elements from 1 to 5. One reason. Right? Right table. Lord, move. So this is Ah, What I'm doing is one of the ways off implementing inserting in the beginning. So to insert in the beginning, I have to sift everything to the right. So let's sift everything toe right before you went in 13 using the new from several. I would write a from Collison first, what is in his one last season, this bone symbol T assembly and then listen to Because, no, everything will be coming to the second prison and then the first let's print all elements . Uh, so for K V in years Mm, No. Bring kay and read and in and after moving developments, let's print again. So what will happen? This move copies elements so it will not remove this element. So 12345 will be sifted towards the feet and this one will be Socrates and one will be effectively empty. So whatever words that prison one of you will still him in there, so one will be repeated. So there is some people. So you see your earlier It was one question 112345 But this was in the beginning. Now 12345 regiments If trip. So one comes out of prison to attack police and one with which was earlier occupied, where one is still lives. So one is repeated. No, I can insert some new element to it. So? So we can write a one call a tow in general. So you see, we have inserted diesel in the beginning on everything else if to torster. Right. So let's say I want to, uh, remove the first element. So what we will do? In that case, let's come and talk misting, misting. So I'm taking from second reason. So this is the original table. I take this part and sift everything to the left. So so too will come to 13 here for here, and five will come here on blast Prison will be left with you re fight so we can manually said that Goodwill. So first, let's try to run this. I come introducing the vital comment. Okay, so this was their lives. Now everything has moved up. So 23455 is repeated. So in learned we can do. Yeah, and the last element. So no. Between 2345 and the first television that everyone is gone So you can use this toe delete element, the first element, and you can use moving this ridge to insert in the beginning. Now, there is another way of calling, which is with extra optional perimeter. It is a table. So earlier we were passing the first reason last reason and new prison where we're passing a table also. So for example, in this case, we want all elements from Mr A and, uh, mostly to no, we do this with new table empty table, so it will return a copy of the original list my copping all elements. So if we're right here to, then it will copy all elements except first. And similarly, here we take all the elements off this tea and this means one police in more than the So this has me dinner stir last index. So that last one is the at the starting at the end, off list to be to upend everything from the state to list Be So let's try this example. It would be interesting. So, uh, let's comment out over lyrical. For we have a list. 1234 40 and we have another list licks and me. It's 10 2030. So first let's try a returning a value, Let's see called table Lord. Hey, uh, and let's run it. So we have corporate everything from here toe this list him. This will be returned and copied to see and we're print Inder list. See who we see that whatever was in the sprinter here. No, let's try ever second case which was copying everything today and deathless to be so We will arrange a table Lord move. Then you won. And now we will again print the new me and let's come into top. So be warned earlier. 10 2030. Now we have upended 123452 Then So this is 10 2031 2345 26. Functions: in this. Listen, we will start our discussion on functions in lower functions. Provide the main mechanism for staff Jackson off statements and expressions in law. And there can be two days off calling a function. So one will be we call the function toe, carry out a specific task which will not return any value but carry out some specific task . And this is also scored a procedure or subroutine in some other languages. And in this case, we will call functional statements, whereas there can be other way of calling a function were it computes the value No, someone mathematical calculation and returns the value in this case, we will call The function is expressing. For example, In this case, uh, this function, uh, carry out some specific tres printing to the concern, whereas in this case, sign it calculates the sign and return the value. Similar recourse. And then this X percentage evaluated and assigned to a so the other different ways we can call it. Now let's see. The same takes off calling a function. So first list off arguments in closed in parentis is this denotes the call. So in this example, you see there printed your function. We have more defend its older do defined. And here we have passed two arguments and these are enclosed in parenthesis. So this general stuff thanks and call. So this is your called so, uh, from one parent to and depending on how many paramilitarism function can take and we will get to see that we are not born to yet We call that many parameters the way it was defined . We can add more or less parameters also in Luke and and elect. So if the call has even know arguments, we still must rate. And until list function, F does not take any argument than in order to call it, you need to pass and empty Parent is. But there is a special case. We're this is optional. Leave the funks function artist single argument and that are going to Jeter literally string or able constructor than the parent is are optional. For example, in print, if you want to call with a stream, then you can write print space. Hello world, which would be equivalent to writing print and within parent is and the next was table constructors. So you see a table construct area. Similarly empty constrictor in both cases and if you're for instance, have really types of funds in here, so did Jerry curl into including them in parenthesis? But it's better to wear. Parent is all the time just to avoid any confusion. And the Lua program can use functions defined Botin lure and in sea or in any other programming languages by the host application. And we generally I lots off functions in C due to perform incisions. And also there are many more operating system specific functions which are available in C but not clean lower. So we can write functions using does in C and then call it from blue and under the originator already tourist performance. Now let's see the final part, which is defining a function. So any function consistent these three parts one is the name. So this is the name, then we have perimeters. So in this killed response antics to perimeters, it can be different, or it can be the risible and then the mean body of the function. We're reside that to logic so and we can call a function return number cargo in different from the number of parameters so generally very people makes the term, but you write parameters while defining the functions with these are the parameters, and when you call, add lets it 10 and 20. So these are the arguments, so you can call function with less than what it was defined. So it's expected to take to manipulate one than Louisville. Handle it, it will add. It will treat it like this so it will treat it like 10 common ill. So if you call, provided less number of arguments. Louisville A pen meals in there. People write more number of arguments if you write 10 20 and 30 renewable, converted toe and 10 20 it will discard the extract parameters. So these are the two days we will handle that. No, let's see example of whatever we have learnt so that we get an idea off a little defining function. Our funks. Any yard which will take two parameters A and B and the suit ended the body of function of it, and and then let's define a local very well, some and insulated with Jiro. And then we will write some call to a plus me, and then we will return the sun. So this is a very simple function. And in then we would call the function Let's run it and you see that it can gratify Preston is 15. Oh no, to illustrate the point that you can add even less perimeters or more parameters. So first, let's take the example of more arguments for you didn't 2030. So I said that in case of extra arguments, it will discard the extraordinary. From then, so is he. Still, it's 15. And now let's see the case off lesser loons. So let's say we don't bus on this, but in this case, we need toe make our court in such a way that it handles such cases. And we also called that before perimeters. Is it somebody? The plan could does not value to a particular perimeter. You saw their default values in some function. It will not erode. For example, in the case of print, let's take the example of the attendant. So what this function does is in just princeling to values, and there's nothing okay , so unexpected. Similar. This is not the way to comment in lower. So you see, in the first case, it prints five nil because you took a trip should be isn't will then be possible. Want to state printer oneto? Then we passed. Want to treat food, but expects only do so. It will discard three and four and just print one toe. No, let's look at our before perimeters because sometimes you may need to define default values for the parameters. In this simply case, it was not required because, uh, if it's new, then also it's printed. But in this case hard from Cem Bey's Neil that you that has passed less perimeters, then if you try to wear, need win into your it will to Lennar. So let's see any example of this. Let's coming toward this function. We don't need it. So you see, it's fine, but if you uncommon this where we're passing less perimeters, we get an editor. So we need to handle that case so we can rate it as a and big or Joe. So this we have already seen that if for expressing evaluates to true, then it will take this one if you value it to force them anything after or we had already seen in never use lectures. If you want remember, Plea was not really a gin and similarly for B. Now, if any of one or both of these values are absent, it will take us. Do you and no, Let's remember, called again to see here for his past. But be is not cost, so it don't teach be as deal and it will add Fight plus zero is potentially will take the value of me. In this case, both are present. So, Captain, in this case, it both verbally and on it will discard extra value. So again 15 And also for the sake of completeness head, you know perimeters, we don't pass anything in this case. ButI and beer Jiro and some sort of Jiro. So that was a brief introduction to functions. We will continue our discussion on things and symbols for their videos. 27. Multiple results: in this listen, we will see quite unconvincing, but they're very handy, featuring lower pitches. Thank cells can return multiple values. For example, we have already seen String Northwind, and we saw that this string NorthPoint's tries to look it a pattern in a string. So this function, if it finds the pattern it will return to index, is the index off the character where the matter starts and the other one very hands and a Motorola sandwich loves the program to get go the reels in this case. So, for example, string their point here we want to find lower and again it's case in city, so kept a little, so it finds it here. If it does not render, it, will return me So 12345 spaces, the six and a little unsettled and it handling. So you will return the first character. It is seven for Student X and then the last two index, which is mine and indexes starts from one we have already seen. So here dysfunction find returns two values which are captured there. No, we can also write our own functions and we can return also multiple values. So we have to list all the values With comma separated, we come after their return cured. For example. Let's say we want to define the functional max or maximum to find element, which is maximum in a given sequence. And we want you to find the maximum value as well s the location they next verity located in that sequence. So let's see it in our cold. So we'll are defined the function we are seeing or to define rewrite the function word than the name of the function and all the perimeters in this case ages sequence. So we will pass away and going forward. Forget to close your songs in with end. So let's store Max Index is one. So we wiliness allergic with this Onda Maxwell us. So we have initialized as the first index of the maximum and the first value is the maximum . So we will I trade through the dart sequins and whenever we find any value which is more than the current maximum, we will update the current maximum value and the index so far I could do 12 lentil sequence blue on finally revealed return board the values it's up to you how we want to order, whether you want to return the value first or the interest. I will return the value first week or disease maximum. So we want the maximum value. And also it is merely the location. And now let's try to call this. So right went maximum Uh, twenties 10. 15 Couldn't deflate 24. So in this case, it should return 25 onder inexorably 1234 Let's try and run it So easy. Jitters 25 grand for which is as expected. Ah, no. When, uh, the function of the number off values that I return again it will depend on the context where the function is called. So if it's called in the context where no perimeters a required and we want just a statement, then those parameters maybe not, visitor, the function body will execute if we are calling this function in your situation where we want one perimeter but we're returning to than the last one blew discarded. So let's see an example of their castle. So let's define ah a few functions. Hong's food usual and its name is You will be good. It will not return anything and similarly defined Multiple versions full on will return one William. Then food will return to values. Hey, Herm, Me So we have three functions one return no value Wonder turn one value on the other one Returning to will use and we try to exploit He could do so do and then, uh or we really find Michael's values. And no, we have excellent equal does who it's called a text three call it takes two and then export Explain, take six. So what do you expect here from? To build attorney and be so x one x two old those values Little explained all other values Print text three Next. I didn't expose explain. And next six So x over next to the expected to be a be a little too right Our guest answer what we get on X trees A and B will be discarded so the extreme should be a x four Is this value 50 Onda? We called food politicians toward values To explain his A next six is me. No, Let's of an urgency, Yves, Our estimate matters like usual. So this 25 4 is Formula our leaders And then here we get to gave me and this Will you ever answer then a and then 50 Amy. And also let's create who? Even y two and we will call and then bring Well, I will try to. So in this case, pool would return just one value so white will get really off. Millie. So this is print earlier? 28. Variadic Functions: in this. Listen, we will study work. Very. Your dick functions in you. Uh So what are very conscience? Function can be very Riddick if it can receive a variable number off arguments. For example, we have already seen a print function where we can pass different parameters. So you'll be right print one it will print. One is where I print one toe. It will print one toe. So let's try it once. So that rumor, we can't even trade in control. I plus he to Then Then it prints a do. Similarly, you can pass many more functions and it will print all of them so that this function has the capability to take wherever number of arguments. It's not redefined that it will take 12 or three or in simple functions, very free pass extra perimeters are do order ignored. That is not the case here. None of the perimeter set ignored all of the year printer so printed any ample verily functions Onda. Now let's define our room a very constant where the target is that we define a custom heart function and whatever number off will use. We pass it should return the some of that. So let's try to define that and well, when dealing with very different since we passed this trip a lot in the perimeters while defining the function. So we'll initialize the sun with zero then. And here you see again, I am using tip a lot, but very small, different between these two super locks Here, dear Bargains looked hiss this reading the curly braces. If we're using this trip a lot, it's it acts as an express. Um, on we call this Where are the express? Um, no, we will update this, um, and finally we will to return the some. So we're hydrating toe all the values passed a year. So this trip a lot within this car, Liberace is your weathered express, isn't it? Behaves like multiple return functions. So this expressing whatever dis completing is an expressive. So this results in in in a list with all the collected argument and the three dots in a perimeter. It indicates that the function is very weak and when we call it with this war collects all arguments internally. So whatever argument is passed to it, it will collect it. And these collected arguments are called extra women's. So we I trade through this list and we updated the value of some and had the current value to it. And finally we return it. And here we are not using this key so well, you'd under school. And now let's are trying some a gamble on this function that we just defined. Let Syria 10 20 30 deem so in this case, you to return. 0 30 plus 30 60 and 75. So let's turn it to receive to turn 75. No, we will remove the last argument No, to return 60. And it does. So we have just created our own custom functions, which can take very well number of arguments and in this case, it will not ignore any of the arguments, as in the case off all functions with steak fixed number of arguments. If you have extra perimeters desire, ignore, but tell me you're not ignored. So if you remember, this was what we call, huh? Extra might have been something to function. And it's completing from curly braces within the car. Liberace is We called as expressing and we call it s we're are expressing Now that we know about how the use of these triple lots We can use these to emulate the usual perimeter passing mechanism in blue. So in general, we defined functions like this. We also are defined the perimeters that to expect in this case, it expects state that images. So what happens? You there? 50 plus more number of parameters. Let's every part five parameters. Then it will assign one to a Toby and five to see, and these six center on will be signaled. So we have to emulate this behavior. So here we pass. Define it as two per lord and we can then keep these exact same variable CBC, and we will assign these triple lords to this. So this stupid lord will return a list off 1234567 But only the 1st 3 billion saying to ABC and the last to be ignored and the rest of the function body they mean logic will remain the same because these variable names are also seem so in this Lee, we have a military, these two. Now, let's look at an example of this, which is Table Lord back from him. So this function receives any number of Hartmann's and return a new table with Holy Tournament. Just like this expression, where are we expressing which we saw? But there's one difference which makes thes two different, so they're not exactly equal, But they're similar, Uh, in that stable or pack also has this table return by Tabled Attack also has an extracted which is in and you do not the total number of arguments. For example, I there's defined a function known ills and again here to plot very differences known ills . And here the object is that if we pass a list off arguments, then if any of the argument is nil, then we will return us false regard. It's known ills. So there should be no no if there is no need little return. True other rifles. Ah, so here we are using our Goodhart and the new field that we just introduced. This is automatically returned by this table back and we compare for each value. And if any values mill mr to return from there, return falls on Def were reason and off this Onda we did not find any such value than we will return True. So if we have to treat nil. It's return falls because we have We're passing meal is free. Pass to three. Then it will return. True is a person empty. Then what? It's written. Let's look at what this in our i d. So far I could 212 arse Norton way. We need toured. - No . So, first, let's trade way ourselves. Then we will matter answers in this case, Clearly the reunion So too soon return falls. In this case, it should return true with their earnings. In this case, it's empty. So none of these journals we got Hardy and will be geo, and it will not enter this look and clear return True. And in this case, it will falls because we're passing Lex musically. So there is some mirror seven D flame. You have no not to use table alert back. So it returns False, true true falls, which is a memory of unexpected good. And, uh, you would have been a using T without give a lot back and instead try using this and then see what happens. Obviously, you cannot use this. Norton goes this three well north Devon 29. table.unpack function: in this. Listen, we will see Table not unpacked from it is special function with multiple terms. We have already seen functions which return multiple values. It takes a list. The organ past two. It is listed in returns as you're told, elements from the list. Oh, so it's reverse off table lot back function which we saw in the previous video while it's turning very erratic functions. For example, if you write print and you can pass multiple really street like 10 20 so you can possible it will will use any prints 10 2030 whatever you pass. So, uh, if you're right, they were Lord on back. And here you see your list. Then it will are treated like that in this print and table not on back will individually separate or these elements, so it will be equal into calling print 10. Calmer 20. Come on. 30 and stirred off Unpacking the list. Similarly, if you have two very well, CNB and you do impact in 2030 for 10 will be assigned to a frontier Reassigned Toby and this started discarded Oh, we have 13 a function A string door plane which finds a pattern and also returns. Uh, the police, um, in the string, if it planes in a string for a young player. Hello is the string in which we want to find the pattern and Eliza better so it will return . This is 12 three full played. So the idea is not to understand how sting not final works, but instead you see their string don't find takes two arguments. One is yellow, one is the string and second is the pattern, so you can create a list out of that full list e. It holds hello, my string as a lender factor. And wherever you were calling passing these really you can pass table Lord on back in that our list itself, now usually tailored and pack, uses the length operator to know how many elements to return. So it works on Liam Cooper sequences because until now you have not been passing any other element. You're just passing listed, and based on that, it reducing the length and returning the individual elements. But do you can provide explicit limits edible, For example, here this is a list. This is a list turn were passing the start and end limits 2 to 3. So their decision one, this is two. This is 34 So instead of returning the all the four elements, it will just return to Elif from start to end because they start to in each toe. If it therefore go to fold into that Written, When did the defendant in this case it will it on just two and three photo three. That is Monday he was dead so you can pass limit cereal with this function. So no. Based on whatever we have learned so far, there's a exercise for you to implement and back through this unpacked function is order digital in C eso. The task is to write it in lieu of using three Kherson. Suppose the video for some time and when you already get back, because I will provide the solution for this. OK, now let's look at the solution. So we have to define function on back and it will take 03 year events. One is the list. We'll call it Ellis than the start index and ending legs. So it's These indexes are not given. Then you have to a gym, their default values ho unpack works if you don't give the limits. You do know start from last element and goes to the last element. So is so a secret to s R one. So if this is there, Yes. Will you take him if this is not there one. Were you taking and similarly equal to me? Well left off the list sequence and know what we will do with evil ray teeth. Oh, start is Liston hair. And then what we will do We will call the same function. We will return the first will you notice and call The same function on remaining in this is and index will remain the same. So, for example, it will start with Let's see, we have some string Ah, the air list 1234 And, uh, we don't want anything. Let's then this will you want to treat home start will be one and will be for so start is less than And so it will return One coma on a peppercorn going to full And this inter will come here It is an evil remain two and four and it will return to and call unpack on three and four and soon So let's straight on a regional first, so it returns 123 but not true. Okay, so it's a really less than equal Toby got if vote Ari cold and we return that value as well . Boat and starting. This is a very inclusive Now let's try passing some value to it. Let's go on from toe to fool. So to return to 34 on No, let's say toe Country of unit works we want to three and you should not confuse with these with Dangerous is neither the values so want to treat to return. 10 2030. So it seems it works as expected. No, let's try. Passing somewhere Lou Bridges start is more than and so this is an invalid value from 4 to 3. This so it will not print anything. 30. Input/Output: in this. Listen, we will start discussing ord input output calories in lower Who input our deliveries. Are you libraries in sort or forced to types of models for five minute place in one is simple model and the second is complete area model. And now we will study about both of these in other for their videos, but could ever give an overview of the Are you level. So its simple modern had models at June se currently input and current or profiles. So you input your file using a Syntex visual. See shortly So you pedophile and you perform 13 or prisons read, write on this simple model legumes that you are working on the current input and current or could files and him and it's a your person operate on those files. So there is some implicit agents in here. On the other hand, the complete model huges explicit file handles So whatever read, write or other operations that are possible and file that you're performing, you do on the side Landel. So let's see. If is the file ended, then you perform that operation on that handle itself. But in simple model, we don't do that eso this complete tell you model a toxin objector into the style that defines Although prisons has methods on file handles Oh, the Ulivieri books all its function in our your table and we will see example of this. For example, I your daughter hope in your daughter you dance on So first let's sisterly work opening the file This will be a applicable towboat simple model as well as the complete model. So a simple Fiallo person by looking no prison uses the following statement three right by your daughter open and provided by the training him and more. And this will return if I landed. So what are the different modes here? Oh, I have listed on a little different modes So it can be our so one example could really you're talking Let's say our file name is distant or Kluwer So we will write destined or Kluwer and in the mold we will go a read So this is just one more s o this is read only more R stands for read only mode and is there deport more? We're an existing for this weapon Then another one isn't a blue The blue fourth writing ever more about overwrites. Existing fire creates a new friend. If you have returned something to if I lost something that already exist in a file some few lines 1234 And you open it in right mood and then write something to the file, then to lower right everything, and it will start from scratch. This is very a penny more comes into picture. So if you don't want oh, you're existing data on start writing from are the end of the line. So it wasn't until this point through. Now it will right here on words and not override their distinct it for 10 more Opens the files or creating you filed for a pending, so it will upended it are not override. Similarly are pluses. Um, more were read and write more foreign existing file. Similarly, the blue pluses transfer all existing detail. Your vocal if I ologists or new file is created victory drink permissions then we have a plus also, which means a panel with three more than ever that weapons and existing file or creates and new fight toe leader there different most man In the further next videos, we will start discussing or simple your model and completely more 31. Simple I/O model: in this lesson we will study Were the simple Are you model off? Ah, you like really? So if you remember this late this late from our previous listen are you library for fighting and increasing is categorized into simple are your model and complete tell you model And in simple modern current input and current output files are assumed and your persons are performed using you're not something X functions so either you to lividity 14 Put our extreme or we will set the import or are to be the handle of some file and whatever we perform using this your dark function will return on that fight whereas in the complete model we explicitly call the functions on the file handle So in this selectivity will focus on the simple you modern. So these are these used implicit trail descriptors that is used the standard input output marks are using a single in book are good fighters And here we will use our your not start Mitchard's so let's look at any jump in So I will be our reading or writing to this lower test Not nothing from that said, If you lines to it, I ever added two lanes. Now, ever open this historical or for reading first, And then we will also see or to right to that. So first, look creative by London, we will call it file Equal toe. You're not open. And then in the filing, we will pass, destroyed or clue, and we will open it for reading. So once we have open, we will set their default input fight. We can also skip this. In that case, it will read from the standard in in pristine. We will need to interfere under control your output with No. But for now, let's set the default input with that file. Whatever we just opened. And then we will bring toe one line from the face. Are your doctor lied? We will also see this. Ah, you know, reading detail here. We're not passing any more dizzy. Optional. We will see what are the different modes. So if we don't pass anything in there, you don't read, it will lead one line from the current reason to uh oh, You see that I'm not using any file and you're president despite handled. But instead we are using our you don't read. And now we will close this file. We need to pass the handle. And now let's run it. So we added these two lines, so it will return the first plane and you see your line one off soil. No, let's Ah, open it forth. A pending also. So depending the it's in religion and we will rightto this fine. Or we need to set the art book saying very said there in no other way, it will display whatever we are writing to hurt our window and not to the file. And finally, we need to close this angry. No, you're not. Truth know what will happen. It will bring the first line earlier on from here onwards, it will upend one line. So here you see, we have just two lane on our cursory here at the third line. So, uh, after joining this program, this would have one extra line here in there. Let's run it. So it prints this to the article and then here you see new line of project to the files and New Line because we had heard this new line also, if there's a need once more and once more now you see three lines up under to it. No, let's see what happens when we commander this include So it will not read from the file. But it will prompt us to enter something value from the standard and put a stream. It's in really livable coming toward this also, so it will not right to the fight, but displayed to the control. Let's earning So this is waiting for this line not from failed but ourselves. We will enter uh, entered Froome control and no in displays that whatever you trade on this new line appended to files is in fact display there so you can see it's still three. What will earlier If we don't meet again and again this is displayed. There's and still Air Street. So that way we can set the input and output extremes to file. No, let's see. Ah, some of the different words with weekend interpret read so these other different her more that we can use retread one needs start a. So this means you can also write a terrorist are all and you should work. It returns all the countries of the file from the current five prison Then we have in this is a small hill to reach the line from the current file prison and moves quite prison toe the next line and star in his reads from the current file prison and returns the number if adjust their defile prison off new. So if you pass this, if we're the current question, there is a number two. It will return that otherwise Neil and then we have number. Were you you will person. Will you like reading, then? Are it so it will read it, but it's from the specified please in the fog. So let's straight. So these air tree will you can trade. I will give some example of this star and it may not be dark tribute for Let's coming toward this defaulting and stood We will print start him So currently, footprint mill Because and we will also coming toward this we will not be writing anything to this. Let's come in toward the whole right or prison. So currently it will not find any number. So it will print mill so you can see it. Prints meal. Oh no. We will add some numbers to it. 10 2030 40. So we have rented, entered four numbers do in the first line. One and one in the second enter So but two year asking it to just ah read one number. So it will just treat the first number 10. No, If you want to read more numbers, we will enter mortal ills. In this case, we are entering tree. So it will re 10 2030 10 2030 What? Let's say here, be inter any string and not number. Then it will return 10. Continue on it will not move forward even if we air for if we want to read even four numbers Still it will read 10. 20. Then you did not find Cem Mil no matter how many and you enter so this can be very useful. When you are reading some file containing numbers, you know that there will be our 56 numbers in each line. 10 2030 40 50 60 so on And you may want to find what is the minimum moth e true so you can read three lines. Find them in move to next line again read three lines. So this can be very useful in manipulating your files on dealing with numbers 32. Complete I/O model: in this. Listen, we will study about the complete I you model off. Are you, like, really just a brief recap? We had seen the slide in other previous lessons. Are you Larry? For five minute placing? Can we are used in two ways. Using simple your modern and complete Tell your model where a simple, modern a dooms the current input current or book and we perform although presents using Ah , you're dark function. So we said doing put reopen afraid are you don't open. And then they said they put fighting with this. And whatever we do, this file will be taken us input and all the functions will be Ah, you're not function name, whereas in the complete model, we use explicit foil handles That is the open Afraid so whatever function recall people call on that fight hundreds and that allows us to work on multiple files. So here, uh, explicit pile descriptors Onda. We use file and then this colon function name and stood off. Are you not functioning as we have seen in the simple model? So this is the same cold from other earlier video. I have just commented out the court that is not applicable. So we open the fight. So this part is same as the simple you model be approved in the file and we provide the bold and uglier be used your daughter input file. So we said their default input file. But now it's not required because we will be directly using the file handle. So here, in the last video, this line was ruined. Are you're not really So the way of calling this completely model is very similar to the simple your model. Only this thing you need to keep in mind. So in the last week, due to a you don't read here, it's while cool 100. And this line is no record and then filed close earlier. It was No, you're not close. And then in the clothes, we provided the file handle again. Similarly, for right upending. So in this case, we open the file pretending this is exactly same as earlier. This lane is again not required. We don't need to set off the trail. And here it was Ah, you're not right. And then whatever you want to write No, we're calling on the island And then they missed a cares it should be fly includes for all the more tough read whatever we have seen, like Star and Star Lister, the number and the default, those Morsi even the same for both cases. So let's see it again. So this whatever they're called, we will use the same cold and coming toward this earlier cool space to the same cool. We will make the changes. The slain is fine. This is not required on, and these this order demonstration of their different moves we're already seeing this weekend. Ignore this. And here's Flein Quayle read and again Ah, for clothes. And now we should get the first lane from tested or global. It's 10 2030 so we should get net value. Yes, So we do get to see if you know this methods implemented, you cannae leak and work it or dismantled the complete model. And no, let's look at one more important function on Fridays it was just foil seek and here we go right to our personal perimeters and these will have some report values if we don't provided So sources from there you want to change this is a fine. So before the file pointer will be in the beginning, off to file. But you can change the final point itself. Very provide the source and there are three valleys for their current. So maybe you have moved here. So from take that question of the starting point. So this Miskell is tells the starting point. And the second parameter is the offset khomeni, uh, by age, to sift so the deportees, currents or whatever the currently do not change that. And the second will sit can ever was devalues like 10 20 or even negative minus 20 or deal . And the before did you if you don't cause anything, that that sort of thing. So, for example, you open the fight, then they said foreign seek. And so when is set, if you write, you just set, then it will take the beginning. You know the oil. If you write end, then, as in this case, it will start from the end of the oil. If you don't write anything or you write current than it, a little current file pointer. Teoh, This is only on line, which is new here. So we said the file pointer, Toby minus 10 from and what it will then go 10 states in the left your hysterics and then they will principle it. See an example of the this and it will be more clear. No, let's more deflate or let's create in new version of this. So the whole reading they will do and hand minus 10. And then we will read everything to look. And we had already seen this more start, which means everything from the current reason. So this is a testicle. So we will see some value like these values any 10 characters. Let's run it So it says the space to file 12 Key hole play six. Servant a main. We see only nine. Well, you because realtor ever knew Ling. No, let's delete that I'm monitoring. No, you see 10 characters and you can count four species Pipe seven minute 19. So this is exactly what you get in our similarly let's Trey the start with you assert. And then I always do tin. So from this tend character on works, it will print everything. This story means everything from current reason. So it starts from the road and 40 ah, sweet starts from here. So including the states of return. We have to space three for you. 68 then the new line main and then dinner. Some believe the date? No, it should bring from 0 30 So I think you're you got the idea how file see works. It can be very useful for man inflating the fighting pointers. 33. Control Structures in Lua: for the next few listens Who live, Study about control structures in lower Lou operates small and convince no set off structures very similar to other languages for conditional execution. We have this and this is in small. I not capitally. Oh, like this. I mean, if some condition and in lower you have to give them. So you think follow rhythm In some languages you may have this curly braces or in Piketon you have this colon and then indentation. But in law, you have to give them and then whatever you want to execute on, then close it with and s. So this is for conditional execution. And for I tracing you lab loops on Deezer while loop four loops very single to any other programming language. And repeat on all of these controllers structures have a sin text with explicit terminators . So for is there is the end. This will terminate it and similarly for while for and while also so for o e d in piers, some list? No. And then finally we have too hard and similarly for while while some condition do and then and and for the pizzeria until which terminates it, repeat something until the so he took these controllers structures have a terminator and the condition X percent off a controller stricter can result in any value we had already seen in our earlier leftists that lower treats as true all the values which is different from falls and any other values. True, even the value Jiro is true. Even the empty string is true. Onley false and Neil are treated as false. So this condition need not we bullion nor places a rebellion about any value beauty value to either tour calls. So any value other than this fall sending our coupe. So if we write if, let's say is 50 and we write if a them, then this is true Let's see, uh, is, uh, received and still literally valued truth through this need not be explicit like a call to true or false. Not like that can be and even so in for their lesson. So we'll study about all of these control of structures one raven 34. If Then Else : Let's look at the simplest controller structure, which is if then else conditional execution for the structure of for you. This is like that, right? Yes. This is the key word followed by a condition. And as we are seeing in last video, that this condition li not be just table you next person. It can be any value and any value other them needle and false evil were toe to So if condition then for this Cuba the altar mandatory. Then you write some block off court. And these two blocks our corpsman. So you can have this current. Listen one, then some block off court and you're done. It can be like that. Or you can have one or more Morrell. Safer statements and then the cold. And also one else. A statement else if you can have multiple else. You gonna one Ana in some other languages like Java are c++ Coursey. You have free to statements. So you if you have multiple conditions, you write sweet own somewhere evil, the real name and then you write kiss. If the value of this very valleys, then they do something. Break if the values 20 when this very well takes a finite number off values. You write different cases and also one before case. But in our law you don't have a switch cases statement. So it is very common to see this kind off team. If else if a statement, let's see one simple or example in over Cool, Let's way have a function, perform or prison. So we want to perform an operation and even give the critters was not great. Read a stream and to occurance let's all of the mind rear preachers. So we will, right? Yes, Secretary called to this place sane then print p one. So you stop retirees. Plus we will perform O p one plus hoping to And then this would be one will convert it to a string because we're using this operator and then the crater itself. So if it's president, it will write like P one plus p two equals d Richert. So let's go, Pete. And here we will need Elsie. The statements plus minus multiplication division will perform for Let's make the tin GIs And if none of these four approaches are passed, we have one last statement. There is no. Then after that, then we will print a no no visitors. And finally we have to end this only one and his record. Not what he told these. So this end corresponds to the beginning off this. Oh, yes, then else look. And finally one and four. No, let's give it some values. Gandhi don't deflate. And here's let's say we give some different. Will you? Let's in this. Now, In these four, it should compute. And here it's a print on known operator. Let's the receipt. 20 plus 20 calories for 20 minus 25 is my ministry. 20 times 25 is 522 125 is deal when it and this one resulting unknown operator because we're only only for cases. So this is how you write a chain off, if else if else statements on all of these are, uh, obstinately blocks you may not need in all the situations, but sometimes you may need, then you contain it like that 35. While loop: Let's look at the next control of structure called blue Guindos. Syntax is very similar toe the syntax of why look in many other languages with only different that here you need to write, do onder the block with and cure as usual in law. So while condition do and then you're under piece of cold so it will repeat what the condition is true and through every time it will take the condition. If it's true, then it will execute this piece of court and come back to the top of the look and again take the condition and again John it until it takes that the condition is false. Then it'll agent or tobacco. So let's see any dampen Cool Itsu no trivia. Your table which has the loose 10 2015 13 We have four elements in this. Our table remember this is that index one. This is a index 23 and four and there is no in next five, only 1 to 4. So let's say we have a local very well I and it's very loose one and we'll be right there. Lloyd e So it I will be new if we provide any index more than four. If they avoid a one, it will return, which is true. He was 20. Results of truth similarly a tree and therefore so while I is true No, didn't I? And what we will do after printing we will increase the value of sorry if we forward to increase this value. Fine. This will keep on printing are the same My eyes one fiddle print in and again 10 10 10 and eyes not changed So it will continue forever. So be incrementally after printing the value of here and then we end. So when we don't Do you see that? Well, let's also bring the value I so that we get an idea of what is I to see me? Silly eyes one. And it prints a resistant than it incrementally. If I toe then it takes whether you to adjust. Yes, it existed 20 many prints. It increments it toe three, then six. Whether Atria just Yes, it's 15. So it prince 15 and increments I do four and it's sick. Have been comfort to the top and sex slavery for a just years. 30 It prints. No, it increments the really. If I 25 and it comes back at the top. It takes you five. Any favorites mill. So it comes out of that loop. So just to clarify it may printing enslave it will bring me. So if I'm not against so these'll what works? 36. Repeat-until loop: continuing our discussion on control of strictest list. Let's look at another looping lower called Repeat until who Here it's VeriSign. Bolos in takes you right, Repeat cable. And then if he was statements So firstly statements will exit Duke and then it will see what is after until after until there were real condition. So is this condition is true? It will exit your little repeater until this condition becomes true, Efforts falls. It will go back and around this court again and again Check the condition. So you see that irrespective of this condition, this are these sort of statements here will be executed at least ones. So let's look at an example for let exit local variable and it's been used him. So we write, Repeat. And what do we repeat? We just bring the value this very licks. And then what we do read agreement X ray one and no, we write until look, which is the condition. So until excess resident so earlier, what will happen? This condition is false. So it is on it. Ah, so you see, uh, easily are principally often then makes it nine. Then takes effect Sizzler than if I were not. It's not actually to look into PT and again campaign and excellent it. And finally, when it reaches fight with printed on detrimental to four And now this condition becomes true through two stops here on One point I have noted here is that the scope of local very well declared inside the loop includes the condition that it's in this book in re declare any local very well than that local where even is accessible within this condition also, so the scope of that very well extends this condition. So, for example, let's say we have a little convertible, which is local. Tow this loop only it's not accessible. Or take this look and it's certain two times X and no, If you rate check for one year, you see that more easy accessible. Let's run it. So since ways to 10 67 x becomes three, why you six. So here it prints three and then declaim. It's extra to know why becomes poor, which is less than five 37. Numerical For: No. Let's look at four loops in lower for Luke has two forms. One is numerical form. And the second is jen record. In this materials focused on numerical for And in the next lesson, we will see what a genetic for. So in numerical for you, right for And here is he do. And here you initialize a loop variable with the value he experian. And then you passed two more, uh, variables. Two more expressions. So this is the starting. So you execute something. Something is this statement for each values he experience for the very well There still he Expecto. So you go from me XP one, Do we expect toe? You said the value of their using the expect three years the inclement. So if this is one on this is let's a fight the system and this is one. Then when where is quite you will execute disease treatment and inclement Here step is this one Little increments way. Six. So next, where become six, it's still Irvington again. It's it will execute execute for all values from 5 to 10 for the value of where Now let's say this step you parts just to so for five to execute. Then the next where you will be seven again institute. Then it will complain. Then again, execute any to look um 11. So it has crossed him so it will execute three times. In that case, no sort of third. Expressing is also optional. If you don't pass, then the default to step values one. I know there are some points true that allow three expresses are evaluated once before the loop starts. So before the movie starts, it will be very Richard on the control. Very valleys, local variable. If you write for I could do 10 and some other values and then some. You ended the look And if you want to use this I outside this look, then it will not be accessible because this is local to this. This is a common mistake. If you want to use the local value, you should keep some level value Also outside this opening local X and you should capture the value of I do that. Were you Now you can use that really roughly the last will you fight Using this X on and use will not change the value of control very busy the control variable, and you have told you to execute from 10 to 20. So in order to ah, exit early from the look, you should not right that I call to 20 so that when it was there, it will automatically exit. You should not do like that. If you want to exit early, you should use the brake statement like if you want to execute for 10 200. But for one case, if their value Dickens, let's say 50 then Brick. But these are not, uh, thinking that control variable. Let's look at some examples. Let's start with a simple example. Let's say you want to it, uh, trick for all the values from 10 to 20 you're right. I could 10 2 20 step will lose one who it turns for all values from 10 to 20. Now you change Step 23 Then what it if it it increments right three. Through the Princeton, I become 13 for 13 and 16 19. Then it becomes 22 which is more than country, so it will exit. No, if you don't pass the last value deported balloon. And as you can see, the original T same as passing one here. And now. Let's say you want to use this really off. I outside. This is not suggested. You see Here it prints middle because this is Look into this. 38. Generic For: in this Listen, we will look at the next kind off hard look, which is generate for group. So here we travels all the values return way and I traitor function. And we had already seen some examples of this in the formal. There's and I Piers while we were study tables and the year though I traitor functions, we cannot many more. I tritscher functions. We can't even write our own Iitrader functions. And it's in Texas like that. Let's say I want to, uh, find out all the keys and values off the table. Then I will write for Kcom Avi in Piers. So this is the traitor forms in here, and we're retreating through this table. And unlike numerical for we can have multiple variables in numerical form. We had won control variable. Here we can have multiple, really was. If we don't need kay, we can write under school as a placeholder. Richer on I'm Later that eat a treason on the loop stops when was terrible becomes as in the numerical loop. The loop variables are local to the loo body and reserved, marching their values inside each treason. So let's look at an example Let's severe table with some keys like 10 20 QWERTY and some ah , known into your keys as well. They kicks, which is 1000. So let's look at a couple off. I treat her from since we were like for Katie in my peers. Yeah, no, we will think Boat key and value. And no, let's so busy with Prince. He's one Thorton for 20 keys to and for key three, The values 30 in the Northman X, which is as expected. And no, we will use another Twitter functionality piers, and let's run it again. That's coming to talk. So now you get all the four, please. One. This is the value you get a key to for value 20 in key trees. Really 30 and this Keys X were explicitly mentioned next, and it's really use 10,000. These are just two examples. We can have many movie Twitter. Constance 39. Break and Return statements: in this. Listen, we will study, board break and return statements. They can return statements, allow us to jump out off a block. So let's just early work break. We already have seen both of these. So we use big toe finished. Look, the three year having a loop and there is some break it and it'll come out of this block group, even if there some statements after this. And if this is a part off some inner block and everyone outer block, then this break will exit or toes the inner broke and that this can be any kind of flu for repeat while or anything, and it cannot be used outside of its use only inside look. And after the break, the program continues in from the point immediately after the broken look, this is the inner loop there some statements after break and there are some statements in this order. Look a little so you'd be called break here. This part will be skipped. It will come out of the Duke and immediately following this look, all the statements will be executed. So let's see an example with multiple loops. So let's exit variable, bitter values 10 and then there. Erica, if Younis to groups when exes list, um 30. And then Wade X is listed in 20 do. And inside this while exes list them 15. And, uh, what we were Louise Smith will think we'll bring from all of these three loops to distinguish from there, the value of X was printed. We will air the prefix. So this is the third level off the loop, Willard. See? And probably X. And then we appearing cream index other ways the Louisville continue forever and then closed this loop. And no, we come to the next look or look that this'll be your second level. So here also they will print the same thing. But with critics of B and again, remember, clean coming the Value X. And finally we will go to the really and this look. And here we will print in order Louisville print a followed away, x and again. So what should be our took Lex first guest. Then we will see that a lot. So X is till we have in his late ex with 10. So obviously it's less than 30. So it will enter this Look. No, the very first statement is another way. Look, with checks, if X is less in 20 and this is also true, so it will enters this part. And here also the first This treatment is a vile statement and it takes with Rex is repeat this look till X is less than 15. So it will exit as soon as it becomes 15. And this is all the truth. Through it will print see and then X which system so seton than expected. It's 11 11 12 13 14 when it becomes after spending 14 years without 15 so it comes out and then it starts. Printing will be 15 16 17 18 19. And then after 19 it prints a 20 08 21 and so on. So let's run it. So there is nothing special airs. No, we will use our break statements. So from 10 to 14 it prints from here inside this than this condition becomes schools and comes here. No looks used in brake A statement. Let's use it in the very you know, they don't some condition if access he quarto and then brick. Uh and so you know that it will just break out of this innermost loop and it will jump here and not outside all the three loot. So no, you have to see that. So it drinks 10 here, then this condition was false. Then becomes 11 then prince 11 again. It's falls into level. Oh, and it becomes 12. No. So, Prince still. And now this condition is true, so it will not increment it. It will not get it as to implement its little Prince Ito and the next statement break. You see here still see till then break. So it comes here and print bxb just ill will and Prince Metal. And then x becomes 13 and it will go back to this. So the innocents it's less than 20. So it will entered this Lopakhin see, local unit will enter and no exist. 13 through it print 13 14 from this inner look. And now this condition will never occur because it has already increased and now it will continue as earlier. So this is just to illustrate that break will, I did sort of just in your group. Now let's look at the return statement. Were used it a lot of time now. We never course. So this return statement returns bridgers from a function or simply finishes the function we have a function through. And if the rate return somewhere based on some condition, then this functional Termini and at the end of this function, if dysfunction ends here, then the very last statement is implicitly this return without returning any value or this function can return value. In that case, we will have explicitly right return like 10 20. But if this monks and is mortar turning anything, then you don't need to write written. But if even if you're right, you did not make a difference. And the last statement so and there's more going that your return can appear only as the last statement. If you're right, return here and then there is some statement immediately following it like print something . Then it will through an error. It can be only last a statement. Let's look at an example. So let's see, we have a function who and in certain that we have a very X equal to 10 and the inclement Exley claim and and it and let's call this function. So you were in this it Kirky Prince, 15 know before this slicks. So very true term. Then we get in her and expected near equal to. So it expects, uh, this function to end after we have returned from it. So decision later. What if using moving it will explain if you had returned and then reaching this case will not make any difference? Because this return is implicit in the concept body, which is not returning any value. So the CEO, uh, return works. If you need something to wear to return, like in the middle of the core, while the working so that you don't want to execute all of this, Then you get very good night, the term and then explain So it will return from here and not print. Oh, whatever is below this, it will drink the layer and it will return from him. But without this, you cannot write return 40. Functions as First Class Values: functions in lieu our first class values with proper lexical scooping. So what does it mean to have first class values? Let's see. A function is a value with the same rights, and other commencement values like numbers or strings on the, uh, program can store functions in variables either global or local and in tables. And Constance can also be positive, er, goings to other functions similar to what we do it. Other variables and, for instance, can return function several years, for example. We have seen thanks an example like this, but this is just a represent is enough The thing on the right, which is who is a variable and it is assigned if function value. So this is a very well, just like the rebel holding any other type of value, like into your string. This variable holes value with your type amongst them, and we will shortly see. And here this is the actual function, the value the value U Thanks, um, and very well, so let's try it, and you will find out. So just, uh, that should be able local very well, for you could afford him. And let's say it's empty. Does not do anything, and we will just bring to the type off. Cool. So you see, it brings folks some relief. We have another. We can reassign food to some interior. And, Lord, let's French Italian. They see no food becomes number. So if we just variable, which can hold and in teacher and string, a table or even a function. So functions are that's very first class values, the treated just like any other that every No, let's see other examples of what we're talking. Or so we have already used print function a lot toward the schools so we can assign that's created table. And in that table we put the value to be keys be and it's the loose print. Know what will happen? The print function that we're using? We can use it to using you. Don't be just to confirm if the right don't be and right 10 20 you don't be bring turn using and look this you see 10 20 sprinter, just like it would be printed using print function. What here we're using a Don't be because we had assigned this our print function available in library to a variable to a key off a table A. And we can use know the exact same. Where's print print? Onda? No. Let's seeing the value printer itself. So let's severe matador cost function toe print. No print will no work like it used to be. It should through another, because now drink is no longer the original print. It would be still neck print so you can train your people work. But print is no longer print. It is no bowling, really. Of course, because printers never function. Been toward already value, which was holding a function which used to do the printing. It was just a placeholder. Now it's holding a different function. This is what I'm tryingto make you understand with the new see print. It's not a function. It's variable holding a value of type function. No prints would be a just like matador cost function so you can write Bring to slaved Ortlieb and it will print somewhere between zero and one. We call sign in course, minus one and one. We go sign in course return values between minus one and one. These functions are like this. I'm doing the same. What course is occurring just accepted by 90 degrees with one. This is minus one. So all the values like between this range So no, If you tried toe call the print they've got fine. The truth. Uh, they need to print it. Also, we got guarantees Just calculating what? Not windy. So you see a blue list 10 1 as expected. So this is calculating the value off this cause I got right and then it is printing it and no, you can a sane lord cause equal toe you not be. You know what is the print? So no, If you write matter, not course Hello. It will bring tell just toe like a difference. We would like some districts here. So you see that matter cause belong Do the YOLO What print was doing? So this way you can manipulate functions and do your first class values, Ana. Now let's look at some more concepts. Call an anonymous functions to. In fact, all functions are enormous at BFC because we were able to assign a function which was designed to print to a different very well and it worked all fun since Aaron illness. Like any other value, they do not have names When we talk about a function name such as print, we're actually talking about a very well that holds that funds him. Although we often assigned functions to global levels, giving them something like a name, there are some occasions when we keep them an anonymous, for example, you must have you would table Lord sort function. So here, the past director table and then there are many different cases here. Infinite possibilities. Let's say I ever table with five keys. I want to sort based on the numeric value off second G. Or maybe the string will your first key or any other ordering me re possible to instead off defining all those possibilities. What this sort? Well, it will accept a function as an argument. So this is the table. And this is also another argument, which isn't songs, Um, and we call this kind of function it order function, and this sort ads Ah, your order folks in. So this is just any other function. Onley changes that it's accepting the function as an argument, and you you have seen that this is an order function. It's just still very well that is holding a value of type function, it seems any other folks. So let's certify in our own And on this function, let's say we want to define the delivery to function. So in mathematics, if you're if you remember, if we have some function like this and we want to calculate their derivative at this point the Stroop off this function at this point, what we will do weaken estimated using Take the value of this This point This is the North s Mrs X. So if affects at this point in your hope X At this point, you can take the difference. This is explicitly takes from these distances the tanks. So it take these two distances subtracted. So if you subject 1/4 x plus takes that is this value everyone and this is free to which is therefore thinks they subtract these two. You will get this value this limped and you subject this point from this expletive text minus six. So we will get this. Will you clear some part of it? So you get this is diet. This is the second part. If you divide this way this you will get this value which will not exactly what you're looking for. But if you keep on sinking this delta very small value, you will take the difference off this point at this point and it will be very close to this actually reverted. So let's implement this function. So we radio decides, therefore, fix its final fix our the earth upon the X all of the different way of writing this you could worth X plus middle tax minus affects do right away their tax Let's implemented flips , Commander, This part of the cool So this is the function we want toe calculate their way to go and this is the data and if not passed, then we will take some small value and we will simply return a function. So when we were returning this were return essentially your value if explosive delta minus fx and this do very WeII Delta. This is their definition off estimate off actual derivative. And we're just returning this function from this alter function and what we will do. Bill a sane call this function directive and live in the same matador sane. So this, if he's met, wrote saying this Jerry w taken in this valley because we do not pass it and it will return a function. It's called Pallister Derivative of this function. So this will no service this inner function. No, we can call, I think Yes, and, uh, sleep. So what this will do? It will kill Great. This sign off the river eight Your sign off. Fine. And they reverted to a Sinus course and reverted all courses minus thing. So in order to compare this with Google, use their Children matador cost function and give it seem milieu. So this function returns course in this case because they're irregular Sinus cause and we're effectively calculating cost fail and no, we're calculating cost five Using the actual maps, not cause forcing. So you re print. We see that this is somewhat closes these two really upto decimal places Phillips degrees. Is this really further their delta? No, Rezidor. It's closed toe five decimal places. So they Chrissy has increased and it's a pretty good approximation. And you see that these two value particularly so this is how you can return from conforming folks in and our leisure and almost function. And even if we have another function, which exception function Oh, we can bus in new function there. Let's instead of fighting man not saying we will pass another function. And no, If you run this, you will see it's calculating. Excess square on derivative of this is two weeks. So it's returning. Always Tim for five in the past year. 10. What's a rich return? It's a return 20 because derivative off excess square will re always two weeks. Whatever value we give, it will return to think that. So this is 20. Who here? We're passing this function, but it does not have a name. It's anonymous. 41. Closures and Lexical Scoping in Lua: in this lesson will study rolled closures, which uses a future. Corey Lexical is coping in lower. So first, let's look at what lexical is coping. So when we write a function in lower and it's enclosed in another function, then it has the full access toe, all the local variables from the including function, and this feature is called Lexi telescoping. So this may sound all this to you, but it's not that simple, and it will be clear when we see some of the examples. Let's see, we have this once in your folder and in this airport or function. We have a local variable X equal to 10 and this function returns another function. They did not return a string or some you know very well Nutri turns a function, and this function has a name on. This is the including function and it has a name you have holder, but this once, um, did not have a name, foods and only one function. And here you see this enormous function usually very well, X, and this variable X is not either an argument to this function or a local very well to dysfunction. It's using the local variable off motor function. So this X is nearly global, where even not local value. So this has a special name in lower you're discord known locally variable already also called value. In orderto call this inner function what you will do You can assign it to a variable if one equal toe f alter. So when you run this, what will happen? It will return before it really return this function So this F one will get the value of dysfunction And now this photo has return. So whenever any friends in returns, these local variables are no longer available. So this is not in the school. But if you call this a phone, what will happen? It will print X Could do it Will first inclement value fix and then print Tex. But this ex belonged to this F alter function and Richard return. So how will this next more system memory So, Lou, as a way off and doing this and that's where he was telling. This is not so simple. This lexical scoping feature corexit on discord in our I d and very busy. So we had, uh, local from some Your folder. - No , we will assign it to a weapon. You know, when we call a phone this circle dysfunction inner function with depends on next. So let's sit on it and see what happens. So it prints 11 and which is expected because we're the signed X equal to 10. So this is expected. What? Not so this if you look at it first because you are this external marriage in the school wants. This has return. But you see that it has preserved the value of Tim and Italian currently then and entered that So let's serve in it once more. Now it drinks 11 and then could So somehow this is not This did not simply return this function, but also the value that was stored here. What? This does not happen for any other variable. Ah Lewis saves on the variables which are needed very any function that is. And I know something that is returned from it in order for it to function. Otherwise, this function will not work. This will simply given, other than it takes is not defined. You're trying to implement it. So this is what Louis XIV's using Villiers and cruel years are similar to function, But it's not just a function. It's a function less all it needs to access non local variables correctly. So here, uh, one is a clear over the function. This or now let's look at one practical example. Let's get rid of this. We want toe design. Some counters create counters and we will use clear for that. So we have a function is called create country. And from there go start the country waas a perimeter count. It will start counting from there plus one return function and only one swings him which increments count and then return count and it ends. No, let's create some clears out off it. And we want to start counting from one. So initially it with you. Because you first increments to handle, uh, drinks. Then returned the value. No, we were bring this and calls even when we call it even. It will call this inner function and we have any slated with Jill. So it will implement it to one and one. And let's do it a few more times. So you see, Princess 12 and three. No, let's create another counter. No, Call it C two. And here we start counting from 100 or when you know one. So you see the 1st 1 counts. 123 2nd one When you when you go to when you're a tree. And ah, one important point is that these two are the c r. Two different cruisers over the same function. But they are different clears and they will get separate copies off discount. So these are not getting mixed now, even after calling this sea to a few times. If you try to call, see even again, and C tools to once more, you will see that this even needs still maintaining its original value. So we get 12 trees from the the street. Then we print using the window values returned by the second closer, which starts counting from one euro one. And when we again call the first closure, it still maintains its or in value, which was three. So it increments it and dreams for and see to it maintaining its own copy off count. And it has incriminated one needle trees, so no reprints one euro for so I hope you'll find closure is very useful and try to use it effectively in your cool 42. Pattern matching functions: No. We will start studying award pattern matching in lower. And in this listen, we will focus on the four main pattern matching functions level string library. So these are the four functions that are used. Andi, Representing the string library. These two find Angie. So we had seen earlier while starting a string. And, uh, we will street two more functions Met and Guilmette. So let's see them in some retail as we had already seen. Strings or queen searches for patterns inside a given a string and it returns two values. First, the start index where the pattern matter started and end index were it still buried on the pattern on both of the indecision included. And if he does not find a match, it will return until there are also two optional perimeter. We're third Parliamentarian Index there tells you where to start the search. By default, it will start from the beginning. On the port perimeter is a bullion which indicates whether we want to do a plane search or we want to include patterns. ALS by default, we don't pass it, it will treat patterns as patterns, and if we make it true, it will ignore any pattern. So let's look at any company. So first, let's say we have a string riches, a little word and, uh, let's kept to the start and this is in I n g. So we will write a string door, planed then the string and in Leap actor We can also pass to optional parameters and we'll shortly see those. So no, look sprint I n g So it should start from 1 to 3/4 and slave one and Flavor, who'd prince one? And for you, as expected, Onda we can use string dot sub function with substitute We returned the sub string art off that string. Her example we can print know that we know Ah, well, from where to where this is phoned We can return the value of sub string from I to J And it is as expected, hello from one to fight. The sub string is hello And we can also, uh for in a single letter In that case, would during this is will be seem because they're lookers from three to tree would return the first technicians of that and you write any either in something Then it will return Neil. No, let's look at the second function, which is string dot match. It's similar to find in the sense that it searches for pattern, but it's different in that it will actually return the pattern that part of the stream that matched the pattern. So if you're doing a simple service like we did in the earlier case, hello, it will not be useful because the pattern that you're searching for if we found it, it will return that. But it's it becomes more powerful than you provide it with some patterns, and we will certainly see how to define these patterns. For example, easiest string. It includes some date and we give it person deep Lis. Then it's less so we give you tips batter. Then it will find that, Yes, I found it in dating this history. So this can be very useful in such situations, and in the plane case, it will not be useful. I know in the string dot find we forgot to explain the third and food parameters which are optional. For example, in this case, Oh, if this is the string which includes this square braces and if you if we try to find it. This and we don't provide the 14 dicks. It will give him a letter because there is a special meaning off this in patterns. So by default it will treated it as a pattern. But tell you see, we give the sea same pattern. We start sizing from first intakes and we make it true that is, make it plain search on ignore patterns. In that case, it will find it. And it is at index three. 123333 Now let's look at the third function, which is Jesus. So it substitutes the string. These amines global substitution, it will substitute everything. Oh, it has three men, the tree parameters and one optional perimeter. Obviously you need a string in all these cases a pattern. And here you need a replacement district. If it found a pattern with water string to replace. It's basic UC is to substitute the replacement string for all occurrences of the pattern inside the string. The fourth perimeter limited the number of substitutions. If you don't give it forth. Primitive ritual substitute all occurrences. If you passport perimeter everyone, it will replace just one occurrence. If you pass it has to. It will replace only two occurrences and it returns an optional it returns. A second original told, which is number of times. It made this substitutions. So let's look at this. Let's have you ever string noise killed and we want to replace killed with no. Great. So this will return the finalist drink. So if you try toe, print it, it will bring the new string with the replacement. And we said that it returns the second perimeter also, which is number of occurrences. Number of times it made the replacement, which is one in this case. You can also ah, replace letters here. You We provided a word to replacement. A word we can a droid it with some letters also. So we want to replace all the ills but exes and then Prentice. So you see, all the ills have been replaced with excess and Noah. We give it a pattern which is not present. So the original string remains that it is. You know, you did not find a pattern and here you do not return the second value, which is ah, number off occurrences or we do not capture two. It should print Jiro, as expected, it prince in general because you made zero replacements. Oh, no. Let's pass the additional perimeter. A number of substitutions. So we will leave with this one. But instead we will put a limiter, which is one and no, it will print it. You see that the first l is replaced, but the remaining at least not replaced. So did he always strings or diesel works? Finally, we look at a string door, deem it you met function returns a function that I treats over all occurrences of pattern industry. For example, we have desist, re some mustering and, uh, we want to extract all the world sort of this and store it in a table. Initially this world listed empty So what we will do we need We can provide a pattern here little the bring the world so it prints some. Then it prints string and the year also inserted in the word list and we will discuss shortly this pattern percent is it Lis matches the sequence of one or more alphabetic characters. That is words 43. Patterns: Now that we know about the four pattern matching functions in lower, namely the find match Jesus and Guilmette, it's good time to start looking into how we can satisfy the patterns. If you remember all of these functions, take one string perimeter, which is that string where we want to playing the pattern. And then we have pattern perimeter also and some other That image is so you know, we have been spraying some plain text, but this becomes all these functions, becomes a much more powerful than we can specify pattern. Since, um, good way. For example, if you want toe find date in a given stream, then you contract trait some pattern off Duits, for example, A good way of writing. There it is like Do de mm. Wait so deep. There are two digits followed way to digits and then for years. So you know this pattern so you can just despite like this was in deeper Cindy. Then once less than again person, deep person D and then 4% ease. So this will automatically look for this pattern on it will return you the date because you cannot find it by exact words. You don't know which date it is. So most pattern matching libraries used backs less as an escape character. But patterns in lower use this person sign as an escape on any skipped alphanumeric character has a special meaning. For example, person to it matches any letter here with a or person B, so it will not any digit. So these 80 are all alpha on your character. We will see the exhaustive list of this also on any skip, non alphanumeric character represents the characters, so person D does not denote it will find the little find any dessert, the gold. This is alphanumeric, similarly person table not find it. It will find ah, any little like every city. But these are non alphanumeric. For example, percent not will thirst for not in the string. Similarly, percent star will search for star and so on. No, let's look at the character classes. A corrector close is an item in a pattern that can match any characters and the specifics it. So this example I already give this pattern will look for this pattern and it will be masked. The dudes here is the it goes to list off character closeness for dark means all the characters or sinti letters or Cincy control characters. Person do idiots. Person G is printable characters except the spaces, then lower case letter ponchos and characters, space characters, upper case all for numeric and exodus in religious. So are the more commonly used when our person to a person be sometimes lower and upper cases space and California characters. So these would be more used, and we will use a lot in our examples. And here you see that all these characters are having lower case values. Is the right the upper case? Then it will be the opposite of that. So percent a means letters on a person to a viewing known letters. Similarly, Person D is four digits and or sent D capitally will before normally it, so you can try with all different communism's. So here it will be non uppercase, imperious with like apple you. So first, let's see the rules. Then we'll see examples off all of those. Some characters are called magic characters and have special meanings. For example, these sort of parentis is the north percent plus minus a strict question mark 10 square braces than this symbol carrot symbol on dollar symbol we already seen on this one. This is an escape character and used to splice by the patterns on this is alphanumeric and on non on poverty characters. So it will exactly serves four question mark. Similarly, this will serve for person shine If yourself a verdict corrective, then it will have a special meaning which we just saw here. No, let's see character sets. So we will also cover on these characters as we go along. So the these two, uh, square braces these form characters it So you can specify you wouldn't character classes, for example, in the pattern. If you right, this is square record, then Jiro one then closed the square record than this pattern means their search for any, uh, character building this square record which is zero or one. So it will look for zero and one day it similarly here, this is the big name. This is Emily, and this person followed by normal heretic is the character itself. So this the nerves opening bracket square record on this person close record denotes this. So it will look for oh square records because everything else is within this older square record similar earlier. We have listed a love ovals in capital agile a small letters and the beginning and the denotes character sets. So it will met any viable either in small kiss or, uh, upper case. And now we have this special symbol. It was also listed here in the magic character. So this means negative or complement off whatever is the pattern. So this dear Owen mattered any gear or one digit having the roar one value. And here this symbol in front off it will mean non man religious, that is, are 234 and so on. But not Nero or one. So the symbolist were useful. It will negate every logic. No, we have some reputation or optional modifiers. So still, no, we have been explicitly writing all the patterns. But if we want that, uh, if you want, no matter does it, it will. So if I say if we want to match two buttes, then we have to write it toys so we can use reputation character here on instead of writing two times, we can write it. Ah, bless here. So this will mean one or more repetitions. So this will match one digit toe treaty, forties one or move similarly star will mean dear or more. So did your different reputation characters plus meaning one or more a strict means and you're more minus means zero removed but lazy repetitions, so this is a strict will. Try to find them maximum length better. Where is this minus below to look for your mood but smallest possible patterns who had Soon as it breaks it will exit. The district will go until then, and if everything else in between satisfied it, then it will return that we'll see an example of that and it will be more clear. And this question mark means off. Smelled zero or one. So either zero or one, not more. So let's see example off all of these. So first, let's see the sample off extracting date from a text. And no, we need to satisfy the pattern So it's personally men's less person B Person B's less and let's run it. So you see it has engendered it. It's able to extract under it from it. Let's look at another example there we will print. Let's say we have a text called a lowered with a few experts exclamation marks. So we want to replace substitute old and non alphabetic characters with some other symbol. So we will use String North and Jesus And, uh, so we have seen that capital letters means approach it so small letter a means for their take characters. So Capital Letter A means normal 40 characters. And let's say we want to replace all of the way a strict symbol. And when we run, it receded. Oh, all the poverty characters, air pressure. But all the known all poverty characters are going instead. There are a strict symbols. This is for comma. This is for white space and then these tour for it. Clem isn't on this four denotes how many substitutions made. Jesus. Come on. Now, let's see some more examples So it returns if because we're writing captured early, which means non deeds. And here this is the only letter Onley all for a bit dressed. Others are digits, so we make it. It's more likely to return one because it will return just the first occurrence. Let's move forward. Let's say our text is no B A, B, C. 123 See me here to treat one and no, we will use the character set using this square braces on inside that we write Hate me or see on Let's wasn't it. So it matches be on it terms on the B right? So let's copy it. And here we write this. So it's the a portrait of this, So not a B or C. So here is B B A B C. So it should return one. Because this is the first well character which matches this these tour compliment off each other. So the 1st 1 returns be the very first character on the 2nd 1 returns this one because before this, nothing matches. No, let's do an excess. I just counting the number of bubbles in a given a stream So I have mixed in the characters and again we will satisfy the characters. It e i o u a e i o u. So this disability Tonder so did you to the string and also the number of substitutions. So we're not looking a substitute registry or let's bring that as well so it will return. Ah, this is string with all the bubbles. Replace to it. No, in fact, removed from the street and also the number of substitution. Visual Vitre. Number of ovals. So let's run it and you see three bottles are there that's counted the 1st 20 then e and I . So you test three vocals so you can assign it to variables, which I was doing this now and you can get the number of orbits in a given text using this simple pattern. No, let's extract Ah, and I'm good from the stream. Of course. Let's see. It will bring just one. Did it then? If we write it one or more occurrence so it will print 1234 Also, let's so is the right person D it brings one is right person b person d It will drink the 1st 2 leads so we can write. It was a a strict little night in fact, gear or more so it will not return anything because here itself, it will matters Did or more so, dear Oh, it will matter in return. So here plus will be useful and it will look for one or move So it starts here. What will extended to one or more similarly minus, which is also the raw removed saying, My district, it will also return from the beginning and it will not return anything for Let's move ahead on we will see a comparision between, uh, Estrich in minus symbol Alter. But first, let's see one example of gastric. It's a want to extract. This parentis is from a given a stream. There can be this empty parenthesis, or parentis is with spaces in between. So let's say or text is percent andan This parentis so it will look for opening. Parentis is then personal. Tous means the space hand and you know what a mortar spaces. So this opening parentis is followed by a year or more space and then all the way close Parent is this so its able to find the parentis? No, let's drive it a few spaces and again you should work. So trains are this parentis is through. It works. No. We will see the difference between s stricken O minus symbol which are boot Jiro or more re petitions. But one is lady reputation on one is normal, so it will try to find the maximum pattern and it will try to find the smallest land battle which message that for Let Sylvia C program and we have to remove, see cold and we have to remove or look commented, commented Cord, and lets it in this simple example. We are using multilane comment in a single line. So we have index then the I heard some comments going C or C plus plus we right Marty Linn comments using this ah, slash followed way, a strict and then everything in between his comment until it meets this gastric and less again, there is one more comment. So what we will look, we will find this pattern. We'll start of the pattern and this end of the pattern and replace everything this empty string percent it's less. In fact, Slesin in percent stuck then this means any character Oh dear or more of this. Then again, percent start and then this slash again and we want to replace this week. I'm history. So if you drink this, you will see that, uh, returns just index and you see one substitution because this is the beginning off the factory, the engineer or more characters fall away. End of pattern. So this is the big name and this extends from here to there you are more characters, and it finds you too. So everything else is Oh, deleted. So you just see in Texas on this into way, which was not part of the good, not part of the comet. Oh, it's going so no, we will use this minus So what this will do. It will try to find the shortest possible pattern coach. It's lady repetition. And then again find shortest possible better so it will delete both of these comments separately. Let's run it. Clearly, you see it correctly returns in texts into away, and it makes too soft tissues of the Restless returns just in Texas. So I hope it's clear how Estrich and minus are different from each other. 44. Date and Time Functions: lower standard Library provides very useful functions for manipulating data in time, and these can be represented in two forms. The date and time. The first representation is as a number and decision really in Indonesia, and it's not in standard but on most six systems. This will you know, the number of seconds in some fixed date, and we call that it book on boat in politics and we know systems. They pockets close to January 1970. Gero Gero, Gero UTC. But this is not this tender, but it's ah, the same one. But for 600 new on the Representaciones, as a form off table on such date tables may have the following significant feels you're month on day. These are pretty obvious from the name than our minute and second. So did six. Pills are pretty obvious. Year denotes the year, month, day hour, the next hour in my uni knows the minutes And is he Cedeno's do seconds? Let's look at these three fields won't do, they know and all fields except this last one I use DST are in teachers on this the blue day denotes day of the week, for example, they can be Sunday Monday and is any of the seventies and here one building or Sunday Or, in other words, for Sunday we will use one or two will use Monday and so on. Similarly, why did you know day of the year? It can be 1234 So year hasn't really 3 65 days, and it just starts from forced to generalise off was January denotes one? Similarly, second January's too on the first ferry would be 32. And this Ah yes, DST is a 1,000,000,000. All others are into use. And if it's true, daylight saving is in effect. Let's look at an example. Let's say we want to denote this new September 16 1998 on this time so clearly this 10 is second this. Then this is the hour for Butte, and this is our sorry 23 and 40 80. The minute on this is second. Now this is clearly the year and September easement, so it's the ninth month. So we will use nine. On day. It's extend. So day 16. And if this is awareness day, then week David Lee for because on Day one Mondays, too, he was the three burner default and I use our DST is false because its name one main nine it and the war tells why d Day of the years through which to 59th day clearly today in the September. So it's nine months. So almost 3/4 of the year is complete, so it's 2 59 and these date tables do not include it. Angel, and it is up to the program to interpret them correctly. With respect to 10 years in for the reduced, we will look into a specific date and time functions. Who is your date and with dark thing. 45. os.time function: in this. Listen, we will look at Wester time function. So when we call waster time without any arguments, not you, right? Who is dark time and then you call it on. There are no arguments. Then it returns. Corin Dating time recorded as number and we have seen their This number on politics and Windows systems are number of seconds since first of them 197 year and you went zero euro you to see. So let's see it in already full its in store the number of seconds in a variable called it so where your team will give the number of seconds in 1970? No, let's define some constants which we will divide in order to convert the second toe first our than our today and day to Yes. So in order to can work day two years what we should do? I ate 3 63 If you're going day and you want to come work here 3 65 were more accurately 3 63 point two for two. So this is days in the years Next. If you want to convert second toe over, you need to divide way 60. It will convert two minutes and again 60. It will can work too Hours, so seconds. Oh, you know what? If you want to convert 2nd 20 first, converted to over then are divided by 2024 because 24 hours in any so second to over and 24 . So it's seconds in a day and finally we need second two years. So first converted today second today aan den day Two years which is 3 63.2 for two. No, let's bring the current here. So divide this day which is Ah, interior denoting second since 1970 2nd 2 years and we also need to weird 197 years because this will give the remaining time That is after 1970. So just had 1970 and you sort of get the current here. So anyone you get 2020 That is 2020. This is the current here. Now let's print the other times That is hours. So did it. More deluded. Second, it took they so the silly game in terms off seconds aan den. We will divide ways second to over. So this will give the current hours it is 19 minutes in your busy time. Similarly, print minute, second to our and then do it with 60 and similarly seconds. Just more dilute. 60. So this is 2020 19 hours, five minutes, 14 seconds. Let's run it again. No. Same everything seemed just 25. So the Levins again have bust? No, against exports against you. See, second is changing. Next is on a few times. So that this minute all 13 years You can also try, uh, converting this UTC time to your local time and see how you can do that. Naturally able to exercise. Now you see, it comes six from Miniter changed. So does he. Always door time works and you can get back in the date year, uh, minutes against everything from this interior interior value. 46. os.date() and os.difftime(): in the last video we had seen one day time function called Was Dark Thing. Today will see another daytime from some cold with no date, and we will also see a diff time function, which can be used toe compute their difference between two times. So what does whose door dick do? It converts A given number, which will represent a time to some higher level represent is in much more readable format . Oh, either indeed, table or string? So here, Who is your date? And these things are optional. Botero's name. If you just rate who is known date. Still, it'll work. It will pick the current date and time, and it will convert it to inform it, which it is readable. So let's try it first, so you'd be right with Gordon Date. It prints this the current date in abbreviated form of their day, then month, then the actual date. And this is the time the default Asian 12 over form it and then followed by the year. So this is the default behavior and then you see two optional permitted One is the format, the format in which you want to represent the reeled Ah the real that we saw here. This is one of the former, it's and one of their Defour form. It's but you can't despite custom Formative, for example, if you right percent a Smalley, there is a difference between small and capital letters while it's just playing former's, and we will shortly see examples of that. So if you write percentage than this will mean their day off the week. So today is Friday's, which will represent if what? I So let's straight. If I write capitally, then it will write the same thing, but in complete name. Not every Richard name, and you can combine multiple search form. It's It's not that you just write one for Mitt if you want date and a month, let's see the annual rate percent is less or sent him. Then it will print their day and month, and you can insert texts older in between. Forward Wait this former and everything between one double corpse and then one Watts analyst. The times tempt. If you don't give, it will take who is not pain. This was dark. Time represents the current time current data in time since the AARP octane, which is first generally 1970. So if you're right this time, it gives you a number. So this can be given it a second perimeter toe this on This need not be current time. You can give any time. For example, if I write Western Day then this. If I write who is not time, it will be We need to a specified the form it here. So you see these tour same on listens against ivory left. So by default it takes the current time only what you can provide any other thing. Let's say this was the current line very close to Currently we have no changed So if you see it's the same But you can subtract some value from it. Let several present then you see there tear. It was 13 hour, 14 minutes 29 seconds. So now it's a 12 hour 57 minutes and 49 seconds. That is roughly or 16 minutes less than this. So you can give any number can be represented rest time here and it will convert it to a readable form it and there is another useful form. It which is start D. It represents this time the time, useless fight Or if you don't testify, the current line in terms off a table. This was a stringer. Present reason this are this is just drink the second ways table former. So if you just give this apartment and it will write it as like the equals do month equal to the value of month than a year and the time also. So let's try. You talk So you see you give the same time what did tabular form in so days? Don't even what is 30 and this is false Minute, month, second and other things. And there is another important thing that it will give you The are putting local former so you can get the time June in formation. So you see the time journeys five hours, 30 minutes. I heard off the GMT time, So if you want everything to win Oh, UTC time. You have to specify this exclamation mark before the first first of the former. It's not all of those. So, for example, if the right always dorn date, it gives this time and if later it was door date this person see by the very default apartment and if you right. You know the six Clements and work. You will see their difference our time. June was aired by five hours, 30 minutes. And if you compare these Ah, here there's a difference off 5/30 minutes. Andi. You can combine multiple formats or sample if I want to write. Yet today is percent e in the montage. So presentable print the complete day that is Friday in the month off person kept will be This is the month So today's Friday in the month of February so you can add multiple of these Onda. Let's say Want to print date in some particular former Let's say De followed, by the way. And let's turn month also so you can combine multiple of these farmers If I write person to , there will not be anything because it's just ahead by 5/30 minutes. But let's say who is your time minus So now its ninth off. Every let's print our this is 13. So no, you could print hour and minute. And now a year, this exclamation. So you see, the difference is you see that I did not add exclaims and in front off them, but still the minute is changed by 30 minutes toe accommodate for the time zone difference . If you were exclaims into other other of the former, it's it will be just printed as a string. So only the first exclaims and will make a difference here. No, let's look at the exhaustive list informants. We have already covered some of these, and you don't need to remember each and every one of these, and some are very intuitive. You will get used to it while programming in lower so person tea and capitally teaser the we could a name for young people sending on a Syrian on Sunday. Similarly, bees for a month. Same three letter and completely I didn't see is the date and time in this apartment, and this is the default value that is printed in person these their day of the month. It can be from one toe turkey even and person capital. It's is the hour in 24 hour clock, so it will you from 0 to 23 and we also have a 12 hour clock form it for capital A then a small Jay's day of the year one toe, 3 65 similar Lievremont Small limits for mint captain limits for a minute. So you see your capital edge was for our capital in four minute and capital yes for second . So time things are in capital letters than this person to small piece for him or PM The blues for a week. Small level for weekday, 0 to 6. It starts from certainly so generous under Capital of Louise week off the years it can be from 0 to 53 the small exes. Their date Capital X is the time, and this or since he combined data contain ah, Then small way is to really tear capital ways earlier. Percent that small jet is timed You. Then this person person will just bring the percent saying so. If you just trade one person, it will get confused because they used for specifying the former. So if you want to print the percent saying itself, then you have to proceed it with person sign. Then we have any useful function called Always Door def Time, which can be used to compute difference between two time stamps. It was just there difference in seconds between two, given numerous times for jumper. Let's say we have. This was the time. Oh, everything is same. The days attempt and then the T two is everything is same days nine. So there is a difference off one day. So if you write with your different even anti too, it will give you time in seconds. So one day has 24 hours, 60 minutes on 60 seconds. So this valuable reprinted. So let's try it out. So Stephen is who is dark time? You're equal to 2020 Monty Quarto Oh month What we have taken. We have taken well, but we can take self the current time also. Then they call to 21. This will be some numeric value. Similarly, let's defying T to everything is same days 20 22. Let's make it. I couldn t on no will. Print was dark disdain Stephen t. Two. So if you do, I did solar to divide it by 60. So this Valerie minutes that's divided me 3600. So this is the number off our switches. 24 to 1 day has 24 hours. So in general, this generally works same as the taking their defense of these Stephen NT to but for some systems, it may give different regions, so it's better to use or different when you are trying to find their difference between two times temps. 47. Modules in Lua: in the next few listens with a study. A what? Model? Sand packages in lower so many languages provide mechanisms through which we can organize the space off lower limbs and ah, these languages provide packages for young Berlin job and pearl or name spaces in sleeplessness. Eso, the main purpose off the packages is too are providing basic mechanism in order to avoid collision among names defined in different level res. So, for example, ins sleeplessness. You write name space earlier to see name Space one, and within that name space, you can define different functions F one F two and so on. Similarly, you can have another name. Space name is place to and you can have the same function name in another names face as well, and while calling, you have to specify lake and this one F one. So this will call F one belonging to name Space one. So it helps to avoid collision in the names. If you are defined everything but our names faced and there will be a collision between these two functions of missions. Similarly, in ah, Java, you have ah kee vertical package. So you write the package and then pack his name and then you defined class and other things . And then, in some other fail, you can used their off classes function using pack his door, a function name similarly in C plus. Plus, we have the cure name space. We also epic is important and other languages but in Louisville don't have an explicit mechanism for defining the packages. But we can define practices using tables, the mechanism off tables We have already seen what our tables in lower So we considered model is just like a library that can be loaded using required and as a single global name campaigning at people. And Morgan, seen Lou can be manipulated the same way as any other lower table. So we have seen that we can have a local variable which can hold a new number string. It can also hold a table. And we uh no. We have seen that more Dussel Abel's underneath. So a local very one week in a sane and Morgan. So we used a require keyword using this we load. Ah, moderate. So Mattie is a pretty fine model in lower. You can define your own model and I mean for the lessons, we will see how to load Ah and define our own more guilt in lower. No, I have been talking about models in lower but not packages. So because they're nothing but a complete tree off models, what is mean to a complete two years? Models are You can have multiple levels in a model so you can are define immortal. And within that you can have some organs and so on. And we have also seen that in overly listens that we can every table and the dinner table. We can have keys and of one of the keys may hold on other people and so on. So the same hierarchical concept is followed in, Model says Well, and the so the core. Also studying more deals and practices in Lieu are the models. Once you're 48. Modules as Tables: in our previous listen, we had seen that there is no explicit away or keyword in lower for defining model tour packages. But we have seen that we can define or lower models as a table. So in this listen, we will see how we can manipulate the models that we applauded as it normal lure table so it can be manipulated in the exact same way as any other simple lower table for young below , we assign a table to a local variable, and in this case, we use require keyword Lord a model. So Matt is immortal and we use require and this model is loaded in local. Very well. Um and this him is off type table so we can call the daughter greater on this local variable because him is a table, so we can call them door sign. And this will call sign function on this 3.14 which is very close toe by. So this would give some value very close to zero. This is just one way we can call it in other ways. For example, we can call require Matt, and we don't descend anything. Toe this library to a local variable, but but we just call requirement, and then we can call Matador Sign. So by default this well with a name in which it will be loaded. But we can assign it to any other very William as well. And another way would be to call require Matt and then a sane in the specific function. So this metal, every lab eso function lakes course saying and absolute value and any some other constantly power, So we just want to use a few functions. Then we can load specific functions to some local variables we can assign, especially function off this model to a local variable, for example, a sequel, Toe Matador, Tsien and then call Ah yes, off 3.14 So these are all different ways we cannot manipulate models in lower. So let's see some example in our I d. So we can. First call is a question Met aan den. We can sprint Math Nord sane, and we will call 3.14 which is very close toe by solar TSA. Run it and you can see the values very close to general and this is has expected and Noah, we will modify it. So let's store this met more duly into a local variable and this will be off the table. And no, we will call just in broad saying So Let's in digital here this sign of Jiri old Sergio. So you get exactly zero knowledge. So trade The third mentored, which is we call requirement. Then we store the same function into some local variable. No, it's a sign matador scene and no, we don't need to call it on model. We can just call Sign which so we have ah, stored the sine function which is defined inside this a model Matt into a local variable sign. And then we can use local this local variable as a proxy for this so we can call sane off you, which is zero. Let's go back to our by example 3.14159 and let's turn it so this is very close to zero. Distant dress stood power off minus six, which is approximately zero 49. require - load module: continuing our discussion on modules and packages in lower. Let's see what is required function we have already seen. Ah, a bit off record points in hourly listens. So let's a receipt in more detail. So first of all, or did require function eso It's a high level function and it is used to Lord and model. How do we load a modern? We just called required and it's a function. So we give a parent icis and them string literal and we can load Ah, this mortal to local variable And here I'm using Met. But by before to be some of the standard modules like Matt String are you is Table and other ah models are by the foretell ordered with the same name the modeling. But we can lord it different names and weakened in court endured devious or m door saying. But even if we don't, uh, import these kind off standard models, it will work. And when calling require, we can have ah, string literal, as is the case with this example. So the single argument can be either a string literal or can be very well. For example, here we're calling with a string literal, but we can ab in local Morgan and more the variable which horse? The name of the model. So this is string literal is held in this local variable. And now if we call the same thing local and make a little request moored. But they're different series that when it's a string literal, you can call this or this is exactly same as calling goulash Met So an equal to require Matt or chemical too require parentis. Ismet Otar accepted. But if this is not a string literal, as is the case here, we're calling with a variable which holds really of a string little This is not same as calling required and more. You will give a space here. So this will true in it or not Ah, it's not allowed. If it's not a string little, it will complain that expecting a string little what you're calling more so this you need to keep in mind so but heuristic with ah parentis if you're using a variable and it's also very common toe ignored this parenthesis and use the string little the actual name off the model so I can give a brief them off. This for that. You get my point, salute to a call local am equal to the question met and it will explain. Then I call this still it works plane? No, I store matting to this acceptable and you see, um, ex acquittal. So in this console, there is a problem that it does not store in local. So X is a big net. No, I call I would skip local Emmy Cool too. Request X. So this sort of work fine, because I have added the apprentices. But no, if we remove despair intereses complaints. Although exit is still holding this mess. So when you're not using string Little keep in mind that you give the parents. This is now let's move on. We need to know how the require function works. So it works with the help us able called Pakistan are loaded And what the stables worlds. Whenever we require any Morgan, it will be added to this table. So this back his doctor lorded Is it even and for example, in over kids it has a more detailed map which itself is your table, as we have seen in our previous listens or similarly, it will have other people's like string people all too. Then are you with and some other tables standard models. And if we define our own Morgan and we will see how to define our own models later, and ah, we then load this mortal using require then, uh, when you print because dark loaded, you will see entry for your own more. You'll also like mortal in equal toe able, and it will contain the functions that Europe defined inside your custom model. So whenever you call, require modeling it 1st 6 Whether this model is already present in Pakistan, loaded table or not. If it's present, it will simply return this value. Whatever is the model you're calling require bit, but if it's not present, it will move for their. So if the model is not a loaded here, then it searches for the world file with the same name as the modern name using the variable akkus door. But so when you print back is not part of this holds a list of parts inside it, where it will first look for this mortal. So if you call required ah more one, then it will look within the list of this parts Ah, for a file called Moored Wonder to lure. And if it finds a file it will loaded to using Lord file more than one daughter Lower Mr Resulted a function which record in order, Lord Stefansson that when called lords, the more do so in order to function. Ah, but it may not represent, uh, within this package or what? Ah, whatever is the part is stored in this So what it will do It will no look for in modern limit searches for c leathery been that name And it looks for because Lord see pot and ah, if it finds it a celebrity, then it will use back is dark lordly Here it will using Lord file here it's using Pack is not lordly looking for a function Corn Lou open under school Morgan him So this is the Lord er in this case in this case Lordy, Lord Foyle Hair. It's blew open morning. So either way, if it finds in the lower part or C library, it has in order. So no matter whether the model was found in a lawful order, delivery require now has a loader. And what is the function of Law Order Lord, is your function that when called Lords, the morgue finally required costal order with two arguments. So either way, it will have a loader. And what the way to call the lottery's toe past two arguments. When is the model name that was called with required? And there is the name of the file. Very it got the loader most more duties and just ignore these arguments. If the Lord returns any value, require returns this value and stores it's in the back. Historically loaded people are to return the same value in future as we have just seen to force require into loading same model choice. If you want that every time it called requires made require should do the entire work and load it again. Then once you're done, you can sit back is not lorded, Not more name equal to new. And this is the name of the custom model. So when next time it calls required, it will. Sick packages are loaded table and it will not find this morning, and it will re do the work salutes to see some examples to get over hands under this, uh, for example, back is not loaded or happens If I do this, it will. Our source used number off lorded models because a Z we have seen already it will contain Matt String Table are you was and many more standard models. So it will slurred this console with all of those So in order particular individual models we can print. So this will just print this more Do you see This morning starts with this braces So this morning itself a table and it has the list off various functions. So functions are first class surgeons in lieu and B you're assigned to a variable So obvious function is there are call sign is there Arc sine is there and all the similar Matt functions which you can think off like our referendum and alerts again called Pakis Door loaded north Ah, the string. So you see the different string functions are stored here Then similarly there are always Then they're more deals for you and you can try different things And you can also load your own mortal Onda. We will see our greater model in detail later work for time being, Let's create immortal my model equal toe empty table and simply return my model. So this did not have currently any function? No, What we will do here, we'll call my model equal to So first. Let's take that kids door Lord did not My model, it's it will printing. So my model is not yet ordered. No, I call Chemical too Is the question my Morgan? So in this case, it it will look for my model or glue in the Oh, this spot no designed it back is your pot and it will find it and it will load it so you can see that Mm is not new. It's an empty table as we have defined here. No, If I call like a stork loaded or my model, you see that it's not meal here. It was nil hair. It's not mill, but you. Concerted two nil and it will or reloaded on little to look at the contents off Pakis Dort part and back is nor see. But so I hope you got some good understanding off how what is required function and how it works in lieu, in order to Lord a model 50. Writing Modules in Lua: know that we have the basic understanding off more jewels, how model to work and how the require function works in lower. We are ready to create our one model, and we will see two methods off creating models in this listen. So in order to create a model, we will create a table we have already seen that mortals are nothing but able on. This table has a number of functions and their implementations. So first recreate an empty table, we can give it a name on. Do we put all the functions we want to export inside this table? And finally, we returned this table at the end off this file. So either we will return in the table name, which is the first metal, or we will return a list which will have a list of functions were just defined inside dart function. So let's look at the first method. I call it simple mortal mental. So first, uh, it's a file called a movie Dort lower or whatever is the name off your model and you create an empty table and then you create defined some functions and finally you put it inside this like more doubtful one Nicola this You could have also written like a local more equal toe. Instead of creating empty table, you can start the signing. We're loser like food one equal to function and the exact same function definition and football and other funds and definitions. And finally you return more. I have done it in exactly this way for stay clear to table Put the functions insider. So go Terry current and we will see that both are equivalent genderen exactly the same way . So first let's look at this material one. So yeah, I have created ah profile called to read or lower And here I will re creating our model which will handle different off presence on a rectory into the director. Can we end diamonds? No, but let's say we're considering it to. Time is no butter that is in plain X ray plane. So first we need to create even then, what are the presents that we want? Picks food? One method can be hard to creativity, given its two coordinates. So let's be flying this songs and so either way, like, ah function inimical to function or local function andare Grint list So it will take two arguments. Xingwei. Because in we denote victory EDS X then ah unit Victor, Let's say I this unit director along extraction plus way and you need to retire alone. Why direction? If we have more confidence, we would have more unit vectors. So we need to variables to values X and way to denote a veteran toady hand ribbons. So every victor will have ah, two features or two properties called X and Y coordinates. So x equal it works. You can give a different name also like I n g and their total to work and returned this winter and and and I forward to give it a name. Let's give it new. We go here we are creating a new rector. No, we want to urge to Victor's so it should take directors even anybody to. And it would return the result of that so we can return X equal to move even detects. So the victim medicine works like the yard. Ah, the confidence off two different directors along the same direction. They're different values along different conference. So all the values along ex confidence are added together and wait wither. So here we are just providing Wait where two victors and not move, so it will take exactly 22 Surgeon who's resultant X component result will also director who actually Oh, so in this case, we have I we will not. I So you have to maintain consistency. You need to keep in mind what are their two features here? And, jeez, be even Georgie. Plus we told ORT g similarly for subtract on and or let's say, we want to give a function for printing the victor bring to fix and it will take one victory in Onda and drink it. So let's say we want to print it in table form. I could too. So this would bring the victor on. Well, maybe now we These are just local from some. These are not part of this table. This more do that we want to export. So what we'll do to be dot whatever name you want to give you can give a different name, but I will keep the same name as the name of local variables. And once we're done with it, if you want to keep some ah functions private, it cannot be accessed by any other model, which is Oh, importing this more dependent you can you miss? Keep assigning it toe this table. So for jumble here, subtract is a local function or we will see the most it shortly solar. It's exported first. So no, we have cleared anymore. You define some functions for that model and then exported the model and here in the claim cooled we can have very well let's savic on this will call request Rick Duty And then let's say we cleared a few victors. Even Nicole toe ignored new 10 and 20 So 10 and 20. So you're so dizzy over X ray plane, then 10 and 20. This is a terrible reason somewhat like this resistant. This is 20 on This is we who won. We can write it as 10 20 or then I plus 20 years. Let's say we create another victor which is middle image of this that is minus 10 20. This is very to and is were these it will reeled in a victor like this whose ex competent will radio on why you will be 40. So this listen this So these directors every girl and you can droit here also this will be 90 degrees on this will be Ah, not 90 degrees. Sorry. This is our twist to one race you. So it's more than 45 degree so you can find out to what is There are the Greek word. You will see that it forms and I should sell a strangle. Well, this values him at this value because their magnitudes are same. So let's see their duty. Never. Korb. Let's create a victory to acquittal. That's not new. Minus 10. 20 on local equal to. So we have added undies and we will also call over rent function. So Victor drink tricks who we and then we will run the court regard some better. Ah, so we have missed some end somewhere. So in c placeless This is the problem when you're according in other languages. So here there is no turning off. The function is not like a delivery system, but my end saying Mister care new resign Bring this fine. So let's run it again. So the mistake it at 9 35 in two D. So it's not exported return. So is returning. Now Let's run it And it works as expected, sold The result ended Jiro, because this 10 in minus 10 can salute and then miss 10 20 plus twenties for P. Oh, let's also try earning it. And you see the differences 10 minus minus 10 is 20. On this way value Cancel orb. And no, let's say we want to make this subtraction private. So what we will do? We will not added to the exported from sense list. And no, if we call it, we get him because ah, this when we require all require this model is imported here as a table. The exact same table that we created here. What? This sub is not part of this table. This is a local funds into this morning. So Rick, nor some isn't it? So that is what it is. Complaining. So does he already went private functions? No. We'll see the second mentored offs creating models eso in a limited. We had created tables, then ended some function student and exported that table. So here we defined the functions the same way on. But while exporting, we don't add all of these late a model named orgy full one equal tofu when we don't need to assign all of these. Once we have defined some functions, all the function that you want to expose for treating this table. So you return a table and you return different key and the value are these function definitions. It's alerts mortify Evercore to work with. New Guimond isn't so. We don't need to do much. We will comment about this part of the court and is he also not used so it will not be required. So we will simply return if people there's new equal toe new and already court weird, you can give a different name here. So we returned this. Let's change some in blue and isn't so There were, ah, sealed art. It's the new rheumatism. So there are lots of yard, some extra characters in the print function. And no, we don't over Klein cord, and you see that we don't me to change it. This is so This is just another way off visiting our models and you see these extra characters here, so it's using our new implementation. So these are the two days off easier ways of creating models, and there were some older ways of creating more deals also, in a way, I'm not going to cover that here 51. Data Structures in Lua - Introduction: over the next few listens, we will see how the work with data structures in lower. So first of all, who are later structures or desire the main, the district system that comes to your mind. When you think of data structures, it can be a linear structures like area your link list or two dimensional or multidimensional arrays or mattresses. Then we abuse which followed first in first or principle and then via double ended twos. So, Accuser 100 that is You insert in there and and you removed from the beginning. Um, but double ended cues are you can remove or in searched from bow dance neither of record decks. Then we have suits of which have some properties like you store some there. Loser and duplicates are not alone. So these are has searched internally. Then we have has maps. So in many languages, like Java, are a C plus plus. Also, we have a standard template libraries and there are some very efficient implementation off all of these data structures there, and ah, in low. We don't have any of these, but we have the table. So able is not a religious structure in Lourdes but it's build a destructive that is, we will use or implement. All of these are data structures using table. So in some of the convents, known languages like Oh, well, see we don't have implement isn't for these but we implement all of these using ah a raise or lists. Similarly, we will implement all of these using tables. But I want to say that our tables are much more powerful than lists and a raise in C and ah Lord tables implement all of these structures much more efficiently and over the course off your lessons we will see how toe are used table to implement all of these structures. 52. Arrays: Let's start with the simplest infrastructure court marriage. This is a linear Detroit stricter Onda. We will see how we can use Able said There is in lower. So if you have some, If you have worked with raising some other languages you I know that, uh, there's a linear data structure and there are positions or in this is on there are actual elements which are sitting inside that data structure. So in some languages, like C Professor John Boy, it will start from zero want to And if there are in elements than it will corporal in minus one Oh, in lower there is no such restriction. You can, uh, in certain elements that any index even negative element needed to in distance. But there are some rules which is given mind if you have tow huge some of this tender oh facilities provided by lower celebrities and that says that usually start the indexing throng one. So first, let's see, let's forget toward indexing and let's see how we can or define marriage. So the implement areas by indexing tables within this is integers. So you create an empty table, then for 1 2000 you are treating your index I So first index movie you awful one on we are putting here. I This is one than a off to is do so So here it's one. It's too, and values also wanted to. And ah, you see that here It's not fixed, say, but has we insert more elements? One more index will be created and its size will increase by one. So it is. Do not have a fixed, say, but grew as needed and let Sylvia inserted cogent elements. And ah, the Indus is er from one protection because we have manually ardor Genesis one, 234 Uphill caution. So it's really tried to access. So if we have to access an element element, we will say print it and then it will print element that is stored it. And so it'll print them. But if we go outside this range index range, whatever we have is trained for jumble sales. Ah, 1000 Tim. So this is beyond one pageant and it will return a decision. Underwear off, creating Aires on Do you just provide an initial a journalist So you declare it and defend it in the same state in the same online. And why default? What will happen is that this will get index one. So if you try to print be one, it will print one. If you bring to me too, it will bring 10. So this is that index to this is three. So here you are not riding Index here we were providing in next. Ah, so it has started index from one. If you print be Jiro, it'll give nil. What? No other language like secret lists. If you have created an area like this and you give a square braces here in on the language , then this will be out in the zero. This will were index one. But that is not the case here. Although this lower standard libraries their toe this rule you are free to assign an index . And when you want to find this a definitive, for example in this case is this area. If you use this lent operator, it will print pageant. But I have added two question marks here because this will not always work. And when it will not work, we will certainly see example of this. So first let's create enter using the methods we have seen. So we created empty Devon then for equal to 1 200 What we knew. You put a equal to two times I just to make a change. And just to make a distinction between index and actually I multiplied right toe. No, what I do. Let's sprint. If you re loose from it, let's bring table. That's bring it in. Let's spring the last element at index 100 and let's sprint one index Curtis out of bombs when you do one, or it can be a nearly larger than 100. So you see Art index one. It's two times one Who is this to at in its 20 at 100 just 200 at 10 and you know it's new . And also, if you try to access a zero, it should be No, no. If you use this limp of return, then it should correctly print 100. But this limp of Richard will not always work. First, let's see the others method also, so this is using in its allies list again. If you bring to the limp or sage of this area, then it should carry equipment for so it could blueprints fourth and uh, if you access B zero, it's Irvine, Ill. Me. One be fourth me flavor. So let's first get some renters B zero for three nil because the index by default if we don't provide index you to start from one. So be generous and will be one is the first element system before his 50 be five does not exist. So nil so new 10. 59. Let's run it, Nilton, for signal, as expected. No, we were saying that this lentil return may not always work and when it will not work when we don't follow Ah, the method that it is recommended for in this is that is we are free to give any index for gamble in this case, same as the first example. But the thing is that instead of starting from one, we start from my Aniston and Gore built in, and we create a equal. So I so it creates in my intestine equal to minus 10 than a minus lane equal to minus name . Similarly Geo according to Geo, then on the positive side, you won equal to one, and finally it will corcula. It didn't riches then. So my intestine Chilton So here there are actually 21 elements going my intestine on the negative. Say then one is 0 11 and then then from 1 to 10. 21 elements are there. But it's you. I tried to find the sage minus 10 Hilton her and let me so you can bring to the region This is you can access using the same injustice that you assigned. So what we were in Dixie was saying that you can access later. So let's get some answers. We assign C minus 10 equal to minus 20 so it should print minus 20 then see Jiro Times zero is zero See, 10 will be two times 10 visits, 20 on this result off range which did not assign descendants index at any point of train. So it should be No. And as per our understanding, this will give you 21. But we will see that this is wrong. So you see the sage ist And so this is correct. Whatever we expected but decides is not correct. So it should have been 21. But it's giving then Why? Because the Indus is er from minus 10 all the way up to zero. Then followed way one all the way in. And we have seen that if we don't, uh, saying an index, you just starts from one. So 12 still four. And it is the recommended way that if he was resigning tease. You assign in this way starting from one because of lower level grease, the different implement isn't the function of these provide there to this A room. So here it will see that I must to find the side of this table So it will look for in this is 1234 So still where it was. So here it will ignore this part. It will only consider from one depend so it will print them. So unless necessary user to use in This is from one toe in 53. Matrices and Multi-dimensional Arrays: in our previous listen, we had seen how to represent areas using tables in war. In this listen, we will extend our knowledge for there, and we will represent mattresses or monetary damages militaries. So let's see. What are the different ways of representing mattresses? So I will be talking or different ways of representation off in metrics and the metrics, Is it dearie? We can huge similar concept to represent. Hired them insensible to like freedom. It's no Fordham. Is there a raise? So this eating metrics and it has four columns and flavor rules. So art is five, and C is for so one way of representing would be not oh, table inside table. So you create Oh, people. So let's say this metrics is denoted very variable, Matt. So you create an empty evil and what you do you create. Oh, they're five route for you Create five moral Ebel's. So this will be table one. This will be table toe full. You can run I equal to one. You are so this look will run are things. But in this case, flight teams And here you will create another table which will do not as a rule and this rule has seen more developments or four elements. So again you can run a little Z equal to want to see Go. And you're saying that year Ritalin J whatever you really want to still let sin you and then end and I for work to assign this rule. Matt. So after that your courage in the rule you can Assane Matt, I equals toe room. So let's see how this works. So initially this is empty table No, I e is one that is were the first true I use one Then we look for GE equal to 1 to 4 So this room is empty So Rule one will radio row, pool regional So are the end of this This several will be holding Jiro Mutual Jo Jo And here be resigning, Matt one equal to zero. So no, this match table has when he called to this dear Oh dear on your own you know, again I becomes too for become here Similarly, we create another stable off the rose and we assign it to Matt soon released and while printing also or accessing or doing any or prison on this metrics, we have to access it. Similarly, So it's the right met three I first met. You will look for key too, so it will reach here the second row and within that authority, so it will come toward column. So this is 23 so dizzy all weekend represent and metrics in lower. So let's write a court for this first. Then we will look at the second method. So let's define over rules and columns. Ruiz C is for metrics is empty for equal to want to you go let's store or different values just for fun. So we will store one here tow were 34 then save 67 it and so on. So you see you in the first rule. It's from one to see in the next roids C plus one C plus two until to see. So in first roids. One you'll see in second route C plus one C plus two. So we're just see to every value. So we were trade to represent in 30 years. When did you bliss? So if its first rule it will be J plus zero so we can subtract one from it. And in the second row, every values increased by sea in the told you everywhere we will increase very to see And this camp represented that first rule duly zero second road Will we see The constant third road will be to see three minutes when and then we ended on what we do or the a sane man I equals room and ended So we have created over man tricks. Now we want to drink our metrics. So let's killer difference in tow Drink metrics. And you took pick one metrics in a number of rules. Number of columns So print will print everything print and moved to new lines. So individual values we don't want toe. I moved to new line. We want to print all of these in the same line, so we will use my your art right here instead of print. Oh, you're not trade to then Ah Oh, you. So you see, how am accessing the value of thick metrics that are you through injured column and then and have characters after that? And once we have printed a rule, we can into a new line. No. Let's call this print Mert on this Matt metrics. Oh, and see so is either typically Prince the metrics. 12345678 1911 12 Till 20. So this was the first way off representing metrics. So we have an order table and inside that were in her tables which are rose. No, we can represent the same thing with single lemons. Alonso, Eso what we will do we have Don't be such values. 1234 5678 till 20 So we can have just one people or you can think off one lean years, Eddie. So it will have in this is 1234 So these will denote Rolen for a minister's 5678 Miss Willie Notaro and so on. So what we can do here we can again have and empty metrics and equal toe 12 rules and is equal to I want to call him. We can arm note mapped and or whatever logic we had tears. Oh, no tears This j plus I minus one c. So this is basically the index off. So we represented in linear personal. So these 1st 4 he's followed way. These four followed rate in these four. So how can we access any G? Let's say we want to access toward rule and second Key. So what we will do? Three bliss Ah J J. Is there, so it will be two plus three minus one times c is for so using the same logic, we can put their team logic here. Gee, Pless, are you minus one times? See? And we can assign some value. So let's implemented in and similarly for accessing, Let's say, want to exist toward ruin. Second column It will be somewhere here so we can use the same trick. Your toe access in there. So we will call it Matt toe on. We will not need over where we will be using just one table. So, Matt, then India's Ilta not required and we will need another drink function here. So this is in fact, a simplistic print. Folks in print Mert Hornby or this is just equal into printing an area. I will call it here. We can print Lee nearly also just in one lane, but let's say we want to print in well, this form it. Only then what we'll do. I want to work and then again from in certain the same thing. Let's an urban separate area. So you see these two or mattresses are same, but we have used two different represent is enough undies. What we can achieve achieve similar result. So here in this matter match who is a single one? The missing people on and we are not used an indestructible and we're storing just won t to it on here. We're using tables inside ultra table and we're we can achieve similar kind off Richard for both the cases. 54. Linked Lists: in this. Listen, we will study work link list destructive and in particular we will look at the case off single Xing Leland list. So let's understand what is linked list and how we can represented in lower using tables. So we represent each note with the table. So first, before coming to this late, let's understand what it just singly link list. So our link list is a list off north for we have in order. Andi Snort has to feels in the case of singly linguists, If we have the Brylin Christo, we will have one more field. So this field whole stuff value and this was the point off next Nord. So this is one Nordoff a linguist. Let's say toward civil you've been and currently it's next is null so you can write Neilia or eternally wouldn't bank. Then we have another Nordoff link list and this horse early off 20 This is Well, this is next. Similarly, we have another journal again. Each of them have a common structure. You can see when is well and when he's next. So if you have a table, you will have a field Caldwell really cool to some value, like 10 for the first case. And next it initially nil. So we can say this is and then, you know, nor pen so dizzy just very well in lure. So you see, using this stable structure were basically representing this north. No, the question is how to connect them. Because this itself, this itself is a link list with just one more. But if we make its next point to this by that we mean you see make. So this is over. And similarly, you can define the structure for in 20 and 30 with just value. Well, you're different. This is an 20 Mrs and 30 initially. Next off, all of these is nil. No, what I do. Four next off and then I make it. And 20 and in court, Away able rate and tender next equal to and 20. Or you can write in just one table also, and then next often don't be a Mick and 30 and it's next is still nil. So this really in order end off list to, um, we will be given the first in a lot of the link list. Middles. Ah, it's a singly linked list and we can traverse Onley Didrikson, There is no next from this going to any Nord previous off it. So there is one great reversal from left to right. So if we were given a pointer off this a reference to this first Lord, we can reach to lay another list. And this is a really full of storing data. Oh, in a link list, we store in a linear fashion. And how is it different from a reason some other languages? Because the area is contiguous. And if we have to insert anything Edward in between we have to sift everything. That is not the case in Ah Lord, that is the case. If you are maintaining a fixed index like 1 200 then if you want to or insert one element are 58 food is, um, some other element about occupying 58 47. Then you want to keep guard, Then you have to sift everything to the right. But that is not the case in link list. Let's say you want to insert something before 20 then you will create in, you know Oh, Viterelli off! Lots of 15 and you move this next from here to here, and it's next to here. So you will have a new list. All the ordering will be maintained and this will be done in constant time. Now we have some idea of link list. Let's see the court. So each node is represented with a table. Links are simply table feels that contender friends to other tables. So this is the way to define it. So you So you have list is new. So they're in? No, no. Then you create a list and make its next tickle toe. Whatever was a literalist so you could get in, Lord, and it's next is no pointing to the whatever early list Was there initially triangle and on dissipated. Able is the new list list is no. This when I insert again, I will create in north who's next? Billary the existing list. So this and we will insert value on this whole new tingle with a new list. So you see your this list very really already holding the first Ronald, we don't need anything else because we have the difference off all the other lords. So we have this note we can travels all the nodes so let's write code for this Bennett really more clear. So first of all, let's look the simple way. Or we will try to create three variables and 10 and 29 30 and then link them. And then we will also travels them so local and 10 equals do well equal to 10 next to court . Don't know. We don't need to write it better if we don't write this field in this table than decision. Implicitly eternal. But let's write it for clarity on Let's Air to nor Nerds call it and 20 value 20 30 and a straight away. We can put here next to equal to N 20 but let's do it in there. So at this point of time, we have three independent notes. They're not linked. We have to link them. So we will right in 10 nort next equal to in 20. So now the first connection has been established, but this link is still not there. Then we write and 20 note next week or two and 30 and we don't have any next off, and 30 and 30 is the last North, so we leave it as it is. No, let's very to function for traversing the list. So this will take the list on ways while list is there what we do? I want to print it in this person. So at this point of time, we have this or 10 tennis pointing to 2020 22 30 on 30 is pointing to new. So we will rent it in this personally so lister. Nor, Well, we'll print Lisnard well and then this aero again. We're not using print wiggle that will take us to the new line and we don't want that. And we also need to advance turtle List Mr North Next. So what we're doing initially reports and Tim So in 10 Israeli, it's not real. So we will print its value, which is 10. So we bring to 10 and then this arrow and then we make list ical to list next. So it's next year and 20 so no list becomes and 20. So we come here refusing 20 and in this era and now the new same variable becomes its own next. So it comes here so we print 30 and again we move next and now it's next isn't little. So we stopped or we print me earlier in the end and no weird new line. Let's call the function Traveler's list on and pin. So first, see if we call it on and 30 what will happen? So we're passing and 30 so it will print 30 and make moved to its next regional. It will stop so it will just print for 40 in this case. Ah, okay, So do is missing here. So you see just Prince 30 and because they had nowhere to go back. Worse, we can go only four words. If the right 20 years it will print 20 and 30 and if they didn't hear it, will bring the complete list. So while refering to list were always refering to the first inal, we also call it Heard Head an orb or or in some other terminology, we also call it to shoot. This is derived from the concept of trees. List is also a kind of tree, with just one taylor at each level, but a strange and all can have multiple tailed. So the leader called head or root the first note, and when we pass the first note traverso function, it will bring the complete list, and we can have some more stuff here. If we are designing some a p A or some more. Do, which is dealing with link list or presents than you will provide functions for inserting into the list. Let's keep a globalist that will make things even more simpler. User's pass the list to the function the same way we positive here but for list reason we can have in Global. So we have an empty list and we want to insert value. So what we're doing here, Oh, whatever value we want to insert, we will create it, Nor with that value and whatever was the distinguished. So the list had already three elements under oath, so it really uncertain or before the three elements. So in the beginning, and this polar list will be updated to hold this, will you? And then we called insert ah, flight. Then insert could be, then insert one. So it's inserting in the beginning. You understand why? Because you will be creating old. It's next is whatever was their literalist. So it's next. Is there little list and the list becomes off to the current. Nor so we just upended one node in the beginning, and now you drink it or travels the list. What is the head North? It's just in order to buy this list itself, but we're inserting in the beginning, so five is the last 50 inserted before that one before that. So 1 55 and let's run it so you see 1 55 new. So this is how you can define other functions like you want to do some, uh, reversing off the list. You can write a function from that. You can write the function, which takes two lists and returns and new list with the some of boat or more marching off. Coolest, you can think off. Ah, Lord number off prison that you can do on lists. This was just to get you started. How to create a list singly link list. Or, if you want the link list, you have to modify it slightly. So each nor Novella one will you feel lets it in next and devious. So it's next is this little of every nor will have three fields. No and its previous. So this really previous missile revalue This will read next for all of these. So it's rib useful repointing to this Nord, its previous pointing to this nor and its previous will be no so previous off here it is no mill. And in the case of lovely link list, we also keep their friends off tail. So I heard. Until so next off tail is nil and previous off heard is nil. So it would be a good exercise to implement in the blink. Liston, do our reversal and insert sanity. I hope you understood. Ah, this If not, try to watch it again and you should get the idea. 55. Queue and Deque concepts: in this lesson, we look at another very useful later structure called Q and A blended Q or Nick you. So first, let's understand that you So it follows seafood fee for strategy, which is first in first or so when you go for movie ticket and you're standing in a queue and this is the counter and the guy a year who's sitting is giving you movie tickets and people understanding they want the movie tickets. So this person came first and he will get out of this cute first. The next one will come and he will get our next Hilger. That ticket next and whenever in New Person comes, haven come here. Not in the beginning. So cue followed first in first or whoever comes first. No unusual. This is useful in some of the state doing tasks where server is there. He's getting a number of requests from the client, and he is just nor nor tea. But the server is just doing the request into a queue in order to process nudity. Christo one by one. So here we are mainly interested in Bush smack. So if this is a que we have, someone must in 20 30. Then we will all be insert in the and and we will always removed from the front. So you just exposes both smack. So this is pushed back and this is Bob Foreign. And then we learned there is no sage, so we will implement. Ah, all of this in the next. Listen first, let's see parties day queue, orderly under que So this is very similar to a Q. But it has some personal power. You can see pushback is still little up off, 20 still lives. I just deal. We have introduced do things Whose front? So we have again 10 2030 Then we can insert here. Begin also insert here and ah, we can removed from here and we can also remove from here. So what is our personal lives? Uh, discomfort toe you. This is a reasonable and this is at least least tour additional and we have accordingly those two MPs So in the next Listen, we'll just implement doubly ended cues where we will implement all of these five functions . And it's very simple toe update this to get a simpler version or that you can do that as an exercise. So see you in the next Listen 56. Deque implementation in Lua: in our previous listen. We just saw what are cues and water. Lovely 100 cues in Dublin, in queues, we can know, insert and remove both from the beginning of the Cuban end of the queue. So we will implement all of these five bps into our court and we will create in the form of more doing so. We will create our own model named ridicu and we will heard all of these functionality to that. And then we will create a chest cold or the client called Bear. We will import this model and right over claimed called. So let's begin. So I have created two fires, one big you where we will define our modern women. Functionalities and dick you test were real important this model So let's begin quickly. So first awful charity function to create in new who will never be our defining in the infrastructure. We need a mechanism toe, create a new instance under infrastructure. So our first let's understand how we will achieve that. Then we will go to implementation. So when the q is empty, um, it will it will not have any element. And at any point of time, we will be having doing this is because we can insert and remove from beginning and end as well. So we keep one index. So all of these values are being stored at some key. So we will keep track off this the first value, which is first, or it will. This first will dinner the first key and this will do not last UNIX or the last key so initially began initialized first to it. Zero on the last ret minus one. So whenever you see there to last his less than first, then the queues empty when we insert in the end. So initially, let's say first is zero last in minus one. Let's say the insert in the end, so last moved away. One first is not enough because we're inserting in there and so last become zero and we haven't element here. Let's it then, no boaters having value of zero if insert again in the end, we will implement this l 21 and it really repointing here. So whenever be in certain turned Oh, the increments the last value and put a value there when it will be removed from the last we make the last value nil. And then you're the criminal last, will you? And when we insert in the beginning, we will insert towards the left. So whatever the value, first it will increment. We won. So for Stanley inserting the beginning let's of 50 here then this s will become minus one. So whenever we're inserting the beginning, we're in agreement in the first And when we're inserting and then we're implementing the last And the reversal happened when we're removing or popping. So when report from last, we make it new and detriment This lost. And when we pour from beginning we make this new and incriminate the first and when last becomes less than first Bender Curious MP and this size it will return Last minutes First bliss one go In the base case, you see, last minus first is minus. One plus one is zero When we are both are pointing to the same index Lefty Jiro. Then we have inserted one element. So Jiro, my energy to plus one that this plus one. So I hope it's clear Snow, Let's begin. Our implement isn't so. We have to insist. So we need to return even consisting off first tickled zero last according to minus one. So most of the litter structure you will see that is simply an extension off able. We reading something started to it. No, let's first to write the signature off all the functions. Then we will fill them different on and then we need push back. Then we need or front and we don't need a value. We go do whatever reason of front. We will hope that then woke back again. We don't need a value here whatever reason in there and will report Oh then weird sage which will return the number of elements in the queue. Let's say recently put function for printing that you so that we can test in the it's called What is the CUC at the moment and in orderto export this morning what we will do even return all of these functions So news there whose friend them push back. You can give a different name if you like, but I'm keeping it Same then or friend open back. So no, we have exported all the functions. But we are not here different. You find him. We have just different you, Knoller to define the post front. So while pushing in the beginning, we don't need to Ah, check for whether the Q is empty or not. But while we're popping, we need to check whether the Q is empty or not, because you cannot fall from an empty queue. But in pushing that is not required. Whatever is the first element pointing to first index, we were discriminated and insert the value there. So what do we look? Was front? We will do self from north, first, equal to self absorbed post minus one and then sell. We put this value transforming to this key were the first disappointing, and post Mac will be very similar. Let's Koppett for instead of Khost, it will re last instead of minus it. Very plus no, we little forth from front. So we will make this self dark for stick or two nil because first is pointing to there this , uh, left most value. So we want to put in here when we were writing both pull front. So whatever is the value of this question? Next, make it Neil and move this first hair to 20. The objective version would be 2030 and first will point here and last here. So last remains where it was forced to move here. So for Stijnen committed and we make this Neil So we will exactly do that here. Oh, we're popping from front. So if self owned art first is more than self door last, remember, this is the case when Ah oh, the queues empty. So we cannot hope from an empty Gilbey Girls, there is nothing in it. Then level the turning it off. But if this is not MPRI, level it and we're them. We amid this equal to Milan in increments in the first, on a walk back we were losing blurting work again the same MP tick. Then we will make last equal to nil and last tickle toe lost minus one onda And there can be a variant of this pop functions Or in some cases, you may be asked that you not just remove it but also return the value than additionally, you'll first copy this Very whatever is here in the local very even for you number local well, equal toe this and finally after popping it, you can return well. But let's see, in our case, we're not returning. We're just hoping it were just removing it. But you can easily make their change similarly year come back. You may be asked that nor just for Pittman told to return the off the Value Onda Society is very simple. It should be returned. Self Lord lost minus self dork. First this one aan den bring to Kew so we can have we have to bring the all values starting from first still lost. So I really exist. Self Court first and Wales Idenix less than equal to sell food or lost. So this takes care of the empty case as well because rendered simply first is more than lost. So I really exist equal to first. Oh, so this condition really, really good in the beginning itself, so it will not bring anything. Let's give some space victory in the elements And in the end, we learned a new lane. Oh, I think we're done with this. Implement isn't on backs plays in Cuba, So we have added all the functionalities knowledge, right? A client called sorely cuticle toe. You'll call declare Did you and we will create a curier. Let's call it Cuban equal to Dick your canoe, so this will create a Q. Then alleged Awesome also presents so cuter with front putting toe Cuban worked in. Then looks do a few more also presents. And then let's insert 20 and then 30. And for a change, alerts insert in the back 40. And then we print de que dirt sage off Cuban. So first we will bring the size and then we will bring the cure itself. So what we will do? Bacuna alert Drink you Q. One salutes gets our enter what it should print. So we have a look. Use empty insert, then in the beginning, so we got them. Then we insert when in the beginning 20 is inserted in the beginning and 30 in the beginning again. 13 the beginning, then 40 in the end, so forth becomes here. So dizzy or a bogus? No, let's earn it. Oh, so there is some. So here there's something between our implement isn't perhaps we're not heralding the induces correctly, so let's stop it. So let's look back at our Korb. We have used todo No! Okay, so I understood of the eight year never implementing this RDX. So is its printing the first element of again and again because 30 is the first. And you see that idea axis pointing to first. And we're taking this so it will never reach the last. So this was a blunder. This loop Bolivar terminate. Now let's run it again. No, you see Prince correctly sizes for because we have inserted for elements and this is 30 2010 4 p, which exactly matches with our own estimate. No, let's do a few more or prisons here, let's do some for. So what will happen after this 30 will report, then do one more pop so that we just all or all off our functions. Then we pull from next 30 spot for his back popped severe left with 20 eaten. So let's do this exercise again size and renting it. And our guests here is 2010 and let's run it, and it correctly says that sizes too on, but also prints 20 and 10. So you see, ah, how easy it is to implement is such a powerful later structure called Lovely 100 Q I leave it as an exercise for you to implement to which will be a simpler version of that off this one where we will not who's in the front. So this function will not be there. Similarly, uh, Pop back will not be there. It only pushed back. You put in there and and all from front and side will be there. 57. Implementing a Stack data structure : in this would you rule Study War stacks? What artist? Tax new does structure andan. We will also see how to implement that in lieu The first let's understand stack and how is it different from Cuba? So if you remember our discussion on cue, you were late But you ve seen over real life We're standing in a queue. So the person that came first that entered the two first that will come out first and the person who comes last, will or get persist In the end, we also saw a doubly ended cure dick where we're allowed to add or remove from bottoms Stacks are somewhere different in that Ah, instead of FIFA would notice first in first, all stacks follow leaf notice last in first or so. Whatever you do for whatever is most first will opt last 10 Whatever is most politest the last element there was pushed when we pop notable development that will be removed So ah, let's see, we have stuck and it's growing from mortem to top such diva inserted Then I pushed me. Then I pushed see, so does it the state off stack and instead we have no sign off Don't. We cannot randomly access any element as is the case with Terry. It is We can only exist in the top element and we can only remove the top element if we won't remove, Be than first remove See than the moon be then pushed back. See? So only your prison celeb will be to get the value of stop to push a value Here you will pass the value and what it is now you can also have site. And so his new studio in orderto purport to work correctly or it can be turned away The level record as well. So dirty for peace Corland MP stuck. We don't do anything or it can be taken care by client. So there are molecules. You can implement it so they want to push a value to the steak. So what? Deliver the change. So here we want to push me. So this would be our any serious tech. When we pushed the it becomes this. So was he disbarred? These are untouched here in ears on Ladies Postaer On the other end. If you want toe pop something, then it will be always support from the and here. You don't need to assign passive value because it's not on. What do you want to pop? You can. Just for the top element. There is no choice here, but in case of person, you want to post any really whatever you want because you can push, but you don't have control over where you want to insert. It will have inserted in the top only and in the pulpit will be removed from there. Top only. So there's the basic concept off stuck. So putting it together, if this is the stack you pushed me, it gets posed on the top and on the same stage. If you do pop, it will be against the move from top. So how can be implemented? So let's sue first try to see how can we implement on the bushel prison. So we have a nice enough top, as I said earlier, So this is pointing toe up. So when the stock is empty, that is, it does not have any element. We can have topical toe geo, so we will do similar Do deck Implement isn't so. We have able. So this is tag really not able. When we call new and it will have dropped initialized to zero. So you never read? The stop is also denoting how many elements are there initially there are developments so top is zero. So when we do No, they want to Louis. Then all we will implement it. I'm not writing the code. We will shortly, right? They couldn't you also. But let's and stand here So first they will make topic or two. Oh, Bliss One crypt. So now first angry puts a value up will become one and then the will assigned the value of dis index. I don't. So the key is one and the values will be so the next time we do plus top will become too and value of key to equal toe. Let me will you? So this is only implement Bush? No. How can we implement Pop? So you doctor was having a really off three. So then report nor poppies pointing to second element Remember, for Stanley inserted, we implement a top to one. So the key was one. So in the table key one was holding the value off one. He too was holding the value off B and key tree was holding the value off. See? So we will leave it on Kate from one toe. So we're still one will be holding a Who will be holding be? We're called to remove it. Oh, first maker, Self topical to kneel. So what will happen by doing this? So our earlier in this table one was having he too was having me and three was having see so no, we make and top what you call 23 So we make self topical two nil. So this is replaced Vinyl So ah g equal to nil is a girl into this key not existing at all . So we have removed it from our table. And one thing they need to do more is topical. Do Nope. Minus one. So now top is equal to two. So whatever it was second last value that was inserted office for ending to that Because the last value has been popped. So you see Oh, it's very simple. Much more simple than our victim Fluent isn't. And for returning the sage well, we will return this stop so we can simplicity and self door top. So when we have 12 in topical to to when we have one topical to one When we pop this also, we will increment by one so terrible become zero and size will also be zero Ondo in pop you goner personally handle the case that you So what is less than or equal to zero Babel Aero not stack is already empty. So let's ah quickly implement this. If you understood this part, I think implementing it should be very, very, very easy. So I have treated to files one mistake brought lower and the richest tec pistol or lower. So you can see So let's implement the stack first. So we need a function for new Whenever we are implementing any destructor of Israel was provide a function floor new energy to good give it the name new itself Return a table which talk initialized to Jiro and and so news implemented And you remember Finally we also return a table new call to new for news implemented and also added in the export list No What is the function? Push local Because local Songshan in Commander top earned cert its value Corleto well, let's it no need for him to take it and look sedative You make a pickle too. No, and then metre minted. And there to do from there tired pop here next to weaken hard site stage on one thing we did in the case off. Oh, because to implement the print function. So this is just for our debugging purpose to see whether what is the current value off stuck? So we will I heard different function Also drink this tech so we can have for equal to want to go leisure The valid witnesses don't You're great self are you looks her the space between elements and Wyndham lets air the square record 100 pop in the beginning and end and the same thing in there And they will also in the new Lanier's and let's exposed this to the plant So I think we have invented it in any other function I don't see useful So the year things letter available in a general started a structure Let's disturber implement isn't with client kuhb And here we will stuck local Starkey cool too. Request on this Isn't capital letters stuck? Let's create a local stack stack nort you so a new stack is created. Then we will put some values to it. Stagner push often Next, A few more items. 2040 for p and now let's printed. Bring the size first. So what's so different? First, let's put our guests eso it should bring done. And this I couldn t 30 for Pete and top Is this 1 40? We will also print the top and then we painted the stack it since And then let's lose him or proper since once. So what should happen here? These 30 and 40 should go away because these were the last one that were inserted. So first for TV report, then 30 will report And when you call a function recursive lee or one function inside other solar So this is tech can be seen when you have a function is and this calls if one and this F one calls have to If they call SEFKO then you see all these functions are get and they're very well search for being the stack And first, if you will complete the function that started last will complete first. Then you go back toe the calling function than if one will complete and finally f will complete. So you see the stack Do trust bacteria. So after popping Z will again do the same thing Burnside, stop and also printing this tax. Let's run it. So the guard. So meters we generally good. So mirror and off First to go. Oh, our attempt to call nil value field. So it printed hillsides. SOS. Problem is, um print Prince Turk. Ah. Okay, so there it is there to were trying to call up and it's stacked. Just lay number 11 Lane number 11. Is this so we have not exposed the top. Ah, salutes exposed the top also, although this stop and sire turning same thing, let's make it explicit. And let's not only token and now it works. Ah, Okay, so first to be inserted these four elements So size is for on the top is for Okay, So I am gonna mistake years tops would return the top element and not the top. So we will return the value for that key so that you're not sending the tough, very, really same thing. But the both songs in the North end be generally ever truffles and in stuck of it is used to get the last value that was inserted. So now it should bring 40. So it brings 40 goes for peace there at the top. You remember this bacteria. So when we put its post in the top on top, it's pointing to this new. Really? So now the opposite E. So the top is 40 years and it correctly prints that sage is full. Then we bring the stack, which is 10 2030 40 Then we pop So tropical response. So for this part than 30 become stop and traditional support and 20 we can stop so say it is too. The office 20 as expected. And I did not under this the expected, really we just carpeted. So now it Princeton 20 viz is, as expected. 58. N-Queens Assignment Solution: in this Will you be able solve the famous in queen pageant? Uh, first, let's understand the puzzle And in order to make you understand it, I will use the value of and to be for because there would be easy to understand. And this can be generalized for it queen or higher order values also. So the problem is that you're given four queens or in general in Queens, and you have it in close and this world, in this case, for cross for to see the number off queens, it simmers the number of rules and columns. So this is a square grid and the current isn't is dirt or no queen scandal in the same room . So same rule is not Lord. So you know, only one queen can like. You can see these are the two possible solutions for for for queen puzzle similarly seem column Mortal world. You will see that each column has one queen and also no villain Morton load. So if you see this cell or credits daylan disease, it's stable on This is David. This is Donald. Anything along this So Donald for R c cell number RC In general, this is our sh are a true and see it column and we're talking war this. So what are dividends off Farsi? It's R minus one C minus one ar minus two C minus two Similarly decide R minus one C plus one ar minus to C plus two. So we have 1234 or two 34 to Lebanon for 33 year or ah three tour this 21 similarly 23 and 1/4. So we will solve it using backtracking and let's see the solution. The approach that we will follow first, let's see this these two configurations, you will see that they're all rallied. You see, another two queens are in the same room. None of them are in the same column. And also, if you look at this, none of them were longer. It's diagonals. Similarly, for this, none of them are a long diagonal. And for this all to and for this hold. So this is a valid solution and this is just me remainer of this human mirror. You see, uh, three distance away from meter three distance away from meter, then one distance close to close to mirror. Here also close to middle than four. Distance for distance two and two. So these two are valid solutions. There are no other valid solutions for this working people. So how we can solve this problem, you have to print all such Confucius is not just one configuration to let's see the approach we can have. Ah, separate. Ah, good. Same as this input for storing the So listen where we can mark. It's still as cross if it's not valued or two if it's valid. But we don't need that in cross in space to store or so listen, we can do it just in Oh, in sales only because we know that in one Drew one queen will be there and it has. None of the rules can be empty because there are inroads and there are in Queens. So we just keep track off all the queens from one to food, and this is over. So listen in the court that is provided, and we have represented in the court with a So is there, which provides the solution and the value. After one willed North in Rich column, the Queen one is placed so we just keep track off the columns for each queen devalued in Norton Queens for screening. So if you look at this configuration, this area will be, Ah, first green in second column. So it will be too. Second green and fourth column. So four third green and first column. So one and fourth queen in third column. So three. So this configuration is represented way using just and aerial say's for So this is over. So listen that we will feel ultimately. So what we do here? We start with this. First we frustrate to place the first queen, we find a safe place for it. So we, um we call in Queen on first. So if you see the course Nipper dirt is provided, These are some of the utility functions for taking efforts safe to place our queen in see it column. And this is already implemented for you. This is nothing. But when you're going to place our queen, you check from one to R minus one. You don't take greater than all because you are not placed. Not yet. So you look over in the rose. If there is any queen in the same column, if there is any queen in the left or right? Never. So this is just do safety condition. And then this is the for printing the solution. So, in order do print this area in this form, you check. You go for the first room and a chick for each row. You will look for all the columns and you see even column number becomes too. It matches with this. So you place Q dear other where you place some cross or some other characters that is up to you. And no, we look at the main part that is this in Quinn function that you need to complete. And you see, here we have put one because you will start by placing First Queen and this will again call ah on second Queen the same function on if it finds a valid confusing for second. It will call itself for third green and so on. And we will stop them in crosses. This Ah, this value in. Then we will print the solution and then continue. So let's understand the soldiers and first. So we tried to place it here for screen. So we call in Queen on wouldn't your tics if it's safe to place. You see if toe place first queen in first column If it's your safe, then we will do. Yeah. One. We could do one and then we will call in Queen four. Do so we please here. Then we go to next. True, we try to place here. It's not safe. So we could. This is the parent queen. Then we take next column again. North's if so, we take next column. You did say so. We place here and call in Green on 1/3 on 1/3 again we take from here. Is it safe to please? There's no Here's North Devon here. No, it's in the same room. Here's no, it's no one of So we did not find any. So listen, when we place the second queen in third column so even back trick. So we had already trade for this and this and this also we found her. There is no solution. So we will place it here and then call in Queen on three again. So we will retake. Throw me a Is it safe? No. Is your tooth? Ah, yes. Because it's Norden Dive in all of this and this So we please here and we call in Queen on Fourth Queen. So it starts from here. Is it safe? No. Here's no same column. Here's no same Deylam. Here's no, it's the same column. So we did not find a solution for this by placing the third green here. So we go back and we trade the next column. But here we cannot place since it's Dagenham here also, we cannot place So why placing this screen here also would not find solace in. And we have trade all the columns for second Queen when the first Queen is here. So this is not possible. So we have exhaustion. Disposability first going cannot replace years, if you please. Here we don't get any solution. So we tried the next value of see this is here and we try to please the 2nd 3rd and fourth queen. So for second Queen can replace here. No. Can you please? Here's blow. Here's no here. Yes, you say it's safe. Then we try to place The third Queen can replace here. Looks like yes, because no, nothing in Devon, Nothing in this rule. Nothing in this column. Now we try to place fourth queen can replace here? No, here's no same column. Here's yes, it's safe. So now we have placed Fourth Queen and we will try to place 15. But we have cross this four, so we will print this configuration. Whatever is the value, so does the loser accordingly objected. So here it's, too. Then we placed it in the fourth, then one, then three. So we will bring this whole listen. Once we print this terrorism, we take four next solution. So we have trade all the configurations then Q is here. Second Queen is here for Queen is in the first column. So we will go back and try for her queen by placing it here first. We will try for fourth going by here. It's not possible. So we tried all the possibilities this already printed. So we try next cell. But it's not valid, so we will not print it. So we have tried all possibilities of Fort Greene. Wintergreen is here full. They go back. Police. We cannot place here here also herald four year being adjusted. All the possibilities for first green being placed here. So we go back, move forward. We already printed this solution and we place queen here Then we take four second queen here. It's possible than 30 queen. It will be here on fourth win. It will be here. So we will again printed and next to we will place the first green here and we will not find the solution. So the two solutions air to full 13 on 31 food to salutes right The court for this. So if we tried to place Fifth Queen, we have released more than and so a printed We know that we have placed all the queens other ways. So not endear Martel's Yeah this award we were to do for C equal toe one toe end do if it's safe toe place in the Queen in Scotland Number C then e off in equal to see And Gordon, please the n plus one between there is it from the sea sense here for ends here on this condition is here So the suit work Let's try to run it Andi, you see it has printed the configuration the other two configurations. So if you don't understand our try toe easy do it yourself It's not to their easy problem backtracking. Ah, the concept seems very true. Will you try all the possibilities? If you try to understand this problem, let's say you are writing a maid's on and it has to Let's a go from here to here. So what did we do? It will come here. It has one. So listen So it will come here. Here it has to absence off his block to my left and right. So lets say, takes lift. It comes here, it reaches didn. So it goes back towards no state, then tries the other possibilities. So it comes here a straight street here it has two possibilities and it picks. This one comes here. In contrast, Durden so goes back and traced the off the ropes and and finally it will find the solution . So it's just like exhaustively searching for all the possibilities. So here also we tried to place the first Queen in first our top left corner and we tried for the steps ultimately released, injured in where we were not able to place the third Queen. So we know that this often was wrong. So we went back and changed. Ah tried all the possibilities for second queen. And if we did not get the solution, we went back and try to change the police and off first clean itself. And then is he do for 2nd 3rd and fourth? So regardless so listen, we printed it, then. Whatever was the remaining configure is, um we tried for their configuration so that we get all the solutions, but the cording seems to be just to line three lines. So, you know, generally it's difficult in the beginning, if you are according ah, backtracking thing. So I just tried to understand what this represents exactly the same thing. What we saw in the explanation, and after some practice, you will be able to get that. 59. Iterators and Closures: over the next few listens. Well, a studio traitors and Gen req for In and in this listen, I will give a brief introduction off by traitors in lower. So first of all, what is a traitor? A treasury, any construction that allows you So I treat over the elements off it. Hellickson in lure. It's represented way functions. Each time we call the function, it returns next, Children from the collection and we will shortly see who, Why, this is so and ah, and I treated needs to keep track off some state with between successive cause. For example, when you run, you know, using hype here or here it returns key value and your calling it Foursome Alex in. So in one you know, first addressing, let's it prints of first element of this collection. In the next call to it, it's somehow keeping track. Not I have. Don't feel first elements, or next time it call is made, it will try to access the second element and so on. So it needs to keep a state for keeping track off charities and how to proceed from there. Soap lawyers can be very useful for the scenario. Oh, because they provide an excellent mechanism. Oh, for this kind of ask. So let's see what is closer if you don't remember it. Closure is a function that access is one or more local variables from it, including function, including environment. So we have some variables here in this school. Then there is your function, and this excesses these variables. It needs thes variable in order for this function to work. So these eso access is one or more local wherever it's from. It's including environment, and these variables keep their values across successive calls. So the closure allowing the closure to remember verities a longer travel. So and this is where it will help in attracting making iitrader function and to create a nuclear, we must also create it's known local variables. Therefore, it lawyer construction typically involves two functions. Enclosure itself, a function and a factory, the function that creates the closure. Plus it's including variables. So let's look at an example of closures. So here we're creating a trillion, a simple iitrader for a list so you can think of this D as a list. And over here, unlike I peer, which returns key and value or the index and ah value in that index. It will simply return value, not index, that Sharia separates name values. Eso You see this there is a variable called I keeps track off the index that is the state who charities and it returns function. This is the close, your function or very treated, and he receipt increments I by one and then return the value it that index in the given list. So this is how we are financially. Oh, I traded for closure. And in this example, this is the factory function sort. Remember, we said that we will need to are two things. The closure itself, which is dysfunction because it's it's, er, doing the job of why treating it's incriminating index and returning the value of that index. So this is the actual closure function, and this is bill factory function that is creating it. So this closure keeps this. It's a state in its external variables. D and I d does the collection. I denotes the current index an east time we call a traitor. It returns in next value from the list year, and after the last element, it will return nil on. We will get him that we have reached the end. Call you to turning mill and we will stop. So for example, we can have a list. Oh, in 20 30 40 So let's satar just four elements this list Ben recreate and a treated and recall it this factory function will use and we provide the collection here D and no, we will not need to call values anymore. We will be calling writer So over began travels this list using while loop so well This this is Luke is true. We will keep calling Writer. So what decided Will do it will eso This is holding a decide traitor function whose task is to incriminate Index and returned the Valuer Dart index So when we call I, it will return in because I was in this illegitimate made it one and return or the value it in Knicks one. So I returned 10 and then we can have a chick that if this well is new than record off this loop So let's right. You two never called. So first, let's define our Oh, I tried to function. So this is the factory should know We have defined over included and earned. I treated, including the factory and Will Your functions aan den. We will create our list. It's if it's milled in Kubrick and no, let's run over Chord. So you cto since 10 2030 40 50 and then nil. And after that it is this condition and you'd came out of this loop some release. We want to return inaccessible so we can a I d. Invent and we can print idea in well, so it drinks Lynn Dix as a less value. So this is so you can right a custom I treated for yourself, but instead off calling a room knighted for Onda, calling this item multiple times and adding this chick when where is Daniel and then accessing the value, it would be easier to use genic for. After all, it's designed for this kind of high treason only. So let's use the same I traitor for our genetic for, uh so well, right for well in values era who do and let's modify this pullback to return, just values. Then let's run it. So the first part ill nil comes from over method of calling originator, and the 2nd 1 is using this general for which also calls over a traitor