anishtain4 Posted May 12, 2012 Posted May 12, 2012 What would you do if you want to make a function whose input arguments be like setq? I know optional arguments are not allowed in vlisp and I've considered the list input, I was wondering if there is any way to make a function just like setq? Quote
ketxu Posted May 12, 2012 Posted May 12, 2012 With only lisp i think No. Just write your lisp function in ARX, NET or sth Else ^^. And you can use list agr like (setqq (list var and value)) Quote
MSasu Posted May 12, 2012 Posted May 12, 2012 To mimic optional arguments to a function I think the best solution is to use a list of dotted pairs: (defun test( listOptVars ) (princ "\nVariable V1 = ")(princ (cdr (assoc "V1" listOptVars))) (princ "\nVariable V2 = ")(princ (cdr (assoc "V2" listOptVars))) (princ) ) Use it like: (test '(("V1" . 1) ("V2" . 2))) (test '(("V2" . 2))) Quote
MSasu Posted May 12, 2012 Posted May 12, 2012 Alternative approach: (defun test( listOptVars ) (foreach item listOptVars (set (read (car item)) (cdr item)) (princ (strcat "\nVariable " (car item) " = "))(princ (eval (read (car item)))) ) ;discard all variables - cannot be localized (foreach item listOptVars (set (read (car item)) nil) ) (princ) ) Quote
anishtain4 Posted May 12, 2012 Author Posted May 12, 2012 Thanks Ketxu, guess I have to come along with this, this does not worth learning arx thanks Msasu but as I said I've considered list input, it's not good in this case cause I have to make up the list from calling function, well I can simply call this function Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.