2

I have a defun get-quotes with one mandatory and 2 optional arguments. I would like to do something like this:

(let ((articles 
       '("/home/matt/art/mice.pdf" '("/home/matt/art/cats.pdf" "Smith, "Neural Pathways in Cat Brains" 3)))
  (dolist (thisarticle articles)
     (get-quotes (SOMEFUNCTION thisarticle)))

Where SOMEFUNCTION checks thisarticle, and if it's a string, passes it directly as an argument, or if it's a list, makes it available to get-quotes as a set of elements (rather than a list object). My understanding of elisp is pretty vague, so I may be missing some fundamental point. Many thanks for the help!

The possible dupe in @Drew's post is quite helpful, but since the new answer from @abo-abo was a little easier for me to follow, I'm going to accept it rather than the slightly more technical answer in the earlier question. Thanks to everyone though.

Drew
  • 75,699
  • 9
  • 109
  • 225
Matt
  • 105
  • 5

1 Answers1

2

Something like this, the new function to learn is apply:

(defun get-quotes (x &rest y)
  (cons x y))
(let ((articles
       '("/home/matt/art/mice.pdf"
         ("/home/matt/art/cats.pdf"
          "Smith, \"Neural Pathways in Cat Brains\""
          3))))
  (dolist (thisarticle articles)
    (if (stringp thisarticle)
        (get-quotes thisarticle)
      (apply 'get-quotes thisarticle))))
abo-abo
  • 13,943
  • 1
  • 29
  • 43