1 00:00:08,160 --> 00:00:11,120 It's graduation day. We're going to move from the beginning 2 00:00:11,120 --> 00:00:14,390 student launguage to the next most advanced language. 3 00:00:14,390 --> 00:00:18,040 It isn't a big move, but it's a good move. 4 00:00:18,040 --> 00:00:21,883 The way you do is you go into the lower corner of Dr. 5 00:00:21,883 --> 00:00:25,799 Racket here, and you switch from beginning student to. 6 00:00:28,060 --> 00:00:30,800 Beginning student with list abbreviations. 7 00:00:30,800 --> 00:00:36,586 Now what are list abbreviations? Well, by this point you probably gotten a 8 00:00:36,586 --> 00:00:41,247 little annoyed at having to write something like cons a, cons b, cons c, 9 00:00:41,247 --> 00:00:45,456 empty. When all you really wanted to do was make 10 00:00:45,456 --> 00:00:51,882 a list of three items A, B and C. And what lists of abbreviations do, is 11 00:00:51,882 --> 00:01:00,840 they let you write that more compactly as just list, A, B, C. 12 00:01:00,840 --> 00:01:04,935 Now lists created with a list primitive are exactly like list created with the 13 00:01:04,935 --> 00:01:09,420 cons. And that's a list of three elements. 14 00:01:10,460 --> 00:01:15,357 If I run this now, what you'll see is that because I've turned on the list 15 00:01:15,357 --> 00:01:21,001 abbreviations language, Racket shows me the value of this expression using list 16 00:01:21,001 --> 00:01:25,925 notation. And it also shows me the value of this 17 00:01:25,925 --> 00:01:30,920 expression using list notation. So, you can still construct lists with 18 00:01:30,920 --> 00:01:34,415 cons, and in many cases you'll still want to construct them with cons. 19 00:01:34,415 --> 00:01:36,930 But, you can also construct them with lists. 20 00:01:38,780 --> 00:01:41,200 And Rackets always going to show them to you with list. 21 00:01:41,200 --> 00:01:48,516 Now, just like cons, list is a primitive for constructing lists, and it's a 22 00:01:48,516 --> 00:01:55,999 notation Racket uses for, presenting list values. 23 00:01:55,999 --> 00:02:05,490 And so for example, you can say list plus one two plus three four plus five six. 24 00:02:05,490 --> 00:02:09,680 So this is a call to the list [UNKNOWN] with three [UNKNOWN]. 25 00:02:09,680 --> 00:02:13,624 When you run that you'll get back this 3, 7, 11 because those operands have reduced 26 00:02:13,624 --> 00:02:17,046 to values before the list is created and so what you see is a list with the 27 00:02:17,046 --> 00:02:22,415 values. Now, an important point here, which is 28 00:02:22,415 --> 00:02:28,305 that when you construct lists one at a time in a function you're still going to 29 00:02:28,305 --> 00:02:38,001 want to use cons and let me show you why. Suppose I say define L1 is list b, c and 30 00:02:38,001 --> 00:02:45,317 define L2 is list List d, d, e, f, now I'll run that, now I've got those two 31 00:02:45,317 --> 00:03:02,100 definitions. Now watch this, if I say Cons a onto l1. 32 00:03:02,100 --> 00:03:04,260 That produces the value I probably wanted. 33 00:03:04,260 --> 00:03:07,614 Which was to take the list L1, and add an a to the front. 34 00:03:07,614 --> 00:03:16,044 On the other hand, if I say list. A, L1, that doesn't produce the value I 35 00:03:16,044 --> 00:03:19,466 want. That produces a list in which the first 36 00:03:19,466 --> 00:03:23,309 element is a, and the second element is the value of L1, which is some other 37 00:03:23,309 --> 00:03:27,277 list. So I get a front end list here that has a 38 00:03:27,277 --> 00:03:30,510 as it's first element, and a list as it's second element. 39 00:03:32,060 --> 00:03:35,240 I'm not saying you can't have lists with lists in them. 40 00:03:35,240 --> 00:03:40,003 Sometimes that's exactly what you want. All I'm saying here, is watch out when 41 00:03:40,003 --> 00:03:45,720 you're trying to add one element to a list, you use cons. 42 00:03:45,720 --> 00:03:50,701 You don't use lists. You use list when you're trying to make a 43 00:03:50,701 --> 00:03:55,390 fully formed list all at once. So for example, you might want to say, 44 00:03:55,390 --> 00:03:59,410 list L1 list L2, that might be a perfectly reasonable thing to say. 45 00:03:59,410 --> 00:04:04,270 And conceivably even this middle thing would be a reasonable thing to say. 46 00:04:04,270 --> 00:04:10,583 But, usually when you write something that, you're going to want to use cons. 47 00:04:10,583 --> 00:04:16,215 Let me show you one other list primitive that sometimes is quite useful, it's 48 00:04:16,215 --> 00:04:21,895 called append. And it consumes two lists and what it 49 00:04:21,895 --> 00:04:29,950 does, let me comment these things out. Append consumes two lists, and what it 50 00:04:29,950 --> 00:04:37,190 does is it produces a single list by adding the two lists together. 51 00:04:37,190 --> 00:04:42,540 So it's kind of like string append. It contains, it contains all the elements 52 00:04:42,540 --> 00:04:49,707 of L1 followed by all the elements of L2. Now one final thing about list notation 53 00:04:49,707 --> 00:04:55,497 rather event [UNKNOWN] notation. If you find list notation confusing, you 54 00:04:55,497 --> 00:05:01,256 don't have to start using right away. We're going to use it so you need to be 55 00:05:01,256 --> 00:05:09,431 able to read it. It is still perfectly fine for you to 56 00:05:09,431 --> 00:05:23,410 write, that lists that way, instead of, instead of that way. 57 00:05:23,410 --> 00:05:25,085 They both mean the same, they are both correct. 58 00:05:25,085 --> 00:05:29,309 I think of most of you will soon find it more convenient to use list notation, but 59 00:05:29,309 --> 00:05:35,230 Kan's notation, is still perfectly valid. There's a few exercises that come up now 60 00:05:35,230 --> 00:05:38,210 to help test your understanding of a list notation. 61 00:05:38,210 --> 00:05:41,809 And in particular to test the issue of when to use cons to add something to a 62 00:05:41,809 --> 00:05:43,140 list.