From: Paul Donnelly
Subject: Re: Problem in beta reduction
Date: 
Message-ID: <87y74k4wmh.fsf@plap.localdomain>
suchi <··············@gmail.com> writes:

> (define (reduce
> f)
>   ((lambda (value) (if (equal? value f) f (reduce
> value)))
>    (let r ((f f) (g
> ()))
>      (cond ((not (pair?
> f))
> 	    (if (null? g) f (if (eq? f (car g)) (cadr g) (r f (caddr g)))))
> 	   ((and (pair? (car f)) (= 2 (length f)) (eq? 'lambda (caar f)))
> 	    (r (caddar f) (list (cadar f) (r (cadr f) g) g)))
> 	   ((and (not (null? g)) (= 3 (length f)) (eq? 'lambda (car f)))
> 	    (cons 'lambda (r (cdr f) (list (cadr f) (delay (cadr f)) g))))
> 	   (else (map (lambda (x) (r x g)) f))))))
>
> This piece of code is supposed to do beta and alpha reduction. But
> when I try to run it, it gives me an error saying reduce as been
> redefined. I am unable to figure out why is that. Any ideas?

Because there is already a function named REDUCE (which does something
unrelated), and you're redefining it. Since you're getting an error
rather than just a warning, your Scheme probably protects built-in
functions. How about calling your function something like LC-REDUCE to
resolve the collision?
From: Paul Donnelly
Subject: Re: Problem in beta reduction
Date: 
Message-ID: <87r6ac6lcl.fsf@plap.localdomain>
suchi <··············@gmail.com> writes:

> On Jul 2, 2:40 am, Paul Donnelly <·············@sbcglobal.net> wrote:
>> suchi <··············@gmail.com> writes:
>> > (define (reduce f)
>> >   ((lambda (value) (if (equal? value f) f (reduce value)))
>> >    (let r ((f f) (g()))
>> >      (cond ((not (pair? f))
>> >        (if (null? g) f (if (eq? f (car g)) (cadr g) (r f (caddr g)))))
>> >       ((and (pair? (car f)) (= 2 (length f)) (eq? 'lambda (caar f)))
>> >        (r (caddar f) (list (cadar f) (r (cadr f) g) g)))
>> >       ((and (not (null? g)) (= 3 (length f)) (eq? 'lambda (car f)))
>> >        (cons 'lambda (r (cdr f) (list (cadr f) (delay (cadr f)) g))))
>> >       (else (map (lambda (x) (r x g)) f))))))
>>
>> > This piece of code is supposed to do beta and alpha reduction. But
>> > when I try to run it, it gives me an error saying reduce as been
>> > redefined. I am unable to figure out why is that. Any ideas?
>>
>> Because there is already a function named REDUCE (which does something
>> unrelated), and you're redefining it. Since you're getting an error
>> rather than just a warning, your Scheme probably protects built-in
>> functions. How about calling your function something like LC-REDUCE to
>> resolve the collision?
>
>
> It doesn't give me that error now.. Another problem in (let r ((f f)
> (g())) though, it now says:
>
> #%app: missing procedure expression; probably originally (), which is
> an illegal empty application in: (#%app)
>
> Any idea what it means?

It means that you forgot to quote the empty list you're attempting to
bind G to. Since you wrote () instead of '() or (quote ()), it's
attempting to evaluate (). Since its car isn't a function (rather,
it's nothing), you get an error telling you that you can't apply
nothing (illegal empty application). It even points out that you
probably caused this by writing () without quoting it.