 Okay, thank you. Yeah, so so my name is Jonas and I travel around hacker spaces as part of funding the noise bridge in San Francisco, but the day they got to the month we got to place I moved to Australia and we didn't have a hacker space so I went to some meet-ups and talked about Maker spaces and they just meet in pubs and talk about maker spaces there But suddenly somebody had a house which he wasn't using so we got to use the house and when I moved to Hong Kong and they had no place They had meet-up once a month and I said well, why don't we just come and Talk about making instead of talking about we want to talk about making And let's meet once a week instead of every once a month and that's how we got started them Suddenly when people are doing something you have maker spaces, so I like it. It's great. Yeah dim sum labs Yes, so I've been in your old place which was near the the temple, right? My mask. Yeah, it's a beautiful area. I think it was a Swedish restaurant nearby, so Yes, so I like making I like playing this stuff I used to work at Google and I built data storage for Cloud and and so on And it's big But it's also small because when something is so big it has to be small and that's why I like microcontrollers So I'm playing with something called the node MCU. How many have heard about the node MCU? so node MCU is like just USB breakout board for the ESP 8266 and maybe even more people heard about that one, right? But I really like the node MCU because you just connect to it and it just works and you compile your C code or you can do other things, so How many have been using C for it or Arduino IDE so we have few there how many play with the It comes with node, which is we Lua, the Lua interpreter So few people try to use that one I try to use it because what was what was available But you get stuck in it because it actually runs out of memory very fast You write a few function and each function you define in source code for Lua, which is a high-level language takes about 800 bytes and you have about 14 kilobytes. So you define Eight functions in your out of memory I was like, no, I can't do that, but it was really happy to have it in the beginning. I have to play with it. So I thought like What what do I want with this device? Well, I want it to be some program I want a program on the device. So I want it to be interactive and actually the Lua works fine, but it's kind of tedious to upload files and so on and I thought like which environment is good for this Well fourth is one language and and Lisp is a very old language and I thought wow What if I could take this chip and maybe I could also This is in the future find a LCD display, which is big enough connected to this and maybe connect the old keyboard to it Then I would actually have a small computer which Wouldn't be a general-purpose computer. It would be a programming machine So you could program on the go. It's almost like a laptop, but the about the web browser And and I think it could be interesting for people who want to learn to program because it's a thing you only program on and It's not finished So you can do a lot of things yourself and it's not difficult to do it, right? so This comes back to the idea of a list machines and stuff like that, but to get back to to Making obvious things So I Said I can write a better language I can write a list and I haven't written a list for 10 years So I thought it was time to do it again. And so how many people know Lisp or scheme or common Lisp and Let you burn on the old guys. Yes. Yes Kind of it's it's a very interesting language to learn because it changes the way you're thinking and programming computers and Small computers is changing your way of thinking from programming bigger computers, right? and and so you need to be taking care of resources and Lisp is very interesting language because it's very compact to do something powerful, right? And it's pretty high level in the way you Can program it's right because you're not bogged down with the memory allocations and stuff like this So just learning it for the course of learning it itself is actually worthwhile for you become a better programming C Plus plus and in in Java script and anything else if you learn this I agree with you, but you know Implementing the Lisp interpreter is a very big challenge if you want to be Frugal on memory they used to blow the stack space out on a tops 20 with yes You can do that. You can do that, but it's it's interesting. So so There's a few few features of the list. So my goal is to be a better environment than the Lua for for programming, right? And I concentrate on speed so I'm like two times slower than Lua on the device for a simple loop but I I Pushed it down so that I handle like something called tail recursion. I don't know if people know what this is this is when a function call itself and it doesn't wait for the return value and this doesn't grow the stack and GCC is a compiler which is intelligent enough to handle this and newer compilers can handle this these days So I had a number of goals with writing this thing like it would be an alternative environment But I wanted to be so far self-hosted that you can connect to device and program it and as I said maybe make a home computer again Where you want to program on it rather than playing games and downloading software in installing it, right? So maybe people would actually write their own web browser or web server and stuff like this So some of the design goals are Embedded small list and there's a several challenges to this because I don't know if anyone use the ESP and you try to do something more than just sending data from it You maybe you read a web page you try to scrape something and suddenly you can't use the parser You actually have to go and get what you want where you want it I mean you have to write your own kind of specialized code, which is just cool actually So you have to be memory efficient is 40 kilobyte of RAM available when you start your program but all the libraries and Standard I or printf they all take up a lot of Memory so you end up with usually about 14k available I think on the Lua and I'm about maybe 20 k k available Some of it is allocated for usage from in the list So everyone who doesn't know Lisp knows JavaScript maybe So JavaScript has something called closures, which is a when you return a function Which is going to be called later and and this is a very fundamental to scheme, which is a variant of list which Makes if it's kind of an object orientation DIY you do it yourself And so all the orientation at least doesn't require you to have a lot of libraries or anything It's just you have to do it just create an object and you can send messages to it It makes people really understand what we're doing People have used the Lua. They know that you have kind of a terminal interface so you can type and edit And you want to be able to easily add functions to this language, right? So the first working variant was a thousand lines of C code So Lisp is not bigger than a thousand lines of code And and so if you're going to do a really really big project and it's very difficult to build First you should write the list and then you write your project inside the Lisp This will be less code and you'll be done faster than actually Trying to write the stuff in C++ to start with quite often if if you if you're used to this kind of way of thinking So these are some some node features which only make sense to So thousand lines basically the basic the basic scheme and all your basic functions So then you're writing C code for like direct hardware control of specific bits which Might add on right. It's basically make make dedicated look functions For things that are going to deal with well, I don't have all those parts yet, right? Yeah, that's my idea So I have a simple one where you can read an input pin and write to output pin It's all a matter of if I have underlying functions available in C then I can add it, right? So currently I'm using something called ESP open RT OS Which is a not operating system, but it has operating system Tasking facilities and it can do Interruptible code and so on I'm not using all of those features, but it's a it's a nice framework for compiling stuff and but I'm thinking about moving to another one because They say like oh you probably could connect PWM stuff to it But we don't have an example code and when you say like you take some example code and doesn't work and Actually, you take Arduino code. It always works because somebody else wrote it and for your platform and it works, right? So I'm thinking about switching it over But it's it's a very portable C code because I run it on on Unix on a Linux To develop and then I just move it a flash it to the device, right? So Okay, so let's get to something real Here is just the files and It's essentially just two files at the few files at the moment So so the the most important one is is Lisp dot see I started with one file and then there's some some drivers to to make it understandable, right Comments, there's a lot of geeky stuff in it how I store data So for example, I try not to allocate things on the heap. So an integer is stored inside the object pointer And this makes you save it memory allocation because how much does a malloc cost in memory from a heap you malloc one byte How many bytes does it cost? Well, it's aligned on eight bytes typically so you will at least allocate always eight bytes And so it needs four bytes for the next pointer three pointers and memory sizes. So you end up wasting seven bytes, right? So so in this case, you don't even allocate the integers But it also means the integers are a bit smaller, but usually you loop over smaller numbers so Then there's a number of data structures Don't want to go too much into that storage, but one thing very very important with the list so so let's Now we just gonna run the list here. It's not running on the device yet but yes compiling it and and running it on the command line and so we start it and here we have a list and Lisp is prefix notation so you say first what you're gonna call and then the arguments and Actually, if it was C the equivalent would be this it's also prefix actually But for some reason people think that this is full of parenthesis So please count how many parenthesis over here? There is one two and one two here, but there's an extra comma here, and I don't understand what comma does Now here is the thing you don't write this in list, right? So in list you actually have to tell the computer what to do So you say that you actually want to do a plus three of of Five times six or whatever it was I was doing right and actually this is the parse tree of of Your other thing right and this is what makes list powerful because your program is data and The least interpreter is interpreting data which happens to look like this So it's it's a program by definition and therefore it's a self Thinking machine. No, it's not intelligent in any way. It's so dead simple That you can write a list inside a list in less than 50 lines of code. It's like maybe 20 lines of code and So so this is the magical part of it. Now this pass this strange thing that things are Symbols so symbols in list by really important So I using a function called set Q and I can say foobar and it's free So now we have a symbol defined as foobar and when I evaluate the value it's free So I can say plus foobar and now this will be six, right? Now This also have something called Function, but we don't call it a function. We call it a lambda and a lambda is Let's say we call a function X X X we say lambda X and I want to hear from somebody who doesn't know lisp what this does Right, it just takes an X. It's a function taking an X and it returns X plus X and we give it this this the lambda actually evaluates to an expression Which is a function. So it's already Object-oriented because functions are objects and then we put that function inside the X X X and Okay, this is a the old one So we can give it a Number and now we have created an abstraction in this language, right? So how do you do other things which are not plus? Well, you don't really do anything else from plus in Lisp You just call functions and there's a function called if so We can say if 3 is equal to 3 Then we want to return 42 otherwise return 9 So this returns 42 and if it's not true Then it returns the third value, right? So this is This is all you need kind of to do a lot of stuff. Okay That's a very simple syntax, right? now, how about We we want to not return the number 42, but they actually want to call Call a function which we already define which is called X X X And we want to call it on 42 if it is equal, right? So this will give us 84 right, I'm lucky today because no bikes apparently my list So This is programming right now. Does anyone know a function which calls itself? Right in cursive function, right? So let's do some recursion at which function do we always define when we do recursion? Fibonacci yes, so Call it f and so it takes an n And if n is equal to 0 we return 1 and otherwise we multiply n by calling the function named f with n minus 1 and Here is where everyone goes crazy. I Hate list by parenthesis. I have to count them At the moment. I have an interesting bug that when I get to the end of line I just padded with as many parenthesis as there is so you can't write multiple lines at the moment So there's not too many parenthesis. You only start a few and you don't need to end them if it's It's ends now this is much lighter when or easier when you have an outline and you have an editor and so I'm working on that too So now we have function called f and it should actually show the name there So it's all the version of the software and f of 0 is what if n is equal to 0 when we return 1, right? So wow, we're lucky today About 1 how about 6? So it's just 1 times 2 times 3 times 4 times 5 times 6 so it's 4 7 20 not 4 20 Now we can do this on a really big number and Let's do it on a really really big number and You are royally screwed. Why does it still work in it? I'm going to reboot it and this is actually error message from My machine because I put in a limit where you can only recurse to certain depth And this is not us running out a C stack is running out of another stack which I use for garbage collection purposes Okay, so now we've been swimming around enough in the non non real world So let's get to a more real world than a simulated world on a computer. We will actually connect to Maybe a device. Let's see if we can do that today So here we do here it is a Lisp so Secret function I have is called mem and it actually gives me some stats here It tells about what's allocated freedom blah blah some geek stuff and the number of cons cells available So only have 485 consels available. So you can only have a Few elements in a list a few hundred before we run on memory We have 13k free and that is not used by cons so we allocate consels. This is actually still free This just can be used for things like strings which allocate One thing we saw is that we we can create function we can create names of functions, right? Well, you have to allocate both strings to Actually, you don't need to you store them in the point to two if the name is Up to six character Six characters in a to Z can be stored inside 32 bits Because it's five bits is a to Z is 32 characters possible and five times Six is 30 And then I have two bits left over which tells you that this is an atom stored inside the pointer So the pointer actually doesn't point to anything So this saved me two kilobyte of Ram Otherwise, this would actually say how much memory I have 13k So it used to say 11k before I did that so this like tricks like this which makes it really cool now So we can test this we can say foobar and we actually didn't allocate anything that is the same foobar fee foam It's a longer name. Let me see we have out one allocation of 29 bytes and They still use 29 bytes because an atom never gets thrown away because that's it's a global inquiry. How many minutes? Okay, so now Let's let's see if we can do something more fun here. We Create the function f we will not see again and Lambda n if n equals to Zero return one otherwise is n times f Minus n one. Okay, I think it's Huh, I think that if you were not easy questions plus and not times So it's plus This is faculty function actually so yes, so it's faculty function. Sorry. It's a f-function If what I know Sorry, sorry. Yes, it's still f right so good points good points Multiplication is more expensive. So it's more fun to do it, right? So we can still test that it works And this is actually probably where both of those function would be the same right so we can do f6 now Let's do something more fun. We can say trace on And then we run it So let's do it on a smaller value Oh f1 So here it actually shows you all the function call we do in f in the valve So f1 is called and then this is an expression being evaluated So you can follow and debug your program and you can each point see what value is being returned So it's zero return true is returned for the equal sign, right? So n equals zero is true and then you have one one one one with being returned top up, right? So you can do things like this now. I have a built-in function called feebo feebo nachi and it Yeah It's doing a lot of work. It's a good test for for for everything, right? Control C Actually, it's finished. So let's do it. Let's Turn on offer tracing and we do feebo 10 and that was really fast something right printing Because printing is what makes your program slow. So you can we can tear time it So it took stereo zero sign So let's do 22. Let's take some more time. That's 22 recursions actually So let's took 1930 millisecond and you can just see you increase it by one It takes So now we're talking about Fibonacci if you're not she is different because it's not one recursion It's calling itself twice with two different values. So it's really like the worst complex algorithm You can design the computer. So it's really slow and you increase one number. It takes almost double time, right? So this time function is a way to to really be able to to test test these things now That's only took a certain time. So now we're looking at this. Okay. What is my computer doing? Oh, is it doing control T? Control T control T control T. So we see here actually a small stack being printed. I'm a load is 0.99 and it says that we have a time function calling 20 Fibonacci or 20 freaks the one actually means Fibonacci is calling itself 23 times on the stack and So you can kind of see what's going on and see that it's responding, right? So this is kind of fun to to run this way So it means it's not dead when it's doing something and the overhead of this check. It only test every a few 100 milliseconds or overhead is not even 1% To add this functionality, right? And most most computers will not not respond while while you're doing this stuff, right? So, okay So if we do this again, we can do control T You can do a control C Okay. Now, how many people have been uploading programs? to it Ah, I have to do So you have to add a path with tensile compiler And I say we're gonna put A later version on it She that's not that's not the latest version. Let's get the super latest version CDSP And That didn't work Okay, let's do it the hard way so ESP list is available on github and you can download it and you can run it on your machine, but you can also Download the whole environment for for this one and compile it yourself or you can get a flash image for me, right? So this is a good way to play with it So 24% for the same person writing writing writing writing. This is really tedious. It's kind of fun because you're doing something really complicated but You change one Function in your code and it takes like a minute to upload it and test it again That's why using an old MCU using Lua using list would make your program much easier You just edit the function which which you're changing, right? So, okay, I'm almost out of time. I think But I wanted to see if we can run this one like this So we see it's still doing that but I do control C now It actually shows you the stack of all the calls and both the parameters were so you know where you are so This could actually be Simply made into the bugger where you look where you are and then it could continue You could single step once you put a control C in it And this is actually a debugging added. We bought any overhead to the interpretation really being done at the moment I'm happy for people to play with this list and contribute functions and the particularly We need to add more hardware functions for it to to make it really playable At the moment, there's a there's a function called in one function called out They give it a pin number and you can set or read a value so That's the main thing. Yeah Yes, I have a dual core ESP 8266 is two node mcs. So I used to have a quad core about when I sold two cores What do you mean instances Right it in this case it just prints a stack and exits But it doesn't actually need to exit when you print the stack it could continue And it's actually you could tell it to print the stack continuously And you can see it grow and shrink it because it clears the screen before printing it out Which is quite fun So one could really make an interactive environment on it where you your program is stored here One of the things I want to do now is that when you write at this program it takes space and I want to make it That you write a function and I write it to flash memory Which means the RAM will not be used at all and as long as all your function names are six characters or less A to Z it will take no RAM at all almost and and so it will be stored in flash And this enables you to to write really big programs and change them and Without actually using RAM RAM will just be your data Your hardcore data, right? So it won't take any space and that would be one major margins according Relative to the Lua thing. Yeah, you've been talking the entire time about your Lisp interpreter. Sorry. Yes So what's what's your day job? My day job is People ask me what I do and I say as little as possible. I Only do things which is fun at the moment. I used to build cloud stuff at Google storage Big and small I used to build big database systems But at one point of time I was in IBM and I built tiny databases which ran on Palm pilot in in 2000 Yeah, 2000 and Ronald Sony Ericsson and other embedded devices like Sony and so on and and but small and big It's the same thing because once you have something small You need to be frugal about memory when you build a database it stores a lot of data You need to be very frugal about memory because you want to store a lot of data in it, right? So it's the same problem It's just two extremes of the same same usefulnesses of that so I think in principle There's a in reality is a sweet spot, right? Yes, you know you you've optimized to a certain point where you're not you know breaking your back every time you need to you know think about The limitations of some of the trade-offs. I try to optimize for fun I'm not having fun and you're not paying me an awful lot of money. I won't be doing it Right. So this is fun so far. Yeah, very interesting project All right, so I think units will definitely hang around sure sure sure I'm happy to talk to everyone and know what you're doing because That's what a hacker space is but it's not