Page 1 of 1
would like to enter multiple arguments w/o progn to defmacro
Posted: Sun Jul 06, 2014 8:45 pm
by joeish80829
here is the macro, it is used to time 1 or more functions:
Code: Select all
(defmacro $ (form &optional (count-form 1000000)) `(time (dotimes (_ ,count-form) ((lambda () ,form)))))
for 1 function I run like this:
for multiple functions I run like this:
how can I make it so I can run multiple functions like this:
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
Posted: Sat Jul 12, 2014 10:57 am
by logxor
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
Posted: Wed Jul 16, 2014 9:11 pm
by joeish80829
Thank you very much for your reply:)...for my purposes I have to be able to run:
to time multiple functions at 1000,000 iterations
I have to be able to run:
to time one function at 1000,000 iterations
I have to be able to run:
to time one function at 1000 iterations
and I have to be able to run:
to time multiple functions at 1000 iterations
Re: would like to enter multiple arguments w/o progn to defm
Posted: Fri Jul 18, 2014 10:41 am
by logxor
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:
Code: Select all
(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
Posted: Fri Jul 18, 2014 4:45 pm
by joeish80829
Thanks man, I really appreciate that, that will help my mind travel diiferent directions,now , knowing that:)
Take Care