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))
wwolf
in reply to Jonathan Lamothe • • •Sensitive content
try `apply`:
(apply 'concat (my-function arg1 arg2))
Jonathan Lamothe
in reply to wwolf • •@wwolf Ohh... that feels much safer.
Thanks!
hajovonta
in reply to Jonathan Lamothe • • •Sensitive content
(concat . (my-function arg1 arg2))
is really:
(concat my-function arg1 arg2)
Try to visualize the cons cells (and re-read how Lisp represents lists as cons cells) to understand why.
So this is actually correct.
Jonathan Lamothe
in reply to hajovonta • •@hajovonta Yup. Got my answer.
I had figured out why it wasn't working. I was just unaware of the existence of the
applyfunction, which turned out to be exactly what I needed.Thuna
in reply to Jonathan Lamothe • • •Sensitive content
Jonathan Lamothe
in reply to Thuna • •@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.