Why does (the beginning) act on the Scheme?

I tested in Racket and Chez Scheme and found that it is (begin)valid, but (define a (begin))not. For example, with Racket, I got

> (begin)
> (define a (begin))
; stdin:56:10: begin: empty form not allowed

And my question is, why is it allowed (begin)at all? Is there any specific reason / intuition for this?

+4
source share
2 answers

The beginning of the form has two goals.

1. To sequence the evaluation of expressions 
2. To "splice" sequences together (used by macros)

The first of these is what is used most often:

(begin e0 e1 ...)

will evaluate the expressions e0 e1 ... in order.

The second is used when a macro expands to several definitions and / or expressions.

As an example, below

(begin
   (begin d1 e1 d2 d3)
   (begin)
   e2
   ...)

will be flattened by a macro expander in:

(begin d1 e1 d2 d3 e2 ...)

" () ?". begin 1 (), begin . 2 () (begin) , . (debug expression), expression ( ), (begin), .

+3

, (begin ()), (if () ).

0

Source: https://habr.com/ru/post/1665095/


All Articles