What exactly is #lang

Hi, very basic question here. What is the correct name of "#lang" in Racket ? Is it a "reader form", a "directive", a "reader macro", or something else?

2 Likes

From 1.3 The Reader

lang starts a reader extension use; see Reading via an Extension

1 Like

Thanks for the reply! Exactly in this section, they refer to #reader and #lang as "reader forms", or simply "forms". That's why I asked. I guess the former is the right name.

That answer is a technically correct answer, given a deep understanding of the guts of Racket, but typically one encounters #lang at the start of a file and it is more simply (and still accurately) thought of as a declaration of the language of that file. One could say that the parser for Racket is simply checking for #lang and then handing it off to some more specific language to continue parsing (and expansion and compilation, etc) from there.

3 Likes

Robby Findler via Racket Discussions
notifications@racket.discoursemail.com writes:

That answer is a technically correct answer, given a deep
understanding of the guts of Racket, but typically one encounters
#lang at the start of a file and it is more simply (and still
accurately) thought of as a declaration of the language of that
file. One could say that the parser for Racket is simply checking for
#lang and then handing it off to some more specific language to
continue parsing (and expansion and compilation, etc) from there.

For something in between these two answers, see

https://docs.racket-lang.org/guide/languages.html

I was happy to see this material added to the guide (at least I never
noticed it before).

I have yet to follow it through and see if I can answer my own question
about using brag as a module language inlined in a file by calling
reader.

d

2 Likes