2

makelist is a procedure that takes an item and an integer n and returns the item n amount of times.

(define (makelist (n item)
    (cond
      [(null? item) '()]
      [else (cons item (makelist (- n 1)))])))

my procedure returns a syntax error, can anybody help me out?

leppie
  • 115,091
  • 17
  • 196
  • 297
Frankie V.
  • 23
  • 3

1 Answers1

1

You can just use: (make-list n item) :)

Your syntax error is due to incorrect define.

It should be:

(define (makelist n item) ...  

Note that you have a extra ( before the n.

leppie
  • 115,091
  • 17
  • 196
  • 297
  • @FrankieV. - If you're going to be programming in lisp for any length of time, look into [autopairs](http://www.emacswiki.org/emacs/AutoPairs) or [paredit](http://www.emacswiki.org/emacs/ParEdit) or both. A [highlighter](http://www.emacswiki.org/emacs/HighlightParentheses) wouldn't hurt either. I'm sure comparable utilities exist for whatever editor you're using, even if it isn't Emacs. No Lisper I know keeps track of parens manually. – Inaimathi Oct 09 '12 at 14:06
  • Indeed, Vim has a Scheme syntax module and will help track your parentheses ;) – itsbruce Oct 09 '12 at 16:57