问题
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:
- Does it mean that
define
has no return value? - 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:
- At the top level, or
- At the very beginning of a "body".
In neither of those places is a "return value" relevant.
来源:https://stackoverflow.com/questions/18799032/whats-the-return-value-of-define-in-scheme