Questions tagged [iteration]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
17 views

Iterate with both value and index

I want to iterate over a list with both the index and the value in the loop. Currently, the code looks like this: (let ((my-list '(a b c))) (cl-loop for index below (length my-list) for ...
4
votes
3answers
79 views

idiomatic way to lexically scope variables in a cl-loop body

Here is some asynchronous code in a cl-loop: ;;; foo.el --- -*- lexical-binding: t; -*- (let ((my-list '(a b c))) (cl-loop for index below (length my-list) ...
0
votes
1answer
31 views

Confusion about iter-defun

I'd like to make an iterator that yields pairs: (0 1) (1 1) (1 2) (2 2) (2 3) (3 3) etc. I've tried variants of the following: (iter-defun iter-rectangle-sizes () (let ((rect '(0 1))) (while ...
0
votes
2answers
170 views

Loop through top-level headings in Emacs Org-mode

I want to apply (org-id-get-create) to every top-level heading in the buffer. How can I loop through all top-level org-mode headings in the current buffer?
0
votes
3answers
132 views

how to do a next in a elisp dotimes loop

By next I mean next as found in ruby/perl/python/etc #!/usr/bin/ruby for i in 0..5 if i < 2 then next end puts "Value of local variable is #{i}" end
3
votes
4answers
266 views

How to mapcar uneven lists?

I am aware I can use mapcar to join 2 lists into pairs, however all the map functions seem to quit at the shortest list. This for example (cl-mapcar #'concat '("1" "2" "3" "4") '("a" "b" "c")) ...
0
votes
1answer
71 views

Emacs loops mysteriously

I am using emacs 25.3 and I observe that one indentation function that I wrote loop mysteriously. My function goes following: (defun aut-indent-func () (interactive) (defun loop (begin) (...
1
vote
2answers
288 views

How to loop over every line in a buffer? [duplicate]

I am searching for some kind of reduce function, which loops through every line of a buffer, but I can not find it. Does anybody know the name of such a function? Something similar to Perl while (&...
1
vote
1answer
65 views

Searching for multiple items with occur

I am new to Emacs and I am trying to search for all words entered one by one using 'occur'. I am trying following code: (defun occurlist (ss) (interactive "s\Enter list of search items: ") (...
5
votes
1answer
60 views

How do I properly populate a function by iterating over an alist?

I've defined a function that is supposed to iterate over an alist, and use the CAR and CDR of each element in the list to populate the regexp in re-search-forward and the replacement string in replace-...
1
vote
2answers
220 views

Standard emacs lisp function for “collect-if”

Is there a standard emacs-lisp function replacement for (defun collect-if (PREDICATE LIST) (loop for el in LIST if (funcall PREDICATE el) collect el)) Example toy application: Extract the odd ...