How to learn the *core* of Racket?

140 views
Skip to first unread message

Yushuo Xiao

unread,
Nov 6, 2021, 5:33:43 AM11/6/21
to Racket Users
I've learned some Racket, and can comfortably program in it, but I only learned it as an ordinary language, much like Scheme. I know Racket is much more than that, for its "language-oriented" features. Languages become a first-class member in Racket, and to my understanding, even "#lang racket" is just a language built on some core. What I want to know is, what's the very core of Racket?

I've noticed that in the Racket Reference there is a section "Fully Expanded Programs", which seems the very core of Racket. But it still takes an S-expression form, and apparently Racket allows language customization on the syntax level. I wonder if the S-expression language is the core of Racket, or the entire Racket has a different structure?

I would really appreciate it if anyone could explain it in a simple way or could point out some good (and short) material for me to read. The Racket Reference is too long, and I believe the core Racket can be well explained in a much shorter piece of text, if I just look for a brief understanding.

Also my question may be confusing, because I don't understand Racket well at all. Feel free to correct me or ask for clarification. Thanks in advance!

David Storrs

unread,
Nov 6, 2021, 6:53:53 PM11/6/21
to Yushuo Xiao, Racket Users
Hi Yushuo,

On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao <dev....@gmail.com> wrote:
I've learned some Racket, and can comfortably program in it, but I only learned it as an ordinary language, much like Scheme. I know Racket is much more than that, for its "language-oriented" features. Languages become a first-class member in Racket, and to my understanding, even "#lang racket" is just a language built on some core. What I want to know is, what's the very core of Racket?

It depends on where you stop measuring.  You could argue that...

...#lang racket  is the core, because it's what comes in the installation.  Things like gregor, struct-plus-plus, and csv-reading are packages that you install from http://pkgs.racket-lang.org/ and are therefore outside the core.

...#lang racket/base is the core, because it's the most limited set of Racket that comes by default.  It mostly consists of only the basic list manipulation functions, and if you want to use other things then you need to include relevant libraries such as racket/match (giving you the 'match' special form) or racket/format (giving you the ~a function), or racket-string (giving you the string-length function), etc.

...Raw lambdas and a few special forms are the core, because everything compiles down to those.  (Approximately speaking.)

...Lambda calculus is the core, because it's what all LISP descendants are based on.

Once you start talking about other Racket languages with different syntax and semantics, well then all bets are off.


Does this help?


I've noticed that in the Racket Reference there is a section "Fully Expanded Programs", which seems the very core of Racket. But it still takes an S-expression form, and apparently Racket allows language customization on the syntax level. I wonder if the S-expression language is the core of Racket, or the entire Racket has a different structure?

I would really appreciate it if anyone could explain it in a simple way or could point out some good (and short) material for me to read. The Racket Reference is too long, and I believe the core Racket can be well explained in a much shorter piece of text, if I just look for a brief understanding.

Also my question may be confusing, because I don't understand Racket well at all. Feel free to correct me or ask for clarification. Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/63b1134b-16e4-4447-828a-1e607013bd7cn%40googlegroups.com.

Yushuo Xiao

unread,
Nov 11, 2021, 6:04:53 AM11/11/21
to Racket Users
Thank you for your comprehensive answer! It helps a lot. I also read more about Racket after I posted the question and now I think that the few special forms (as stated in "fully expanded program") are the core. All languages built in Racket will parse and convert their syntax into syntax objects (S-expressions) and then expand to these special forms. Am I right?

David Storrs

unread,
Nov 11, 2021, 9:47:03 AM11/11/21
to Yushuo Xiao, Racket Users
Sure, that's as good a definition as any.

John Clements

unread,
Nov 11, 2021, 11:15:39 AM11/11/21
to Yushuo Xiao, Racket Users
> On Nov 11, 2021, at 03:04, Yushuo Xiao <dev....@gmail.com> wrote:
>
> Thank you for your comprehensive answer! It helps a lot. I also read more about Racket after I posted the question and now I think that the few special forms (as stated in "fully expanded program") are the core. All languages built in Racket will parse and convert their syntax into syntax objects (S-expressions) and then expand to these special forms. Am I right?

That’s a true statement… but that set is by no means fixed. These core forms then get compiled into native code (in CS) or bytecode (in BC), and changing this core set is certainly possible. It’s probably wiser to think of these core forms as an intermediate representation language in a compiler. I would agree that it’s an important IR, in that it’s essentially a subset of the racket language itself, but it’s definitely not an immutable ideal.

Apologies as always if you knew all this already,

John Clements

