What's the principle of Racketscript

hi, I'm interested in racketscript and want to make it stronger.
hmm,what is the key in racketscript,the racket->js compiler?
as an language-oriented language ,what adventures does racket have to do that?
racket's nature tools seem to be good at translating self-def languge to racket source code ,
but how can let racket code to another language?

Yes, I agree! Racket's natural means of extension is by creating languages that expand into Racket, and racketscript is targeting JS instead. However, the compiler tower can still simplify this kind of translation. Specifically, the fact that Racket expands into a smaller core language means that translating "all of Racket" only requires translating those core forms. [Disclaimer: I'm not at all familiar with the implementation of racketscript.]

2 Likes

Is the smaller core language the ~26 items listed in the grammar at 1.2.3.1 Fully Expanded Programs ?

1 Like

Yep, those are the ones I'm thinking of.

2 Likes

I thought it would be fun to find the relevant code in Racket implementations

Not sure where to look in GitHub - racket/racket: The Racket repository though?

S.

Sorry for the slow reply. I don't understand your question, and maybe you can refine it? I think you might be asking where the code is that defines these forms, or where the code is that "implements" them (that is, defines what happens when they run), or something else entirely!

Exactly that!

Thank you

Yeah, well, I was afraid you were going to ask that. The problem here is that Racket is a compiler. That means that instead of there being a single place in the code that says "this is what a lambda means", what you'll find instead is instructions for translating a lambda into assembly language. Now that Racket is built on top of Chez scheme, this consists of a little bit of work in Racket (I believe that core forms are transformed into linklets, which already are Chez scheme or are translated in a fairly straightforward way into Chez scheme), and then you need to read the Chez compiler. The Chez compiler is what's called a "nanopass" compiler, which translates a chez scheme program into assembly in a series of many small passes, each of which produces a complete program that could in principle be run by an interpreter for that language. This architecture is documented in a whole bunch of different places; my favorite source is Jeremy Siek's compiler-building textbook. I think it's fair to credit Kent Dybvig with the largest share of the design and implementation work for this; he and his students have done a ludicrous amount of work to build and maintain this compiler.

Let me know if I misunderstood your question! Or if I'm mistaken!

1 Like