Cello is a recreational programming library that brings JavaScript-like features to C, including garbage collection, dynamic typing, reflection, and functional programming capabilities, achieved through a runtime system that modifies the C language's behavior at compile time and runtime.
Cello: A High-Level C Library for Experimental Programming
Added:hello everyone and welcome to yet another Recreation programming session with Mr zoing So today we're taking a look at a think called cello which is a library that brings higher level programming to see right I I heard about this uh Library uh quite some time ago right but recently I just briefly looked into it and I thought this could be a banger stream to to do to explore this library and stuff like that so essentially it brings a mod powerful runtime system right so it has a lot of high level capabilities as you can see so this is definitely not a standard C right this is definitely not a standard C but um it it even has like a runtime inspection and stuff like that and apparently it achieves all of that by adding a little bit of a blo into the runtime of the language it even has a garbage collector as far as I know right they even say it's yeah there we go so here is the list of things that these things supports like optional garbage collector you have generic data types polymorphic functions interfaces type classes Constructor D pure c not C++ mind you pure c not C++ constructor destructors optional garbage collection exceptions and reflection right so and here's an interesting thing like a lot of people use C precisely because it doesn't have any of those things and the reason why people don't like all of these things who who use see is because all of these things come at a cost right they all come at a cost at additional code at the round time that you usually don't see right usually don't see that code because it's automatically generated for you by a compiler it's perfectly hidden from you right so you so to not distress you to not think about all of the ca that you paying right so but people who are doing C they are actually aware of this cost right and that's why they don't really like this kind of stuff but I I suppose this library was some sort of an experiment of like let's bring that cost into C and see what's going to happen right so it's more of like experimental Library like I don't view this Library as something serious that you should use in your like production code or anything I think it's like a small little fun recreational programming experiment which I actually respect I like this kind of like interesting experiments that you can have in here and so let's go ahead and take a look at that right so let's download this entire thing so here's the download button and download button leads to uh an archive right so which is good right so let's go ahead and just unpack it so just a second my my laptop is a little bit slow right cello uh there we go I'm going to open it in here and we're going to uh just W get this entire thing so we're doubly getting this entire stuff okay so so uh what do we have in here so we have a lot of source code as far as I can tell right so we have a lot of source code and uh is that just like literally GitHub source code is this literally GitHub source code it could be actually uh looks like it looks like it's basically GitHub source code uh yeah it is except Benchmark so it doesn't contain any Benchmark so you have make file and I suppose you you you you have to build it yourself right so you really have to yeah you have to build it yourself so here are object files there we go so and um as if I understood correctly this entire Library consists of basically two components the library itself a make file actually buil a static library and a dynamic Library which I kind of respect right so if you don't want to keep uh the this bloated run time in your executable you can put it in a separate Dynamic Library which I understand so this is the first component and the second component is the header that you include that's pretty cool that's really cool I really like that that's a really cool way to you know to improve the unboxing experience of your of your library just put a huge freaking asky art at the top and you when you open the file just like holy [ __ ] [ __ ] it's it's literally like an unboxing devices like you you open the box and there's some sort of like a pretty card in there like it's just something like that so I like it's a 10 out of 10 unboxing experience for the library I I'm telling you it's a 10 out of 10 unboxing experience I really appreciate that so and as you can see there's a lot of like a syntactical interesting things there is a lot of syntactical interesting things and where are all these syntactical things defined they're probably all macros right so and a macros cannot be part of the like static labrary that you're linking with right it has to be something with a preprocessor right and all of that stuff is located in that header so because of that I view this Library as a two component Library it's the header that adds the additional syntax as much as it can because the C preprocessor is rather limited right it's limited in terms of what you can do with this uh right and the actual runtime that you're linking with either statically or dynamically another interesting thing in here is that um it says it has garbage collector but garbage collector is a rather complex system that requires some sort of initialization right usually if you if you ever used any like additional garbage collectors that you use in C code they have some sort of a initializer uh command initialize a function so you have to call some sort of like in need GC at least to start the GC thread and like allocate some memory for data structures for the GC and start doing thing like you have to do something notice how here you don't do anything like you you literally don't do anything like how do you get a garbage collector if you like just start and write normally that's a very interesting question like like how do the [ __ ] do you do that well it from what I saw it is done with a preprocessor believe it or not modified main exactly so we can even try to find maybe something like Define main there we go so as soon as you include this header your main is actually replaced with a custom main which creates a new garbage collector like straight up literally here is the new garbage collector so yeah and then it also it even kind of substitutes like look at that if you have some sort of a main right main like that this entire thing this entire thing will be replaced with this chunk of code right with this chunk of code uh which calls to salamine and then it substitutes the Declaration of salamine so when you uh Define a body of main you in reality syntactically Define a body of cello main that's what you're do so the the entry point like you're not defining the entry point you're defining like this additional thing and it wraps it around to initialize the gabage collector and stuff like that so that's how they do that right and that's why um the you know the header part of this library is also rather important because without it you won't be able to like start and initialize the the runtime uh and what's cool about this library is that it's rather simple right so it's hackable you can understand how exactly it does all of these tricks um right so when I saw when I saw that this is the moment I realized okay we need to stream that we need to stream that because this looks [ __ ] cool if this is the kind of tricks this Library doing this wors like worth exploring honestly it's worth exploring wouldn't work in c89 needs at least c99 understandable actually understandable but again I don't perceive this as a like a serious like a you know production ready Library I see it as sort of like a recreational programming experiment which is rather cool and if somebody uses this in in production well yeah okay so there have cann't be used in production okay let's actually read the answer so it might be better to try sell out on a hobby project for exactly uh cello does aim to be production ready but because it is a hack it has its fair share of audities and pitfalls and if you're working in a team or to a deadline there's much better tooling support in community for languages such as C++ exactly so even the project itself doesn't really takes itself seriously and that's what I like about it that's what I like about it it's just like it's yeah it's it's kind of an interesting experiment and we also don't really take it seriously that much but if you manage to use this in production well good for you so this is the [ __ ] I like right it's just like a you know not serious about itself we're just having fun we're just having fun we're just having Recreation programming and just for that just for [ __ ] that I'm giving it a star that that's it like that already disolve the star no matter how good or bad this library is just for this attitude this is a star instantly just like I really like this kind of attitude towards programming towards technology this is what we need more um and the reason why it has this attitude is because it's a pretty old library it's coming from the time where the attitude towards languages and towards library was like that all the time I think the main problem with the modern uh like Frameworks and Library communities and language communi is that they take themselves too [ __ ] seriously the the tribalism is [ __ ] insane those communities it's just like we're taking we we we are the replacement of C++ don't you [ __ ] dare to stay on our way we we're gonna [ __ ] kill C+ so this is the kind of [ __ ] I see and it's [ __ ] disgusting like and the um the attitude towards this kind of stuff in the past was like that this was the attitude let's just [ __ ] have fun holy [ __ ] and that's what we what we need to bring back that's what we need to bring back anyways I'm sorry so um let's give it a try so um let's try to maybe write a hello world as far as I know it has its own even print right so it even has its own print statement or something like that uh let's go ahead and just like do that okay so uh this is what we have I wonder if we can just do mainc uh right and what we have to do we have to just include the cello I I kind of instinctively wants to pronounce it as C uh but I was actually instructed before the stream not to say it like that because it's pronounced like cello but again I I don't speak English so if I mispronounce the the name of the library I apologize right so please forgive me uh my my my first language is actually is actually Russian so uh what we need to do in here suppose it's just print right so that's what we do so and let's just say hello world right let's see how exactly it works um so you know what I think I'm going to create a make file so in a make file it's going to be something like that and I'm going to do CCO Main main.c and I expect it to not compile I actually expect it to not compile exactly because it cannot find the cello header so what we have to do we have to now give it a path where it is located it is located in include so there we go uh yeah so here's an interesting thing um conflicting types of cello with int ooh aha here's an interesting thing if you are defining an entry point it must be uh with arguments you cannot use a variant without the arguments that is very freaking interesting ha so so here's one basically Pitfall and odity right so because this this is what they warned us about in the fiq right it doesn't it comes with its own pitfalls and audities and stuff like that because it uses the macro to expand this kind of thing uh you only can have an entry point that always accepts arguments like you always have to accept the argument you can't have a variant without the arguments otherwise it's not even like a Linker error it's a compiler error right right away and it's a really cryptic one as you can see right so it's just like it points straight into the header right and if you don't understand how the internal of the library works you might be you might get confused because of that uh a like pit swipes your drives on uninstall Y what was the library that did that was it like a bumble I think it was a bumblebee that did that right so they they put accidentally like a space somewhere and if you try to uninstall it it just like wipes out your like user folder or something I remember there was such such a funny incident like it's also pretty sad incident right but it's like it's funny at the same time anyways so so we must have arguments in here and if we try to compile as you can see now we're failing with um you know Linker errors right so let's actually try to link this entire thing statically right and see how big of executable it becomes uh right so I think it's going to be interesting to maybe even compare uh right so if I take a look at this thing so the so it's a cello a I'm going to say link specifically with this one and search for the libraries in this folder right search for the libraries in this specific folder uh there we go and let's try to build this enti and it builds okay so how big of a file we got uh 47 kilobytes which is not that big honestly so if I link it with a dynamic dynamic one right so uh let's actually do minus B right well I mean yeah so 16 KOB right so this is we're linking with this entire thing dynamically right so that means it will be dynamically loading that stuff and if I just use a right it basically baks this entire Library into the executable and we get 470 kilobytes honestly considering like a rust hello world right if you take a look at the rust hello world unoptimized and [ __ ] uh right so it's so as far as I know like I don't have a rust C in here yeah rust C doesn't work in here it's I think it's like several megabytes if I'm not mistaken right so it's several megabytes so let's give it a try it's going to take some time it needs to warm up some CES you need to read all of that stuff from the hard drive and also using like a 10 years old laptop so anyway let's actually take a look at LS uh let's take a look at the subs 20 okay uh thank you uh back one for t one subscription with message yo in thank you so much for bits with a message I'm just a guy who's programmer for fun me too thank you thank you so much for 100 bits uh Andy otter thank you so much for tier one with the message I'm back hypers welcome back really happy to see you uh so and if we take a look at this it's 3.7 megabytes 3.7 megabytes so the runtime of rust unoptimized is bigger than the high level C cello just just to put it into perspective right just saying right so you may say that oh it's overblow it like a library it puts a blo into C like the runtime that rust baks into its own executable is actually bigger so so but how is going to be optimized that's a very good question how do you do optimization in in Russ I don't quite remember I think it's a c ah [ __ ] I don't remember uh Russ see um so something like help yeah and I think it's just something like opt uh opt level I don't remember uh what was the what was this thing who remembers yeah see opt level three yeah let's go ahead and do that um C opt level uh three all right so and it's still 3.7 megab so I didn't think it actually does anything useful but any anyway anyway so maybe there is a way to actually optimize the size like rust has rust compiler has a lot of different flags so I do expect it to have some way to actually strip it up strip it I already removed the the thing uh right so I'm sorry anyways so we're not looking into the rust today uh so again there are probably some ways but it doesn't really matter um okay so let's actually rebuild this entire thing one more time uh and uh let me see okay so this is hello world and how much time does it take it's pretty fast right so initialization of the garbage collector doesn't really take that much time it's just like a one millisecond and this is roughly the same amount that you would get from an actual C uh so which is which is fine which is totally fine uh all right so I would like to take a look at some interesting features in here right so we have stack objects that are create that created using percent so essentially you can have VAR which is essenti like um type inference in C so VAR is just a type inference so if I Define something like this uh right so if I Define something like this it just like infers the type automatically and I wonder how exactly it does that that's a very interesting question so let's actually try to compile this entire thing uh okay so I'm pretty sure it is in fact some sort of a macro so let's actually do Define VAR okay there's no defined War what is war though okay oh fair I suppose like I mean okay generic programming by the way that probably breaks all of the type checking and [ __ ] it probably [ __ ] breaks all of the type checking because now if I do something like 69 it's going to complain that it's not assignable to voice star yeah the the pitfalls and Oddities everyone the pitfalls and audities oh boy that's that's pretty cool um so but how like what is a dollar though uh let me actually see so do we have a the Define dollar there we go uh so you do a mem copy so this is more like an expression I would like to maybe straighten it up a little bit uh what's up with this expression okay um so you have VAR ARG right so you can have a bunch of [ __ ] in here uh so you allocate something on a stack mhm okay ahuh and then you copy all right so there is a special thing to allocate a bunch of data on the stack and then whatever you put in here whatever data you put in here is just copy it into this stack I see how it works I see how it works okay so analog stack uh so you just do header any oh so AOG stack just declares an array of bytes of the size of the type I I see okay so like how it that sort of like allocates any sort of type uh on this stack right you have some sort of a type well it takes the size of of that type it takes size of the that type and just allocates like a blob of that size and just basically copies the bytes of that type to that blob so that that's how it is allocated on the St uh and it completely ignores the alignment XD pit Falls the noties we were warned so I mean it's fair right again like when I encounter things like that in this Library I completely forgive it because it's just like the library is self-aware right so it kind it kind of knows that it does these kind of tricks um so it also has a header too let's actually take a look at that so header in need oh it has additional thing um yeah which is also is just like a VAR okay so VAR is like um it's like an object in JavaScript I suppose so yeah it's basically JavaScript in C right and VAR is an object and suppose um through the header you can actually dynamically dispatch on different types right so you have a pointer you probably cast it to the header right and if I take a look at the definition of a struct header where is the struct header uh it probably has like a type tag of some sort called it which is also VAR by the way but I mean probably maybe it's just like cast it in in some way but uh yeah so essentially cello operates on this objects a dynamic objects so they talked about something like a fat fat pointers right so they had some sort of concept of fat pointers uh yeah fat poter Library I about this Creation in internal workings uh so how does it work I recommend reading a fat Point library to get an overview of how cello works you can also check okay okay so we're going to be reading uh where is the where is the article uh reading a pointer Library a fat pointer Library uhhuh okay aha so here's a full reference documentation for all types I suppose fat Point library was something separate and then they just merged it into um because if you if you look at the fat Point Library it's it's the official website I suppose um right I suppose this is the fat Point Library all right that makes sense so I suppose vars are the fat point bottom left articles uh yeah uh just a second my mouse is dying my Mouse is dead actually okay uh oh I don't know oh okay finally I think I clicked something correct but anyway so we became like uh you know the the article reaction streamers now like so I'm now going to be reading the article and periodically making my you know pointless remarks and giving my pointless opinions while reading it uh so The Proposal fat pointer were proposed by Walter bright okay do you guys know who's it's an inventor of De programming language right so it's an inventor of De programming language by the way I really recommend you to Google up about Walter bright and his work right and also try to look up for his Talks on YouTube he also gives a lot of talks and stuff like that especially like all the talks uh Bolter white Bolter white uh so he is an incredible programmer right he is so [ __ ] knowledgeable like every time I find a talk from Walter bright and like listen to it I always learn something new like it he's insane it's just like so [ __ ] cool uh right so he knows a lot about programming or system programming and stuff like that really recommend um so the idea of fat pointers is his idea uh so let's actually see I want to take a look at the proposal uh what the [ __ ] am I looking at C's biggest mistake Dr dos the world of software development and it's loading it can't load we need to cook sea the the website is dead so I it's just like okay we're not going to be reading that so as as NC extension M to avoid a numerous pedf that come from the relationship between pointers and arrays uh the problem is this in see when you pass an array to a function it decays to a pointer meaning uh what you actually pass is just a pointer to the first element in the array this wait isn't fat pointers what we today modern software developers call slice uh pointer plus the size of the array okay so I don't have to read that then so I suppose okay there there are slices right so okay um so it's a fat point it's just a slice okay fair fair fair uh fair fair fair um anyways so let's uh take a look so you can actually allocate AR race so he objects are creating using you it is almost like a Plus+ holy [ __ ] sh my all right so we can create that and the real question is so this thing claims to be uh garbage collected right so it claims to be garbage collected but does it clean up after itself right if I do something like while grind is it going to clean up after itself we just allocated some array on a hep it uh blew up with some conditional jump or move depends on initialized value but it didn't leak any memory it actually didn't leak any memory because it has an optional garbage collector it actually collected it um like after itself it did some weird Chic like what the [ __ ] is this m but at the same time so maybe they forgot to initialize something like what the [ __ ] is that like why is it why my garbage collector depends on uninitialized data what the [ __ ] is that disgust disgusting this [ __ ] cting but yeah as you can see we have a garbage collector Inc who needs JavaScript who [ __ ] needs JavaScript if you have cello look at that web should have used C instead of JavaScript if web used C instead of JavaScript using cello the world would have been a better place it wouldn't been a bad place we we' be already colonizing Mars by now but you know JavaScript is stagnating the progress of the entire Humanity that's what happens that's what happen when you use Shady programming languages anyways so uh all right so then we can do for each I'm actually really interesting okay so let's take a look at new how does new it even highlights that oh because I'm using a mode that is also compatible with C++ right so uh so let's take a look at the new Define new okay all right so uh we just pass the uh variadic arguments as a tuple as a freaking Tuple you know what I think I need to do some some stuff in here uh I want to do e tags on uh on uh cello. so that basically indices all of these things and it should theoretically allow me to easily jump around right so if I do something like this and then I say okay use this text file uh and I can actually jump to the definition of look at that so then I have duple XP for experienced users and it's it takes two arguments and just like puts them together so that's what tup XP is this is some sort of like a syntactical uh you know shuffling around so I don't think it's that interesting uh right so new width what new width does not even exist look at that ah o because we're using this unusual syntax and stuff like that e tag broke and it couldn't properly index any of this stuff so yeah by the way um so this could be another problem with using this library is that some paress may break on that right because again it adds additional things that are very unconventional for C uh so eag broke like I can't jump there so it is what it is and it isn't what which is kind of weird like it shouldn't break because V is just like a type so it eag didn't recognize it as a type so it's kind of weird I I don't fully understand it so oh it doesn't even it's just like a forward declared ah it's probably an internal function it's it's in the library somewhere so we have to actually look inside so you know what I'm thinking uh I think I need to do the following thing so let me maybe find all of the files the name of which consists of like any characters dot uh [ __ ] find type file name uh like any character Dot and ads with either C or H right let's find all of these files so here are all of the files there's not that many of them uh only 39 so that's totally fine and I'm going to shove all of these files into e tags like that so we're going to index the entirety of this Library so now we have 45 kilobytes so there's everything in here so now uh if I just try to do something yeah there we go so I'm jumping inside of the run time of the library right so here I accept the type which is also like a variable construct so it's a Lo uh and a Lo is just this thing it's just this thing which is not telling me so it's some sort of a there's a lot of magic in here I'm I'm telling you bro there's a lot of magic so this is the function uhhuh and in here we create a new instance of some sort of a object type instance damn bro that's like the entirety of this is like a high level language within C it's literally like it's a scrip in language inside of C right and everything is an object everything this is actually kind of cool like everything is a VAR VAR is just a void star and you dynamically like like check do use reflection on those objects to figure out what the [ __ ] is that uh right so that's that's what you doing here damn this this is such a funny Library like holy [ __ ] sh everything is an object everything is just a void star that that's how it works uh like even has self yeah unfortunately it couldn't like use uh dot notation syntactically like it couldn't easily bring the don't notation to to this language I think it it would use it if it if it could but yeah like notice how like it everywhere it passes VAR like it's always passing VAR somewhere damn bra uh there's garbage collector so yeah Mark and sweep I suppose that's what it's using in here for garbage collection anyway this library is something I'm telling you this is something uh again I want to take a look at the the V grind right so if I take a look at the V grind so how many allocations there uh right so there was 21 allocation and 21 free right so that that's pretty cool uh right this one is a little bit concerning this kind of stuff is a little bit concerning but I mean garbage collector works at least garbage collector works anyways so we have a for each uh right and it's kind of a cool for each because it even supports like a in uh keyword right look at that so and uh let's actually go ahead and just like copy paste this entire thing in here uh so this is our for each object over a type so you can even take a type of this entire thing uh so make B uhhuh all right so object five uhhuh is of type int object three is of type int and this is of type four okay okay this is kind of cool notice how the print F of uh cello doesn't take the type of the uh variable it needs to print unlike the classical C right where if your uh object is of type of integer you have to put D in here if you pass something else in here it's going to be completely [ __ ] broken you don't have to put any types in here guess why because it uses reflection right so it can in refer these types for you right and this is one of the conveniences that you can actually bring in if you just add a little bit of a runtime cost right uh so you just store the types at runtime and because of that since you know the types at runtime you don't need to ask the programmer to provide the type right so we can just grab that type um to be fair this is not ideal solution in Ideal World because the types know when the types are all known a part of runtime quite often the types of are known at compile time right so I think in the ideal World print like formatted print uh functions should actually always use compile time type uh if possible right so compile time tab if possible uh but we're even not in Ideal World we are using cello in C so this is this is far from the ideal World anyway so it is what it is and it isn't what it isn't can it Implement a jit for this dude do do you know what is jit do you know what is jit it's a just in time compilation the program is already compiled it's already compiled wild we can say it's ahead of time compilation anyways uh so yeah okay so we got to thing I wonder if okay this is a very interesting thing can I now also print the array so the the way you print a thing you just do it like that right so array of integers uh and then I can just do something like this uh and then I say items then I say items okay so if I do something like that that's some sexy output except zero xit what the [ __ ] is that bro this looks like a major printing formatting [ __ ] up like I can I can even already see how that mistake was made it's it's the hex it's the hex value this is so [ __ ] cool but brav what the [ __ ] is that like I mean I I wonder how did it come to be so how can we even search for this kind of stuff um I suppose just a second um just a second I want to actually find in source code where that [ __ ] happen so probably the way it works the formatting thing is this right so we're going to be ignoring this stuff at this so we ignoring this stuff and also ignoring this stuff right so I want to try to grab this kind of stuff but that means I'll have to escape these things uh let me find okay uh unexpected end of file so it's probably because of these things um what is that BR what is that BR I don't fully understand what you don't like in here maybe I should just like not use this uh thing okay so maybe this is because of [Music] that uhhuh uh-huh uh-huh uh found it found I think this is what it is uh percent p in print already adds a zerx so this is one of the things that happens actually so that's the bug essentially uh so let's do let's actually go into the main C into the original main C and uh if I just include STD iio I don't know if I need to include STD iio but anyway so if I do just p and I just take a you know void star like you know 69 for 20 or whatever maybe in zero x uh right and I try to maybe be main uh yeah so on top of that um we can say percent P already adds 0x uh something like that there we go as you can see it already adds ZX you don't have to do that but what's funny is that is it consistent across different compilers does anybody know is the format of percent piece standardized in any way is it standardized in any way maybe the reason they did that uh is because maybe it's not standardized maybe it's just like whatever um so I don't know I'll try to check check the standard okay so one of the things we can do we can try to just like remove this entire thing um on top of that we can find all of the places where maybe this thing is done like that let's actually find all of the places which probably do something like this because it looks like it's a common mistake it could be actually a common mistake uh so let's actually grab our n uh specifically for this kind of stuff in how many places okay so there's quite a few places that do that actually so it is a very common not sure if it's a mistake per se but it's uh percent p is implementation defined okay okay okay okay so it is in fact implementation defined so one of the solution to get rid of that weirdness would be something like having a macro right so some sort of a macro that by default like let's call it like uh percent p PP which stands for percent P right and essentially you would just do uh you know z x% p and if uh def GCC right you actually Define PP uh like this uh like this and if and basically you have like a chain of uh if depths for different compilers right since it's like you implementation defined and then how you use it you just use it like this like printf uh like PP some stuff like uh you know uh something like this at uh blah blah blah new line and that's how you use that you just basically embed it in here uh since um C allows you to have multicomponent string literals it is going to work right so in C uh let me actually use simc mode because it's not particularly visible right so in C if you have something like that this is considered a single string literal this is a single string literal right so if you have just like a sequence of the separated chunks of string literals this entire expression a sequence of tokens is single string literal because of that tricks like that work right so essentially you can Define like a custom thing that is sort of abstracted away and you can easily inject it in here because that will consider this entire thing a single Str leral right so this is how it's usually done in C um right and this is the way I would solve this problem right so essentially by default it is 0 x% P then I would look at different kinds of compilers right check different kinds of common compilers and see for which compiler I need to add this zerx uh and I would just like do it like that so this is how we do that but I mean so the project is already established like that it's not that big of a deal honestly right it's it's kind of funny right so when you compile this thing with a compiler that does this zerox automatically but ultimately it's not that big of a deal um it's just a little bit funny just a little bit funny but again this is not particularly serious Library it's a library for recreation programming you can add a check to autocom Dos just like there's no uh there is no problem in computer science that could not be solved with just yet another layer of obstruction right except too many layers of obstructions um so yeah anyways so that's pretty cool it does a lot of introspection it does a lot of Reflections I really [ __ ] like that I really [ __ ] like that uh so uh yesu yesu yes let's take a look at some other things it does um okay so you have hash tables chat they edit hash tables to see that sounds like a banger title for YouTube holy [ __ ] YouTube people would click the [ __ ] out of the title I know that because I post there all the time so yeah the edit hasht to see finally everyone been waiting for this update holy [ __ ] she is actually usable [Music] language okay that's pretty cool um so yeah you can this is rather convenient honestly all right so maybe maybe I should start using that bra brovsky brovsky what the [ __ ] brovsky uh so apple banana pear all right so what is what the [ __ ] is I what the [ __ ] is that huh it's sort of like a ah ah I think I know it wraps values into vs right because cello operates with Wars but integers and string literals like a in the vanilla sea they're not bars so you need to rub you need box them I remember they were talking about boxing I do [ __ ] remember they were talking about boxing I remember that um so let me see so if I go to learn yeah so there's a boxing yeah unique poter so oh no boxing is a separate a type is another wer round C pointer with one additional Behavior as compared to ref when a box object is deleted it also call Dell on the object it points they have destructors holy [ __ ] [ __ ] but I mean it's also has garbage col collector so that means it also calls its Destructor when it's garbage collected this is a truly a JavaScript of C like what the [ __ ] they literally implemented JavaScript inside of CE what the hell wait a second the author of this Library uh wrote a book actually they are a book author they're boook like who are you uh Daniel Holden I don't know who that is you may know me from a book I wrote and the book they wrote is build your own lisp no wonder it feels like JavaScript so yeah that's that's so [ __ ] cool man this is such a cool project I love it it's like it's quirky it's weird and it's self-aware of that it's so [ __ ] cool I love it you you read that book so some some people actually read this book uh that's so cool uh the clickbait possibilities for the stream are in exactly so thank you thank you so much Daniel for for providing so many clickbait possibilities damn this is a cool Library man what the [ __ ] what the [ __ ] so we have hashtable so we can try to do some maybe you know word frequency analysis my my favorite you know you know exercise when it comes to using hash tables and stuff like that is when I just like take the in the content of the file split it by the tokens AKA words and just like count how many times a certain word like you know occurs in in the text this is something that we can do um right so using these hash tables and also the uh the capabilities of this library right because it's s convenient actually it's rather convenient so these things they take the vanilla C values and they rub them into vars right because by by themselves they're not going to be usable right so we can even actually test that so if I try to do something like this it compiles but then I simply replace that with just a van string and it will probably crash it didn't crash itself but if I try to do something like that yeah so I think I know why it didn't crash with a string because a string is a point to char this is a pointer to char VAR is a void star in C yeah yeah so uh you already know right so it's the chart to void actually like allows you to do this kind of stuff so because in see even if you enable all of the warnings and stuff like that uh C allows you to convert any specific pointer to void star and void star to any specific point the only thing that is strictly forbidden is any specific pointer to any other specific pointer so you have to go through this hoop of first generic pointer and from generic pointer back right uh so be because the conversion from specific pointer to generic one and from generic to specific one is to godamn common in see that it's kind of pointless to prevent you do that uh right but if you're trying to convert specific to another specific that's already kind of sus uh right so yeah that's already kind of sus and this is probably not what you want to do unless you know what you're doing so anyway that that's why it kind of worked uh like with with strings but it didn't work uh with integers so this entire thing kind of wraps specific values into uh into vars and I wonder how exactly does it do that es especially with the integers right so let's actually take a look at that actually take a look at that so we're going to do Define uh okay it uses that goddamn stack allocation [ __ ] that allocates arrays of btes on a stack so to to to just pass a goddamn integer literal to a hash table it needs to allocate an array of bytes on a stack copy the representation of that integer to that array and give the point to that thing to the H I'm I just like I'm outraged and amazed at the same time holy blow yeah exactly holy blow this again this is outrageous and amazing at the same time I [ __ ] love it it's just like I'm [ __ ] fing so the just like yeah compile will optimize all of that out of course of course the compiler will just optimize all that out of course this like yeah this library is blur it is really [ __ ] blur I love it uh so damn bro damn so and if I try to print this entire thing obviously right so something like this uh so we have t uh all right so this is prices and what do we have in here so boom and it prints everything in here with the hexi of the values the hexi the sexiest uh all right not just hex numbers sex numbers oh funny uh what else do we have in here so you can have arrays obviously that's pretty cool so you just Define an array and then you can just have values in here uh so then iterate over indices using the range you can even have slices def find a normal C structure make it compatible with cello yeah it turns it into a VAR right VAR is not really V oh my this is really [ __ ] JavaScript so JavaScript damn so in then wait this is kind of bizarre just a second this is sus how the [ __ ] does it do that uh how the [ __ ] does it do that that broke the selection is broken completely but anyway um so that I defined the struct and then it correctly initializes the fields of the struct how does it wait wait wait the freak don't freaking tell me oh my I I think I think I know how it does that and I'm disgusted and amazed at the same time I I think I [ __ ] knows how to do that so essentially you have this um right so this thing right you have type and you have you know VA args yeah it it has v yeah people already figured out it's it's VA ARS [ __ ] right so you you basically do something like V ARs and maybe since you know the type yeah since you know the type you can oh okay so that's not that big of a deal honestly right if since you you have the type and it just uses the type and then it takes the bite representation of that type right so of that sort of struct literal right it probably just m copies it right it just m copies it like that or something okay fair fair it's not that bad it's not that bad uh right it's not that bad and then we just like create add on a stack or I I I think I'm getting a hang of it right so the convention kind of makes sense it's really intuitive so um dollar just means that it's on this stack so it does this all the entire like bite on the stack thingy uh right it's it's very consistent like you can intuitive understand how it all works so you can do you can do comparisons you can huh wait but but how simp works then H so less or equal does it compare so you can do hashes hashes I can understand how it does hash it just hashes the bites that's fine but how does it do CMP CMP is sus CMP is truly sus so how does it do that H all right so let's take a look I'm really curious about that so Define CMP okay CMP is not uh that okay so there's a struct CMP all right uhhuh self and other object okay let's take a look at the implementation of this thing um all right so we taken instance of CMP it must Implement CMP inter you can yeah you can have interfaces and [ __ ] but we never actually said that the pointer has a comparable interface we never actually said that we actually never said that like how do you even do that then this is sus I I don't believe that this is going to work chat I think they're debating us just a second I think something broke this is not copiable by the way they made it impossible to copy does anybody understand how the [ __ ] this works like I mean it falls back to mcmp apparently ah okay uh that's very interesting uh I wonder if I can just um um um I don't know how to copy maybe it's done intentionally so you don't copypaste code because copy pasting is bad uh but if I used like a Apple products I maybe I would have just screenshotted this entire thing and just like did O OCR and like copy pasted really funny um but anyway so it also falls back back to M CMP I don't really see oh yeah okay so if if C and CMP available just returns that otherwise size of the type uh type of and type of that and just m CMP okay so just that's M CMP can compare type to type I'm I'm going see thank you thank you so much all right okay that's pretty cool that's pretty cool that's pretty cool so what what are based features do we have right so we explored the examples let's take a look at the documentation right so uh this is the boxes that we have this is arrays exceptions files all right so we can actually read files that's pretty cool um all right so here we write in file um how do we read from a file so [ __ ] off and I'm pretty sure it is implemented in the most blurst way possible this is this is such a cool library right because it implements all of this like a conventional High language thing but it does so in the most most cursed way possible I [ __ ] love it how does it do that like it's well I mean it just like probably wraps around some [ __ ] and just like calls this and calls it then whatever since you have like a the whole dynamic object system you can just do that right so because files probably have aociated distructor with them right and it's a dynamic generic object so and since you're passing it in here you can just like kind of sort of schedule on the level of preprocessor to call the destructor of file at the end of this entire thing so it's it's not that big of a deal uh right so you can Implement that if you have this like a very much Dynamic generic system it's not that hard to do um right it's not that hard to do can you just read the entirety of the file somehow right so new file here we are just scanning and we can just like you know read some stuff from it which is cool so what what do we have in terms of strings I'm interested so okay string object maybe can you can I manipulate the strings easily so definition Str struct value okay that's cool um so you can do usage definition implements um yeah so for for example can I split this entire thing uh split I should be able to split this string but it's kind of difficult to see so derives the loog cast copy size okay so this is the interfaces that it derives implements a sign C string so it's singable format get uh concat you can concat this entire thing so what about implementation of format um so I let see so scan resize let me see if I can manipulate it easily right specifically I want to be able to split but if I just contr F split uh I don't see anything maybe it has something to do with slices right so partial um iterable come on my Mouse is dead so if I do split we don't have anything um all right so zip multiple ah it's it's probably like ziping the uh you know the containers and stuff like that so balanced binary tree damn to and apply function apply so you can do functional programming with this thing right so we can do functional programming [ __ ] off so you you can have lambdas it's not really Lambda right so just like so you take X which is a tuple of one to three you map them with convert to int function and just then [ __ ] off ah okay just just okay I want I want to see if it works actually I want to [ __ ] see if this [ __ ] Works um okay so I actually copy pasted it in the word so for got uh V uh right so here we can Define this thing like so uh so let's just return zero and let's maybe reformat the entire thing uh right again so we're just iterating one two three strings specifically uh all right and if I try to run it it freaking works so but it's just show right show just prints this entire thing but we can actually print it properly more or less uh right so with n and just y um right so we can do some yeah so it prints them separately so to speak and how does it convert string to an integer right it creates a new integer object and there is a method look from that's a really bizarre name what's what's up with that name it doesn't luk position how does luk from what the [ __ ] is Luke from like it doesn't even explain what the [ __ ] it is uh so it's a function ah it's a method of interface show so there is a interface show uh so there's different interfaces in here uh and I suppose I can actually find so here's the show uh the show class is used to convert object to and from strings okay okay okay so and the methods are like yeah there we go this is how it works so essentially show is a way to convert between the value and a string and string of Val basically serialize and deserialize in some way right and looking is converting from a string to that type D Luke is a very interesting name for person yeah exactly it's a very interesting because because show because [ __ ] show damn that makes so much [ __ ] sense because you show and then you look is just the [ __ ] this is fun I love it Luke is the opposite of show it's like in the opposite end right so because somebody shows to somebody who looks anyway I'm like I don't know so and all of the functionality I suppose it's hidden Within These interfaces right so we want to do something with this is like a proper object oriented stuff but in C [Music] oh boy oh boy oh boy where is my soy H where is my soy so this is how we convert that um yeah and it needs to be allocated and as you can see we're allocating it on a hep though look at that we are allocating it on the Heap uh because we want to be able to return it otherwise we won't be able to return that and then we're just mapping it and we're just iterating it I wonder okay so what if I just print this I think as a map right what does map even return does it return a new array or does it return some sort of a like iterator that calls convert to in lazily that's an interesting question actually so let's actually see what will happen it's a it's a object that actually calls this sh [ __ ] you know lazily we can even check it out right so we can do something like uh right convert convert to int was called uh like so so this is a new line yeah convert to in was never called it was never called It's a lazy iterator just like in freaking python so and if you want to do something right so you first have to do something like you know I want to call it access right so like in um in in h right so because hkers like to call a bunch of access access right so because X is a single element several X's is X's that's why they do that because it makes sense right so then we can say X in this thing and then we're printing AIS just like that right and if we do that it doesn't even [ __ ] compile M doesn't even fuing compile what okay so it's something that is s uh for each do oh it's not for each God damn it okay yeah only then it actually call that so you can have lazy evaluation in C I wonder if you can have infinite data structures like in Hill which are computed as you iterate through them can you have something like that so we need to take a look at the I think map is a interface that does that right apply app function to iterate so map type is an interal that applies some colable okay I guess I guess you can do that yeah through map maybe you can do that so you have current you have funk you have eer um so maybe there is a yeah so there is eer e yeah class implements by types which can be looped over this allows them to be used in conjunction with the for each Macro as well as various other components of cello to signal that an iteration has finished an iteration should return a a cello object terminal yeah that's actually very interesting okay so if I want to so there's some examples but what if I want to have my custom implementation not none yeah not none actually so yeah I feel like you can have infinite data structures like I mean as soon as you go into this generic Dynamic domain you can do pretty much anything at the cost of runtime right so it's all at the cost of runtime as usual all right so I think I want to uh make a small break and make a c of te and after that uh we're going to try to implement some something in this uh in this Library so one of the ideas that I had I wanted to try to implement the class classical example that I usually do is just like analyze the frequency of words in in a text file right so we can try to load up the contents of the text file into the memory the entirety of the file uh split it by tokens and just use a hashmap to analyze the frequency and I want to see how convenient it is to use only the cello uh functionality to do that so read file the contents of the file only using whatever cell provides split and uh parse the text only using using the functionality cell provides and of course use its hash table and we can just see how how well it works another thing to use cell 4 would be maybe a simple game right because it's it's very much Dynamic oish right so it's very easy to create like entities that Implement like a common interfaces and stuff like that you know like this kind of like simple stuff that works for simple games right not not in not entity component system but you know op kind of entity stuff could be also interesting but I want to do the frequency analysis I think frequency analysis would be dope uh all right so let's make some break and all right we are back so let's actually write some U you know word frequency analysis right how do we read [ __ ] from a file that's the real [Music] question oh I think it's it's it's file actually uh yeah there we go um so it's not even a file so file that's bizarre ah oh so URL is actually sensitive to to you know to the case right I couldn't actually find capitalized f it redirected me to some weird place uh okay but I mean URL standard actually says that it is you know case sensitive so it's understandable um all right so have file and I suppose I suppose what I want to do maybe I want to accept uh you know the command line arguments file through a command line argument uh I wonder how I can do that so here I have obviously like args and [ __ ] like that but I wonder if there's any way to work with command line arguments in cellow does anybody know um right does anybody know so args I'm I'm pretty sure there's nothing um so at least maybe it would make sense to turn that into an array right to turn that into an array uh so taking these arguments and turning them into an array but I feel like it's going to be kind of difficult um right because like how do I even [ __ ] do that like I don't think I can easily do that um hm has anybody actually solved that problem yet in GitHub so if I have already an array How can I convert that so there's some examples in here uhuh cello World okay so Cella world. C okay so this is just a hello world nothing interesting um iteration so what's up with iteration ah it's all the uh examples from the front page um so I wonder if they ever actually discussed anything like that like command line arguments command line arguments uh nobody ever discussed that apparently right so maybe what people do they just use a vanilla um vanilla C approach right so the use of vanula SE approach we can try to do vanilla C approach if we just simply create an array of floats something like ARS uh new so this is yeah we are allocating the array on the on the Hep so this is an array of strings and this is uh this is compilable so this is totally compilable maybe one of the thing we can do we can just iterate through each individual argument right so Arc C uh plus plus RC C and just push each individual argument into to the arcs but the question is how do you do that how do you even do that uh so do you have something like oh my God it we have interface push all right so what if I do something like args uh push right so there is a method like literally push you can do push args but then if I want to do ARG VI right so if I want to do AR VI how do I even freaking do that so obviously this may not work I might try to do something like this right so because I'm taking so there's not that much difference between string literals and yeah so I may say Okay allocate that on this stack so I think that's fine I think that will work and after that I will say okay uh just print this whole thing just print the arcs and we can see what we can have in here okay [Music] uhhuh I think I [ __ ] up something ahuh you didn't see [ __ ] okay you didn't see [ __ ] uh all right so we got an array and it's just main okay so I think I forgot to put a new line in here right so I forgot to put yeah there we go so here is an array and uh we can just do full bar Buzz all right so look at that plus plus J moment exactly so we can like as I already said my challenge is to use as much of cello functionality as possible because of that I feel like I must par command line arguments using cell mechanism as well uh right so maybe maybe we can do something like this so this is going to be args as array right and in here we're going to just like accept the whole think like that and we're going to return VAR uh so and essentially I'm going to be just doing it like this so arcs as array Arc C arc V right so is it going to work and it's SE fed because I forgot to return ARS understandable never and now it works uh the cool thing in here actually believe it or not is being able to for each this entire [ __ ] uh so man this is so cool actually [ __ ] hate how cool it is actually even though it's kind of like additional bloat but it's [ __ ] cool like the fact that you can just do this kind of thing um yeah that's that's that's dope that's [ __ ] dope I like that uh so AR is an array but here's an interesting thing so you can okay you can do p push at how do I pop things right so I pop them from the um at a given key zero okay so we can try the following thing so here's my args so this is my arcs and then I just do while so there should be something like a len args maybe even empty while this entire thing not empty I don't know if empty exist or not what I'm going to be doing is essentially uh pop at so um args I Z pop Arc Z and I just like print this enti thing I might as well even in line the whole thing so do we have in the array any interesting methods what kind of methods so array is a type data structure uhuh so derives size it has a size so interface I really like how easy it is to explore the documentation as soon as you understand the interface mechanism of this library right so each type Implement a bunch of interfaces so you probably yeah so this is kind of convenient so we have sides in here um all right so so that means we can just just do something like size size is greater than zero so while we have that uh we're just doing this kind of thing so this is ARG and let's go and it doesn't even compile because uh it really doesn't like that uh so where is the pop uhuh so pop at MM pop the object from uh object self at a given key hm so maybe that means I have to do something like this is that what it wants maybe that's what it wants pop add uh void values ah oh I see yeah I see I see so that means first thing you have to do you have to get a value out of that so there is a get so you get args at zero and then you okay I see so it's two separate things in here uhhuh and yeah we've got some weird stuff in here um and what's funny is that it didn't we went out of this stuff that means we the size was not modified the size was not let's take a look at the size uh so this is going to be something like this so percent size size of AR uhhuh so what you don't like I don't understand H am I it's probably not size it's probably Len but I mean it is size just just look look at that so it has size right size yeah so here it is it's it size ah yeah yeah yeah yeah you're right you're right okay so this is the pitfalls and what was the quirkiness right pitfalls and weirdness and quirkiness uh all right so when I do get yeah so it it returns you literally size T it doesn't return you the the VAR object let return you the VAR object size is weird so sizes where size is not what I would expect in here so it return returns something bizarre size is size of ah [ __ ] I see I see all right so what do we have in here so how do we do the length of the objects then um oh it's just L okay all right right right so so that means we have to do something like this um right okay so now it works now it works but do we have to still wrap it into the object yeah so this is the the problems that yeah you can't do that because it's not compatible but yeah so and that's how we can uh operate with this entire thing that's is very cool all right so the reason why I want you to do this kind of stuff is that now it's relatively easy to just have a program name right so where I simply get um you know args I Z right and then I pop at args I Z I don't really like the fact that it's um two operations in here I really don't like the fact that it's two operation so you know that I like this shift operation that accepts an array uh right and it just like pops out from the left and returns you that value while modifying the original object I really like this kind of thing so basically a combination of get zero and pop at zero so we can try to introduce that so this is going to be shift and this is basically the axis which is also a bar and we can combine this enti stuff together so this is the X which is get uh AIS at zero uh right then we do pop at AIS at zero and then we return the X so that's what I want in here uh right and so that's what will allow me to do shift args there you go and and then I can do print uh program name uh which is something like that program uh name so it would be kind of nice to have like a cello highlighting some sort of a cello highlighting I wonder if there is a package for that so let's actually see there should be something cello mode no there's no cello mode look at that H that is kind of weird Mya uh so orange duck um I I'm surprised nobody done that it loads too too long anyway uh maybe I just have to wait a little bit no there's nothing you can switch to JS mod you're genius honestly damn GS mode totally works oh my god get it works better than I expected what the [ __ ] all right we're doing JS now I guess anyways it even highlights in I didn't expect that like what the [ __ ] uh why does it highlight in so now it's it's perfect right so if I try to do something this now it works so the the reason why I want you to do it like that so is that now Len if Len of ARS is actually lesser equal than zero right so we can always do something like uh error uh no input is provided all right so and on top of that we can even do something like print usage uh so this is basically the program and just input so this is the new line uh this is the new line and this is the program name that we got and here we're going to just return one uh yep so uh we provided some input but yeah segmentation fold nice the [ __ ] is that why did it Su fed why did it SE F I didn't expect that honestly uh let's let's try to find out where exactly we can actually compile maybe what if I enable all of the warnings and all of the extra stuff right so maybe we'll be able to catch something no we we didn't really catch anything useful but now at least we are compiling with debug information so that means we can use a debugger the tool the scary tool that a Twitter Tech absolutely badshit scared about they would never [ __ ] touch this tool because it's too [ __ ] scary for them uh all right so let's actually do ggb uh Main and we can just try to run this entire thing right and now we know exactly where it failed uh right away so it's it's on the printing actually so uh let me see so something something like that 24 uh so it's here right let's bizarre honestly uh so if I don't print this program name thingy so what is going to happen uh so it's going to be fine right so we extracted the program name but it's not printable for some reason should allocate it in a hip maybe it should allocate sh on the hip so we get this yeah okay so XIs so as in Ray so this is allocated on the hip maybe it has something to do with maybe it allocates these things on the yeah I this is what I thought about actually this is what I thought about maybe we have to do something like this let's give it a try ahuh type of has magic no h new string return new string return we already allocating array of strings on the Heap in here right and just do it like that [Music] um but I don't think it it's I feel like it it must be in here something it must be in here yeah yeah it has nothing to do with this kind anything has nothing to do with this like I'm pretty sure it's somewhere here right it's it's not even about shift I can like in uh in line the shift you're leading me to a wrong place chat stop please stop uh right I can even in line and I'm pretty sure it will still complain because it has nothing to do with shift right I'm going to even comment it out and I'm pretty sure it is going to uh SE fult so what is it saying that's args uh and this is another ARS it's not about shift it's not yeah right you're leading me to a wrong place okay so uh I feel like what it does it copies the string to the stack in here and that's not what we want to do in here actually this is not what we want to do here so let's actually see uh all right so what do we do in here so Define uh new right so we Define that and then we Define bar args so there's also new row and new root I have no idea what they mean but um it's kind of hard to tell so new WID as well well I mean it's just like redirects to here okay so maybe what I have to do is a new string this is what I feel needs to be done in here this is what I feel needs to be done in here so it has to be copied like that uh but it doesn't like it as a bat magic number uh wasn't allocated by shello mhm um so maybe yeah how can I even duplicate that like I want to allocate a string uh arv needs a r ahuh but it does it need o does it really need a rra no this is nasty this is [ __ ] nasty estimate so [ __ ] nasty how do like I mean this is allocating on a stack but we're trying to allocate it on a on a hep already so this is not how it works right so you're leading to a wrong place okay chat I'm going to just put the sa mode soon if you're going to continue doing that um all right so this is allocating okay so I need to have a bunch of strings examples for Strings there's not that many examples for a string uh right all right so you you can ah so they do actually that right with s where you just have it allocated on this stack but then you do this additional yeah this this is kind of weird but I suppose it works I suppose it works okay so maybe that's the thing but it doesn't make sense it actually doesn't make sense um uh and here yeah it still so FS um so we can try to maybe maybe it SS for a different reason now uh BT let's run it all right BT uh yeah it still doesn't like that uh still doesn't like that um so that is bizarre I really don't know what's up with that why does it not like what I'm doing in here so this is on a hip I'm just sit rating through this entire thing I'm yeah then on this hip and I just pushing you need to wrap on the print also I do not believe that because it's already a VAR it's already a VAR I shouldn't be a I shouldn't print it printing it wait a second what when I do get um so where is the get operation we may take a look at this so I'm surprised I'm wasting time on this yeah it's a VAR like I should not do in R for for for VAR it's already VAR [Music] um so like why am I wasting time on that this is unacceptable honestly I don't like that I don't like the fact that I'm wasting time on this uh like I should not be doing that yeah well I mean at least it works but it's a garbage right so that means I should not do that uh means I shouldn't do that what's like how do you do that like I'm obviously doing something wrong in here I'm obviously doing something wrong okay so copy copy copy that's a good one um somebody said smart things finally chat saying smart things so there's a copy what's what's up with copy copy class can be used to override the behavior of an object when a copy is made of it copy object okay okay so uh can I just say copy so and yeah so we're just copying this entire thing and copying actually the copy is registered with the garbage collector as if it had been constructed with a new perfect perfect perfect perfect perfect perfect perfect this is garbage brother I'm disappointed this is garbage bro okay I can I can get it sure but then I can I get wait don't [ __ ] tell me it probably removes it from I I think I know what the [ __ ] is going on chat this is me right now yes um I think it [ __ ] nukes the object when you pop at I think it's literally what it does it just like nukes it so that mean oh my God so that means what I have to do I have to do copy not here I have to do copy here bro yeah like copy needs to be done here because feel like pop at like literally nukes the object out of the hip garbage collected my ass that's everything I have to say about this garbage collected language how is that garbage collect it's it's not really GC then yeah exactly like what the [ __ ] is this and it's also well I mean it exit it abnormally and stuff like that so that means I don't have to copy in here I feel like I feel like I don't have to copy yeah so I don't have to copy in here so copy in here is not needed um so yeah so what we have to do we have to do copy in here and only then we'll be able to do shift ARs and that will work properly optional GC so okay yeah so I suppose I can disable it maybe um so pop goes back to CPU Stacks so pop would move the pointer after the copy that is why it removes the element but I still hold the pointer to to the thing after I popped it don't I that's that's really bizarre so that means things wait are you telling me things on the stack are not considered the root of GC are you telling me things on the stack are not considered the root of GC I mean it's a it's a funny little Library um so what do we let's not be too harsh to it right it's fine that's fine anyways uh so yeah here what I want to do I want to do file path right so we figured that out everything's fine chat everything's fine right so shift AR and here we can just do something like a file P we'll eventually get a hang of with right so we just have to burn ourselves several times on different pitfalls right so they warned us about pitfalls here they are here are the pitfalls um yeah so no input is provided what we can do we can provide our own source code uh there we go so and here it is file path we managed to do everything successfully oh no [ __ ] way just a second um all right so cell H pop at pop at uh can I hu maybe here how can I even do that I don't freaking know so where is the method pop at I probably have to do something like grap or M pop at uh yep what the hell is that push definition I don't see it honestly but but any it's it's an array C okay po oh so it's this one okay yeah it distracts the item I see I see it now what a shame brav why would it distract it though so that's kind of doesn't make any sense I wouldn't expect it like yeah you're in a garbage collected environment like just let let the com the garbage collector do its thing so as it's if it's yeah it's own the array so combining these two kind of models of management together doesn't make any sense right so you either do the ownership model thing right or you do garbage collector where everything is just like allowed and you just like let the garbage collector do its thing like you you can't combine them that creates a really huge dissonance right so that results in this kind of situation that results in wasted time so both both is not great yeah I agree with that but maybe there is a like a reason behind that but I mean we just demonstrated that it's kind of bad right by by wasting it like a little bit of a time we demonstrated that this kind of approach is kind of bad so you probably don't want to combine these kind of things maybe you want AR Ray of ref for strengths maybe so I'm not really aware of the concept of ref yet so maybe I need to learn that first I kind of vaguely remember the con of the refence cello uh so anyways anyways anyways anyway so we have a file path how can we read so I have [ __ ] in here opened up why do you have cck anyways so let's put away our cxs and open files uh it opened the wrong thing again okay so file um oh you you even provide the the type thing in here which is kind of funny so so for writing but what about reading though okay so here's the reading I can open file for reading I can have some sort of a buffer into which I'm reading and yeah that's really interesting so the problem here is that I can't really see the methods of file right does does the file have any methods that I could have used uh all right so I don't well I mean we have these kind of things dog format okay so you have stream okay so it has this classical s sick s sty s FL all right so maybe we can Implement read the enti of the file through this thing that's one of the things we can do right so we can essentially figure out the size of the file um yeah it's it's basically like a post thingy yeah a PO thingy so then we can uh resize so you can even resize the strings right so we can allocate the string and just return it like that so what I want to have what I want to have is a read entire file that's what I want to I think in 2024 like every language should just have this function like reading entirety of the file this entire model of streaming file in 2024 with modern computers I feel like it's kind of outdated isn't it right so we have so much memory and we don't really we rarely work with files that don't fit into that memory right so and what we end up doing we just end up like reading the entirety of the file into the memory sometimes you may have uh 30 gab xim well I mean yeah sometimes you may have huge files but I wonder can you just memory map that file because I know that in Linux when you memory map a file it's not red yeah just map it so Chris says that you you can just map it and I believe Chris because he he probably worked with this kind of stuff so when you AAP a file it's not read into the memory immediately right so it's read as you trying to access the pages where the file is mapped right when and the pages are not actually mapped so when you try to access them uh you know some sort of interrupt is issued right and then konel looks at the interrupt and says oh let's just map this page right and then continues your program execution from where you were trying to access that page and you kind kind of slowly reading that file but but the question is does operating system unmap some of the pages of the file over time if they were not accessed for too long is that something that operating system does all right so that means if I need if it does so it's kind of like a combining best of the both world of reading the entirety of the file into my memory and also streaming API where you can just memory map a huge file and just slowly process that file from left to right and that will basically be in terms of like accessing the actual file as the streaming API but in terms of convenience is going to be like reading the entirety of the thing into the memory did I understand that correctly or I'm just saying [ __ ] because I'm not sure [Music] uh so yes and you have uh hints to tell the that you will ah [ __ ] you know what's funny uh the I have a dead row of pixels on my monitor and uh it actually covered this entire row so I couldn't actually read it on my second monitor this is by the way I'm buying the the new laptop because the the pixels on this monitor are literally dying I have like patches of dead pixels in here this monitor is pretty much unusable uh right you can H to tell the OS that you will access the file streamly nice that's very interesting just like uh usual swap mechanism it can just unmap them as necessary this is actually kind of cool so because of that it just like doesn't make any sense to not have an API read entire file I think this entire streaming API is just like a leftovers from all the days when it makes sense but it doesn't make any sense anymore but we kind of stuck with it because a lot of uh code depends on that stuff it's kind of funny interesting you didn't switch to I didn't get my new lap well I mean I do have a new laptop but it's a it's a backup week laptop and I'm not sure if I can stream from it so uh right so it's a it's a laptop specifically in case this one dies so I don't lose a computer on which I can do things like send emails and just access my accounts and stuff like that so it's literally like a just emergency laptop it's super cheap uh it's like 300 bucks right but I mean it's not that cheap like I could have bought fisting forget everything I said but I mean still it's just like my emergency like a backup laptop um so read entire file so uh file path file path going to read that um so what we're going to be [Music] doing but can I actually do that on this stack and will that mean that when we well I mean I can just do this right so with and let's go so F in new file so this is the file path and I'm going to be reading it in binary dang so then I suppose I'm allocating the result maybe I'm going to call for the content and that's the thing I'm going to be actually returning uh right so I'm returning this entire thing uh and all that stuff doesn't really matter that much I think uh so this is the string so I want to S this uh thingy so uh this is the file and position and origin but the origin is it the same as how do you use that because if you take a look at F6 right this one is not origin it's a wz it's wz but what the [ __ ] is that [ __ ] s sick origin okay so let's go into the source code of cello and maybe just literally grab as SI and hope that there are some examples of how to use this thing uh right do you have any examples on how to use this shet not a single example all right so there are some methods uh so maybe I could do something like this so there's a method stream sick how what's what's the name of the actual thing in here so if I do method uh you def finding a method uhuh offset of and you're just like looking for this thing uh so stream stream shallow uhhuh so seek to the position posst from some origin in the Stream I'm I'm just trying to figure out the size of the file but there's not a single example on how to do that one thing we can do maybe if I if I manage to find the actual implementation of s because I haven't learned how to search for this for methods where is the actual method implementation right it's kind of weird and quirky and stuff like then so just to Seck uh so there's a process Seck uh so there's a yeah okay so it's called file sck okay it's file sck and how do we even do that oh we just it just pushes it to FS which is a POS okay but it's not the origin it's a w and when is basically allows you to do things like bro do you even know how FC works and it's question to the creator of this thing uh so s and right so it's not a specific orig like it's a it's a numeration which gives the meaning to the offset depending on this enumeration the meaning of this variable is just different that's what it is like so and the only reason I can understand how to use this function is only looking at the implementation and just confirming okay so you just using posix right so it's not really origin it's they rename the param name yeah it's just like anyway so fi we've got fi um so we got to the to the end of this entire stuff all right so and then we do Estel which gives us the size of the whole thing so Estel of F and so that means I can resize the content to size right so I'm resizing the content to size so that after after that I can just read it so but that means I have to set like this right so as you can see depending on this enumeration right so zero just means a different thing so it's a zero from the end and this is zero from the beginning essentially right so um yeah that's what it is so we're reciting the content and how do we read the whole thing um so okay so there should be something in this stream read so you can okay okay so we just do s read uh it's a f and this is the output and it's not even a string bra how do I read into a [ __ ] string bro okay there's some [ __ ] like scan from and stuff okay so where is it coming from uh scan from scam from I don't know where it's coming from honestly so because it's not defined anywhere in here so it's kind of hard to tell uh scan from so there's a scan can you just like is there any read so there's a stream s read what I want is just a read and bytes into a string object how do they do that can cougle no Hogle can help you if you have types we have types uh so there's a C string Okay C no there's well wait aha all right so that that's a good idea okay okay so let's actually take a look at the c c like interface like string interface that's what I want to say uhhuh so it has a C string mhm Returns the object representing uh should be overwritten by types which represent it so and so I suppose C string doesn't do any copies and just Returns the point to the buffer internally um so you should have to manually n terminate problem Maybe so let's take a look at how this thing is implemented yeah thank you thank you so much by the way Chris I think I need to give you VIP uh and just a second go you VIP now um so let's take a look at what it does yeah it just Returns the value okay so it's it's pretty straightforward so that really means that they have to n terminate it okay um so uh which is no I really don't need to n terminate because I'm not going to be using as a C string I'm going to be using the C string method just to get the pointer right so I don't really have to do that I think uh so cstr content and that's the size there we go so that should be it honestly uh so if I try to compile well yeah let's go find make uh okay so that seems to be working so read entire file file path and this is content uh right and then we can just print that content uh like this h i mean what I I don't know there's lots of lots to unpack in here let's put it this way there's lots lots to unpack um if the string can you just print it as a string bro like I have a string just print it as a [ __ ] string um so yeah cool but at least we managed to read uh so oh maybe it's a debug out with maybe that's a good point actually so let's actually find maybe print you know it would be kind of cool if the head itself also contain documentation about the functions like you know in case of R you know what I'm talking about rip right so in case of R you uh right so you have documentation in here just a little bit that explains how this entire thing works um I suppose this thing is created for people who primarily going to be using this documentation but I mean I quite often like to look into the source code um so it's really printing at character by character huh maybe I don't know um so formatting so I'm pretty sure there should be like a format interface right so and this is where we're going to be um looking the documentation for yeah for how this entire thing works so read and write from format strings and there's no information about that so for like how this entire format thing works so I think s will string a string okay probably um let's give it a try Okay Al so that means you need to specify the type I wonder if you can just do it like that that n it has to be can I just say is there any like a generic way to say bruh just print it as whatever type it is right if it's a string print it as a string if it's an integer print it as is there any way but not in a debug way where it escapes special characters because I don't want to be thinking about what type it is or whatever yeah it's like a dollar is like a show in h right I want to be able to say like whatever it is just just printed as whatever it is like normally and okay we going take a look at how it's implemented though so let's see so um print so print width uh print with all right so what do we have in here okay so it uses format two h two paper paints oh yeah it's like I I freaking hate these things um all right so maybe it's something like format format 2 is that how we're searching for them um yeah so what are the methods yeah so string format 2 yeah things like format to reprint f huh so it's probably just piggy bagging of of the thing yeah just using the standard print for this kind of [ __ ] all right whatever so I think I'm it doesn't really matter that much for me uh cool we managed to actually like parse command line arguments we managed to bring this entire thing and honestly things like this like representing arguments command line arguments as the array then shifting like popping from the left without killing the whole thing and reading the entire file the functionality of this function should be part of the library I feel like if the library is here to be high level C I should not be doing these kind of things but some may say that reading the entire file is just like a like a taste right it's sort of like a preferential thing but at the same time I don't think so right so because like that's what you want to do anyway in the in the 2024 when you Reon file you just want to read the entire of the file and that's it um right so I feel like the library is a little bit of oldfashioned in that regard and it is in fact old library right so I remember this Library when I was in university I graduated in 2013 how old this library is actually does anybody know so it's not really modified that often right so 3 years old um so what's the easiest way for for us to to actually find out how old it is can we just get um like a g colone the whole thing is it going to be too much for us only 300 commits so I think downloading the enti of the thing would be too much it was actually pretty easy so so I just want to see how old it is well that's looks about right honestly yeah yeah so 12 years ago it's pretty old um so yeah it does feel like a little bit old fashioned in that regard um because again I remember like if I graduated in 2013 right so minus like 12 yeah roughly that that's around the time I remember about it I think it's like when it came out Dam I'm so [ __ ] old brah bro I'm so [ __ ] old holy [ __ ] disgusting I'm also so grumpy God damn it anyways so let's Contin ah JN blow is probably looking at me and laughing uh anyways so m so we read the entire thing so the next step would be to actually split the file into like tokens right but let's actually startop with lines um so let's take a look at what we have in here um so is there any way to split things so I think the easiest way for me to find out is to maybe grab this entire thing uh like so maybe even SRC maybe even sell H mhm split there's not a single mentioning of split in the entirety of the Herer in any freaking way in any case Okay so uh let's take a look at the source code itself uh maybe it's just cold kind of differently I don't [ __ ] know uh Rest In Peace So yeah exactly split so you you telling me there's no way to split this entire thing uh we'll just end up writing all the obstructions at this point yeah exactly so uh so already sing for two and half of an hour and I think it's too much uh already so we're going to call it at that uh right so I'm going to rename this entire thing to cat right so this is basically cat uh and I'm going to say that we didn't implement the like a frequency analysis tool we implemented cat but this is not a real cat honestly because cat accepts several files it concatenates several files that's kind of the point of this entire tool um all right so for example if I do like this kind of cat where I do cat make file right so it just actually prints them sequentially so if I try to use my cat it doesn't really do that it doesn't even exist just a second I need to rebuild it uh right if I try to do it like that yeah so that's a weird some string type does not Implement Class C so yeah um anyways uh so let's actually try to maybe fix that somehow oh yeah okay okay so this probably uh what I need to do so let's rebuild this entire stuff yeah there we go so as you can see it processes only one first argument right proess only one first argument so one of the things we can try to do in here to make it like a proper cat is to just them how can weate through them we can do for each uh right so it's going to be file path in uh args right so something like that and because of that we don't even have to shift anything in here and if I try to do something like this it just worked that's how easy it is to modify your program using cello that was actually kind of cool honestly that that that was super freaking cool um so yeah so we can even do something like input like let's go files dot dot dot that's what we have in here uh no files uh the provided so we've got uh a cat program right so yeah so what's my verdict what's my verdict uh it's a pretty fun recreational programming Library which is slightly outdated which is probably because nobody really uses it right so I feel like if somebody actually sat down and try to use it in production they would notice all of these pitfalls and would try to fix them somehow maybe contribute like a reading entire file or do something like it it lacks some content you know what I'm talking about it's a very cool engine right because this entire thing forms this uh Dynamic engine right but there's not that much content within the engine itself right and the the reason why there's not that much content is because people are usually probably don't really use it that much anyway and they don't use it that much anyway because it's not really production thing it's more of a recreation programming fun project and stuff like that but overall I think it could become it has a potential of becoming kind of a useful thing right if you had like more Utilities in here it's kind of cool how quickly you just can rump up the development right so because you can write away to have like a hash table Dynamic things and it's just like just prototype things it's it's really cool to prototype things in this stuff so yeah that's basically my verdict just use JavaScript yeah these days you would just use JavaScript but I mean it's a library from 12 years ago uh so maybe 12 years ago it was kind of cool uh but at the same time I mean it's more lightweight than no GS for instance right so and it gives you a self-contain executable right how much of a self-contain is it it is pretty selfcontained look at that it only depends on lipc that's already better than Swift executables just saying that's that's already better than Swift executables so uh anyway dude and Swift doesn't even have a garbage collector [ __ ] sweet oh this thing has a garbage collector it's kind of weird garbage collector especially considering like pop at thingy which just nukes the elements after you pop them out right so but still um so yeah how about that uh so it's it's a really interesting thing it's a really interesting thing that's my verdict cello very interesting thing has a potential probably would never realize but I don't know maybe maybe maybe maybe so yesu yes yesu so thank you so much uh everyone for the subs uh let me see Ni thank you so much CH par to thank you so much DF thank you so much for twitch primee with the message sodan AER rare legendary white panger look at it look at it uh all right I guess that's it for today that was super fun uh thanks everyone who's watching me right now I really appreciate it uh thank you so much to go thank you thank you thank you uh have a good one and I see you all on the next Recreation programing session with AO AO Mr Ain love
Up Next

Cheney's Garbage Collection Algorithm Explained | Two-Finger Approach
@lecturemeivin1034
1.6K views•2021-01-31

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

Lexer Explained: From Characters to Tokens
@TsodingDaily
44.1K views•2023-02-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science
































![二次元配列 [C/C++ライブ]](https://i.ytimg.com/vi/OzX6kJ9414c/maxresdefault.jpg)






