For Programmers: Free Programming Magazines  


Home > Archive > Scheme > March 2008 > Beginner question: can't identify the error (mzscheme)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2008-03-17, 10:19 pm

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?...zd6j06x6s6sh7w6):


(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

2008-03-17, 10:19 pm

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

2008-03-17, 10:19 pm

On Mar 17, 7:03 pm, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu>
wrote:

>
> 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

2008-03-17, 10:19 pm

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

2008-03-18, 4:44 am

On Mon, 17 Mar 2008 11:10:09 -0700 (PDT), Bjoern
<BjoernGT@googlemail.com> wrote:

>On Mar 17, 7:03 pm, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu>
>wrote:
>
>
>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...


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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com