From: Chris Manuel
Subject: SCHEME question
Date: 
Message-ID: <3630922C.26A9E3A2@acadiau.ca>
HI;

I have this recursion program in Scheme and I am not sure on how it goes
about getting the answer:

(define (flip L) (if (null? L) () 
                               (append (flip (cdr L)) 
                                       (cons (car L) ()))))

1 ]=> (flip '(a b c))

;Value 1: (c b a)

can anyone explain to me how this reverses what u pass as parameters?
Thanks

Chris Manuel

From: Rainer Joswig
Subject: Re: SCHEME question
Date: 
Message-ID: <joswig-2310981651050001@pbg3.lavielle.com>
In article <·················@acadiau.ca>, Chris Manuel
<·······@acadiau.ca> wrote:

> HI;
> 
> I have this recursion program in Scheme and I am not sure on how it goes
> about getting the answer:
> 
> (define (flip L) (if (null? L) () 
>                                (append (flip (cdr L)) 
>                                        (cons (car L) ()))))
> 
> 1 ]=> (flip '(a b c))
> 
> ;Value 1: (c b a)
> 
> can anyone explain to me how this reverses what u pass as parameters?
> Thanks
> 
> Chris Manuel

I have next week's homework task for you:

  Please write a "better" implementation and explain your solution.

-- 
http://www.lavielle.com/~joswig
From: Chris Manuel
Subject: Re: SCHEME question
Date: 
Message-ID: <36309D67.1DEB4902@acadiau.ca>
Rainer Joswig wrote:
> 
> In article <·················@acadiau.ca>, Chris Manuel
> <·······@acadiau.ca> wrote:
> 
> > HI;
> >
> > I have this recursion program in Scheme and I am not sure on how it goes
> > about getting the answer:
> >
> > (define (flip L) (if (null? L) ()
> >                                (append (flip (cdr L))
> >                                        (cons (car L) ()))))
> >
> > 1 ]=> (flip '(a b c))
> >
> > ;Value 1: (c b a)
> >
> > can anyone explain to me how this reverses what u pass as parameters?
> > Thanks
> >
> > Chris Manuel
> 
> I have next week's homework task for you:
> 
>   Please write a "better" implementation and explain your solution.
> 
> --
> http://www.lavielle.com/~joswig

Umm, I dont know why u posted that under my article.
From: Chris Manuel
Subject: Re: SCHEME question
Date: 
Message-ID: <3630BD88.CBDCB997@acadiau.ca>
Windsor wrote:
> 
> In article <·················@acadiau.ca>, ·······@acadiau.ca says...
> > HI;
> >
> > I have this recursion program in Scheme and I am not sure on how it goes
> > about getting the answer:
> >
> > (define (flip L) (if (null? L) ()
> >                                (append (flip (cdr L))
> >                                        (cons (car L) ()))))
> >
> > 1 ]=> (flip '(a b c))
> >
> > ;Value 1: (c b a)
> >
> > can anyone explain to me how this reverses what u pass as parameters?
> > Thanks
> >
> > Chris Manuel
> >
> Here is an explanation in LISP fragments:
> 
> I assume you understand cdr, car, cons do.
> 
> 1. (append (flip (b c)) (a))
> 2.     (append (flip (c)) (b))
> 3.         (append (flip ()) (c))
> 4.            (cond ((null ()) ())) <= end the recursion and start
> returning "up"
> 
> Line 4 returns nil.
> Line 3 appends nil and (c) => (c)
> Line 2 appends (c) and (b) => (c b)
> Line 1 appends (c b) and (a) => (c b a)

So basically when you (append (flip (cdr L) L gets replaced by (b c)
then eventually works down to L being ()? 
And the append funtion works by appending c then b then a, therefore
giving you the reverse of (a b c) which is (c b a)?

Thanks a lot!!!!
From: Barry Margolin
Subject: Re: SCHEME question
Date: 
Message-ID: <WY6Y1.43$VI.493375@burlma1-snr1.gtei.net>
In article <·················@acadiau.ca>,
Chris Manuel  <·······@acadiau.ca> wrote:
>So basically when you (append (flip (cdr L) L gets replaced by (b c)
>then eventually works down to L being ()? 

If you have to ask this, it suggests that you don't know some of the
simplest things about function calling in Lisp or Scheme.  Before you can
understand recursion you need to understand function calling in general.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Chris Manuel
Subject: Re: SCHEME question
Date: 
Message-ID: <36310615.494E465A@acadiau.ca>
Barry Margolin wrote:
> 
> In article <·················@acadiau.ca>,
> Chris Manuel  <·······@acadiau.ca> wrote:
> >So basically when you (append (flip (cdr L) L gets replaced by (b c)
> >then eventually works down to L being ()?
> 
> If you have to ask this, it suggests that you don't know some of the
> simplest things about function calling in Lisp or Scheme.  Before you can
> understand recursion you need to understand function calling in general.
> 
> --
> Barry Margolin, ······@bbnplanet.com
> GTE Internetworking, Powered by BBN, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.

Believe me I know some of the simpilest things about function calling in
Scheme. This is just a program our prof gaves us today and Im trying to
figure it out...
From: Erik Naggum
Subject: Re: SCHEME question
Date: 
Message-ID: <3118233853184493@naggum.no>
* Chris Manuel <·······@acadiau.ca>
| Believe me I know some of the simpilest things about function calling in
| Scheme. This is just a program our prof gaves us today and Im trying to
| figure it out...

  I hear they are more sympathetic to using USENET for solving students'
  homework problems over in comp.lang.scheme, which is also more specific
  to your homework problem.  please don't tell them I sent you.  thank you
  for not posting homework problems to comp.lang.lisp in the future.

#:Erik
-- 
  The Microsoft Dating Program -- where do you want to crash tonight?