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.

  • Well, stringp returns true t if an object is a string, nil otherwise. Does that help? – Andrew Swann Nov 10 '15 at 14:19
  • Thanks Andrew, that did help. And drew, now that i have ab0abo's answer, the answers in that link help. – Matt Nov 11 '15 at 1:04
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))))

Not the answer you're looking for? Browse other questions tagged or ask your own question.