enoll@cctr.umkc.edu wrote:
>Hello,
>I am just learning to use Scheme and am very much a novice at it. I seem to
>be having a problem I cannot account for within the limited scope of my
>knowledge. I was hoping someone out there might be able to help me get back
>on track.
Actually, the problem is the limited scope of the variables.
>If I key a definition such as the following into edwin
>(define (xdefine arg)
> (let ((left (car arg)) (right (cdr arg)))
> (define left right)))
Is your intent to be able to do this?
(xdefine (cons 'foo 22))
foo => 22
You won't be able to that without macros.
>then do meta-o, I receive an error message to the effect that
>(LETREC ((LEFT RIGHT))) has the wrong number of arguments.
>which is confusing because I had not specified LETREC in the xdefine procedure.
Section 5.2.2 of R^4RS says that ``... internal definitions can always
be converted into a completely equivalent LETREC expression.''
So your internal (DEFINE LEFT RIGHT) is being converted into a
(LETREC ((LEFT RIGHT)))
Note that this letrec has no body. This is because your original code
has no body after the internal definition. LETREC requires a body and
thus you get the ``wrong number of arguments error.''
I should also point out that you should generally use internal
definitions for internal procedures only. The reasons for this
are rather complicated, and I can't think of a clear way to express
them. I'll post them if you are interested.
|