| notPythias 2007-08-27, 8:32 pm |
| Hello elder Schemers,
I just got this error:
;ERROR: "tmp/09f9.scm": even?: Wrong type in arg1 3.0
Does this mean even? expects an int and got a float?
By the way, this a learn-by-doing thing for me as I go through SICP, so
I would prefer answers phrased in terms of general debugging tactics
rather than specific instructions. If you have any advice for a Scheme
newbie post it, even if it has nothing to do with my question.
In particular, is there any kind of function reference for R5RS Scheme?
Google turns up a bunch of documents that look about right, but they're
all billed as Guile manuals and I thought that was a different
implementation tweaked to work with C/C++. In any case, none of them had
the sort of argument-type / return type / running time / etc. sort of
information I've come to expect of a function reference.
Hoping he's posted in the right place,
nP
---------------------- copy of the error message ------------------------
;ERROR: "tmp/09f9.scm": even?: Wrong type in arg1 3.0
; in expression: (#@even? #@exponent)
; in scope:
; (base exponent tmp) procedure **-iter
; (**-iter . #@define)
; (base exponent) procedure **-fast
; defined by load: "tmp/09f9.scm"
;STACK TRACE
1; ((#@cond ((#@< #@exponent 2) (* base tmp)) ((#@even? #@exponen ...
2; (#@let* ((first-place (#@truncate (#@/ (#@log #@value) (#@log ...
3; (#@convert-base 2 13)
------------------------- copy of my program -----------------------------
(define (**-fast base exponent)
(define (**-iter base exponent tmp)
(cond ((< exponent 2) (* base tmp))
((even? exponent) (**-iter (* base base) (/ exponent 2) tmp))
(#t (**-iter base (- exponent 1) (* tmp base)))))
(**-iter base exponent 1))
(define (convert-base base value)
(define (convert-base-iter value n place)
(if (= 0 n) '()
(cons (/ value place) (convert-base-iter (modulo value place)
(- n 1)
(/ place base)))))
(let ((first-place (truncate (/ (log value) (log base)))))
(convert-base-iter value first-place (**-fast base first-place))))
|