Question

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?
Was it helpful?

Solution

"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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top