Questions tagged [mapping]

30 questions
19
votes
5 answers

Map a function across a property list?

Q: what is the idiomatic way to map a function across a property list? The various mapping functions (mapcar and family) map a function over a sequence such as a list. How does one use these functions when dealing with a property list, i.e., when…
Dan
  • 32,584
  • 6
  • 98
  • 168
18
votes
5 answers

How can I map over a vector and get a vector?

The only thing I've found that works is (eval `(vector ,@(mapcar #'1+ [1 2 3 4]))) => [2 3 4 5] but that seems far too complicated to be the 'right' way.
Sean Allred
  • 6,861
  • 16
  • 85
16
votes
4 answers

Is there an idiomatic way of reading each line in a buffer to process it line by line?

In Python I'd do the following to process a file line by line: with open(infile) as f: for line in f: process(line) Trying to look up how to do the same in elisp (with buffers instead of files), I found no obvious way. (What I want to…
The Unfun Cat
  • 2,393
  • 16
  • 32
9
votes
3 answers

How to apply mapcar to a function with multiple arguments

I have packages variables that have list of github users and package names. (defvar packages '('("auto-complete" . "auto-complete") ("defunkt" . "markdown-mode"))) I want to git clone if the file is not exist yet. (defun…
ironsand
  • 403
  • 3
  • 14
8
votes
1 answer

Speed up org-map-entries when matching by property

Question: Why is org-map-entries property matching so slow, and what can I do to speed it up? Background: I have a relatively simple use for org-map-entries: grab the effort (in integer minutes) from all org agenda entries with tag goal and a given…
holocronweaver
  • 1,319
  • 10
  • 22
6
votes
2 answers

Emacs - Understand elisp syntax (mapcar '1+ '(2 4 6))

I saw this example code: (mapcar '1+ '(2 4 6)) ⇒ (3 5 7) But I do not understand '1+ here. it will apply a function to a list but this style obviously not like a function. If means add, the function should be +, what does '1+ mean?
beetlej
  • 1,056
  • 1
  • 7
  • 20
6
votes
1 answer

How can I translate my .vimrc into evil-mode

I have heard of the power of Emacs, but I have a ton more experience with vim and an extensive amount of shortcuts in my .vimrc file. I would like to transfer these mappings over to Emacs evil-mode. What would be the best way to do this? One example…
Jason Basanese
  • 215
  • 2
  • 7
4
votes
2 answers

mapcar but return non-nil element only

Is there a function that applies a transformation to a sequence and returns only the non-nil values? Right now I am using the following (as an example): (seq-filter #'identity (mapcar (lambda (x) (when (< x 3) (+ x…
Tohiko
  • 1,589
  • 1
  • 10
  • 22
4
votes
4 answers

Combine two lists elementwise

I need to combine two lists elementwise. Given two lists that look something like, (setq qux '("foo" "bar" "baz")) (setq quux '("xyzzy" "thud" "blat")) I need to use each corresponding element to form a new list, ("foo:xyzzy" "bar:thud"…
Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
4
votes
2 answers

How do I splat the arguments to the `or` function?

I would like to evaluate a list of booleans like (nil nil t) into a single boolean, such that if any element is true, then the expression evaluates to true. I first looked at the (or) function in elisp, but it does not take a list of booleans as an…
Linus Arver
  • 152
  • 1
  • 6
4
votes
4 answers

Map function onto nested list?

Q: how can I map a function onto elements of nested lists? For flat lists, we can use mapcar to apply a function to each element of the list: (setq flat '("kittens" "puppies" "otters" "bunnies")) (mapcar #'upcase flat) ; =>…
Dan
  • 32,584
  • 6
  • 98
  • 168
4
votes
1 answer

Function to allow select a directory and run a command on its files, descending recursively?

I sometimes work on legacy code, and they have mixture of tabs and spaces. I use whitespace-cleanup function in whitespace.el to clean them up. But I have many files, so i want to run the command on all of them (excluding the .git directory). What…
biocyberman
  • 962
  • 7
  • 17
3
votes
1 answer

How to add a value after a given value in parts of a list, returning a new list?

I have the following structure: '((a (1 2 3 4)) (b (1 2)) (c (1 3 4 5)) I want to return a new list that's similar, but that has a 7 inserted after each 2: '((a (1 2 7 3 4)) (b (1 2 7)) (c (1 3 4 5)) How can I do this?
shackra
  • 2,702
  • 18
  • 47
3
votes
1 answer

How to map or iterate over a list of files and set the result to `org-agenda-files`?

looking for a little help with my function. I'm trying to create a loop-while that'll return a list of files back to org-agenda-files. It's just not working though and i keep getting errors. Any ideas how I can get this to work? Any using a…
3
votes
1 answer

Why does Flycheck complain "mapcar called for effect" when my function returns the result of mapcar by design?

Since installing Flycheck I've been bombarded with complaints about the elisp functions I've used reliably for years. This is the first one I can't understand. Here my function is designed to return the result of mapcar, not to produce side…
1
2