Re: Storing values separately for cl-loop
tpeplt <[email protected]> Fri, 10 Jul 2026 10:45:26 -0400
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
Heime <[email protected]> writes: > On Saturday, July 11th, 2026 at 12:34 AM, tpeplt <[email protected]> wrote: > >> Heime <[email protected]> writes: >> >> > How can I store the result of (format "%s %s%d%s%s" prefix "<" i ">" tag) >> > separately for cl-loop? >> > >> > (let ( (prefix (if (= (length comment-start) 1) >> > ;; Single character comment start >> > (make-string 3 (string-to-char comment-start)) >> > ;; Multiple character comment start >> > comment-start)) >> > (tag (if tag (format "%s" tag) "")) ) >> > (cl-loop for i from 1 to n >> > collect (cons (format "%s %s%d%s%s" prefix "<" i ">" tag) >> > i))) >> > >> >> Can you describe or provide an example of the output of >> ‘cl-loop’ that you are attempting to produce? It is unclear >> (to me, at least) what you are asking. > > I want to have the following line > collect (cons var i))) > > where var is constructed previously from (format "%s %s%d%s%s" prefix "<" i ">" tag) > > The cl-loop output would be something like '((";;; <1>kc") . 1) (";;; <2>kc") . 2)) The following expression will generate that result: (let ((prefix (if (= (length comment-start) 1) ;; Single character comment start (make-string 3 (string-to-char comment-start)) ;; Multiple character comment start comment-start)) (tag (if 'kc (format "%s" 'kc) ""))) (cl-loop for i from 1 to 2 for my-string = (format "%s %s%d%s%s" prefix "<" i ">" tag) collect (cons my-string i))) See (info "(cl) For Clauses"). The FOR clause has many variations/capabilities. The use above is described in the subsection that begins with the text: ‘for VAR = EXPR1 then EXPR2’ As it says there, "If you omit the ‘then’ term, EXPR1 is used both for the initial setting and for successive settings..." -- The lyf so short, the craft so long to lerne. - Geoffrey Chaucer, The Parliament of Birds.