Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the definition of "top-level-form" in Racket

Tags:

racket

The Racket Reference sections 11.9 Expanding Top-Level Forms and 13.2 Evaluation and Compilation use the term "top-level-form" and the descriptions of the functions (eval top-level-form [nm]) and (expand top-level-form) in the reference manual have "top-level-form" as their function argument, but I'm unclear about the definition of "top-level-form". What is the meaning of the term "top-level-form" within the Racket language?

like image 412
Harry Spier Avatar asked Nov 08 '11 02:11

Harry Spier


2 Answers

The intuition here is that these functions all deal with "top-level forms" as opposed to a form that depends on a lexical environment. As a semi-obvious example, eval can only deal with top-level forms, which is why this:

(let ([x 10])
  (eval '(* 3 x)))

doesn't work. The usual use of just "forms" is talking about any forms, such as inputs to macros -- which of course can have such references.

like image 156
Eli Barzilay Avatar answered Oct 22 '22 10:10

Eli Barzilay


I have now found the precise definition of top-level-form in a kind of Backus-Naur format in the Racket Reference manual section 1.2.3.1

http://docs.racket-lang.org/reference/syntax-model.html#(part._fully-expanded)

like image 1
Harry Spier Avatar answered Oct 22 '22 11:10

Harry Spier