[plt-scheme] help - a simple dispatcher problem

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Dec 6 22:00:50 EST 2004

It's hard to tell what this code is supposed to do without the
definition of `pp'. But, you may want to read about `member' in the
manual.

Robby

At Mon, 06 Dec 2004 20:51:09 -0600, actuary77 at comcast.net wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I am trying to write a simple dispatcher and I am having scoping problems:
> The idea is to look up a symbol in a list:
> 
> 
> (define a '(x y z))      ; list to be used for lookup
> (define b '(i j k))
> 
> 
> (define (afunc)
> 
>    (define (dispatch m)     ;  dispatch
>      (let ((arg m))
> 	
>        (define (lookup n)     ;   lookup
> 	(let ((the-list arg))	
> 	  (set! arg m)
> 	  (pp the-list)
> 	(list-ref the-list n)))
>        lookup))
> 
>    dispatch)
> 
> 
> (begin
>    (define myfunc (afunc))
>    (define newfunc (myfunc 'a))
>    (newfunc 1))
> 
> ==>  returning error - 1 is not a list
>       it appears that the list a is being
> 	redefined by the symbol 'a or??
> 
> Question:
> 
> How can I rewrite to recognize the symbol a
> passed to myfunc as the orginial definition a?
> 
> If this makes any sense.
> 
> Thanks,
> 
> David Koch
> actuary77 at comcast.net


Posted on the users mailing list.