This is even better because your labels are runtime values, so you can compute goto destinations at runtime via string interpolation or such, making it even more readable.
@swagrina Жыл бұрын
Also, you can have multiple labels with the same name, meaning the same goto call will jump to different labels depending in which block the goto is (since you do a linear search through the list), increasing maintainability.
@rogo7330 Жыл бұрын
GNU C extensions have runtime-evaluated labels. But GNU C is mostly heresy (despite being actual better version of C, not like C++), so be carefull and put ifdef __GNUC__ everywhere.
@samgiz Жыл бұрын
@@swagrina A goto call should always jump to the same instance of a label (the first one in the list) as it iterates through all blocks from the beginning, not from where it was called.
@swagrina Жыл бұрын
@@samgiz that is correct, my bad. The code was so readable that I got confused.
@johangamb Жыл бұрын
@@samgiz it would be a trivial change to make the iteration looking for next label start from the previous block being executed (and loop back to start again if not found on rest of list), in which case you really could have multiple identical labels, as the guy with headphones wrote, drastically increasing maintainability and code scanability
@pasc4le Жыл бұрын
I started to doubt it some weeks ago, but now I'm sure. His villain arc has started.
@starup4960 Жыл бұрын
Compsoy: recursion Compchad: recursion in a try catch 10/10 video
@monad_tcp Жыл бұрын
I though he was going to implement full blown call/cc , or import setjmp/longjmp , but a try/catch is essentially that, setjmp/longjmp. Use this knowledge with care.
@angelcaru9 ай бұрын
10/10 comment, i managed to segfault in Python
@angelcaru9 ай бұрын
wtf?? its not letting me reply to another comment
@mosomiliardaru Жыл бұрын
dude you've reached pure programming god tier by now
@ribosomerocker Жыл бұрын
ocaml isn't pure
@__gadonk__ Жыл бұрын
@@ribosomerocker 🤓
@ribosomerocker Жыл бұрын
@@__gadonk__ 🤓🤓🤓🤓🤓🤓🤓🤓🤓
@K5RTO Жыл бұрын
@@ribosomerocker what man has made filthy, a god makes pure
@miran248 Жыл бұрын
He got so pure he overflowed.
@anon_y_mousse Жыл бұрын
I recently installed OCaml to get some project that someone else wrote to compile so I could use it. I learned a little bit of ML like 20 years ago and knew Caml and OCaml existed, but never used them. Your video hasn't changed my mind on goto, but it has changed my mind about even getting into OCaml.
@AlgoFodder Жыл бұрын
Senior Dev strats: "Let's hallucinate like ChadGPT".
@matrixnorm667211 ай бұрын
it's over for gotocels
@fille.imgnry Жыл бұрын
Holy moly! I last watched your videos 2 years ago, and there were so much ”more” of you then. Nice! Looking good. Your content is still top notch as usual.
@R3AktoRMacedonia Жыл бұрын
Bro you look like stereotypical "Mad Scientist" on the thumbnail :)))))
@januszkszczotek8587 Жыл бұрын
19:10 You have optional arguments with default values. E.g. `let goto_block ?(name = None) ...` and call it `goto_block ~name:(Some "foo")`. Mutual recursion is possible by chaining the function definitions with `let rec foo = ... and bar = ...`.
@replikvltyoutube3727 Жыл бұрын
Tsoding has ascended into implementing goto, as recursion syntactic sugar
@monad_tcp Жыл бұрын
everything is syntactic sugar
@freesoftwareextremist8119 Жыл бұрын
What CompSoy programmers have to do to mimic a fraction of the power of Common Lisp.
@paoloose Жыл бұрын
beautiful control flow, I didn't ever wonder before if goto could be implemented in any language teachers only resort to saying that goto is garbage but you come up with this beauty of state machine
@teej_dv Жыл бұрын
great video :)
@javajava7867 Жыл бұрын
Oh , first time a project shorter than an hour, you're becoming a youtuber🎉🎉
@johetajava Жыл бұрын
I love your presentation style :'D Keep up with your divine mission!
@frechjo Жыл бұрын
I think that function used as an intermediate step, to control where to "jump" execution, is usually called a "trampoline". I've seen it used similarly to implement things like tail call optimization in languages that don't have it, like Javascript XD. Which seems like a completely different thing at first sight, but it¡s actually related. Tail calls behave as a jump or goto, and that's why they can be eliminated in the first place.
@two-spikes Жыл бұрын
best preview ever made on KZbin now implement gotos in C like they're not yet implemented
@Lars-ce4rd8 ай бұрын
Beautiful and useful. I love DRY code. Also thanks for the gist so I can just copy-paste that into my projects. Sincerely, thank you. See you in hell.
@l.piekha100 Жыл бұрын
Siberian Chud
@neshkeev Жыл бұрын
Why don't you implement a continuation monad with the call/cc function in OCaml? It will allow you implement the `goto` thing more efficiently
@ben__01 Жыл бұрын
millions must ocaml
@dulr10 Жыл бұрын
You either die a hero, or live long enough to see yourself become the villain. That was the comment I would put while watching the first part of the video. I changed my mind when the irony and meming ended. I gotta say that this is the best video you uploaded in a while in my books. The former Tsoding (the real chad imo) would be proud of you.
@Phillip3223 Жыл бұрын
Actually I have that whole "lable" vs "label" spelling issue too
@necuz Жыл бұрын
theater theatre 🤷🏻♂
@Q__Q Жыл бұрын
this is one of the only videos that i actually understood what he was talking about
@MrJCraft Жыл бұрын
This is true art!
@necuz Жыл бұрын
Your approach of skipping blocks that shouldn't be executed reminded me of the same approach being used to implement loops in "M/o/Vfuscator", a C compiler that generates only mov instructions.
@Novascrub Жыл бұрын
Somebody read the Lambda papers.
@parseemizuhasi93386 ай бұрын
The best CPS(Continue Passing Style) vedio.
@HelloThere-xs8ss Жыл бұрын
What a villain to admire
@Bleb1k_irlАй бұрын
"Today, I woke up.And chose violence."😤 😂😂😂
@hooxenv9692 Жыл бұрын
chad goto and compsoy LOL will be borrowing those for sure!
@000dr0g Жыл бұрын
as an F# hacker, I approve this message.
@alurma Жыл бұрын
Algebraic effects are awesome
@warko4 Жыл бұрын
GOTO reminded me of Basic but also MacroB in cnc programming, I'm using it a lot with G-CODE on Swiss lathes..
@monad_tcp Жыл бұрын
20:06 shot out to F#'s computational expressions (not to use the compsoy "monadic")
@Vulto166 Жыл бұрын
That was fun! Thank you Tsoding!
@realdebil. Жыл бұрын
i love you mr. tsoding
@dupdrop Жыл бұрын
I learned some lua for configuring neovim recently and was surprised to discover that in lua 5.2 they actually added goto to the language. Does that make lua the chad-est dynamic language now? Kind of ironic since they don't even know the only true correct number to start counting from, but then again, would a true chad care about that?
@replikvltyoutube3727 Жыл бұрын
The tables start at 1
@dupdrop Жыл бұрын
@@replikvltyoutube3727 I know. Real programmers count up from zero ;)
@yjlom Жыл бұрын
@@dupdrop real programmers count down
@vnshngpnt Жыл бұрын
Based Lua
@safariknight3239 Жыл бұрын
@@yjlom so would the first element be index -1 or 0?
@davidrudpedersen5622 Жыл бұрын
Very gigachad
@JeremyGluckStuff Жыл бұрын
CompSoy
@Scouarn Жыл бұрын
I tried to do it myself before watching. I defined a binding operator that does the try-with, but you can't jump forward this way (I'm still hacking it I have some ideas). Also I think it can be done by defining labels as mutually recursive functions that tail-call each other. My half working solution looks like that : let* loop = make_label () in goto loop; goto exit; (* Doesn't work since exit is not defined *) let* exit = make_label () in ...
@luvincste Жыл бұрын
coming from c#, isn't there a conditional catch? you could divide the blocks in multiple catches each one for a label, and then throwing you owuld go in that 'case', like a sort of switch
@monad_tcp Жыл бұрын
no, we don't do that here, we do match, no label jumps from machine code
@realdebil. Жыл бұрын
wait, it's all a state machine? always has been~
@primosoma Жыл бұрын
i like compsoy even if i don't know what it means
@felix.5507 Жыл бұрын
I see one possible improvement and two problems. If you change line 16 to also [] -> throw Goto entry than you have even some kind of interfunction jumps. The problem that arises from that is what happens if you try to jump a Label that is not defined and what if the user catches or throws Gotos themselves. But the bigger problem I see with this approach is to have the jumps being calculated at runtime. That kind of violates the advantage of goto in my eyes because of the huge Overhead beeing generated. But I am no programmer and don't have any education in this field! But I love your unique apoaches to everything you do. Keep on comming up with such interesting ideas. I hope you can keep making content and wish you the best of luck.
@pstrusi Жыл бұрын
I've noticed that you always use Emacs for your workflow, btw superfast. My question: do you use it cause is really highly efficient in comparison to others modern IDEor text editors. I'm aware that this is a controversial area, but as an amateur programmer, is very confusing and I'd like to know professional opinions. Many, nowadays, are commenting that VScode is the replacement of Emacs. Do you agree? Emacs is obviously more powerful but young generations are not sticking to Emacs community. Thanks for any insight
@alexanderkovalev391 Жыл бұрын
hmm, looks like an interesting challenge for me to sneaky commit something like that into our production erlang code
@NuclearShadowYT Жыл бұрын
one way to introduce new syntax in a language is to make a preprocessor which converts your new syntax to an implementation in the language
@michalbotor Жыл бұрын
todaY wE arE goinG tO enD thE worlD so lets start with implementing 'hello world'
@ih_aye_aitch Жыл бұрын
This reminds me of the special operator LABELS in Lisp
@WilderPoo Жыл бұрын
State of the art
@kuyajj68 Жыл бұрын
The thumbnail forced me to watch this 😂
@Tekay37 Жыл бұрын
I'm not sure if you bullied Exceptions, functional languages or both here. Either way, I like it.
@valovanonym Жыл бұрын
What a madman
@angelcaru9 ай бұрын
badass intro
@adrient8288 Жыл бұрын
How is this so close to your old channel type of video and simultaneously the polar opposite of it
@caio_c Жыл бұрын
I wouldn't be able to figure out something like that, tsoding is slowly ascending to programmer mage levels
@liquidsnake6879 Жыл бұрын
"Today i woke up and chose the violence" and that's the story of how i subscribed and that was before the "double dick operator" which is a beautiful name and an excellent way to ensure nobody ever forgets it lol
@el_chivo99 Жыл бұрын
conditional jumping would also be easy under this approach!!
@ErikBongers10 ай бұрын
I wouldn't trust a language that hasn't goto. And that hasn't nullptr.
@ismaelvc37287 ай бұрын
Instead of an unconditional "goto loop", it could have been "if !i >= 10 then goto loop", no need for the "out" label, it would be a do-while though.
@ebriussenex98508 ай бұрын
Сверхчеловек сверхразум
@martinstrnad32435 ай бұрын
Very similar to tagbody in common lisp. 👍
@beachneosculpordwarf Жыл бұрын
I am very afraid of mutations, what do I do
@timwhite1783 Жыл бұрын
You get a like just for that thumbnail 👍
@abdelrahmandwedar Жыл бұрын
Structured programming: NOOOOOOOOOOOO!!!!
@cynocephalusw9 ай бұрын
Tom Harding implemented GoTo by using circular reasoning.
@dirrelito Жыл бұрын
I think the same thing in Haskell would have been much more beautiful. Goto statements should be implemented in a pure way.
@dirrelito Жыл бұрын
callCC seems like magic--- but your implementation in this stream seems like essentially CPS
@renato360a Жыл бұрын
this isn't really goto (fully) because you can't have multiple gotos inside one "block". Unless you make redundant copies of chunks of blocks.
@AK-vx4dy3 ай бұрын
Impresive but... try catch is a goto. Also := is from Algol, and i don't know wich is better, := for assigment or == for comparision, first is less error prone
@monad_tcp Жыл бұрын
28:51 can your C even do that ! If it compiles, it works !
@mellowyellow7523 Жыл бұрын
SOMEONE TELL TSODING TO STOP SAYING RIGHT EVERY 5 SECONDS I CANT LISTEN TO IT
@sddsddsd-o4h Жыл бұрын
здарова, будут туториалы для начинающих?
@rodelias9378 Жыл бұрын
That was great!!
@jorios550 Жыл бұрын
I wonder how it would look lime in a language that supports macros
@evlogiy Жыл бұрын
Wait. So Rust is basically a low level ML language!? I just started with Rust and never tried OCaml, but this looks very familiar for some reason...
@SimonBuchanNz Жыл бұрын
Rust was initially implemented in ocaml, and it takes several details from ocaml including a lot of it's naming, but it deliberately draws from a lot of different types of languages.
@ilovepeaceandplaying8917 Жыл бұрын
pog
@suryaprakash-sh5bf Жыл бұрын
Sir can I have your neovim config
@ernestodelgato9307 ай бұрын
Pretty sure he mentions he's using Emacs at 6:53
@suryaprakash-sh5bf7 ай бұрын
@@ernestodelgato930 yea thanks bro
@IBelieveInCode Жыл бұрын
"I implemented Goto in OCaml" Yes, but what for ?
@diegorocha2186 Жыл бұрын
To show you that he can and you cannot!
@vitalyl1327 Жыл бұрын
Language which does not have a goto is a crappy compilation target - and, therefore, a crappy metalanguage. You cannot compile parsers efficiently, for example, if you don't have a decently fast goto.
@youtubelisk Жыл бұрын
I have a hard time understanding tsoding's sarcasm. Most things just whoosh by me. Are people scared of for loops? Do students use recursive? What is soycaml? ~$ man tsoding-jokes
@ea_naseer Жыл бұрын
zig doesn't have a for loop.
@anon_y_mousse Жыл бұрын
@@ea_naseer Yeah it does. It's a weird syntax, but it's there.
@csori1075 Жыл бұрын
CompSoy lmao
@straight2heaven_ Жыл бұрын
нифига у тебя лицо злое на превью.
@TsodingDaily Жыл бұрын
Мизицем ноги об стол ударился специально для превью.
@spidorak254 Жыл бұрын
@@TsodingDaily Мизинцем* bro
@minzmango1915 Жыл бұрын
i love you
@trejohnson7677 Жыл бұрын
yes.
@mra-f3x Жыл бұрын
When AI videos again??
@idk24lol Жыл бұрын
something
@alurma Жыл бұрын
Good but using if is soy. Computed goto better
@alurma Жыл бұрын
Not chad enough Kappa
@postmodernist1848 Жыл бұрын
akshually, functions have namespacing and labels don't so this "goto implementation" has some limitations P. S. Don't call me 🤓
@user-tk2jy8xr8b Жыл бұрын
Try using CPS for that purpose next time ;)
@pookiepats8 ай бұрын
Ocaml soy? Lmfao
@arcane.wizard Жыл бұрын
I love your content mate. This is one of the few channels that provides based HQ content for C chads. Nowadays, the majority of YT tech. content creators 're making garbage for JS soydevs: ""x Is A gAmE cHaNgEr!" "sToP uSiNg y! uSe ThIs wheelReinvented.js nOdE pAcKaGe InStEaD!"
@CPSPD Жыл бұрын
@@andrewdunbar828I literally cannot stand Acerola but the video content is always so good. Recommended definitely.
@Waldganger64 Жыл бұрын
HOW DARE YOU.
@bruisedbug Жыл бұрын
im sorry, but you look like "the west has fallen" wojak
@CherishedMe8 ай бұрын
so basic...
@varshneydevansh Жыл бұрын
master
@user-pe7gf9rv4m Жыл бұрын
this reminds me of single-store/assign in LLVM IR type stuff
@motorbreath693 ай бұрын
If you install utop you can run OCaml REPL inside Emacs using C-c C-e to eval function and C-c C-b to eval buffer just like emacs lisp. Makes developing much easier.
@SimGunther Жыл бұрын
Congrats, you rediscovered call/cc
@alurma Жыл бұрын
But typed!
@frechjo Жыл бұрын
call/cc preserves the execution context, it saves the state of the stack, no? This is a trampoline, it behaves similarly, but without preserving the state of the program, it only jumps to where it's told.
@ribosomerocker Жыл бұрын
chaddest solution: ```hs main = replicateM_ 10 (putStrLn "Hello World") ``` i thought you'll use delimited continuations, but your solution is way worse! congrats! i suggest you look into continuations, delimited continuations, continuation passing style, and defunctionalization!