When I do something like


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


and then invoke it with


Code:
(conv3 1 2 3)


I get the error


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


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


I get the desired response, 321.

EDIT: nevermind; there was an extra set of parentheses.
Glad you found your error Smile Also, I'm against the special syntax for defining, not that it really matters. I think
Code:
(define conv3
  (lambda (x y z)
    (+ (+ (* x 1) (* y 10) (* z 100)))))
looks a lot cleaner, and emphasizes that functions aren't any different from regular numbers/values/cells. Also, if you're going to do a lot of Scheme, I would recommend either: a) using Emacs with some Scheme mode, b) getting a different editor that can help balance your parentheses, or c) tabbing out your code. Any of those would help with coding (And, (a) actually does (b) and (c) for you Wink). Just my two cents Razz
_player1537 wrote:
Glad you found your error :) Also, I'm against the special syntax for defining, not that it really matters. I think
Code:
(define conv3
  (lambda (x y z)
    (+ (+ (* x 1) (* y 10) (* z 100)))))
looks a lot cleaner, and emphasizes that functions aren't any different from regular numbers/values/cells. Also, if you're going to do a lot of Scheme, I would recommend either: a) using Emacs with some Scheme mode, b) getting a different editor that can help balance your parentheses, or c) tabbing out your code. Any of those would help with coding (And, (a) actually does (b) and (c) for you ;)). Just my two cents :P


eeeeeewww, emacs (Has /usr/bin/emacs been moved to /bin/shells yet?)

Anyway, I've found another conundrum:


Code:
guile> (define (interest amount) 
(cond
 [(<= amount 1000) .04]
 [(<= amount 5000) .045]   
 [(> amount 5000) .05])
)
guile> (interest 4000)


yields


Code:
Backtrace:
In standard input:
 197: 0* [interest 4000]
 192: 1  (cond [ (<= amount 1000) ...)

standard input:192:1: In procedure memoization in expression (cond [ (<= amount 1000) ...):
standard input:192:1: In file "standard input", line 191: Bad cond clause [ in expression (cond [ (<= amount 1000) .04] [ (<= amount 5000) .045] [ (> amount 5000) .05]).
ABORT: (syntax-error)


I'm not sure where this came from, as it was copied straight from the text I was using... (http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-7.html)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement