Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about AST formats in the Racket book section 1.2 #175

Open
siadat opened this issue May 20, 2024 · 2 comments
Open

Question about AST formats in the Racket book section 1.2 #175

siadat opened this issue May 20, 2024 · 2 comments

Comments

@siadat
Copy link

siadat commented May 20, 2024

Thanks for this great book. Just started reading the Racket book and I had a question regarding Section 1.2 (page 4). The AST examples are written in a format that is similar to the BNF grammar, and are not Racket code. Is that intentional?

For example, the AST for negative 8 is represented as this:

(Prim '- ((Int 8)))

The equivalent Racket code would be

(Prim '- (list (Int 8)))

I'm learning Racket at the same time, and I was wondering why we don't use Racket to represent the AST. Thanks!

@siadat siadat changed the title Question about AST formats in the Racket book Question about AST formats in the Racket book section 1.2 May 20, 2024
@jsiek
Copy link
Collaborator

jsiek commented May 20, 2024

It looks like I forgot the single-quote in a bunch of places.
That is, in Racket,
'(1 2 3)
is another way to write
(list 1 2 3)
I'll look into fixing this when I get back from vacation.

@siadat
Copy link
Author

siadat commented May 20, 2024

Thanks! In the grammar, (exp) represents a list with one expression, which matches the ASTs. So, if we update the ASTs we might want to consider updating the grammar as well, perhaps to something like this:

exp ::= (Prim '- (list exp))

Just an observation regarding single-quote vs list: with single-quote the expressions inside the list get quoted as well and the result may be different, e.g. (list (+ 1 2) 3) != '((+ 1 2) 3).

I am excited to continue to follow the book this week. Enjoy your vacation! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants