Common Lisp宏学习之 LOOP


实例1:输出list

(loop for i from 1 to 10 collecting i)
;;output  (1 2 3 4 5 6 7 8 9 10)

实例2:计算1到10的平方和

(loop for x from 1 to 10 summing (expt x 2))
;;equal   (+ (expt 1 2) (expt 2 2) ... (expt 10 2))

实例3:统计在一个字符串中元音字母出现的次数

(loop for x across "the quick brown fox jumps over the lazy dog"
      counting (find x "aeiou"))
;; output  11

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注