Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Beginner question: can't identify the error (mzscheme)

0 views
Skip to first unread message

Bjoern

unread,
Mar 17, 2008, 1:44:56 PM3/17/08
to
Hello,

I get the error

procedure application: expected procedure, given: 0; arguments were:
(0)

But I can't figure out where from. Any advice? What is a good way to
find it, I am using emacs+mzscheme.

My code (trying to brute force answer to #2 in this collection of
maths riddles http://www.scribd.com/full/2264371?access_key=key-7nt5zd6j06x6s6sh7w6):


(define (min-cost steps)
(let ((min 0))
(let loop ((fail-index 0))
(if (>= fail-index (length steps))
min
(let ((tmp-min (+ fail-index (list-ref steps fail-index))))
(when (> tmp-min min) (set! min tmp-min))
(loop (+ fail-index 1)))))))


;find best (= min worst case costs) arrangement of step-count steps
that sum to n
(define (min-steps steps-count n)
(let calc-minimum ((steps '(0)))
(display (list "steps" steps))
(let ((sum (apply + steps)))
(cond
((> sum n);illegal combination
(display "illegal")
(list n steps))
((= (length steps) (- steps-count 1))
(display "final step")
(let* ((last-step (cons (- n sum) steps))
(cost (min-cost last-step)))
(display (list "cost" cost last-step))
(newline)
(cons cost last-step)))
(else
(display (list "calc-minimum" calc-minimum))
(let* ((steps-inc (cons (+ 1 (car steps)) (cdr steps)))
(min-inc (calc-minimum steps-inc))
(steps-next (cons (0 steps)))
(min-next (calc-minimum steps-next)))
(if (> (car min-inc) (car min-next))
min-next
min-inc)))))))


(min-steps 3 10)

Abdulaziz Ghuloum

unread,
Mar 17, 2008, 2:03:23 PM3/17/08
to
Bjoern wrote:
> Hello,
>
> I get the error
>
> procedure application: expected procedure, given: 0; arguments were:
> (0)
>
> But I can't figure out where from. Any advice? What is a good way to
> find it

> (steps-next (cons (0 steps)))

You can just read your code to see where the error is coming from.
Eyes usually make a good tool for spotting errors.

Aziz,,,

Bjoern

unread,
Mar 17, 2008, 2:10:09 PM3/17/08
to
On Mar 17, 7:03 pm, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu>
wrote:

> > (steps-next (cons (0 steps)))
>
> You can just read your code to see where the error is coming from.
> Eyes usually make a good tool for spotting errors.

Many thanks! I guess I was so used to other programming languages that
I expected cons(a b) instead of (cons a b). Really, I looked at it for
quite a while...

Jens Axel Soegaard

unread,
Mar 17, 2008, 7:34:14 PM3/17/08
to
Bjoern wrote:

> I get the error
>
> procedure application: expected procedure, given: 0; arguments were:
> (0)
>
> But I can't figure out where from. Any advice? What is a good way to
> find it, I am using emacs+mzscheme.

The easiest is to run it in DrScheme. You'll find that the
expression (0 steps) is colored red.

--
Jens Axel Søgaard

George Neuner

unread,
Mar 17, 2008, 11:57:10 PM3/17/08
to

Try scanning your code backwards - it's a proof-reading trick that
makes spelling and local grammar errors stand out. Reading forward,
your expectations can blind you to the errors.

George
--
for email reply remove "/" from address

0 new messages