arc> (mac iter (var list . body) (let i (uniq) `(if (is nil ,list) nil (withs (els ,list ,i 0 ,var (els ,i) next (fn () (++ ,i))) (while (< ,i (len els)) (= ,var (els ,i)) ,@body (next)))))) #(tagged mac #<procedure: iter>) arc> (iter a '(1 2 3) (prn a)) 1 2 3 nil arc> (iter els '(1 2 3) (prn els)) Error: "car: contract violation\n expected: pair?\n given: 1" arc> (iter a '(a b c d) (prn a ", " (next))) a, 1 c, 3 nil
(mac iter (var lst . body) (w/uniq (i elst) `(let ,elst ,lst (if (is ,elst nil) nil (withs (,i 0 ,var (,elst ,i) next (fn () (++ ,i) (= ,var (,elst ,i)))) (while (< ,i (len ,elst)) (= ,var (,elst ,i)) ,@body (++ ,i)))))))
-----