Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s not obvious from the text, but the compiler was previously written in TypeScript (which was kind of a strange choice for the language to write a compiler in).


TypeScript compiler is more of a transpiler, not a typical compiler that creates a binary. I don't think it was weird choice.


Bootstraping compilers is a common activity and TypeScript is a nice language.


“Nice” doesn’t mean “well suitable for writing a compiler in”. It’s strange to think that all languages should be equally good for writing all kinds of things, and choosing a web language for a non-web task is doubly strange.


Yep. I remember years ago when they celebrating getting the C# compiler working in C#.


That was the Roslyn project! Yes they were also excited that it would allow more devs to hook into the computer and also enhance it.


Its not strange, its very common. Its called "bootstrapping".

> Bootstrapping is a fairly common practice when creating a programming language. Many compilers for many programming languages are bootstrapped, including compilers for ALGOL, BASIC, C, C#, Common Lisp, D, Eiffel, Elixir, Go, Haskell, Java, Modula-2, Nim, Oberon, OCaml, Pascal, PL/I, Python, Rust, Scala, Scheme, TypeScript, Vala, Zig and more.

https://en.wikipedia.org/wiki/Bootstrapping_(compilers)


Yet people wouldn’t write a Fortran compiler in Fortran, or a MATLAB compiler in MATLAB.


I don't consider it strange, and I'm not alone: https://news.ycombinator.com/item?id=37171801


is it not common to write compilers for languages in the language being compiled itself? rust does this i think?


It is fairly common, yes. Sometimes those compilers (or interpreters) aren't the primary implementation, but it's certainly a thing that happens often.

Most of the Rust compiler is in Rust, that's correct, but it does by default use LLVM to do code generation, which is in C++.


note that as others have said, "compiled" is a stretch, but nevertheless...


Programs that are less than full compilers in some sense can be bootstrapped.

For instance, this compiler for a pattern matching notation has parts of it implementation using the notation itself:

https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl

Some pattern matching occurs in the function match-case-to-casequal. This is why it is preceded by a dummy implementation of non-triv-pat-p, a function needed by the pattern matching logic for classifying whether a pattern is trivial or not; it has to be defined so that the if-match and other macros in the following function can expand. The sub just says every pattern is nontrivial, a conservative guess.

non-triv-pat-p is later redefined. And it uses match-case! So the pattern matcher has bootstrapped this function: a fundamental pattern classification function in the pattern matcher is written using pattern matching. Because of the way the file is staged, with the stub initial implementation of that function, this is all boostrapped in a single pass.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: