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)
> (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,,,
> > (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...
> 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
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