What am I doing wrong in this Scheme statement?

Started by
1 comment, last by swiftcoder 11 years, 3 months ago

(Note to Mods/Staff: Wasn't there a Functional or Lisp Prefix in the list before?)


(define (subtract-1 n)
  (string-append "Number is: " (number->string n))
  (cond
    [(= n 0) "All done!"]
    [else (subtract-1(- n 1))]))

I keep getting the error: define: expected only one expression for the function body, but found 1 extra part. I'm not understanding why I'm getting this.

Beginner in Game Development?  Read here. And read here.

 

Advertisement

I did never write a lot of scheme, but it looks to me like you have one closing parenthesis to much in line 2.

rnlf is correct - i'd advise you switch to an editor with better brace-highlighting.

The interpreter is seeing '(string-append "Number is: " (number->string n))' as a complete statement (because it is), with the cond expression incorrectly trailing afterwards.

[quote name='Alpha_ProgDes' timestamp='1358194237' post='5021553']
(Note to Mods/Staff: Wasn't there a Functional or Lisp Prefix in the list before?)[/quote]

For some reason it wasn't enabled in For Beginners (only in General/Game Programming). I have enabled both prefixes in For Beginners.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement