About this episodeThis show covers Lisp, one of the first functional langauge that is often used for academic purposes, but also has a place in industry…
This show covers Lisp, one of the first functional langauge that is often used for academic purposes, but also has a place in industry. The episode talks about Cuda, how to write a Roguelike, becoming a good programming, and DOS games on Chrome. The tools of the biweek are Google Native Client (NaCl), a way to run native C/C++ code in a browser, and Handbrake, a way to make copies of your video DVDs.
★ Support this podcast on Patreon ★Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Lisp
Oh really? See, the guy who sits next to me, he has a weird chair. Like, when he does have to sit or want to sit, his chair is such that he like sits on his shins, kind of. What? He's like, yeah, because his desk is high, right? So he can't use a regular chair. So he has this weird chair where his knees bend like only a little bit. And you kind of it's more of like a leaning than a sitting. But yeah, he has a stand-up desk. Is he standing?
So now I've gone to... Yeah, I had the same thing. Did you? Yeah, I sat on it. I sat on it, and I was like, I'm going to try this out because there's one in our cube. And after, about halfway through the day, around like three or four in the afternoon, my back started really hurting, and I couldn't figure out why. I was like, God, I just have back pain. I don't understand. And I was like, wait a minute. It's this freaking ball. Yeah, I didn't
Yeah. You have to kind of use your arms. They have one of those, but it's made of like plastic fiber instead of wool. And so it has, it gives you like the worst rug burn. So I tried it for the first time. Yeah. And I got about halfway up the rope and I gave in. And when I was coming down, my hands, they just got all tore up. And then all
Again. Yeah. They stuffed me in a trash can. It wasn't pretty. But they have like those things that, have you seen these? They're like platform, like tables. They look like tables, but they're anchored into the ground and you have to sort of jump onto the table, but it's really high. It's like twice the height of a coffee table. They actually have different sizes, but the one I was on was like that. And so just from standing still, you have to jump onto this table and then jump off and then keep going back and forth. And they had like a whole bunch of different, like they had like a little demo day and I went to it and they had a little routines that you should do to get, you know, more fit and stuff like that. But being fit is definitely huge over here in California.
Yeah. So I know you've been, you've done this a little and I've done some of this, but there's a, you know, the new, one of the new things that's come out recently is general purpose programming of graphics processing units. So the things that are in your computers, pretty much all the computers nowadays to some extent to run your graphics and, you know, accelerate anything to doing with drawing to the screen with 3D rendering, like for games and all that's handled by these GPUs, which basically come down to many cores, small, lightweight processing cores that are able to do tons of tasks in parallel. For instance, when you have to figure out where a triangle should show up on the screen, there's maybe millions and millions of triangles on us in a given frame of a game. And so you can do all of those calculations in parallel. And so these Graphics Processing Units have gotten really, really good at doing
So AMD and NVIDIA. And Intel's now starting to do, well, both of them now are starting to even, Intel and AMD are starting to do interesting things with putting CPUs on, or GPUs on the CPUs directly and putting really high bandwidth connections between them. So that's kind of interesting. But NVIDIA has a language that you use to do this general purpose programming for GPUs. And AMD has their own as well. But NVIDIA's is called CUDA. And it's a kind of a dialect of C, which is limited. You can't do a lot of the same things you might be able to do in regular C or C++. But for the most part, it's just a C program. And it runs, you know, maybe thousands or hundreds of thousands of threads. And each one just does a little task. So massively parallel. And that's really good for certain operations like image processing operations, graphics operations, certain kinds of like simulations like Monte Carlo simulations, where you choose random numbers and run a little simulation based on that random number. Things like that can be really good. The problem is that the code between what you write for a CPU and what you write for a GPU are so very different from each other. It can almost make the expense of going through creating a separate, you know, code base for your CUDA programs. Unless you're one of these few cases that get a thousand X speed up from it, it almost makes that not worth it. And it's better just to buy or pay more to get the latest and greatest CPU so that you can just have one code base.
Yeah, and the other part of it too is, you know, the GPU, you have to communicate with it. It's sort of like an external processor. You know, whereas the CPU, it's right on board. And so because of that, debugging is much easier on the CPU. Like you could take a program that's running and just stop it and say, all right, right now, what's the state of the system? Now let's process one instruction. Now where are we at? But, you know, because you have this GPU on a completely different card, you know, the debugging becomes much more difficult. You can't do the kind of cool, hacky things that you can do, that debuggers do for a CPU. Right.
Oh, and the other thing is that the pipe between the CPU and GPU, the PCI Express bus, is limited in its speed. You think it's really fast, but it's really not all that fast. So there's all this overhead of sending data to the GPU to get processed and getting your results back. And so there's a crossover point where when your data gets big enough and parallel enough, it makes it worth it to send it there and get it back. It's faster. But below that threshold is better to do it on the CPU. But if your program has dynamic size of data, you kind of either have to have code in both and choose on your own which one to run, or you just got to pick one or the other and suffer non-optimal cases. But what would be ideal is if you could write, for instance, just CUDA code. Well, ideal would be just write C or C++ code and have CUDA automagically do all of this for you would be awesome. But short of that, if you could write CUDA code that when you're below a certain size limit, the overhead's too much. And so you go ahead and just run that on your CPU or in some case where the GPU isn't available. So for portability reasons, to be able to run the CUDA code native on just the regular processor, the CPU would be
Yeah, so all those cases are really important cases. And it has not been something that was the first priority because they wanted to get this working right first. But now it looks like some other people are making progress in being able to compile CUDA code down to run on x86 to enable this kind of thing to take place. So it was kind of an interesting article. Hopefully we'll see more of this in the future because it could be a big boon to the widespread use of these GPU processing paradigms.
Yeah, yeah, definitely. Yeah, I think it's awesome. So a lot of people kind of Write us and they say, "Oh, I really like making video games." Or I think somebody sent us an email a little while ago, and they were using, I think, Visual Basic to write video games. And games seem to be, as you masquerading as somebody else. Oh, but they, you know, a lot of people get into computers because of games. I mean, I love games. That's one of the reasons why I got into computers. A lot of my friends have said, "Oh, the reason why I got into computer programming is because I wanted to make games." And, you know, of course, making games is really, really hard. There's a lot to it. And, you know, often it's done by teams of people. You know, back in the day, when the games were on Atari and there was like four-bit graphics, one guy would make a whole game. But nowadays, most games are made by teams of hundreds of people. However, there is still a community of people who are just single developers or small teams making games. And one of the more popular communities is called the roguelike community. So a roguelike is essentially it's a game derived from Rogue, which is an ASCII game made, I think, in the 70s. But the idea is it's ASCII art. So you're a little at sign and you move around on the screen, and the screen's made up of little period signs for the floors and for the floor tiles and a little like the little pipe symbol and the minus sign for the walls and things like that. And so, you know, the graphics are simple. The gameplay is often quite simple. Sorry, sorry, the mechanics and the visualization, the GUI is simple. But the gameplay can become very complex. And so people can do really interesting things. And it's typically brutally hard. Yeah, there's often brutally hard. Or just, you know, the games are incredibly complex. Like Dwarf Fortress is one of the more popular roguelikes. And you actually, you know, you manage a civilization. And this guy implemented an economy that kicks in. You have a king and you have to have these nobles that have to be managed. There's an entire water system which the creator of Minecraft kind of lifted. And so now you can find it in Minecraft. But at the time, Dwarf Fortress was the only game that had that kind of fluid dynamic system. It had the 3D, it has a 3D environment where you can destroy any of the blocks, kind of like Minecraft. So Dwarf Fortress is and continues to be, you know, an inspiration for many other games. And Tarn Adams, the creator of Dwarf Fortress, received a ton of notoriety. And I know of several roguelike developers who got job offers from game companies just because of their involvement in roguelikes. So for people who want to make video games, this is a great way to get into it, is to make a roguelike. And for people who want to do that, there is this website, which is how to write a roguelike in 15 steps. At one point, it was a while ago, but I don't even remember when. But at some point I went through these 15 steps and made a roguelike. And yeah, and it's really rewarding because at the end, you have a finished product, and you've also learned a ton. And you've learned about when do I create new classes versus when do I make things data-driven. So for example, when I started, I had a Sword class. And then I had a Flaming Sword class and an Ice Sword class. Like they're all .cpp files. And I had all this code and no data. And I realized, you know, I don't need all this code. All I need is just a Weapon class. And then I can have a little string, which tells me if it's a sword or an axe or whatever. So, I mean, that was a valuable lesson as a programmer is how to make the code data-driven. And, you know, I could go on and on about all the things that I learned from these 15 steps. But it's really useful. And for anyone, any kids out there who want to start making their own video games, it's a great way to start. Yeah, or adults.
So, the title of this article is actually Become a Good Programmer in Six Really Hard Steps. And it's kind of funny because the author of the article actually says that the six steps should take about 10 years or more. Oh, I'm sorry. Actually, I think the first five steps take 10 years. And then step six begins at the 10th year and can take possibly forever. And it's a little tongue-in-cheek, but it's kind of good to go through. And it really does in the same line that you're talking about, you know, learning to program games and teaching you programming because of that. This guy just kind of goes through the phases that people tend to go through. And therefore, if you're trying to go through it or wanting to go through it, understanding what it's going to take to get there and what it involves and kind of how you grow and what kinds of things to expect at various stages. And, of course, everything is a little different for each person. But the same basic outline of how you go from learning your first game or doing something that inspires you to want to get into programming to becoming a software developer at a company as your job. That's a pretty similar path amongst a lot of people. They have small variations, but it tends to be almost the same for many people. And so this guy has defined that pretty well and given some guidance and some help for people who are on that path.
Yeah, yeah. I read it and, you know, I thought it was, like you said, very tongue-in-cheek, but a lot of it is really true. I mean, some of it, like writing your own programming language, creating your own language, really kind of puts things in perspective. I mean, I feel like I agree that kind of everyone should do that at some point. Just make some simple language that, you know, all it does is, let's say you can pass it some new operations. Like you make a, you know, plus plus. So one plus plus two is something else. Like, I don't know, maybe it adds two twice. I don't know. It doesn't have to be useful, but just the experience of going through and writing, you know, a parser and a lexer and then actually writing the interpreter. And things like that is extremely useful. Definitely, definitely. So, yeah, part of becoming a good programmer is being able to sort of work magic. Take things that were meant to be in one environment and bring them to a completely different environment. And Google Native Client kind of does this, where it can take programs that were meant to be, you know, on your desktop and bring them to the web. Actually, put them inside of a browser. And it's quite amazing how it works. But this news article kind of talks about one specific application where this guy has taken DOSBox, which is a DOS emulator, and ported it to Google Native Client. So what you end up with is if you're using a recent enough version of Chrome, you can actually have a DOS operating system in your browser. And he uses this to actually let you play DOS games in the browser. So he's created, like, this MS-DOS file system, like, on his server, I guess. And you can load up different games. So he's got, like, Falcon 3.0 and TIE Fighter and X-Wing. And, yeah, he's got all these awesome old-school DOS games. And you just literally just go to the website, as long as you're using Chrome, and it's right there. And you just start playing. It's pretty amazing. And it really kind of showcases the power of Google Native Client.
Yeah, it's totally awesome. I played a little bit of TIE Fighter. You know, to not get in trouble or anything like that; he only has the demo. I don't even know how he got his hands on the demo of TIE Fighter. He must have just had it from way back. So you only can play the first level, but it's still pretty amazing. And I think, you know, as part of the port, I mean, you should be able to just run anything you want. Like, I don't know the details, but it's a complete DOS operating system. So if you have your own TIE Fighter, you should be able to bring it to the table, I think. But either way, it's really freaking cool. Sounds awesome. And yeah, you guys should check it out.
It's no. Oh. It's actually Google Native Client. What a twist. Yeah. So my Tool of the Buy Week is Google Native Client. I've been messing around with this, and some of you might know I do a lot of work on MAME. I'm the creator of MAME Hub, which is... Well, for people who don't know, MAME is an acronym, and it stands for Multiple Arcade Machine Emulator. But now it's grown to cover almost every arcade machine ever made and many modern consoles—or not modern, many retro consoles like NES, SNES, and all that. So this is sort of like the one emulator to rule them all. And I've been doing a lot of development on MAME, and I'm the creator of MAME Hub, which lets you play MAME games online. So you could play Super Mario Bros. online with someone in England. You
That's right. As long as you legally own the cartridge in your house. And if you want, if you're in the Bay Area, you can borrow one from me. I think I still have all my Nintendo games somewhere. Anyway, so I've been using Native Client for porting MAME to it and things like that. I've been really into it. And it's just, you know, creating some sample apps in it; I can really see there's tremendous potential in this tool chain. It's just amazing. I mean, imagine you take something that you wrote, maybe in high school or in college, or maybe it's an open source app that you really like. And, you know, as long as you can get it to compile in using this Native Client, it runs in the browser. I mean, it's a website. And so you can, you know, make changes and, you know, anyone who visits your website automatically gets the latest version. You don't have to worry about deployment or anything like that anymore. You know, it lets you do awesome stuff like, you know, immediately get people signed in. And you can sort of, it has a JavaScript wrapper around your code. So you can do cool things like make Ajax requests to some web server. And so you can do all the cool web things like, you know, tap into different web services like the weather and things like that, and tie all that into your desktop application really easily. So it's awesome. It's getting more and more popular. There's, like I mentioned in the news section, there's some really cool demos. And, yeah, I'm a big fan. So I like to see what kind of cool stuff people make with it. Very cool. So, Patrick, what's
But the big one is originally it was for the Mac OS. And then they've come out with versions for the others as well. And what this allows you to do is it's really easy for putting videos that you have permission to on your transcoding them so that they will play on your iPhone, iPad, Android device. Oh,
Yeah. So if you had a DVD of your wedding and you wanted to watch that on your tablet, then you would use this to convert it. Because the tablets and phones, although they will often play different videos, like many different kinds of videos, they're typically optimized for a certain resolution, you know, the screen size. And then also for a certain set of encoding parameters because of the fact that, you know, they have hardware acceleration to do, for instance, H.264 decoding. So if you put it in that format, it's going to perform a lot better or maybe not perform at all if it's not right. And what the nice thing about HandBrake is is that it has all of those presets in there. So you can just say, I want this file encoded as for an iPod Touch 3G or third gen. And so it'll do that. Or an iPhone 4 and it'll know how to do it. Or I want it for an iPad. And it'll go ahead and choose the right width or height and ratio for you. And also what encoding parameters to use, what bit rates to use. Those things that whenever you open up a video encoding thing and go, I don't even know what to choose here. Can I please get some like auto button? It kind of has for you. And so you can just say what device you want to encode for. And it'll just kind of already have the presets in there.
I won't say that. You may say that, sir. I won't say that. There are certain people who want to charge for their applications often have very good reasons for doing so, and they are more than entitled to try that. Fair enough. So, okay. Enough philosophy. Time for the discussion of our programming language of the week, Lisp.
That's right. Lisp is the language we're going to be talking about. It's really interesting. It's definitely, if you're into computer science and sort of the understanding, like, the history and sort of the more, I guess, the less hands-on, the more kind of pie-in-the-sky theory and things like that. This is a good language to know. So, it was actually invented before it was implemented. So, someone, and do we have the person's name? Let me see. John McCarthy, back in 1958. So, Lisp was a very old language. He kind of formalized this idea of Lisp and sort of the core functions that constitute the Lisp language and sort of proved that Lisp was Turing complete and things like that. Before, there was even an implementation. I mean, this was just all done in paper. It was a thought experiment, right? And it wasn't until much later, actually, I guess a few years later, that Steve Russell created the first Lisp implementation. So, yeah, so Lisp has a wide history. Because Lisp is so tied to computer science, there's just tons of different dialects of Lisp. You know, there's Scheme and things like that.
It seems to be probably the, how do you say this, like the most well-known, least used programming language. Like, people use it, but not everyday. Like, people don't use it in their everyday jobs. But it seems like everybody who goes through computer science learns it. Or even people who are just interested in computer programming will pick it up. And they'll at least play with it, if not learn to be experts in it. You know, at least know it, but then not use it.
Yeah, that's right. Yeah, and I think, you know, part of the problems with Lisp, and we'll talk about this more in the weaknesses, but is that it's just, it's so fragmented, right? I mean, this isn't really a problem with Lisp as much as just the, just, I guess, the social sort of, just the events that transpired. But Lisp is so fragmented. There's many different compilers for Lisp, or interpreters, I should say. And, you know, there's so many different dialects. And for a long time, none of the interpreters were open source. So, you know, each one sort of had its own nuances. And so this is, I feel like this is really kind of plagued Lisp. But the two things that are sort of critical to Lisp are CAR and CDR. So, C-A-R and C-D-R. And the way this works is, think of everything in Lisp as being a pair. And the pair is actually called CONS. So you have a pair of objects. But the objects themselves, they could be anything. And to get, to go from a pair to the specific, like, elements in the pair, like the first and the second, you would call CAR to get at the first, or you'd call CDR to get at the second. And so just with CONS, CAR, and CDR, that forms a basis for the entire Lisp language. It's, a lot of it's based on lambda calculus, which gets into some pretty heavy stuff. Basically, lambda calculus is sort of a formalism. You know, we talked about first-order predicate calculus. We were talking about Prolog. And so this is just another way of sort of representing numbers and the computations on those numbers. And you can read about it more on Wikipedia. But understand that, similar to Prolog, Lisp is sort of based on calculus. And so because of that, you can imagine it's not something you're going to write, you know, device drivers for, right? So this is something that's kind of very theoretical. However, there have been Lisp machines. Have you heard anything about this?
Yeah. Well, it was a little bit before my time, I guess, although maybe I was still quite young when some of it was going on. But the Lisp machines was kind of an effort when the personal computers were first coming out to have a machine that was for individual users, which although didn't directly implement Lisp, so there weren't assembly level commands that said, you know, the parts of the Lisp language directly. What it did was provide a really simple stack-based processor as opposed to a register-based processor, which I guess gets pretty in-depth and probably outside the scope for this discussion. But instead of register-based, it was stack-based. And the commands themselves were meant to be very easily derived by Lisp code. So a Lisp code would translate into very few instructions as opposed to on a normal register-based CPU, for instance. A single Lisp command may take many, many machine instructions to implement. And so this processor architecture was put together in something called a Lisp machine that was meant to be easily programmed and efficient at writing and using and running Lisp programs.
Right. So, I mean, you know, think about the difference between, say, C and Lisp. So in C, you know, just from a data perspective, in C you're dealing with arrays and pointers that point to different spots of memory. And so you do pointer arithmetic. So, for example, if you have an array and you want to loop through the array, you would, you know, have a pointer at the beginning of the array and then you would sort of increment. It's very numerical. You just say, I want to push my pointer a little bit further and read the data over here and then push it further, kind of like you'd read off a tape or a record or something like that. In Lisp, you don't have arrays. What you have are, as I mentioned, these pairs. Yeah. So you have pairs. So if you want to have, say, a list, if you want to have an array, let's say, in Lisp, then what you would have is you'd have a pair. The left, the first element in the pair would have some item in your list. Let's say it's a list of numbers. So the first element in your pair would have the number, say, four. And the second element of your pair would have a pair in it. And in that pair, the first element would have a number, let's say, two. And the second element would have another pair. So you see, everything is done in pairs. And any of the two elements in the pair can be either an atom, which is a number or a word or something that's immutable, something that can't change, like a constant. Right? Or it's either a constant or it's another pair or it's nil. Those are your three. Those are the only three, you know, things that can exist. So as we mentioned in JavaScript, where there was only four things, in JavaScript, there's nil, you know, array, object, and literal. In Lisp, there's only atom, which is the same as literal, pair, and nil. There's only three. So, you would think that because it's so simple that, oh, you know, you must be, like, really low level. Like, you must use this for drivers because it's such a simple language. But actually making the language very simple is really what gives it the power and gives it the ability to represent incredibly complex things. And we'll talk about this a little more when we get to the strengths. But understand that, you know, a machine, a regular machine that just has a bank of memory where you can just do malloc and get arrays, that kind of machine doesn't run Lisp very efficiently, especially, you know, 30 years ago, 40 years ago. So the idea of the Lisp machine was let's make a machine with the constraints of Lisp in mind. Let's make a machine that deals with things in terms of pairs.
Right. And, I mean, it seems like they were fairly successful at doing that. It was just that the competition in the market was somewhere else. It was in the traditional register-based machines running C. Yeah. So it seems like there have been many of these instances in the even short-lived software world where even if something made sense or was technically superior, it won out. Something else won out because of just market inertia or, you know, happenstance or various other things. And, you know, the Lisp machine kind of fits in that category.
Yep. Yeah, I'd like to think that, you know, being an AI person and being sympathetic to Lisp, I like to think that it's sort of the grandfather of many other languages. Like, you know, other languages like Python, JavaScript, which, you know, is based on... JavaScript was based on Scheme, right? It was inspired by Scheme. It was influenced, yeah, yeah, yeah. Yeah, and Scheme is a dialect of Lisp, so there you go. And, you know, even MATLAB, which is now very popular, you know, Lisp is sort of the grandfather of all interpreted languages and is a good source of inspiration for languages that came after and offered, you know, much more boosts in productivity, you know, without all of the hindrances that Lisp has. Yeah. Yeah. So, yeah, so as we mentioned, there's many dialects. But one of the reasons why there's so many dialects is because it's really easy to write an interpreter or a compiler for Lisp. In fact, you know, as we mentioned with the, you know, become a good programmer and six really hard steps, the author even mentions that, hey, you should write a Lisp interpreter as your language, you know, because it's a good start.
Yeah, and keep in mind that, and this is true for all languages, I don't know if we've mentioned this before, but most languages are written in themselves. So, and we have talked about this where, you know, we talked about Python being batteries included, where there's a huge corpus of tools that you have that are available to you when you start programming. The vast majority of those tools are written in Python. This is true even of, you know, C and Lisp and other languages, just to a lesser extent. So, you know, 99% of Lisp is written in Lisp. And, you know, if you could take, like, the common Lisp libraries and, you know, use your own interpreter, you could really have your own Lisp, like, fully featured interpreter in a day. I mean, of course, it wouldn't be fast. It would be nothing like C Lisp. But, you know, it still would be fun, you know, it's a toy to play with. And it seems
like the other thing is that there are a lot of people who take Lisp and use it as kind of an intermediate language where you write something in Lisp and then you compile. Like, we talked about people doing this to JavaScript before, but people kind of use Lisp as an input language to the compiler, I guess, and then compile it to some other form of a language. So there's Clojure, which is C-L-O-J-U-R-E, as opposed to, we talked a little bit about the Clojure kit tools last week or last episode. And that is implementing Lisp on top of Java. So using the Java virtual machine and using Lisp as kind of, I guess, what is that, the front end to it. Yeah, nice. And saying, how do we do that? And it's got a lot of popularity. And there's also the, everybody kind of has their own little ways about some of the finer nuances of the language. And so each of those tends to kind of get its own spin-out dialect, which initially starts out really close to the one it started from, but then slowly drifts away over time.
Yep. Yeah, so some of the strengths of Lisp. One of the strengths is that it has very, very efficient hash tables. And this is tied directly to the fact that there's so few data types. It does a lot of sort of like clever tricks with the pairs. And it can actually store a ton of data in a hash table very efficiently by sort of reusing the same data. Lisp is amazing at this. Well, we should explain what a
Oh, yeah. You've probably never done that. So, yeah, so a hash table is something that essentially maps one data type to another. So, or one value. Yeah, I guess one, yeah, one value. Maybe that's a better way of saying it. Essentially maps one value to another. So, for example, let's say you wanted to store the days of the week. So, if you put in, you know, zero, you got Monday. If you put in one, you got Tuesday, right? So, in C, you could just have an array. And at the array index zero, you would just hold the string, a pointer to the string Monday. And one, you'd hold Tuesday, so on and so forth. And then you'd say, you know, days open bracket, you know, two to get Wednesday, right? What if you wanted to go backwards? Like, what if someone gave you the string and you wanted to return what day of the week it was in numbers? So, if someone gave you Monday, you wanted to return zero. So, in this case, you'd have to use essentially a map. And the map would have to map strings to numbers. See, an array, you can think of an array as a map, which maps numbers to something else, whatever's in the array. But whenever you need to map something that isn't a number, let's say you need to map, you know, a floating point number or, as I mentioned, a string. Or maybe you need to map a chessboard, like the entire board, like a whole class with the pieces and where they are. You need to map that to a number. To do something like that, you have to use a map. And one very common map implementation of a map is a hash table. What a hash table does is it takes, it basically is based on the principle that you don't actually need the key. So, in other words, I don't actually need to store the string Monday in this table. You know, what I need is when I get the string Monday, I need to know to return zero. But that doesn't necessarily mean that I need to hold Monday in the table. So, that sounds a little confusing, but take, for example, let's say that your hash table, instead of storing the whole string, it just stored the first two letters. So, that would be sufficient, right? If someone passed in Monday, then I would just take the first two letters, MO, and just look for that in the table. And that would return zero. And I've saved some data. I didn't have to store all of Monday. Now, you know, I couldn't use one letter, because if I did, then Tuesday and Thursday would both map to the same location. That's called a collision. Right. And so, there's ways to deal with that even. So, it's not the end of the world. But, you know, I could store two letters and save a lot of data. And so, hash tables, you know, there's a lot to it. You know, if you're really good at hash tables, hash tables are sort of the backbone of just about everything in computer science, especially distributed processing or, you know, web and stuff like that. So, it would take a whole show. But, in a nutshell, you know, Lisp and the way Lisp works, the objects in Lisp are very hash friendly. And on top of that, Lisp can do a lot of object reuse. So, it can implement hash tables very efficiently, very quickly. It can implement them without using a lot of memory. And this is really important for the applications, which we'll talk about later. Sure. Mm-hmm. So, do you have any other strengths for Lisp? So, one thing that,
Well, I guess this is one of those—it could be a strength and could be a weakness—is that you can use Lisp to parse itself. So, the difference between data and instructions in a C++, Java, Python program is very clear. It's very much, 'Here's my code,' and 'here's the data I'm storing.' I'm assigning this data to this variable. And only in a few kind of edge cases where you might talk about function pointers or, you know, some kind of obscure things where your variable stores a pointer to code or code somewhere. But that isn't the usual case. It doesn't normally happen. But in Lisp, you can have your program represented as these pairs. So, you can—this is very easy to intermix both the data and the program. And that means that you can manipulate the program. So, that's known as self-modification. So, when the code, as it's running, changes the code that's running. And in Lisp, this is easy to do because, like I said, there's no real distinction between data and the program. And that's a strength. That gives you—there are some really powerful techniques that you can do and that make really efficient code. It also happens to be something that can be very hard to understand. But it's one of those where great power comes great responsibility. If you use it wisely, it can be very powerful. And if you use it poorly, it can cause problems. But Lisp
is really good at doing that. Look at, like, the roguelike, for example. So, let's say you're making a simple roguelike game following the 15 steps. And, you know, you make a sword. And, you know, you have this Sword class. And you have some data. Like, you have the Great Sword where the name is 'Great,' and it does, like, 10 damage. And then you have, like, the Awesome Sword. So, you have some text file. And the text file just has, you know, 'Great Sword, comma, 10.' 'Awesome Sword, comma, 20.' You know, 'Light Sword, comma, 30.' And so, like, then you write some C program that looks at your text file. And then says, 'Okay, create—you know, create a Great Sword. Create an Awesome Sword.' And then put these somewhere in memory so that I can fill my world full of Great and Awesome Swords. But what if I wanted a Flaming Sword? And when you hit somebody with it, they caught on fire. And there was all this code and stuff like that. Well, you know, that can't really go in the text file. You know what I mean? You can't describe the flames. Yeah, you can't describe the flames and the effect and the person catching on fire and what that means. All that logic. You can't just put that in the text file. I mean, you know, you'd have to put it in the C file and then know that, 'Oh, a Flaming Sword has this,' right? But with Lisp, you can just—your data and your code is the same thing. So you'd have, in Lisp, you would have, you know, a pair. And the pair, the first element would be the name. And the second element would be a pair, which would have the, you know, damage. And then, you know, the third element there could be an entire Lisp program, which is what happens when you hit someone with the sword. And you don't have to worry about reading your data from the text file like you do in C and, like, you know, creating Sword objects based on the data in the text file. You just load that Lisp file and it's done. So, yeah, you could do some awesome stuff with it. But, yeah, I mean, it makes it very difficult to debug and things like that.
So with all of the—these things are nice features; everything's a pair. And the language provides some abstraction. So I guess we should say that even though everything under the hood is a pair, the languages allow you to not have to literally, if you want to make a list, have, you know, a pair where the second element is another pair and the second element is another pair. They give you the power to just, you know, make one long list and do that pairing for you.
Yeah, I mean, it's—you know, they've done a lot to make it less painful. So as Patrick mentioned, if you have 10 items, you can just put a single parentheses around them. And Lisp under the hood knows that it's like a bunch of pairs that are all chained together. But the fact is, yeah, I mean, there's just—you're dealing with pairs. And as you might imagine, there's a lot of data, a lot of variables you might have in your code. You're going to have a ton of parentheses. That's kind of endemic of Lisp programs. So fortunately, if you use Emacs, you can—it'll match up the, or actually, I guess most modern, or not even modern, most editors will do this for you. But it'll help you match up the parentheses. But yeah, it still can make things a little cumbersome.
Yeah, it's not really a weakness, but it is something when people look at Lisp code. Some languages you don't exactly know at first, like C++ and Java. Sometimes you have to kind of look at certain lines of code to kind of understand what it is. When you look at Lisp code, it's really easy to tell because you just look for all the parentheses.
Yeah, I mean, think about this. As we mentioned, again, everything's a pair. So if you want to add two numbers, what you really want, you want a pair of a plus sign and a pair of a two and a three underneath it. So you have now Lisp, with CLisp and more advanced Lisp, you can take away the parentheses around the two and a three. But you're going to have a parentheses and then the plus sign and then two and three. That's another thing about Lisp is that everything is in prefix notation. So if you want to do two plus three, you actually want to do plus two three. And so because it's in prefix, let's say you wanted to do two plus three minus four. It would actually be plus minus two, three, four. So now that doesn't make any sense, right? Because the order of operations, you don't really know. You know, prefix notation doesn't really give you order of operations. So to deal with all that, you specify the order explicitly. So to do two plus three minus four, you'd actually do open parentheses, open parentheses, minus sign. Yeah, I think you said that. Yeah, minus sign. Open parentheses, plus sign two, three. Close parentheses, four, close parentheses. So just to do something that simple, you already needed four parentheses, like two opening and two closing. So it can get pretty cumbersome. But one of the other, you know, weaknesses of Lisp beyond just the syntax is that it doesn't have direct memory access and doesn't really have much in the way of hardware access. So people have written extensions. But, you know, for the most part, it's not really designed to, you know, fit the model of a computer. And this is one of the, you know, things that really hurt Lisp. But that's, you know, that's what inspired people to make the Lisp machines that they did, you know, 20, 30 years ago.
able to manipulate specific memory locations. Because that's, you know, for people who have never done it before, it may not be obvious. But that's how, at the lowest level, all the drivers work. So the things that control hardware all come down to basically putting certain values at certain memory locations. And doing that causes something to happen electrically on that peripheral device. And that's how device drivers are written. And so if you don't have the ability to control exactly what the contents of a certain memory location are, then you're not going to be able to control that device. And you can't write device drivers. And that's what a lot of low-level code is working with, those kinds of things.
Yeah, I mean, you know, a lot of people are probably too young. A lot of people listening to the show are too young to have serial mouse. But when I started learning about computers, I had a serial mouse. And what that was was the plug for the mouse had, how much does a serial port have? Like eight pins, I think? Nine. Or 16? Nine pins?
Okay. Yeah, so just think of that. It has nine pins. And, you know, it naturally fits an array. You know, if you want the eighth pin, then you call array index seven, right? So, I mean, the way that computers are architected and built, you know, the way memory is laid out, all of these things sort of fit the linear, you know, C model. And, you know, back when it was really important, when speed was really important before computers got as fast as they were. And when, you know, storage is really important before hard drives got as cheap as they are now, the languages like Scheme is completely dominated. And only now are people starting to leverage more, like, productivity-focused languages like Python. But Lisp was really sort of only, you know, useful to academics at the time when it was most popular.
Yeah. So, Lisp was very used a lot in planning. And so, let me explain a little bit of what planning is. Planning is basically searching through, like, a particular space and figuring out sort of what are the optimal actions to take. So, for example, path planning is, you know, let's say you have, again, let's say you're making a roguelike game and you have this grid world, you know, sort of like where the whole world is just a grid of numbers. You're at coordinate X. You're at, you know, coordinate 3, 5. And then you take a step to the left. Now you're at coordinate 4, 5. It's very discreet, right? And so, you know, you want to navigate through some maze in this grid world. What you want to do is to plan. You want to sort of try all the possible moves you can make and then see where you are. Are you closer to the goal? Are you further away from the goal? Like, what's the state of the world after these different actions I could take? So, again, going back to Lisp strengths, right? Let's, you can create a hash table where the key is the entire world, the state of the world as it is. So, in this grid world, the key might be just your position. And the value would be, you know, how close you are to the goal. Or maybe even just you want the hash table to store as a key the state of the world and as a value whether you've seen this state or not. So, if I take a step to the left, that's a new state. So, I'll put that in the hash table. And then, let's say I try taking a step to the right. Well, that puts me in the same state I started at. So, I go to my hash table. I say, hey, here's some new world I discovered. This is the world where I'm at coordinate 4, 5. And the hash table says, no, you've already been here before. Like, don't bother trying to go further. Like, you've already tried all the actions when you're at 4, 5. And so, doing this will keep you from just going left, right, left, right, left, right. So, eventually, you'll explore all of the possible game states, all the possible world states, until you get to the state where you're at the goal. Now, to take it to the next level, the hash table could not only say whether you've been at that state before, but it could say how you got there. So, you know, once you get to the goal, you can say, okay, this state of the world that I visited or that I'm at now, how did I get here? Check the hash table. The hash table would say, oh, you got here by making a move to the right. So, you could do the opposite, backtrack, right, make a move to the left and say, this state of the world, how did I get here? And it could say, oh, you got here by moving down, so on and so forth. So, this is planning. And to do effective planning, you need good heuristics, which that's just simple algebra. So, you can do heuristics in any language. But you need an awesome hash table, and Lisp definitely gives you that. So, it was very useful for planning. Expert systems, it was also good at this. This is kind of a buzzword. Expert systems is basically planning, but instead of planning over something very discreet, like as we mentioned, planning through a grid world or something like that, in the case of expert systems, you're planning over rules. So, this is similar to Prologue. Actually, this is almost exactly Prologue, but at a lower level, yeah. So, in the case of Prologue, it's this really high-level abstract language where you're specifying these rules. In the case of Lisp, sort of, you would be creating the Prologue interpreter, essentially, in Lisp. But you could also do other low-level things. Like, you could have rules that were mathematically based. You do things like that. And so, a mathematically based rule system, which parsed natural language, it basically tokenized the languages, the natural, tokenized the text into syllables, and then, based on the syllables, tried to get an understanding for the language, like where the noun is in the sentence, where the verb is. There's a system that did this called SHRDLU, S-H-R-D-L-U. And it really made Lisp famous. So, what this guy did, he was able to scan an entire encyclopedia. And then, for each sentence, he was able to figure out where the noun, the verb, the object of the preposition, all the different parts of speech for that sentence. And then, he created a hash table for each sentence, where the key was the, I believe the key was the verb, and the value was the noun, something like that. But basically, because he scanned the entire encyclopedia, you could ask it questions like, how many toes, or how many legs does a zebra have? And it actually could tell you answers in English. So, you would literally type in, how many legs does a zebra have? And it would answer you, a zebra has four legs in English. And this blew people's mind, right? When this program came out, people thought, okay, we're going to get a human robot in the next five years. Now, this program came out in the 60s, right? Or maybe not that late, maybe like the 70s. But, I mean, it shocked, like it rocked the AI community. Mm-hmm. And it was done by Lisp. And it really made Lisp very popular at the time.
Another thing that people use Lisp for, and you talked about it a little before, but Emacs. Yeah. You mentioned that it will help you do the parentheses matching, which a lot of editors will do. But Emacs uses a version of Lisp as a way to do its extending the Emacs editor. So, Emacs is one of the, I don't even want to say anything, because it'll just start a flame war. But Emacs is one of the editors that is popular on the Linux platform.
International Traffic? I don't know what ITA stands for, but Google now owns them. But they were kind of, yeah, like the big back-end infrastructure servers for, they're like all of the major internet travel websites, like Orbit, Travelocity, that went and queried a system for tickets, information, flight paths, times, on-time percentages, those kinds of things. These people like tracked all of that data. They were like the people who all these websites used to get that information from. And all of their software was written in Lisp.
Yeah, that's right. So I think, you know, they were probably, they've probably been around for a long time. Yes. And they, you know, probably when they were around, other languages like Python and things like that probably weren't that popular, or maybe even didn't exist. And so they were, you know, had the foresight to jump on a productivity-based, you know, productivity-focused language like Lisp. And so it's carried them all the way to today. So definitely Lisp has been used in enterprise solutions. Another more academic application of Lisp that was very popular again at the time was Maxima, which is a computer algebra system. So, you know, algebra really is a planning problem, you know, especially at a higher level. Like, you think about it, you have an equation. Let's say you have, like, let's say a simple equation. Like, you have, you know, 4 divided by 2 plus 3. And you just want to know the answer to that. So, you know, that's, you're doing, you have to do planning. And in this case, you only have one thing you can do, which is a division because of order of operations. So you divide the 4 by the 2. That's your one action. Now you're into a new state where you have 2 plus 3. Then you take another action where you combine those and you get 5. But as you get to more advanced things, especially like integrals where there's many different rules you can use or derivatives, or you get to differential equations where there's, you know, 10, if not 15 or 20 different ways you can solve a particular ODE, particular differential equation. So this thing does planning and says, all right, again, let's, here's the state of the world. It's this differential equation. Let's put it in a hash table. And then let's start trying different rules, different ODE, different differential equation solvers. And it can, it can sort of try these rules. And by enacting these rules on the equation, it creates a new equation. And that's a new entry in the hash table. And the hope is eventually it can reduce some really complex differential equation to something much simpler. Or it can reduce some integral using some trig identity into something much simpler. So Maxima used planning to solve many computer algebra problems.
Definitely. So, you know, if a couple of people have been adding us on Google+, that's awesome. Definitely add us. We actually invited anyone I knew from Programming Throwdown, from my Programming Throwdown circle, we invited to the Hangout. So definitely, you know, can take some of your questions and your feedback directly when we do the shows and things like that, which would be awesome. So definitely add us. You'll have to try
Yeah, yeah. But shoot us an email. So add my name on Plus is jgmath2000 at gmail.com. And I think you're P Wheeler, right? PatrickLW. Oh, sorry. PatrickLW at gmail.com is Patrick. Shoot us an email, you know, before you add us to your circles so that we know that, you know, you're in Programming Throwdown and we know kind of that you're not some spam bot or something like that. Although, you know, spam really has been brought to quite a minimum on G+, which is pretty cool. Yeah, I haven't seen too
Yeah, for all of you who have added me, I know some people have and I haven't added you back. I'm working out a system. I'm trying to keep my stream with people that like I'm really trying to pay attention to. And I still haven't figured out how to add people and then not, you know, have them flood out my normal stream. But I have been looking at what you write on my incoming stream. So don't feel like that I'm being mean to you.
Yeah, definitely. I'm going to keep inviting anyone in my Programming Throwdown circle to the Hangout before you record. So if you have any feedback you want to add or if you have any questions or if you have a language, we'll do an impromptu language. I'll throw down the gauntlet right now and say that if someone has the right timing to jump into our Hangout while we're recording the podcast, we will do whatever language they want. Well, I will make it that.
Yeah, that's true. We need somehow if someone comes in and says, 'Oh, I want you to do Motorola Assembly at Bi,' you know, I mean, and we can't—we're kind of stuck. Right? Or I want you to do M68K, you know, Donkey Kong Assembly or something. But, you know, yeah, you definitely have to be willing to help us out because we're going to be floundering a little bit. But I will throw down the gauntlet now and say we'll do any language someone wants if they jump in the Hangout and tell us. Jason might be doing
See ya. Bye. The intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution Sharealike 2.0 license. You're free to share, copy, distribute, transmit the work, to remix, adapt the work. But you must provide attribution to Patrick and I and share alike in kind. There we go. There we go. There we go. There we go. There we go. There we go.
