Skip to main content


elisp question

I just put a call to eval in my code and I feel dirty now.

The context went something like this:

(eval (cons 'concat (my-function arg1 arg2)))

I had initially hoped to use
(concat . (my-function arg1 arg2))

...but this resulted in a call to
(concat my-function arg1 arg2)

Which was not what I expected.

Is there a better way I could've written this?
#emacs #lisp #elisp

Edit: Got my answer. I wanted:

(apply 'concat (my-func arg1 arg2))

Edit 2:
It turns out the code I really wanted was:

(string-join arg2 arg1)

I love reinventing the wheel because I didn't know it was already there.

Edit 3:
Here's the actual code:

(defun lambdamoo-run-text-replacements (str)
  "Perform text replacements on the string"
  (dolist (vals lambdamoo-text-replacements)
    (let* ((from (car vals))
           (to (cdr vals))
           (split (split-string str from)))
      (setq str (string-join split to))))
  str)

Let's see if there's anything else I've reinvented here.
in reply to Jonathan Lamothe

elisp question

Sensitive content

in reply to Jonathan Lamothe

elisp question

Sensitive content

This entry was edited (13 hours ago)
in reply to hajovonta

elisp question

@hajovonta Yup. Got my answer.

I had figured out why it wasn't working. I was just unaware of the existence of the apply function, which turned out to be exactly what I needed.

in reply to Jonathan Lamothe

elisp question

Sensitive content

in reply to Thuna

elisp question

@Thuna ...and this is why I wish I could search for functions by type signature like in Haskell. 😛

I find myself reinventing the wheel oftentimes simply because I didn't know the function I wanted already existed.

in reply to Jonathan Lamothe

elisp question
@Thuna What's funny is I just looked at the documentation for string-join, and it even includes other functionality that I had implemented myself. It allowed me to delete an entire other function.
in reply to Jonathan Lamothe

elisp question

Sensitive content

in reply to tusharhero

elisp question
@tusharhero Oh, I very much do, unless you're suggesting some additional change to the dolist loop.

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.