[plt-scheme] redefinition of built in function needs to be done twice to be recursive?

From: John Lawrence Aspden (news at aspden.com)
Date: Tue Sep 30 09:50:01 EDT 2008

Hi, in the process of porting a program with a different definition of assq,
I encountered some behaviour which I'm having trouble understanding:

pasted verbatim from interactions window, definitions window contains (only)
#lang scheme, run button freshly pressed:

Welcome to DrScheme, version 4.1.0.3 [3m].
Language: Module; memory limit: 228 megabytes.
> (define (assq a alist) (if (null? alist) #f (if (eq? (caar alist) a) alist
(assq a (cdr alist)))))
> (assq 'b '((a . 1)(b . 2)))
(b . 2)
> (define (assq a alist) (if (null? alist) #f (if (eq? (caar alist) a) alist
(assq a (cdr alist)))))
> (assq 'b '((a . 1)(b . 2)))
((b . 2))
> 

It seems that the first definition works like let and the second (identical)
definition works like letrec.

It doesn't happen if you put the definitions in the definition window, and
it doesn't seem to happen if the function's called my-assq.

Can anyone explain what's going on? 

Cheers, John.

-- 
Contractor in Cambridge UK -- http://www.aspden.com



Posted on the users mailing list.