Macros multiple return values
Posted: Sun Feb 08, 2015 6:16 pm
It would be nice if macros could have multiple return values.
Then one wouldn't have to write multiple macros to create special-functions, once for defun and once for lambda
Why is it possible with 0 return-values, and with 1 but not with other numbers ;(
Examples:
Are there already libs for this purpose?
Edit:
I know that in most cases I could return `(progn ,values...) by the macro, but this only seems suboptimal. For example, if i want to be able, to save all returnvalues as list i could do
Then one wouldn't have to write multiple macros to create special-functions, once for defun and once for lambda
Why is it possible with 0 return-values, and with 1 but not with other numbers ;(
Examples:
Code: Select all
(defmacro test1 (a b c) (values c b a))
(list (test1 1 2 3)) ; should be the same as: (list 3 2 1)
;;;for special functions i may have to write both macros:
(defmacro special-defun (name arglist &body body)
`(defun ,name ,arglist (do-something-special)... ,@body (do-rest)...)
(defmacro special-lambda (arglist &body body)
`(lambda ,arglist (do-something-special)... ,@body (do-rest)...)
;;maybe also a third macro, with progn, if this should also be executed normally
;;;instead i could write this:
(defmacro special-procedure (&body body)
(apply #'values '(do-something-special) (append body (list '(do-rest)...))))
;;;now I can use this special procedure for lambdas, founctions and in other places like this:
(defun fun (args...) (special-procedure (do-something args...)))
(lambda (args...) (special-procedure (do-something args...)))
;;without defining multiple macros
Edit:
I know that in most cases I could return `(progn ,values...) by the macro, but this only seems suboptimal. For example, if i want to be able, to save all returnvalues as list i could do
Code: Select all
(list (special-procedure))