Mercurial > emacs
comparison lisp/subr.el @ 27383:b1b3e778f7ac
Make the definitions of dolist and dotimes work
without the rest of CL.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 21 Jan 2000 03:38:12 +0000 |
parents | 674b7f75841e |
children | a10a13dd0670 |
comparison
equal
deleted
inserted
replaced
27382:f2499774f43c | 27383:b1b3e778f7ac |
---|---|
80 | 80 |
81 (defmacro dolist (spec &rest body) | 81 (defmacro dolist (spec &rest body) |
82 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list. | 82 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list. |
83 Evaluate BODY with VAR bound to each car from LIST, in turn. | 83 Evaluate BODY with VAR bound to each car from LIST, in turn. |
84 Then evaluate RESULT to get return value, default nil." | 84 Then evaluate RESULT to get return value, default nil." |
85 (let ((temp (gensym "--dolist-temp--"))) | 85 (let ((temp (make-symbol "--dolist-temp--"))) |
86 (list 'block nil | 86 (list 'let (list (list temp (nth 1 spec)) (car spec)) |
87 (list* 'let (list (list temp (nth 1 spec)) (car spec)) | 87 (list 'while temp |
88 (list* 'while temp (list 'setq (car spec) (list 'car temp)) | 88 (list 'setq (car spec) (list 'car temp)) |
89 (append body (list (list 'setq temp | 89 (cons 'progn |
90 (list 'cdr temp))))) | 90 (append body |
91 (if (cdr (cdr spec)) | 91 (list (list 'setq temp (list 'cdr temp)))))) |
92 (cons (list 'setq (car spec) nil) (cdr (cdr spec))) | 92 (if (cdr (cdr spec)) |
93 '(nil)))))) | 93 (cons 'progn |
94 (cons (list 'setq (car spec) nil) (cdr (cdr spec)))))))) | |
94 | 95 |
95 (defmacro dotimes (spec &rest body) | 96 (defmacro dotimes (spec &rest body) |
96 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times. | 97 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times. |
97 Evaluate BODY with VAR bound to successive integers running from 0, | 98 Evaluate BODY with VAR bound to successive integers running from 0, |
98 inclusive, to COUNT, exclusive. Then evaluate RESULT to get | 99 inclusive, to COUNT, exclusive. Then evaluate RESULT to get |
99 the return value (nil if RESULT is omitted)." | 100 the return value (nil if RESULT is omitted)." |
100 (let ((temp (gensym "--dotimes-temp--"))) | 101 (let ((temp (make-symbol "--dotimes-temp--"))) |
101 (list 'block nil | 102 (list 'let (list (list temp (nth 1 spec)) (list (car spec) 0)) |
102 (list* 'let (list (list temp (nth 1 spec)) (list (car spec) 0)) | 103 (list 'while (list '< (car spec) temp) |
103 (list* 'while (list '< (car spec) temp) | 104 (cons 'progn |
104 (append body (list (list 'incf (car spec))))) | 105 (append body (list (list 'setq (car spec) |
105 (or (cdr (cdr spec)) '(nil)))))) | 106 (list '1+ (car spec))))))) |
107 (if (cdr (cdr spec)) | |
108 (car (cdr (cdr spec))) | |
109 nil)))) | |
106 | 110 |
107 (defsubst caar (x) | 111 (defsubst caar (x) |
108 "Return the car of the car of X." | 112 "Return the car of the car of X." |
109 (car (car x))) | 113 (car (car x))) |
110 | 114 |