[plt-scheme] Question about map

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 3 15:45:11 EDT 2008

On Jul  3, Robby Findler wrote:
> AFAICT, EoPL works fine with the basic example you're giving. I'm
> still not able to divine what is going wrong:
> 
> Welcome to DrScheme, version 4.0.1.3-svn2jul2008 [3m].
> Language: Essentials of Programming Languages (2nd ed.); memory limit:
> 128 megabytes.
> > (map caadr (list '(lambda (x) x)))
> (x)

My guess is that there are two problems here: the first is that `map'
is bound to `mmap', and `caadr' is bound to a function that composes
`mcar' and `mcdr' -- and these make error messages confusing Marco
here:

> >>> My code does not use mcar anywhere. I must assume it has to do
> >>> with the implementation of map (?).



But the real problem is elsewhere:

> >>> This code: (map caadr localdefs)
> >>>
> >>> Produces this error:
> >>>
> >>> mcar: expects argument of type <mutable-pair>; given
> >>> #<undefined>

You must have some `undefined' value somewhere, and that's probably
due something that changed in the language.  (And because of the above
the error message doesn't help.)

To find the bad value I'd start with

  (map (lambda (x)
         (if (and (pair? x) (pair? (cdr x)) (pair? (cadr x)))
           (caadr x)
           (error 'blah "~s" x)))
       localdefs)

and go on from there.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.