From: Sam Stickland
Subject: Mapping on deep-lists
Date: 
Message-ID: <3467A26D.7A8D@ecs.soton.ac.uk>
Hi,

I'm trying to write a mapping function for deep-lists but I can't get it
to work:

I'm using:

(define map-tree
  (lambda (f tree)
    (if (null? tree)
      '()
      (if (symbol? (car tree))
        (cons (f (car tree)) (map-tree f (cdr tree)))
      (cons (map-tree f (car tree)) (map-tree f (cdr tree)))
      )
    )
  )
)

but when I try something like:

(map-tree fact '(1 2 3 4))

I get the error:

ERROR: car: Wrong type in arg1 1

What am I doing wrong.

I have LOTS of things to do so I'd appreciate replies by email but here
is just fine also.

Sam

From: Sam Stickland
Subject: Re: Mapping on deep-lists
Date: 
Message-ID: <3467A2E2.559B@ecs.soton.ac.uk>
Sorrym forgot to add this is in Scheme, which is similar to the EuLisp
dialect.

Sam Stickland wrote:
> 
> Hi,
> 
> I'm trying to write a mapping function for deep-lists but I can't get it
> to work:
> 
> I'm using:
> 
> (define map-tree
>   (lambda (f tree)
>     (if (null? tree)
>       '()
>       (if (symbol? (car tree))
>         (cons (f (car tree)) (map-tree f (cdr tree)))
>       (cons (map-tree f (car tree)) (map-tree f (cdr tree)))
>       )
>     )
>   )
> )
> 
> but when I try something like:
> 
> (map-tree fact '(1 2 3 4))
> 
> I get the error:
> 
> ERROR: car: Wrong type in arg1 1
> 
> What am I doing wrong.
> 
> I have LOTS of things to do so I'd appreciate replies by email but here
> is just fine also.
> 
> Sam
From: Kent M Pitman
Subject: Re: Mapping on deep-lists
Date: 
Message-ID: <sfwd8k7cwmd.fsf@world.std.com>
Sam Stickland <······@ecs.soton.ac.uk> writes:

> I'm trying to write a mapping function for deep-lists but I can't get it
> to work [...]  when I try something like:
>   (map-tree fact '(1 2 3 4))
> I get the error:
> ERROR: car: Wrong type in arg1 1

Try using (trace map-tree) before your call so you can see the recursive
calls printed out.  This will almost surely answer your question.

By the way, I didn't check, but at first glance I'm suspicious that you
are using symbol? and not atom? as your test for leaves.  Numbers are not
symbols, so that means as you visit them recursively, you'll probably be 
recursively mapping over the number and I bet that's maybe your source
of loss.  (I didn't try running your program, though, so can't be sure.)
From: Steve Austin
Subject: Re: Mapping on deep-lists
Date: 
Message-ID: <slrn66h39f.3jk.steve_austin@boycat.kickham.com>
On Tue, 11 Nov 1997, Kent M Pitman <······@world.std.com> wrote:
>By the way, I didn't check, but at first glance I'm suspicious that you
>are using symbol? and not atom? as your test for leaves.

<big grin>
R4RS Scheme doesn't have an atom? predicate
</big grin>
 
--------------------------------------------------------------------------
Steve Austin                                   Powered by Linux since 1995 
············@bigfoot.com                                     RedHat 2.0.18
               Fight Spam - Join CAUCE - http://www.cauce.org
From: Kent M Pitman
Subject: Re: Mapping on deep-lists
Date: 
Message-ID: <sfw67pztdg7.fsf@world.std.com>
············@bigfoot.com (Steve Austin) writes:

> R4RS Scheme doesn't have an atom? predicate

Oops. I misread the previous message.  I thought he was working in Eulisp.

One can, of course, define atom? in R4RS with
 (define (atom? x) (not (pair? x)))

My point was really that one branch was about descending conses, and
whether it's guarded by a (pair? x) or an (atom? x) matters not; the
point is that (symbol? x) is not the right partition point because
that doesn't divide the world into conses and non-conses.
From: Steve Austin
Subject: Re: Mapping on deep-lists
Date: 
Message-ID: <slrn66h2pa.3jk.steve_austin@boycat.kickham.com>
On Tue, 11 Nov 1997, Sam Stickland <······@ecs.soton.ac.uk> wrote:
>
>(define map-tree
>  (lambda (f tree)
>    (if (null? tree)
>      '()
>      (if (symbol? (car tree))
            ^^^^^^^ 

This is the wrong predicate - symbol? isn't what you think it is.
Try (not(pair ...)).


--------------------------------------------------------------------------
Steve Austin                                   Powered by Linux since 1995 
············@bigfoot.com                                     RedHat 2.0.18
               Fight Spam - Join CAUCE - http://www.cauce.org