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.
Dave Marquardt
in reply to Jonathan Lamothe • • •I was wondering why not use "if" rather than "when" here. Well, if is a bit different in that it only allows a single expression as the THEN part. But I wasn't so wrong. "when" is defined as a macro essentially like this:
(list 'if cond (cons 'progn body))
Jonathan Lamothe
in reply to Dave Marquardt • •whenwhen I don't have anelseclause. That way I don't have to bother with aprogn. I just wish that I had thought to extend that logic toand.Jonathan Lamothe
in reply to Jonathan Lamothe • •I should probably throw some comments in here, but essentially the
associn thewhenblock always returnsnilon the first iteration of the loop, and if it can't progress past that point, it'll always returnnilon subsequent loops and nothing will ever happen. As a result, any list I might feed into this function is always going to result in aniloutput.