Jump to content

Recommended Posts

Posted

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?

Posted

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))

Posted

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)))

Posted

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)
)

Posted

Thanks Ketxu, guess I have to come along with this, this does not worth learning arx :D

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...