Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of Define expression in Scheme

To put it simply: My question is whats is the type of a define expression in Scheme?

Take for example:

(define x 5)

or

(define x (lambda (n) (* n n)))

It's a bit confusing for me. Can anyone help?

like image 376
TheEmeritus Avatar asked Mar 19 '13 15:03

TheEmeritus


1 Answers

In Racket define is a special form and not an expression, so it doesn't have a value per-se, if you try to execute something like this you'll get an error:

(display (define x 42))
=>  define: not allowed in an expression context in: (define x 42)

If it were to have a value it'd be something akin to void, but that will be dependent on the particular implementation details of the interpreter (I believe I saw one interpreter return #t after a define was completed)

The constant #<void> is returned by most forms and procedures that have a side-effect and no useful result

The specification doesn't go into details on this point, either - reinforcing the statement that it's implementation-dependent.

like image 149
Óscar López Avatar answered Oct 28 '22 11:10

Óscar López