>
> On Sunday, November 7, 2021 at 6:53:53 AM UTC+8 david....@gmail.com wrote:
> Hi Yushuo,
>
> On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao <dev....@gmail.com> wrote:
> I've learned some Racket, and can comfortably program in it, but I only learned it as an ordinary language, much like Scheme. I know Racket is much more than that, for its "language-oriented" features. Languages become a first-class member in Racket, and to my understanding, even "#lang racket" is just a language built on some core. What I want to know is, what's the very core of Racket?
>
> It depends on where you stop measuring. You could argue that...
>
> ...#lang racket is the core, because it's what comes in the installation. Things like gregor, struct-plus-plus, and csv-reading are packages that you install from http://pkgs.racket-lang.org/ and are therefore outside the core.
>
> ...#lang racket/base is the core, because it's the most limited set of Racket that comes by default. It mostly consists of only the basic list manipulation functions, and if you want to use other things then you need to include relevant libraries such as racket/match (giving you the 'match' special form) or racket/format (giving you the ~a function), or racket-string (giving you the string-length function), etc.
>
> ...Raw lambdas and a few special forms are the core, because everything compiles down to those. (Approximately speaking.)
>
> ...Lambda calculus is the core, because it's what all LISP descendants are based on.
>
> Once you start talking about other Racket languages with different syntax and semantics, well then all bets are off.
>
>
> Does this help?
>
>
> I've noticed that in the Racket Reference there is a section "Fully Expanded Programs", which seems the very core of Racket. But it still takes an S-expression form, and apparently Racket allows language customization on the syntax level. I wonder if the S-expression language is the core of Racket, or the entire Racket has a different structure?
>
> I would really appreciate it if anyone could explain it in a simple way or could point out some good (and short) material for me to read. The Racket Reference is too long, and I believe the core Racket can be well explained in a much shorter piece of text, if I just look for a brief understanding.
>
> Also my question may be confusing, because I don't understand Racket well at all. Feel free to correct me or ask for clarification. Thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/63b1134b-16e4-4447-828a-1e607013bd7cn%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/6929457c-459f-4c25-94c0-ea973b121c65n%40googlegroups.com.

David Storrs

unread,
Nov 11, 2021, 11:22:51 AM11/11/21
to Yushuo Xiao, Racket Users
Out of curiosity, what is it that you're trying to achieve here?  You're not going to program in the fully-expanded language, you're going to program in something higher level.  Is this purely a "learning assembly code is good because it gives you a better understanding of machine architecture" thing?

On Sat, Nov 6, 2021 at 5:33 AM Yushuo Xiao <dev....@gmail.com> wrote:
--

James Platt

unread,
Nov 11, 2021, 11:41:36 AM11/11/21
to racket users
... and from there it's turtles all the way down.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAE8gKoc-8rGaY%2BF2nDLR5BULe1tGnO5BnGAZt-DgBmhCVg_9dw%40mail.gmail.com.

Yushuo Xiao

unread,
Nov 11, 2021, 9:20:20 PM11/11/21
to Racket Users
Thank you very much! I didn't know the set is not fixed. And thinking of them as an IR really helps.

Yushuo Xiao

unread,
Nov 11, 2021, 9:34:11 PM11/11/21
to Racket Users
Yes, you are right! I'm not trying to achieve anything. I just want to get a better understanding of how Racket works. I generally want to know how things work at the lowest possible level, just as learning assembly helps me understand C. And sometimes I have trouble learning things under a higher abstraction, though I know I should fix that...

Philip McGrath

unread,
Nov 11, 2021, 10:03:57 PM11/11/21
to Yushuo Xiao, Racket Users
On Thu, Nov 11, 2021 at 9:20 PM Yushuo Xiao <dev....@gmail.com> wrote:
Thank you very much! I didn't know the set is not fixed. And thinking of them as an IR really helps.

On Friday, November 12, 2021 at 12:15:39 AM UTC+8 johnbclements wrote:
That’s a true statement… but that set is by no means fixed.

To nitpick a little, while it's true that the set of forms allowed in fully expanded programs is not fixed, the last change was in Racket 6.3, adding `(quote-syntax datum #:local)` and removing `letrec-syntaxes+values`: https://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29

So, while not fixed, they are in fact quite stable, and the list of identifiers is exposed through APIs like the `kernel-literals` literal set for `syntax-parse` and, at a lower level, `kernel-form-identifier-list` and the `syntax/kerncase` module. Authors of advanced macros that use `local-expand` and friends need a general awareness of their shapes, e.g. to recognize definitions, splice `begin`s, or recur into local binding forms, so changes have to be unobtrusive to avoid breaking compatibility.

If you're interested in the low-level internals of Racket, you may also want to read the manual section on Linklets and the Core Compiler.

-Philip

Daniel Prager

unread,
Nov 12, 2021, 4:18:07 AM11/12/21
to Yushuo Xiao, Racket Users
An alternative answer to the implied question: "How do I learn the core of the language-oriented features of Racket?"

Check out Beautiful Racket: https://beautifulracket.com

- Dan




--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages