Don't mess with lambda

So we were talking about set!, which will re-assign a variable (or... anything) without having to just define it over again. Naturally, this led to talk about pointers, and that there was not a native implementation of pointers (like C) in Scheme.

This was interesting. I decided to check it out.

So, I tried the simplest example possible:

>(define b 100)
b

>(define (foo n) (set! n (1+ n)))
foo

>(foo b)

>b
100

Sure enough, as expected, b does not change.

I recalled that (lambda () b) should return the memory address of b... what about that?

>(foo (lambda () b))

>b
100

Nope; still didn't change b. Hmm.

Then, as a weird experiment, I thought, what if I tried to actually assign something to a memory address? Like...

>(define (lambda () q) 100)

Some of you are already laughing at me. Yes, I actually typed that into the interpreter... If you take another look at it, what I actually just did was redefine lambda.

It is amazing the things that stop working when you redefine lambda.

quit no longer worked, for example... ;-)

Moral: Watch what you type, and don't mess with lambda.

Add a comment

you're not logged in