| Deutsch English Français Italiano |
|
<104bal0$1h7q3$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <Nobody447095@here-nor-there.org> Newsgroups: comp.lang.lisp,comp.lang.scheme Subject: Re: Looping over array. Date: Sat, 5 Jul 2025 13:51:29 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: <104bal0$1h7q3$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Sat, 05 Jul 2025 15:51:30 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9c931ee261b5fb5197d719e3aa390286"; logging-data="1613635"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/r6+DAq3i4cdwIyoWQGTts" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:pRgSTIotjauJCfM+4NHRq8P3sKo= Christopher Browne wrote: > (loop with array = #(1 4 9 16 "Foo" "Bar" 'frobozz |Bogomatic|) > for i across array > for j from 0 by 1 > do > (format t "Element ~D is ~A~%" j i)) > Element 0 is 1 > Element 1 is 4 > Element 2 is 9 > Element 3 is 16 > Element 4 is Foo > Element 5 is Bar > Element 6 is 'FROBOZZ > Element 7 is Bogomatic We can make it shorter by using a Lispy language instead of CL. Gauche Scheme (use srfi-43) ;; vector-for-each (vector-for-each (cut print "Element " <> " is " <>) #(1 4 9 16 "Foo" "Bar" 'frobozz |Bogomatic|)) Element 0 is 1 Element 1 is 4 Element 2 is 9 Element 3 is 16 Element 4 is Foo Element 5 is Bar Element 6 is 'frobozz Element 7 is Bogomatic Another vector library. (use scheme.vector) (vector-for-each-with-index (cut print "Element " <> " is " <>) #(1 4 9 16 "Foo" "Bar" 'frobozz |Bogomatic|))