This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

would like to enter multiple arguments w/o progn to defmacro

5 posts · 5252 views

here is the macro, it is used to time 1 or more functions:
  (defmacro $ (form &optional (count-form 1000000)) `(time (dotimes (_ ,count-form) ((lambda () ,form)))))
for 1 function I run like this:
($ (function))
for multiple functions I run like this:
($ (progn (function) (function)))
how can I make it so I can run multiple functions like this:
($ (function) (function))
any help is appreciated:)

(it can be changed to a defun to make this happen but the count-form would need to default to 1,000,000 and it would need to stay optional):

Re: would like to enter multiple arguments w/o progn to defm

Depends on how you want to specify the count-form in the multiple-argument version.

Re: would like to enter multiple arguments w/o progn to defm

Thank you very much for your reply:)...for my purposes I have to be able to run:

 ($ (function) (function))
to time multiple functions at 1000,000 iterations

I have to be able to run:

 ($ (function))
to time one function at 1000,000 iterations

I have to be able to run:
 ($ (function) 1000)
to time one function at 1000 iterations

and I have to be able to run:

 ($ (function) (function) 1000)
to time multiple functions at 1000 iterations

Re: would like to enter multiple arguments w/o progn to defm

If it was me then I wouldn't bother with tricky argument-list-parsing techniques, but in this case, what you want isn't complex to implement. The macro just needs to take a &rest parameter and to pluck off the last element if it's an integer (indicating the count-form). If I wanted the count-form to be evaluated, as opposed to a self-evaluating integer invariably, then things would get a bit hairier than the code below:
(defmacro $ (&rest arguments)
  (let ((last (last arguments))
        (count-form 1000000))
    (when (integerp (car last))
      (setq count-form (car last))
      ;; Exclude COUNT-FORM from the list.
      (setq arguments (ldiff arguments last)))
    `(time (dotimes (_ ,count-form) ,@arguments))))

Re: would like to enter multiple arguments w/o progn to defm

Thanks man, I really appreciate that, that will help my mind travel diiferent directions,now , knowing that:)

Take Care