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

Question

25 views
Skip to first unread message

Forty-Two

unread,
Apr 28, 2012, 12:38:10 PM4/28/12
to
When I do something like

(define (conv3 x y z) (
(+ (+ (* x 1) (* y 10)) (* z 100))))


and then invoke it with

(conv3 1 2 3)


I get the error

Backtrace:
In standard input:
43: 0* [conv3 1 2 3]
41: 1 [321]

standard input:41:23: In expression ((+ # #)):
standard input:41:23: Wrong type to apply: 321
ABORT: (misc-error)


Of course, when I substitute the variables in like

(+ (+ (* 1 1) (* 2 10)) (* 3 100))

I get the desired response, 321.

Barry Margolin

unread,
Apr 28, 2012, 12:59:43 PM4/28/12
to
In article
<27551567.1159.1335631090660.JavaMail.geo-discussion-forums@vbqq1>,
You have an extra set of parentheses around the expression in the
function. The parenthesis at the end of the first line is not needed.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Nils M Holm

unread,
Apr 28, 2012, 1:48:33 PM4/28/12
to
Forty-Two <sea...@gmail.com> wrote:
> (define (conv3 x y z) (
> (+ (+ (* x 1) (* y 10)) (* z 100))))

That's why proper indentation is so important:

(define (conv3 x y z)
((+ (+ (* x 1) (* y 10)) (* z 100))))

See what's wrong?

BTW, + is variadic, so you can just write

(define (conv3 x y z)
(+ (* x 1)
(* y 10)
(* z 100)))

--
Nils M Holm < n m h @ t 3 x . o r g > www.t3x.org

Forty-Two

unread,
Apr 28, 2012, 2:31:50 PM4/28/12
to
Thanks, both of you. I wasn't aware that the + function took multiple arguments, Nils, or of the extra set of parenthetis, barry. The code works great now.
0 new messages