Arc Forumnew | comments | leaders | submitlogin
2 points by akkartik 3144 days ago | link | parent

Yes you don't need the nil argument. Since make-list returns a list, do the conses on the way out of recursive calls rather than on the way in:

  (def make-list (size val)
    (if (> size 0)
      (cons val
            (make-list (- size 1) val))))
This is identical to your version, except I dropped the now-unnecessary base case (if now generates the initial list at the bottom-most recursive call) and moved the cons outside the call to make-list.


2 points by jsgrahamus 3144 days ago | link

Great. Still wrapping my head around recursion.

Thanks.

-----