Skip to content

Instantly share code, notes, and snippets.

@cmpitg
Created August 11, 2012 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmpitg/3324442 to your computer and use it in GitHub Desktop.
Save cmpitg/3324442 to your computer and use it in GitHub Desktop.
(defun suml (lst res)
(if (zerop (list-length lst))
res
(suml (rest lst) (+ res (first lst)))))
(suml '(1 2 3 4 5) 0)
@ngnguyen1
Copy link

Ồ. Phải dùng 2 tham số. Hay thiệt. :-)

@ngnguyen1
Copy link

Thầy ơi. Em không hiểu đoạn sau ạ: (suml (rest lst) (+ res (first lst))) Sẽ gọi hàm suml với 2 tham số (res lst) và (+ res (first list)). Nhưng cái (first list) sẽ trả về phần tử đầu tiên của list, như vậy lấy res của list đó thế nào ạ? :-(

@cmpitg
Copy link
Author

cmpitg commented Aug 14, 2012

res là "result" mà bạn. Bạn đọc kỹ lại nhé, rest với res là khác nhau đấy nhé.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment