Created
July 21, 2012 01:07
Revisions
-
unionx created this gist
Jul 21, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ ;;;;;; iteration in common lisp ;;;; do ;; `do` is like `if` in c (do ((x 1 (+ x 1)) (y 1 (* y 2))) ((> x 5) y) ;; when x is bigger than 5, return y (print y) (print 'working)) ;;; output ;; 1 ;; WORKING ;; 2 ;; WORKING ;; 4 ;; WORKING ;; 8 ;; WORKING ;; 16 ;; WORKING ;;; return value ;; 32 ;;;; dotimes ;; `dotimes` is like `range` or `range` in python (let ((x 1)) (dotimes (num 10) (setq x (* x 2))) (print x)) ;;; output ;; 1024 ;;; return value ;; T (print (dotimes (num 10 (+ num 5)))) ;;; output ;; 15 ;;; return value ;; T ;;;; dolist ;; `dolist` is like `foreach` in java (dolist (x '(1 2 3)) (print x)) ;;; output ;; 1 ;; 2 ;; 3 ;;; return value ;; T ;;;;;; `loop` is more powerful for iteration