Rewriting My Language in itself (Porth Ep.17)

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024

Комментарии • 103

  • @nodroGnotlrahC
    @nodroGnotlrahC 3 года назад +59

    Hi. You wondered about the difference between "stack based" and "concatenative".
    "Concatenative" refers to how the composition of functions is achieved. Consider two functions, f(x) and g(x). To compute g of f of x in say Python we would write g(f(x)). In say Haskell we can use the composition operator "." and write g.f x (note - I'm not a Haskell expert, I googled "function composition in Haskell" so I /hope/ this is correct.)
    If we make composition the default operation (i.e. it doesn't have an operator, much as in mathematics the default operation is multiplication, so ab implies a multiplied by b) then we get Polish notation - g f x - and read it from right to left "take x, apply f to it, apply g to the result". Flipping that around, we get Reverse Polish notation, which reads from left to right. x f g is "take x, apply f to it, apply g to the result" and this is characteristic of concatenative languages.
    It is NOT necessary to use a stack to achieve this. Graph reduction or term rewriting also works. So "stack based" describes the implementation method for a concatenative language.

    • @mrocto329
      @mrocto329 3 года назад +1

      > and write g.f x
      Need parens around g.f, so: (g . f) x

  • @realGBx64
    @realGBx64 2 года назад +30

    I love this series as an amateur python programmer.
    I wish there was a class like this at university, where maybe the professor codes the interpreter + compiler in front of the class, they make some decisions together, and some parts (additional operations, etc.) can be homework assignments and the students can do pull requests with their solutions.

    • @jordixboy
      @jordixboy Год назад

      why dont you make it yourself lol

    • @gusic4529
      @gusic4529 Год назад +1

      @@jordixboythey literally said they were an amateur

    • @jordixboy
      @jordixboy Год назад

      @@gusic4529 and what? With enough learning and time he should be capable of doing. Plenty of resources for free to learn, its a matter of taking the time

    • @gabriellevesque2185
      @gabriellevesque2185 Год назад

      ​@@gusic4529We can't save everyone's brain cells 😅

  • @IveGotBeef
    @IveGotBeef 3 года назад +56

    This is the definition of "Hm yes, the floor is made out of floor"

  • @binyamindarshanhcohen4359
    @binyamindarshanhcohen4359 3 года назад +227

    So it was called porth because it's a python forth, now it's called porth because it's a porth forth.

    • @thebirdhasbeencharged
      @thebirdhasbeencharged 3 года назад +15

      He needs to now port it to actual forth

    • @landsgevaer
      @landsgevaer 2 года назад +2

      Is that how PHP also started...? ;-)

    • @ninesquared81
      @ninesquared81 Год назад +3

      @@landsgevaer not sure if this is a genuine question or not, but assuming it is, PHP originally stood for Personal Home Page.

    • @NathanHedglin
      @NathanHedglin Год назад +2

      @@landsgevaer PHP isn't bootstrapped. The interpreter is written in C

    • @yOkay_
      @yOkay_ Год назад +1

      Bootstrapping is so confuse

  • @loukafortin6225
    @loukafortin6225 3 года назад +17

    so on and so porth

  • @jorgehermo9
    @jorgehermo9 3 года назад +35

    The video that we needed, but not the one that we deserved. Great content man

  • @wndtn
    @wndtn 3 года назад +4

    Бутсрапер. Неплохо братик

    • @aciddev_
      @aciddev_ 7 месяцев назад

      ебать кто тут появился)

  • @henrylang699
    @henrylang699 3 года назад +29

    Hey Tsoding, these videos are awesome, I've never understood how languages were actually made so thanks :)

    • @vforsh
      @vforsh 3 года назад +4

      There is a great book called “crafting interpreters” which explains the whole process in an accessible way

  • @Mekelaina
    @Mekelaina 3 года назад +40

    maybe a switch case that checks the int on the top of the stack, then jumps to the appropriate block depending on the value would be helpful.

    • @homelikebrick42
      @homelikebrick42 3 года назад +3

      There is no jump
      Thats why he is using macros for functions

    • @Mekelaina
      @Mekelaina 3 года назад +7

      @@homelikebrick42 he mentioned that the while keyword serves to mark the retern point for the loop right? meaning there should be some jmp assembly instruction. maybe its too complicated to worry about at the moment but once porth is self hosted it might be worth looking into

  • @Michael-rc5ks
    @Michael-rc5ks 3 года назад +31

    When zozi forget to ping discord after streaming for an hour. KEKW

    • @kernelk1931
      @kernelk1931 3 года назад

      how can i get permissions on his discord channel?

  • @Diamonddrake
    @Diamonddrake 3 года назад +6

    I never thought I’d watch this much python content, but I can’t get enough of porth, I can’t wait for the next one. Glad to see you dropped the chat overlay. It’s distracting to see side conversation .

  • @samwise1491
    @samwise1491 3 года назад +3

    Absolutely loving this series
    Would it be useful for macros to define the types they expect on the stack? That way before a macro is expanded you can throw a compiler error like when you call intrinsics with the wrong arguments on the stack. As this language matures I can see there being a lot of macro usage and making these as powerful and easy to debug as possible would be useful
    Keep it up Tsoding!

  • @edwardoakley8659
    @edwardoakley8659 3 года назад +1

    You're videos are great, such a fast and slick style

  • @wChris_
    @wChris_ 3 года назад +4

    forth automatically prints ."" which would be a nice idea.
    For null terminated strings you could add a 0 a the end of the string literal like:
    ""0 or any value for that matter, followed by more string literals, like:
    ""27"[1;32m"27"[1m"

  • @JohnWasinger
    @JohnWasinger Год назад +1

    I remember seeing a piece of artwork that was a colorful double helix of a DNA molecule. The image was generated by itself and was a Quine.

  • @monsieuralexandergulbu3678
    @monsieuralexandergulbu3678 3 года назад +3

    Nice finally long awaited moment

  • @nibbletrinnal2289
    @nibbletrinnal2289 3 года назад +3

    just noticed that there is very very very quiet music in the bg lmao
    any particular reason for not showing stream chat? you reference them several times here and, though you repeat their questions for us to know what you're talking abt, i think it'd be nice to actually see the chat. i dunno maybe ill just have to pop in live from now on lol

  • @wChris_
    @wChris_ 3 года назад +9

    C has two macros: '__FILE__' and '__LINE__' they use double underscores because 1. its UB to define double underscore variables and 2. its unlikely you will ever define a variable exactly like this. So i suggest you change here to __LOCATION__ or something similar.

    • @wChris_
      @wChris_ 3 года назад +3

      if anyone knows how to escape the formatting in youtube comments let me know!
      I dont want half the text to be italic!

    • @uwuLegacy
      @uwuLegacy 3 года назад

      @@wChris_ try backspaces before the underscores

    • @jetison333
      @jetison333 3 года назад +2

      @@uwuLegacy how do you type a backspace?

  • @alexander3293
    @alexander3293 3 года назад +1

    finally what we have been waiting for

  • @superhawk6105
    @superhawk6105 3 года назад

    This makes my brain hurt, so cool
    EDIT: Good explanation of the if/elif block over hashes, thanks ✨

  • @coffee-is-power
    @coffee-is-power 3 года назад +4

    this seems strange but it actually happens to many languages today, practically, every language does that

  • @davidshainidze3930
    @davidshainidze3930 3 года назад +2

    What keyboard do you have? I liked keyboard sounds.

    • @Diamonddrake
      @Diamonddrake 3 года назад +1

      Hearing the typing is what got me hooked on this channel. It’s so satisfying

  • @pinchoboo736
    @pinchoboo736 3 года назад +1

    what version of pypy do you use?

  • @hkhademian
    @hkhademian 3 года назад

    hi , awsome work
    is streq(s1,s2) := strcmp(s1,s2)==0 possible for the last part ?

  • @connormccartney2953
    @connormccartney2953 3 года назад +3

    I swear Alexey Keeps aging backwards.

  • @FEiSTYFEVER
    @FEiSTYFEVER 3 года назад

    Just started tuning in. I subbed when i seen you made a Forth! Bloody incredible language.
    Did you have a look at Factor before you started, would be great if someone picked up the reins on that project.

  • @Mekelaina
    @Mekelaina 3 года назад +1

    what a lovely video to wake up to

  • @playerguy2
    @playerguy2 2 года назад

    "Is this what everyone means when they talk about Porth Forwarding?"

  • @irishbruse
    @irishbruse 3 года назад +6

    Porth OS when?

  • @plabanmondal3111
    @plabanmondal3111 3 года назад

    I have a question.. is rust good for OpenGl??

  • @dtb9165
    @dtb9165 3 года назад

    which text editor are you using?

  • @KangJangkrik
    @KangJangkrik 3 года назад +14

    Did you know that GCC (C compiler) actually made with C? Well... as you know, this is something normal

    • @stefanalecu9532
      @stefanalecu9532 3 года назад +4

      But it definitely used another compiler for bootstrapping

    • @wChris_
      @wChris_ 3 года назад +9

      @@stefanalecu9532 actually C was bootstrapped from B

    • @chri-k
      @chri-k 2 года назад +4

      @@wChris_ which was unfortunately not written in A.

    • @luizguilherme8383
      @luizguilherme8383 2 года назад

      @@chri-k and if A existed could be bootstraped from z (since -1 mod 26 = 25 = Z)

  • @lucasemanuelgenova9179
    @lucasemanuelgenova9179 3 года назад +1

    Where are you from? I don't think you speak Portuguese, but the word you say at 5:26 as a confirmation is actually something you coukd use in Portuguese, so it got me curious

  • @hexadeque1101
    @hexadeque1101 3 года назад +1

    It will only be a real chicken and egg situation once you rewrite python in porth

  • @Caellyan
    @Caellyan 3 года назад +2

    Concatenative programming vs. not = "does function call require surrounding arguments in braces".
    Stack-Oriented programming is a paradigm where function calls are expressed with Reverse Polish Notation.
    I think Groovy is a good example of support for concatenative programming (and enforcing it) while being neither a stack-oriented nor a functional programming language.
    Stack-Oriented programming implies concatenative programming if it's not limited to one instruction per line like assembly.

  • @byterbrodTV
    @byterbrodTV 3 года назад

    I suppose it's a good start to rewriting porth in porth!
    This comment to support this channel

  • @halim_Ha
    @halim_Ha 3 года назад +1

    damn i just found you it's like i found a treasure

  • @roaringfork
    @roaringfork 3 года назад +5

    Love the project. I created a lisp interpreter in Rust once, never thought to write it in itself. Porth is a terrible name. Porth 👄 💦

  • @souzaramon9522
    @souzaramon9522 3 года назад +1

    Can u please make a videou about llvm, and why some guys (brazilians high ego dev streamers) says that is the **only** way to build a interpreter/compiler on top of a high level language?
    kinda fun cause u literally didn't use in this series

    • @ymndoseijin
      @ymndoseijin 2 года назад +2

      de quem tu tá falando cara isso literalmente faz sentido algum

    • @MatheoxMattheox
      @MatheoxMattheox 2 года назад

      quem?

    • @NathanHedglin
      @NathanHedglin Год назад +1

      LLVM allows for compiling for many platforms. Unless one is targeting a VM bytecode like JVM, for production grade cross-platform compilers, LLVM is a must.
      LLVM has its own intermediate language that your compiler can generate. LLVM can compile or make a JIT compiler for you from there.
      It is NOT absolutely needed. Tsoding doesn't care if Porth is portable.

  • @wChris_
    @wChris_ 3 года назад

    A much better implementation of elseif is the on you already have were a second if in the else condition doesn't need to be closed by an end.
    like the syntax you already have:
    if else if else if end
    Note: the single 'end' at the end.

    • @jetison333
      @jetison333 3 года назад +1

      Then you can't nest if else's, which is really often neccesary.

    • @wChris_
      @wChris_ 3 года назад

      ​@@jetison333 I am thinking of ternary style ifs.
      Also if you have a nested if in an else block, should already be using an if-else statement

  • @mathalphabet5645
    @mathalphabet5645 3 года назад

    This is awesome

  • @wChris_
    @wChris_ 3 года назад +1

    puts actually puts a newline automatically at the end of each string! I highly recommend looking at the musl libc implementation as it is much cleaner than the glibc implementation.

  • @GiveAcademy
    @GiveAcademy 2 года назад

    I think I am now inspired to write an editor plugin for this language that will show you what is on the stack as you type… ;)

  • @bigmistqke
    @bigmistqke 3 года назад +1

    27:30 lol

  • @ultrahalf
    @ultrahalf 3 года назад +10

    "Rewriting My Language in itself"
    ah recursion??

  • @banddy1376
    @banddy1376 3 года назад

    Cool project 👍👍

  • @ChristopherSalisburySalz
    @ChristopherSalisburySalz 3 года назад +1

    Tscoding, you know several programming languages. If you had to choose a single language to use what would it be? What is your favorite programming language?

    • @nibbletrinnal2289
      @nibbletrinnal2289 3 года назад +7

      His FAQ says in response to the "favourite programming language" question that he hates them all equally lol

  • @comedyclub333
    @comedyclub333 3 года назад +1

    Sooooo, basically porth.porth is to porth what PyPy is to CPython? xD

  • @freakcdev
    @freakcdev 3 года назад

    nice!

  • @aadityabhetuwal5990
    @aadityabhetuwal5990 3 года назад +5

    you should have considered everything non zero to be Boolean true.

    • @voltairespuppet
      @voltairespuppet 2 года назад

      Or the convention for such checks to be false (0) or not false. Keeping the false and true to specific values. Do you think those values should be 1 and 0, or -1 and 0?

  • @msq7041
    @msq7041 3 года назад

    Hey, as soon as you implement a porth compiler in porth you can just implement it in the porth based compiler. The python based compiler isnt necessary anymore once you have a working porth based compiler

  • @alexanderskladovski
    @alexanderskladovski 3 года назад

    Finally

  • @irishbruse
    @irishbruse 3 года назад +3

    you should write a transpiler from python to porth to save you hand porting the compiler :P

  • @janekk_
    @janekk_ 3 года назад +1

    how is it possible to write a programming language in itself

    • @jetison333
      @jetison333 3 года назад +4

      You first have to write it in another language, and then you can write porth programs. Then you rewrite your compiler in porth, use your first compiler to compile that, and then only use your ports compiler from then on. The whole process is called bootstrapping and a lot of modern programming languages do it.

    • @janekk_
      @janekk_ 3 года назад +3

      @@jetison333 thanks, I forgot that all languages are at the end only instructions :p

    • @janekk_
      @janekk_ 3 года назад

      but why would you do that? rewrite in itself

    • @netscapeplugin
      @netscapeplugin 3 года назад +4

      @@janekk_ It’s a good non-trivial test of the compiler. It can help the developer find bugs.

    • @digitalspecter
      @digitalspecter 3 года назад +1

      @@janekk_ Oftentimes (not always) you're creating a programming language because it's closer to your ideal language than the existing ones.. so you might enjoy developing the compiler further in this better(?) language.. Also, like Netscape Plugin said, it's a good non-trivial test of the compiler but also dogfooding of your new language.. how does it feel to develop in it.

  • @gabriellevesque2185
    @gabriellevesque2185 Год назад

    Porth: Syntax is simple like Python, with compile errors clarity of Java 😅

  • @kisinja4582
    @kisinja4582 3 года назад

    nice elif bro

  • @realGBx64
    @realGBx64 2 года назад

    Ohh you could just write a shell script that sends the file content to std input of porth and saves the output to an asm file and runs nasm and the linker. This is why we have pipes and redirects in *nix systems.

  • @juancarlostorresgutierrez6830
    @juancarlostorresgutierrez6830 4 месяца назад

    pforth

  • @hajji384
    @hajji384 3 года назад

    😳 you're codin pro

  • @cameron6464
    @cameron6464 3 года назад +1

    Please stop talking with that funny voice.