scsh-users
[Top] [All Lists]

Re: Won't output...

To: scsh-news@zurich.ai.mit.edu
Subject: Re: Won't output...
From: Ray Dillinger <bear@sonic.net>
Date: Mon, 22 Apr 2002 23:20:33 GMT

utdrmac wrote:

> Here is my translated scheme. Again, I am not too familiar with it. I made
> this in about 20 min. If you have a better more efficient way, please pass
> is along.
> 
> (define ackerman
>   (lambda (m n)
>             (cond ((= m 0)
>                   (* 2 n))
> 
>                   ((and (>= m 1) (= n 0))
>                   0)
> 
>                   ((and (>= m 1) (= n 1))
>                    2)
> 
>                   (else
>                    (ackerman (- m 1) (ackerman m (- n 1)))))
>             ))

your code is correct.  

 
> I cannot get this one to work:  (ackerman 3 4)
> I left my comp running for about 1 min before I stopped it and it still
> hadn't given me anything.

In order to understand what is happening, try annotating your 
program so you can watch what's going on.

;=================clip==========================

;; first a function we can use to print the 
;; value of something we're working with without stopping 
;; the calculation.

(define print-and-return
        (lambda (z)
           (begin
              (print z)
              (print "   ")
              z)))


;; Then a slightly modified ackerman function
;; based on yours above.

 (define ackerman
    (lambda (m n)
             (cond ((= m 0) (* 2 n))
                   ((and (>= m 1) (= n 0))  0)
                   ((and (>= m 1) (= n 1))  2)
                   (else
                      (ackerman (- m 1) 
                      (print-and-return (ackerman m (- n 1))))))))

;==================clip=======================

This ackerman is just like your ackerman except that it 
prints intermediate results as it finds them. 

Running it won't get you results any better than the ones 
you've already got, but running it should give you some 
idea *why* you didn't get results when you tried it. 


                                Bear

<Prev in Thread] Current Thread [Next in Thread>