What's the return value of `define` in Scheme?

2019-07-18 09:10发布

问题:

I'm curious about the return value of define in Scheme. So I wrote the following lines in Racket

#lang r5rs
(display (define a 3))

And get the error

 define: not allowed in an expression context in: (define a 3)

I have 2 questions about this:

  1. Does it mean that define has no return value?
  2. According to R5RS, define is not an expression. It's a program structure. Is it true that only expressions have return values, and other forms don't?

回答1:

"If a tree falls in a forest and no one is around to hear it, does it make a sound?"

It's not valid to use define in any context where a return value could meaningfully be obtained. So it's moot whether it has a return value or not; you'll never be able to observe it.



回答2:

In Scheme, define can only be used in two places:

  1. At the top level, or
  2. At the very beginning of a "body".

In neither of those places is a "return value" relevant.